Annotation of loncom/interface/londocs.pm, revision 1.715
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.715 ! raeburn 4: # $Id: londocs.pm,v 1.714 2024/12/27 02:32:55 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.651 raeburn 48: use Apache::loncourserespicker();
1.329 droeschl 49: use HTML::Entities;
1.488 raeburn 50: use HTML::TokeParser;
1.713 raeburn 51: use HTML::LCParser;
1.329 droeschl 52: use GDBM_File;
1.578 raeburn 53: use File::MMagic;
1.606 raeburn 54: use File::Copy;
1.329 droeschl 55: use Apache::lonlocal;
56: use Cwd;
1.643 raeburn 57: use UUID::Tiny ':std';
1.329 droeschl 58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
1.557 raeburn 68: my $suppchanges;
1.329 droeschl 69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
1.492 raeburn 82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
1.329 droeschl 87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 89: $map,1,$report);
1.329 droeschl 90: if ($errtext) { return ($errtext,2); }
1.364 bisitz 91:
1.557 raeburn 92: if ($map =~ /^default/) {
93: $hadchanges=1;
1.682 raeburn 94: } elsif ($contentchg) {
1.557 raeburn 95: $suppchanges=1;
96: }
1.329 droeschl 97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
1.709 raeburn 106: my @ids=&Apache::lonnet::current_machine_ids();
1.329 droeschl 107: foreach my $key (keys(%env)) {
108: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
109: my $role=$1;
110: my $realm=$2;
111: my ($start,$end)=split(/\./,$env{$key});
112: if (($start) && ($start>time)) { next; }
113: if (($end) && (time>$end)) { next; }
114: my ($ca,$cd);
115: if ($1 eq 'au') {
116: $ca=$env{'user.name'};
117: $cd=$env{'user.domain'};
118: } else {
119: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
120: }
121: my $allowed=0;
122: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
1.484 raeburn 123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
1.329 droeschl 129: if ($allowed) {
130: $home++;
1.484 raeburn 131: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 132: } else {
1.484 raeburn 133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 145: return $title;
1.329 droeschl 146: }
147:
1.617 raeburn 148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
1.329 droeschl 185:
1.685 raeburn 186: sub validate_supppath {
187: my ($coursenum,$coursedom) = @_;
188: my $backto;
1.677 raeburn 189: if ($env{'form.supppath'} ne '') {
190: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 191: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 192: for (my $i=0; $i<@items; $i++) {
193: my $odd = $i%2;
194: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
195: $badpath = 1;
1.685 raeburn 196: last;
197: } elsif ($odd) {
198: my $suffix;
199: my $idx = $i-1;
200: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
201: $backto .= '&'.$1;
202: } elsif ($items[$idx] eq 'supplemental') {
203: $backto .= '&'.$items[$i];
204: } else {
205: $backto .= '&'.$items[$i];
206: my $is_hidden;
207: unless ($got_supp) {
1.688 raeburn 208: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 209: if (ref($supplemental) eq 'HASH') {
210: if (ref($supplemental->{'hidden'}) eq 'HASH') {
211: %supphidden = %{$supplemental->{'hidden'}};
212: }
213: if (ref($supplemental->{'ids'}) eq 'HASH') {
214: %suppids = %{$supplemental->{'ids'}};
215: }
216: }
217: $got_supp = 1;
218: }
219: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
220: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
221: if ($supphidden{$mapid}) {
222: $is_hidden = 1;
223: }
224: }
225: $suffix = '::'.$is_hidden.':::';
226: }
227: $supppath .= '&'.$items[$i].$suffix;
228: } else {
229: $supppath .= '&'.$items[$i];
230: $backto .= '&'.$items[$i];
1.677 raeburn 231: }
232: }
233: if ($badpath) {
234: delete($env{'form.supppath'});
1.685 raeburn 235: } else {
236: $supppath =~ s/^\&//;
237: $backto =~ s/^\&//;
238: $env{'form.supppath'} = $supppath;
1.677 raeburn 239: }
240: }
1.685 raeburn 241: return $backto;
1.677 raeburn 242: }
243:
1.329 droeschl 244: sub dumpcourse {
245: my ($r) = @_;
1.408 raeburn 246: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 247: my ($starthash,$js);
248: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
249: $js = <<"ENDJS";
250: <script type="text/javascript">
251: // <![CDATA[
252:
253: function hide_searching() {
254: if (document.getElementById('searching')) {
255: document.getElementById('searching').style.display = 'none';
256: }
257: return;
258: }
259:
260: // ]]>
261: </script>
262: ENDJS
263: $starthash = {
264: add_entries => {'onload' => "hide_searching();"},
265: };
266: }
1.709 raeburn 267: $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
268: &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n");
1.484 raeburn 269: $r->print(&startContentScreen('tools'));
1.329 droeschl 270: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 271: unless ($home) {
1.712 raeburn 272: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
1.484 raeburn 273: $r->print(&endContentScreen());
274: return '';
275: }
1.329 droeschl 276: my $origcrsid=$env{'request.course.id'};
277: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
278: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
279: # Do the dumping
1.484 raeburn 280: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
1.712 raeburn 281: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
282: &endContentScreen());
1.484 raeburn 283: return '';
284: }
1.531 raeburn 285: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 286: $r->print('<h3>'.&mt('Copying Files').'</h3>');
287: my $title=$env{'form.authorfolder'};
288: $title=&clean($title);
1.567 raeburn 289: my ($navmap,$errormsg) =
290: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
291: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
292: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
293: my (%maps,%resources,%titles);
294: if (!ref($navmap)) {
295: $r->print($errormsg.
296: &endContentScreen());
297: return '';
298: } else {
299: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
300: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 301: }
1.567 raeburn 302: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
303: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
304: %newcontent,%has_simpleprobs);
305: foreach my $item (sort {$a <=> $b} (@todump)) {
306: my $name = $env{'form.namefor_'.$item};
307: if ($resources{$item}) {
308: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
309: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
310: $tocopy{$1} = $name;
311: $display{$item} = $1;
312: $lookup{$1} = $item;
313: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
314: $simpleproblems{$item} = {
315: symb => $resources{$item},
316: name => $name,
317: };
318: $display{$item} = 'simpleproblem_'.$name;
319: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
320: $has_simpleprobs{$1}{$id} = $item;
321: }
322: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
323: my $marker = $1;
324: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
325: $simplepages{$item} = {
326: res => $res,
327: title => $titles{$item},
328: db => $db_name,
329: marker => $marker,
330: symb => $resources{$item},
331: name => $name,
332: };
333: $display{$item} = '/'.$res;
334: }
335: } elsif ($maps{$item}) {
336: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
337: $tocopy{$1} = $name;
338: $display{$item} = $1;
339: $lookup{$1} = $item;
340: }
341: } else {
342: next;
343: }
344: }
1.329 droeschl 345: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
346: $crs=~s/\_/\//g;
1.567 raeburn 347: my $mm = new File::MMagic;
348: my $prefix = "/uploaded/$cdom/$cnum/";
349: %replacehash = %tocopy;
350: foreach my $item (sort(keys(%simpleproblems))) {
351: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
352: $newcontent{$display{$item}} = $content;
353: }
354: my $gateway = Apache::lonhtmlgateway->new('web');
355: foreach my $item (sort(keys(%simplepages))) {
356: if (ref($simplepages{$item}) eq 'HASH') {
357: my $pagetitle = $simplepages{$item}{'title'};
358: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
359: my %contents;
360: foreach my $field (keys(%fields)) {
361: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
362: my $name = $1;
363: my $msg = $fields{$field};
364: if ($name eq 'webreferences') {
365: if ($msg =~ m{^https?://}) {
366: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
367: }
368: } else {
369: $msg = &Encode::decode('utf8',$msg);
370: $msg = $gateway->process_outgoing_html($msg,1);
371: $contents{$name} = $msg;
372: }
373: } elsif ($field eq 'uploaded.photourl') {
374: my $marker = $simplepages{$item}{marker};
375: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
376: my $filepath = $1;
377: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
378: if ($fname ne '') {
379: $fname=~s/\.(\w+)$//;
380: my $ext=$1;
381: $fname = &clean($fname);
382: $fname.='.'.$ext;
383: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
384: $replacehash{$filepath} = $relpath.$fname;
385: $deps{$item}{$filepath} = 1;
386: }
387: }
388: }
389: }
390: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
391: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
392: my $content = '
393: <html>
394: <head>
395: <title>'.$pagetitle.'</title>
396: </head>
397: <body bgcolor="#ffffff">';
398: if ($contents{title}) {
399: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
400: }
401: if ($contents{image}) {
402: $content .= "\n".$contents{image};
403: }
404: if ($contents{content}) {
405: $content .= '
406: <div class="LC_Box">
1.577 bisitz 407: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 408: $contents{content}.'
409: </div>';
410: }
411: if ($contents{webreferences}) {
412: $content .= '
413: <div class="LC_Box">
1.577 bisitz 414: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 415: $contents{webreferences}.'
416: </div>';
417: }
418: $content .= '
419: </body>
420: </html>
421: ';
422: $newcontent{'/'.$simplepages{$item}{res}} = $content;
423: }
424: }
425: foreach my $item (keys(%tocopy)) {
426: unless ($item=~/\.(sequence|page)$/) {
427: my $currurlpath = $prefix.$item;
428: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
429: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
430: }
431: }
432: foreach my $num (sort {$a <=> $b} (@todump)) {
433: my $src = $display{$num};
434: next if ($src eq '');
435: my @needcopy = ();
436: if ($replacehash{$src}) {
437: push(@needcopy,$src);
438: if (ref($deps{$num}) eq 'HASH') {
439: foreach my $dep (sort(keys(%{$deps{$num}}))) {
440: if ($replacehash{$dep}) {
441: push(@needcopy,$dep);
442: }
443: }
444: }
445: } elsif ($src =~ /^simpleproblem_/) {
446: push(@needcopy,$src);
447: }
448: next if (@needcopy == 0);
449: my ($result,$depresult);
450: for (my $i=0; $i<@needcopy; $i++) {
451: my $item = $needcopy[$i];
452: my $newfilename;
453: if ($simpleproblems{$num}) {
454: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
455: } else {
456: $newfilename=$title.'/'.$replacehash{$item};
457: }
458: $newfilename=~s/\.(\w+)$//;
459: my $ext=$1;
460: $newfilename=&clean($newfilename);
461: $newfilename.='.'.$ext;
462: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
463: if ($newrelpath ne $replacehash{$item}) {
464: $replacehash{$item} = $newrelpath;
465: }
466: my @dirs=split(/\//,$newfilename);
467: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
468: my $makepath=$path;
469: my $fail;
470: my $origin;
471: for (my $i=0;$i<$#dirs;$i++) {
472: $makepath.='/'.$dirs[$i];
473: unless (-e $makepath) {
474: unless(mkdir($makepath,0755)) {
475: $fail = &mt('Directory creation failed.');
476: }
477: }
478: }
479: if ($i == 0) {
480: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
481: } else {
482: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
483: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
484: &mt('(dependency)').'</span>: ';
485: }
486: if (-e $path.'/'.$newfilename) {
487: $fail = &mt('Destination already exists -- not overwriting.');
488: } else {
489: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
490: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
491: ($item =~ /^simpleproblem_/)) {
492: print $fh $newcontent{$item};
493: } else {
494: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
495: if (-e $fileloc) {
496: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
497: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
498: (ref($has_simpleprobs{$item}) eq 'HASH')) {
499: my %changes = %{$has_simpleprobs{$item}};
500: my $content = &Apache::lonclonecourse::rewritefile(
501: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
502: (%replacehash,$crs => '')
503: );
504: my $updatedcontent = '';
505: my $parser = HTML::TokeParser->new(\$content);
506: $parser->attr_encoded(1);
507: while (my $token = $parser->get_token) {
508: if ($token->[0] eq 'S') {
509: if (($token->[1] eq 'resource') &&
510: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
511: ($changes{$token->[2]->{'id'}})) {
512: my $id = $token->[2]->{'id'};
513: $updatedcontent .= '<'.$token->[1];
514: foreach my $attrib (@{$token->[3]}) {
515: next unless ($attrib =~ /^(src|type|title|id)$/);
516: if ($attrib eq 'src') {
517: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
518: if ($file) {
519: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
520: } else {
521: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
522: }
523: } else {
524: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
525: }
526: }
527: $updatedcontent .= ' />'."\n";
528: } else {
529: $updatedcontent .= $token->[4]."\n";
530: }
531: } else {
532: $updatedcontent .= $token->[2];
533: }
534: }
535: print $fh $updatedcontent;
536: } else {
537: print $fh &Apache::lonclonecourse::rewritefile(
538: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
539: (%replacehash,$crs => '')
540: );
541: }
542: } else {
543: print $fh
544: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
545: }
546: } else {
547: $fail = &mt('Source does not exist.');
548: }
549: }
550: $fh->close();
551: } else {
552: $fail = &mt('Could not write to destination.');
553: }
554: }
555: my $text;
556: if ($fail) {
557: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
558: } else {
559: $text = '<span class="LC_success">'.&mt('ok').'</span>';
560: }
561: if ($i == 0) {
562: $result .= $text;
563: } else {
564: $depresult .= $text.'</li>';
565: }
566: }
567: $r->print($result);
568: if ($depresult) {
569: $r->print('<ul>'.$depresult.'</ul>');
570: }
571: }
572: } else {
573: my ($navmap,$errormsg) =
574: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
575: if (!ref($navmap)) {
576: $r->print($errormsg);
577: } else {
578: my $title=$origcrsdata{'description'};
579: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 580: $title=&clean($title);
1.712 raeburn 581: my $formname = 'dumpdoc';
1.715 ! raeburn 582: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
! 583: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1.712 raeburn 584: my %uploadedfiles;
1.567 raeburn 585: &tiehash();
586: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
587: my ($ext)=($file=~/\.(\w+)$/);
588: # FIXME Check supplemental here
589: my $title=$hash{'title_'.$hash{
590: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
591: if (!$title) {
592: $title=$file;
593: } else {
594: $title=~s|/|_|g;
595: }
596: $title=~s/\.(\w+)$//;
597: $title=&clean($title);
598: $title.='.'.$ext;
599: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
600: $uploadedfiles{$file} = $title;
601: }
602: &untiehash();
603: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
604: undef,undef,$preamble,$home,\%uploadedfiles));
605: }
1.329 droeschl 606: }
1.484 raeburn 607: $r->print(&endContentScreen());
1.329 droeschl 608: }
609:
1.712 raeburn 610: sub authorspace_selector {
611: my ($r,$formname,$home,$title,%outhash) = @_;
612: $r->print('<div id="searching">'.&mt('Searching ...').'</div>'."\n");
613: $r->rflush();
614: my $preamble;
615: unless ($home==1) {
616: $preamble = '<div class="LC_left_float">'.
617: '<fieldset><legend>'.
618: &mt('Select the Authoring Space').
619: '</legend><select name="authorspace">';
620: }
621: my @orderspaces = ();
622: foreach my $key (sort(keys(%outhash))) {
623: if ($key=~/^home_(.+)$/) {
624: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
625: unshift(@orderspaces,$1);
626: } else {
627: push(@orderspaces,$1);
628: }
629: }
630: }
631: if ($home>1) {
632: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
633: }
634: foreach my $user (@orderspaces) {
635: if ($home==1) {
636: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
637: } else {
638: $preamble .= '<option value="'.$user.'">'.$user.' - '.
639: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
640: }
641: }
642: unless ($home==1) {
643: $preamble .= '</select></fieldset></div>'."\n";
644: }
645: $preamble .= '<div class="LC_left_float">'.
646: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
1.715 ! raeburn 647: '<input type="text" size="30" name="authorfolder" value="'.$title.'" />'."\n".
! 648: '</fieldset></div>'."\n";
1.712 raeburn 649: return $preamble;
650: }
651:
1.567 raeburn 652: sub recurse_html {
653: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
654: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
655: my (%allfiles,%codebase);
656: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
657: if (keys(%allfiles)) {
658: foreach my $dependency (keys(%allfiles)) {
659: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
660: my ($depurl,$relfile,$newcontainer);
661: if ($dependency =~ m{^/}) {
662: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
663: $relfile = $1;
664: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
665: $newcontainer = $1;
666: next if ($replacehash->{$newcontainer});
667: }
668: $depurl = $dependency;
669: } else {
670: next;
671: }
672: } else {
673: $relfile = $dependency;
674: $depurl = $currurlpath;
1.630 raeburn 675: $depurl =~ s{[^/]+$}{};
1.567 raeburn 676: $depurl .= $dependency;
1.630 raeburn 677: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 678: }
679: next if ($relfile eq '');
680: my $newname = $replacehash->{$container};
681: $newname =~ s{[^/]+$}{};
682: $replacehash->{$newcontainer} = $newname.$relfile;
683: $deps->{$item}{$newcontainer} = 1;
684: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
685: my $depfile = &Apache::lonnet::filelocation('',$depurl);
686: my $type = $mm->checktype_filename($depfile);
687: if ($type eq 'text/html') {
688: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
689: }
690: }
691: }
692: }
693: return;
694: }
695:
1.712 raeburn 696: sub copycrsauthored {
697: my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_;
1.715 ! raeburn 698: my ($starthash,$js,$title,$formname);
! 699: my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
! 700: $title=$origcrsdata{'description'};
! 701: $title=~s/[\/\s]+/\_/gs;
! 702: $title=&clean($title);
! 703: my ($home,$other,%outhash)=&authorhosts();
1.712 raeburn 704: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.715 ! raeburn 705: my %js_lt;
! 706: $formname = 'copycrsauthored';
! 707: if ($home) {
! 708: %js_lt =
! 709: &Apache::lonlocal::texthash(
! 710: yomu => 'You must select an Authoring Space',
! 711: whco => 'When Copyright set to "custom", URL of a published rights file is needed.',
! 712: );
! 713: &js_escape(\%js_lt);
! 714: }
! 715: if ($home > 1) {
! 716: $js = <<"ENDJS";
! 717: <script type="text/javascript">
! 718: // <![CDATA[
! 719:
! 720: function validCrsCopy() {
! 721: var dest = document.$formname.authorspace.options[document.$formname.authorspace.selectedIndex].value;
! 722: if (dest == '') {
! 723: alert("$js_lt{'yomu'}");
! 724: return false;
! 725: }
! 726: var dist = document.$formname.copyright.options[document.$formname.copyright.selectedIndex].value;
! 727: if (dist == 'custom') {
! 728: if (document.$formname.customrights.value == '') {
! 729: alert("$js_lt{'whco'}");
! 730: return false;
! 731: }
! 732: }
! 733: return true;
! 734: }
! 735:
! 736: function init_copycrs_form() {
! 737: document.$formname.authorspace.selectedIndex = "0";
! 738: document.$formname.authorfolder.value = '$title';
! 739: document.$formname.copyright.selectedIndex = "0";
! 740: }
! 741:
! 742: // ]]>
! 743: </script>
! 744:
! 745: ENDJS
! 746: } elsif ($home) {
! 747: $js = <<"ENDJS";
! 748: <script type="text/javascript">
! 749: // <![CDATA[
! 750:
! 751: function init_copycrs_form() {
! 752: document.$formname.authorfolder.value = '$title';
! 753: document.$formname.copyright.selectedIndex = "0";
! 754: }
! 755:
! 756: // ]]>
! 757: </script>
! 758:
! 759: ENDJS
! 760: }
! 761: $js .= <<"ENDJS";
1.712 raeburn 762: <script type="text/javascript">
763: // <![CDATA[
764:
765: function hide_searching() {
766: if (document.getElementById('searching')) {
767: document.getElementById('searching').style.display = 'none';
768: }
769: return;
770: }
771:
1.715 ! raeburn 772: function showHideCustom(caller,divid) {
! 773: if (document.getElementById(divid)) {
! 774: if (caller.options[caller.selectedIndex].value == 'custom') {
! 775: document.getElementById(divid).style.display="inline-block";
! 776: } else {
! 777: document.getElementById(divid).style.display="none";
! 778: }
! 779: }
! 780: return;
! 781: }
! 782:
1.712 raeburn 783: // ]]>
784: </script>
785: ENDJS
1.715 ! raeburn 786:
! 787: $js .= "\n".&Apache::lonhtmlcommon::scripttag(&Apache::loncommon::browser_and_searcher_javascript())."\n";
1.712 raeburn 788: $starthash = {
1.715 ! raeburn 789: add_entries => {'onload' => "hide_searching(); init_copycrs_form();"},
1.712 raeburn 790: };
791: }
792: $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
793: &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
794: $r->print(&startContentScreen('tools'));
795: unless ($home) {
796: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
797: $r->print(&endContentScreen());
798: return '';
799: }
1.715 ! raeburn 800: my $docroot = $r->dir_config('lonDocRoot');
1.714 raeburn 801: my $is_course_home;
802: my @ids=&Apache::lonnet::current_machine_ids();
803: if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
804: $is_course_home = 1;
805: }
1.712 raeburn 806: my $exclude = &Apache::lonnet::priv_exclude();
807: my $srcurl = "/priv/$coursedom/$coursenum";
1.715 ! raeburn 808: my $srctop = $docroot.$srcurl;
! 809: my $resurl = "/res/$coursedom/$coursenum";
! 810: my $res_exclude = &Apache::lonnet::res_exclude();
1.712 raeburn 811: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
812: $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
813: if ($readonly) {
814: $r->print('<p class="LC_info">'.
815: &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
816: '</p>'.
817: &endContentScreen());
818: return '';
819: }
820: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
821: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
822: &endContentScreen());
823: return '';
824: }
825: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
826: my $desturl = "/priv/$cd/$ca";
1.715 ! raeburn 827: my $destresurl = "/res/$cd/$ca";
! 828: my $desttop = $docroot.$desturl;
1.712 raeburn 829: my $subdir = &clean($env{'form.authorfolder'});
830: $subdir = &cleandir($subdir);
831: if ($subdir eq '') {
832: $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
833: &endContentScreen());
834: return '';
835: } elsif ($subdir =~/^_+$/) {
836: $r->print('<p class="LC_info">'.&mt('After replacement of non-alphanumeric characters with _ in target sub-directory name, nothing but underscores was left.').'</p>'.
837: &endContentScreen());
838: return '';
839: }
840: my (%tocopy,%dirs_to_make,%files_to_copy);
841: map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
842: if (keys(%tocopy)) {
843: my (%subdirs,%files);
1.714 raeburn 844: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1.712 raeburn 845: foreach my $possible (sort(keys(%tocopy))) {
846: if ($possible =~ m{/$}) {
847: my $possdir = $possible;
848: $possdir =~ s{^/+|/+$}{}g;
849: if (exists($subdirs{$possdir})) {
850: $dirs_to_make{$possdir} = 1;
851: } else {
852: delete($tocopy{$possible});
853: }
854: } else {
855: my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
856: my $found = 0;
857: if ($path eq '/') {
858: if (ref($files{$path}) eq 'HASH') {
859: if (exists($files{$path}{$fname})) {
860: $found = 1;
861: $files_to_copy{$fname} = 1;
862: }
863: }
864: } else {
865: $path =~ s{^/+|/+$}{}g;
866: if (ref($files{$path}) eq 'HASH') {
867: if (exists($files{$path}{$fname})) {
868: $dirs_to_make{$path} = 1;
869: $files_to_copy{"$path/$fname"} = 1;
870: $found = 1;
871: }
872: }
873: }
874: unless ($found) {
875: delete($tocopy{$possible});
876: }
877: }
878: }
879: } else {
880: $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
881: $r->print(&endContentScreen());
882: return '';
883: }
884: if (keys(%tocopy)) {
1.714 raeburn 885: my (%resdirs,%resfiles);
886: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.713 raeburn 887: my ($notopdir,%newdir,%newfile,%checkdeps);
1.712 raeburn 888: $r->print('<p>'.&mt('Copy to: [_1]',
889: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
890: '</p>'."\n");
891: if (keys(%dirs_to_make)) {
1.714 raeburn 892: unless (-e $desttop.'/'.$subdir) {
893: mkdir($desttop.'/'.$subdir,0755);
894: }
895: if (-e $desttop.'/'.$subdir) {
896: foreach my $dir (sort(keys(%dirs_to_make))) {
897: my @dirs=split(/\//,$dir);
898: my $path="$desttop/$subdir";
899: my $makepath=$path;
900: my $fail;
901: for (my $i=0;$i<@dirs;$i++) {
902: $makepath.='/'.$dirs[$i];
903: unless (-e $makepath) {
904: unless (mkdir($makepath,0755)) {
905: $fail = 1;
906: last;
907: }
908: if (($i == scalar(@dirs)-1) && (!$fail)) {
909: $newdir{$dir} = 1;
1.712 raeburn 910: }
911: }
912: }
1.714 raeburn 913: if ($fail) {
914: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
915: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
916: '</p>'."\n");
917: }
1.712 raeburn 918: }
1.714 raeburn 919: } else {
920: $notopdir = 1;
1.712 raeburn 921: }
922: }
923: if (keys(%files_to_copy)) {
1.714 raeburn 924: unless (-e $desttop.'/'.$subdir) {
925: mkdir($desttop.'/'.$subdir,0755);
926: }
927: if (-e $desttop.'/'.$subdir) {
928: my $num = 0;
1.715 ! raeburn 929: my ($copyright,$customdistfile);
! 930: if ($env{'form.copyright'} eq 'default' || $env{'form.copyright'} eq 'domain' || $env{'form.copyright'} eq 'public') {
! 931: $copyright = $env{'form.copyright'};
! 932: } elsif ($env{'form.copyright'} eq 'custom') {
! 933: if ($env{'form.customrights'} =~ m{^/res/$match_domain/$match_username/.+\.rights$}) {
! 934: my ($rightsdom,$rightsuname) = ($1,$2);
! 935: my $rightshome = &Apache::lonnet::homeserver($rightsdom,$rightsuname);
! 936: if (($rightshome eq 'no_host') || ($rightshome eq '')) {
! 937: $copyright = 'default';
! 938: } elsif (grep(/^\Q$rightshome\E$/,@ids)) {
! 939: if (-e $docroot.$env{'form.customrights'}) {
! 940: $copyright = 'custom';
! 941: $customdistfile = $env{'form.customrights'};
! 942: } else {
! 943: $copyright = 'default';
! 944: }
! 945: } else {
! 946: my $rightsfile = &Apache::lonnet::filelocation('',$env{'form.customrights'});
! 947: unless (&Apache::lonnet::getfile($rightsfile) eq '-1') {
! 948: $customdistfile = $env{'form.customrights'};
! 949: }
! 950: }
! 951: }
! 952: }
! 953: my $sourceavail;
! 954: if ($env{'form.sourceavail'} =~ /^(open|closed)$/) {
! 955: $sourceavail = $env{'form.sourceavail'};
! 956: }
! 957: my $respublish;
! 958: if ($env{'form.respublish'}) {
! 959: $respublish = 1;
! 960: }
! 961: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
1.714 raeburn 962: foreach my $file (keys(%files_to_copy)) {
963: my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
964: if ($file =~ m{/}) {
965: ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
966: if (-d "$desttop/$subdir/$path") {
967: if (-e "$desttop/$subdir/$path/$fname") {
968: $dup = 1;
1.712 raeburn 969: } else {
1.714 raeburn 970: $src = "$srctop/$path/$fname";
971: $dest = "$desttop/$subdir/$path/$fname";
1.712 raeburn 972: }
1.714 raeburn 973: } elsif (-f "$desttop/$subdir/$path") {
974: $dir_is_file = 1;
1.712 raeburn 975: } else {
1.714 raeburn 976: $fail = 1;
977: }
978: } elsif (-e "$desttop/$subdir/$file") {
979: $dup = 1;
980: } else {
981: $src = "$srctop/$file";
982: $dest = "$desttop/$subdir/$file";
983: $fname = $file;
984: }
985: if ($fail) {
986: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
987: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
988: '</p>'."\n");
989: } elsif ($dup) {
990: $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
991: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
992: '</p>'."\n");
993: } elsif ($dir_is_file) {
994: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
995: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
996: '</p>'."\n");
997: } elsif (($src ne '') && ($dest ne '')) {
998: if ($is_course_home) {
1.712 raeburn 999: if (&File::Copy::copy($src,$dest)) {
1000: $newfile{$file} = 1;
1.714 raeburn 1001: }
1002: } else {
1003: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
1004: $newfile{$file} = 1;
1005: }
1006: }
1007: if ($newfile{$file}) {
1008: my $gotmeta;
1009: if ($is_course_home) {
1.712 raeburn 1010: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
1011: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
1.714 raeburn 1012: $gotmeta = 1;
1013: }
1014: }
1015: } else {
1016: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
1017: $gotmeta = 1;
1018: }
1019: }
1020: if ($gotmeta) {
1021: if (open(my $fh,'<',$dest.'.meta')) {
1.715 ! raeburn 1022: my ($output,$now,setsourceavail);
1.714 raeburn 1023: $now = time;
1.715 ! raeburn 1024: if (($file =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($file =~ /$LONCAPA::assess_re/)) {
! 1025: $setsourceavail = 1;
! 1026: }
1.714 raeburn 1027: while (my $line=<$fh>) {
1028: chomp($line);
1029: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
1030: $output .= "<authorspace>$ca:$cd</authorspace>\n";
1031: } elsif ($line eq '<copyright>custom</copyright>') {
1.715 ! raeburn 1032: $output .= "<copyright>$copyright</copyright>\n";
1.714 raeburn 1033: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
1034: $output .= "<creationdate>$now</creationdate>\n";
1035: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
1.715 ! raeburn 1036: $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
! 1037: } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
! 1038: if ($setsourceavail) {
! 1039: $output .= "<sourceavail>$sourceavail</sourceavail>\n";
! 1040: }
1.714 raeburn 1041: } elsif ($line eq "<domain>$coursedom</domain>") {
1042: $output .= "<domain>$cd</domain>\n";
1043: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
1044: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
1045: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
1046: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
1047: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
1048: $output .= "<owner>$ca:$cd</owner>\n";
1049: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
1050: my @deps = split(/\s*,\s*/,$1);
1051: my @newdeps;
1052: my $changed = 0;
1053: foreach my $dep (@deps) {
1054: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
1055: my $rest = $1;
1056: push(@newdeps,"/res/$cd/$ca/$rest");
1057: $checkdeps{$rest} = 1;
1058: $changed ++;
1.713 raeburn 1059: } else {
1.714 raeburn 1060: push(@newdeps,$dep);
1.713 raeburn 1061: }
1062: }
1.714 raeburn 1063: if ($changed) {
1064: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
1.713 raeburn 1065: }
1.714 raeburn 1066: } else {
1067: $output .= "$line\n";
1.713 raeburn 1068: }
1.712 raeburn 1069: }
1.714 raeburn 1070: close($fh);
1071: if (open(my $fh,'>',$dest.'.meta')) {
1072: print $fh $output;
1073: close($fh);
1074: }
1.712 raeburn 1075: }
1.714 raeburn 1076: }
1077: my ($ext) = ($file =~ /\.(\w+)$/);
1078: my $embstyle=&Apache::loncommon::fileembstyle($ext);
1079: if ($embstyle eq 'ssi') {
1080: my $outstring='';
1081: my $changes = 0;
1082: my @parser;
1083: $parser[0]=HTML::LCParser->new($dest);
1084: $parser[-1]->xml_mode(1);
1085: my $token;
1086: while (@parser) {
1087: while ($token=$parser[-1]->get_token) {
1088: if ($token->[0] eq 'S') {
1089: my $tag=$token->[1];
1090: my $lctag=lc($tag);
1091: my %parms=%{$token->[2]};
1092: foreach my $type ('src','href','background','bgimg') {
1093: foreach my $key (keys(%parms)) {
1094: if ($key =~ /^$type$/i) {
1095: next if (($lctag eq 'img') && ($type eq 'src') &&
1096: ($parms{$key} =~ m{^data\:image/gif;base64,}));
1097: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1098: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1099: $changes ++;
1.713 raeburn 1100: }
1101: }
1102: }
1.714 raeburn 1103: }
1104: # probably a <randomlabel> image type <label>
1105: # or a <image> tag inside <imageresponse> or <drawimage>
1106: if (($lctag eq 'label' && defined($parms{'description'}))
1107: || ($lctag eq 'image') || ($lctag eq 'import')) {
1108: my $next_token=$parser[-1]->get_token();
1109: if ($next_token->[0] eq 'T') {
1110: $next_token->[1] =~ s/[\n\r\f]+//g;
1111: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1112: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1113: $changes ++;
1114: }
1115: }
1116: $parser[-1]->unget_token($next_token);
1117: }
1118: if ($lctag eq 'applet') {
1119: my $havecodebase=0;
1120: foreach my $key (keys(%parms)) {
1121: if (lc($key) eq 'codebase') {
1122: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1123: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1.713 raeburn 1124: $changes ++;
1125: }
1.714 raeburn 1126: $havecodebase = 1;
1.713 raeburn 1127: }
1128: }
1.714 raeburn 1129: unless ($havecodebase) {
1.713 raeburn 1130: foreach my $key (keys(%parms)) {
1.714 raeburn 1131: if ($key =~ /(archive|code|object)/i) {
1.713 raeburn 1132: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1.714 raeburn 1133: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
1.713 raeburn 1134: $changes ++;
1135: }
1136: }
1137: }
1138: }
1.714 raeburn 1139: }
1140: my $newparmstring='';
1141: my $endtag='';
1142: foreach my $parkey (keys(%parms)) {
1143: if ($parkey eq '/') {
1144: $endtag=' /';
1145: } else {
1146: my $quote=($parms{$parkey}=~/\"/?"'":'"');
1147: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
1.713 raeburn 1148: }
1.714 raeburn 1149: }
1150: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
1151: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1152: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
1153: $lctag eq 'tex') {
1154: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1155: } elsif ($lctag eq 'script') {
1156: if ($parms{'type'} eq 'loncapa/perl') {
1.713 raeburn 1157: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1.714 raeburn 1158: } else {
1159: my $needsupdate;
1160: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1161: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
1162: my $src = $2;
1163: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1164: $needsupdate = 1;
1.713 raeburn 1165: }
1.714 raeburn 1166: }
1167: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
1168: my $scriptslist = $2;
1169: my $needsupdate = 1;
1170: my @srcs = split(/\s*,\s*/,$scriptslist);
1171: foreach my $src (@srcs) {
1172: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
1173: my $quote = $1;
1174: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
1175: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1176: $needsupdate = 1;
1.713 raeburn 1177: }
1178: }
1179: }
1.714 raeburn 1180: }
1181: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
1182: my $src = $2;
1183: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1184: $needsupdate = 1;
1.713 raeburn 1185: }
1186: }
1.714 raeburn 1187: if ($needsupdate) {
1188: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
1189: $changes ++;
1190: }
1191: $outstring .= $script;
1.713 raeburn 1192: }
1.714 raeburn 1193: }
1194: } elsif ($token->[0] eq 'E') {
1195: if ($token->[2]) {
1196: unless ($token->[1] eq 'allow') {
1197: $outstring.='</'.$token->[1].'>';
1.713 raeburn 1198: }
1199: }
1.714 raeburn 1200: } else {
1201: $outstring.=$token->[1];
1.713 raeburn 1202: }
1203: }
1.714 raeburn 1204: pop(@parser);
1205: }
1206: if ($changes) {
1207: if (open(my $fh,'>',$dest)) {
1208: print $fh $outstring;
1209: close($fh);
1.713 raeburn 1210: }
1.712 raeburn 1211: }
1212: }
1.715 ! raeburn 1213: if ($respublish) {
! 1214: my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
! 1215: if ($path eq '') {
! 1216: if ((ref($resfiles{'/'}) eq 'HASH') &&
! 1217: (exists($resfiles{'/'}{$fname}))) {
! 1218: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
! 1219: }
! 1220: } elsif ((ref($resfiles{$path}) eq 'HASH') &&
! 1221: (exists($resfiles{$path}{$fname}))) {
! 1222: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
! 1223: }
! 1224: }
1.712 raeburn 1225: }
1226: }
1227: }
1.714 raeburn 1228: } else {
1229: $notopdir = 1;
1.712 raeburn 1230: }
1231: }
1232: if ($notopdir) {
1233: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
1234: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
1235: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1236: '</span></p>'."\n");
1237: }
1238: if (keys(%newdir)) {
1239: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1240: '</p>'."\n".
1241: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
1242: }
1243: if (keys(%newfile)) {
1244: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1245: '</p>'."\n".
1246: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1247: }
1.713 raeburn 1248: if (keys(%checkdeps)) {
1249: my %missingdep;
1250: foreach my $depfile (sort(keys(%checkdeps))) {
1251: unless (-e "$desttop/$depfile") {
1252: $missingdep{$depfile} = 1;
1253: }
1254: }
1255: if (keys(%missingdep)) {
1256: $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
1257: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1258: '</p>'."\n".
1259: '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
1260: }
1261: }
1.712 raeburn 1262: } else {
1263: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
1264: $r->print(&endContentScreen());
1265: return '';
1266: }
1267: } else {
1268: my $chkname = 'copytouser';
1269: my $context = 'crsauthored';
1270: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714 raeburn 1271: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712 raeburn 1272: foreach my $key (keys(%subdirs)) {
1273: next if (($key eq '/') || ($key eq ''));
1274: my @items = split(/\//,$key);
1275: my $dir = pop(@items);
1276: my $depth = scalar(@items);
1277: my $path;
1278: if (!$depth) {
1279: $path = '/';
1280: } else {
1281: $path = join('/',@items);
1282: }
1283: $dirs_by_depth[$depth]{$path}{$dir} = 1;
1284: }
1285: foreach my $path (keys(%files)) {
1286: next if ($path eq '');
1287: my $depth;
1288: if ($path eq '/') {
1289: $depth = 0;
1290: } else {
1291: $depth = scalar(split(/\//,$path));
1292: }
1293: if (ref($files{$path}) eq 'HASH') {
1294: foreach my $file (keys(%{$files{$path}})) {
1.714 raeburn 1295: $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712 raeburn 1296: }
1297: }
1298: }
1299: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714 raeburn 1300: my (%resdirs,%resfiles);
1.715 ! raeburn 1301: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
! 1302: my $numpub = 0;
! 1303: if (keys(%resfiles)) {
! 1304: foreach my $dir (keys(%resfiles)) {
! 1305: if (ref($resfiles{$dir}) eq 'HASH') {
! 1306: foreach my $file (keys(%{$resfiles{$dir}})) {
! 1307: if (exists($files{$dir}{$file})) {
! 1308: $numpub ++;
! 1309: }
! 1310: }
! 1311: }
! 1312: }
! 1313: }
1.712 raeburn 1314: if ($readonly) {
1315: $disabled = ' disabled="disabled"';
1316: }
1317: if ($disabled) {
1318: $togglebuttons = '<br />';
1319: } else {
1320: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1321: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1322: ' <input type="button" value="'.&mt('uncheck all').'"'.
1323: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1324: }
1.715 ! raeburn 1325: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
! 1326: &courseresource_options($formname,$numpub).
! 1327: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
! 1328: my $display = '<form name="'.$formname.'" action="" method="post" onsubmit="return validCrsCopy();">'."\n".
1.712 raeburn 1329: $preamble."\n".
1330: '<div class="LC_float_left">'."\n".
1331: '<fieldset>'."\n".
1332: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
1333: '<span class="LC_fontsize_medium">'.
1334: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
1335: '</span><br /><br />'."\n";
1336: my $count = 0;
1337: my $startcount = 4 + $home;
1338: my $lastcontainer = $startcount;
1339: $display .= &Apache::loncommon::start_data_table()."\n".
1340: &Apache::loncommon::start_data_table_header_row().
1341: '<th>'.&mt('Copy?').'</th>'.
1.714 raeburn 1342: '<th>'.&mt('Name').'</th>'.
1343: '<th>'.&mt('Last modified').'</th>'.
1344: '<th>'.&mt('Published?').'</th>'.
1.712 raeburn 1345: &Apache::loncommon::end_data_table_header_row()."\n";
1346: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1347: $count,\$display,\%parent,\%children,$readonly,
1.714 raeburn 1348: $formname,$chkname,\$lastcontainer,\%resfiles);
1.712 raeburn 1349: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1350: unless ($readonly) {
1351: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1352: '<div>'.
1353: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1354: '</div>';
1355: }
1356: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1357: \%hierarchy,\@checked_maps,$home,$chkname);
1358: $r->print($display);
1359: }
1360: $r->print(&endContentScreen());
1361: }
1362:
1363: sub recurse_crsauthored {
1364: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714 raeburn 1365: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
1366: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
1367: (ref($resfilesref) eq 'HASH'));
1.712 raeburn 1368: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1369: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1370: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1371: $hasdirs = 1;
1372: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1373: map { $unique{$_} = 1; } keys(%dirs);
1374: }
1375: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1376: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1377: $hasfiles = 1;
1378: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1379: map { $unique{$_} = 1; } keys(%files);
1380: }
1381: if ($readonly) {
1382: $disabled = ' disabled="disabled"';
1383: }
1384: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1385: my $whitespace =
1386: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1387: $parent->{$currdepth} = $$lastcontainerref;
1388: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1389: next if ($item eq '');
1390: my $currelem;
1391: if ($hasdirs && exists($dirs{$item})) {
1392: $count ++;
1393: my $deeper = $currdepth+1;
1394: my ($newpath,$showpath);
1395: if ($currpath eq '/') {
1396: $newpath = $item;
1397: $showpath = $currpath.$item.'/';
1398: } else {
1399: $newpath = $currpath.'/'.$item;
1400: $showpath = '/'.$currpath.'/'.$item.'/';
1401: }
1402: $currelem = $count+$startcount;
1403: $$lastcontainerref = $currelem;
1404: $children->{$parent->{$currdepth}} .= $currelem.':';
1405: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1406: $$displayref .= &Apache::loncommon::start_data_table_row().
1407: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1408: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1409: $disabled.' /></td><td>';
1410: for (my $i=0; $i<$currdepth; $i++) {
1411: $$displayref .= "$whitespace\n";
1412: }
1.714 raeburn 1413: $$displayref .= '<img '.$icon.' /> '.$item.'</td><td> </td><td> </td>'.
1.712 raeburn 1414: &Apache::loncommon::end_data_table_row()."\n";
1415: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1416: $startcount,$count,$displayref,$parent,$children,
1.714 raeburn 1417: $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712 raeburn 1418: }
1419: if ($hasfiles && exists($files{$item})) {
1420: $count ++;
1421: $currelem = $count+$startcount;
1422: $children->{$parent->{$currdepth}} .= $currelem.':';
1423: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1424: my ($ext) = ($item =~ /\.([^.]+)$/);
1425: my $alttext;
1426: if (lc($ext) eq 'problem') {
1427: $alttext = ' alt="'.&mt('Problem Icon').'"';
1428: } elsif ($ext =~ /^x?html?$/i) {
1429: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1430: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1431: $alttext = ' alt="'.&mt('Image Icon').'"';
1432: } else {
1433: $alttext = ' alt="'.&mt('Resource Icon').'"';
1434: }
1435: my $showpath;
1436: if ($currpath eq '/') {
1437: $showpath = $currpath;
1438: } else {
1439: $showpath = "/$currpath/";
1440: }
1.714 raeburn 1441: my ($published,$lastmod);
1442: if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
1443: $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
1444: } else {
1445: $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
1446: }
1.712 raeburn 1447: $$displayref .= &Apache::loncommon::start_data_table_row().
1448: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1449: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1450: $disabled.' /></td><td>';
1451: for (my $i=0; $i<$currdepth; $i++) {
1452: $$displayref .= "$whitespace\n";
1453: }
1454: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1.714 raeburn 1455: '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
1456: '<td style="text-align: center;">'.$published.'</td>'.
1.712 raeburn 1457: &Apache::loncommon::end_data_table_row()."\n";
1458: }
1459: }
1460: $$lastcontainerref = $parent->{$currdepth};
1461: return $count;
1462: }
1463:
1.715 ! raeburn 1464: sub courseresource_options {
! 1465: my ($formname,$numpub) = @_;
! 1466: my %lt = &Apache::lonlocal::texthash(
! 1467: 'default' => 'System wide - can be used for any courses system wide',
! 1468: 'domain' => 'Domain only - use limited to courses in the domain',
! 1469: 'custom' => 'Customized right of use ...',
! 1470: 'public' => 'Public - no authentication or authorization required for use',
! 1471: 'closed' => 'Closed - XML source is closed to everyone',
! 1472: 'open' => 'Open - XML source is open to people who want to use it',
! 1473: 'sel' => 'Select',
! 1474: );
! 1475: my $output;
! 1476: if ($numpub) {
! 1477: $output .= '<div class="LC_left_float">'.
! 1478: '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
! 1479: &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
! 1480: $numpub).'</br />'.
! 1481: &mt('Publish copied files in selected Authoring Space?').': '."\n".
! 1482: '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
! 1483: &mt('Yes').'</label>'."\n".
! 1484: '<label><input type="radio" name="respublish" value="0" />'.
! 1485: &mt('No').'</label>'."\n".
! 1486: '</fieldset></div>'."\n";
! 1487: }
! 1488: $output .= '<div class="LC_left_float">'.
! 1489: '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
! 1490: &mt('Copyright').': '.
! 1491: '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
! 1492: '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
! 1493: '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
! 1494: '<option value="public">'.$lt{'public'}.'</option>'."\n".
! 1495: '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
! 1496: '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
! 1497: '<input type="text" name="customrights" size="60" value="" />'.
! 1498: '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
! 1499: $lt{'sel'}.'</a></div><br />'."\n".
! 1500: &mt('Source').' :'.
! 1501: '<select name="sourceavail">'."\n".
! 1502: '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
! 1503: '<option value="open">'.$lt{'open'}.'</option>'."\n".
! 1504: '</select><br />'."\n".
! 1505: '</fieldset></div>'."\n";
! 1506: return $output;
! 1507: }
! 1508:
1.329 droeschl 1509: sub group_import {
1.598 raeburn 1510: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1511: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1512: %removeparam,$importuploaded,$fixuperrors);
1513: $allmaps = {};
1.329 droeschl 1514: while (@files) {
1515: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1516: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1517: && ($caller eq 'londocs')
1518: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1519:
1.329 droeschl 1520: my $errtext = '';
1521: my $fatal = 0;
1522: my $newmapstr = '<map>'."\n".
1523: '<resource id="1" src="" type="start"></resource>'."\n".
1524: '<link from="1" to="2" index="1"></link>'."\n".
1525: '<resource id="2" src="" type="finish"></resource>'."\n".
1526: '</map>';
1527: $env{'form.output'}=$newmapstr;
1528: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1529: 'output',$1.$2);
1.534 raeburn 1530: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1531: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1532: $fatal = 2;
1533: }
1534: if ($fatal) {
1535: return ($errtext,$fatal);
1536: }
1537: }
1538: if ($url) {
1.626 raeburn 1539: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1540: $url = $1;
1541: my $marker = $2;
1542: my $info = $3;
1.699 raeburn 1543: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1544: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1545: my @toolinfo = split(/:/,$info);
1546: if ($residx) {
1.604 raeburn 1547: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1548: $toolid = $toolsettings{'id'};
1549: } else {
1.604 raeburn 1550: $toolid = shift(@toolinfo);
1.598 raeburn 1551: }
1.699 raeburn 1552: if ($toolid =~ /^c/) {
1553: $tooltype = 'crs';
1554: $toolprefix = 'c';
1555: } else {
1556: $tooltype = 'dom';
1557: }
1.598 raeburn 1558: $toolid =~ s/\D//g;
1.604 raeburn 1559: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1560: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1561: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1562: foreach my $item (@extras) {
1563: $toolhash{$item} = &unescape($toolhash{$item});
1564: }
1.645 raeburn 1565: if ($folder =~ /^supplemental/) {
1.648 raeburn 1566: delete($toolhash{'gradable'});
1567: } else {
1568: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1569: }
1.598 raeburn 1570: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1571: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1572: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1573: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1574: my @deleted;
1575: $toolhash{'id'} = $toolprefix.$toolid;
1576: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1577: ($toolhash{'target'} eq 'window')) {
1578: if ($toolhash{'target'} eq 'window') {
1579: foreach my $item ('width','height') {
1580: $toolhash{$item} =~ s/^\s+//;
1581: $toolhash{$item} =~ s/\s+$//;
1582: if ($toolhash{$item} =~ /\D/) {
1583: delete($toolhash{$item});
1584: if ($residx) {
1585: if ($toolsettings{$item}) {
1586: push(@deleted,$item);
1587: }
1.624 raeburn 1588: }
1589: }
1590: }
1.604 raeburn 1591: }
1.699 raeburn 1592: } elsif ($residx) {
1593: $toolhash{'target'} = $toolsettings{'target'};
1594: if ($toolhash{'target'} eq 'window') {
1595: foreach my $item ('width','height') {
1596: $toolhash{$item} = $toolsettings{$item};
1597: }
1598: }
1599: } elsif (ref($tools{'display'}) eq 'HASH') {
1600: $toolhash{'target'} = $tools{'display'}{'target'};
1601: if ($toolhash{'target'} eq 'window') {
1602: $toolhash{'width'} = $tools{'display'}{'width'};
1603: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1604: }
1.604 raeburn 1605: }
1.699 raeburn 1606: if ($toolhash{'target'} eq 'iframe') {
1607: foreach my $item ('width','height','linktext','explanation') {
1608: delete($toolhash{$item});
1609: if ($residx) {
1610: if ($toolsettings{$item}) {
1611: push(@deleted,$item);
1612: }
1.624 raeburn 1613: }
1.604 raeburn 1614: }
1.699 raeburn 1615: } elsif ($toolhash{'target'} eq 'tab') {
1616: foreach my $item ('width','height') {
1617: delete($toolhash{$item});
1618: if ($residx) {
1619: if ($toolsettings{$item}) {
1620: push(@deleted,$item);
1621: }
1.628 raeburn 1622: }
1623: }
1624: }
1.699 raeburn 1625: if (ref($tools{'crsconf'}) eq 'HASH') {
1626: foreach my $item ('label','title','linktext','explanation') {
1627: my $crsitem;
1628: if (($item eq 'label') || ($item eq 'title')) {
1629: $crsitem = 'crs'.$item;
1630: } else {
1631: $crsitem = $item;
1632: }
1633: if ($tools{'crsconf'}{$item}) {
1634: $toolhash{$crsitem} =~ s/^\s+//;
1635: $toolhash{$crsitem} =~ s/\s+$//;
1636: if ($toolhash{$crsitem} eq '') {
1637: delete($toolhash{$crsitem});
1638: }
1639: } else {
1.624 raeburn 1640: delete($toolhash{$crsitem});
1.604 raeburn 1641: }
1.699 raeburn 1642: if (($residx) && (exists($toolsettings{$crsitem}))) {
1643: unless (exists($toolhash{$crsitem})) {
1644: push(@deleted,$crsitem);
1645: }
1646: }
1.604 raeburn 1647: }
1.699 raeburn 1648: }
1649: if ($toolhash{'passback'}) {
1650: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1651: $toolhash{'gradesecret'} = $gradesecret;
1652: $toolhash{'gradesecretdate'} = time;
1653: }
1654: if ($toolhash{'roster'}) {
1655: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1656: $toolhash{'rostersecret'} = $rostersecret;
1657: $toolhash{'rostersecretdate'} = time;
1658: }
1659: my $changegradable;
1660: if (($residx) && ($folder =~ /^default/)) {
1661: if ($toolsettings{'gradable'}) {
1662: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1663: push(@deleted,'gradable');
1664: $changegradable = 1;
1.604 raeburn 1665: }
1.699 raeburn 1666: } elsif ($toolhash{'gradable'}) {
1667: $changegradable = 1;
1.604 raeburn 1668: }
1.699 raeburn 1669: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1670: $changegradable = 1;
1.699 raeburn 1671: if ($toolsettings{'gradable'}) {
1672: $toolhash{'gradable'} = 1;
1673: }
1.645 raeburn 1674: }
1.648 raeburn 1675: }
1.699 raeburn 1676: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1677: if ($putres eq 'ok') {
1678: if (@deleted) {
1679: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1680: }
1.699 raeburn 1681: if (($changegradable) && ($folder =~ /^default/)) {
1682: my $val;
1683: if ($toolhash{'gradable'}) {
1684: $val = 'yes';
1685: } else {
1686: $val = 'no';
1687: }
1688: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1689: 'string_yesno');
1690: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1691: }
1.699 raeburn 1692: } else {
1693: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1694: }
1.604 raeburn 1695: }
1.598 raeburn 1696: }
1697: }
1698: }
1.529 raeburn 1699: if (($caller eq 'londocs') &&
1700: ($folder =~ /^default/)) {
1.534 raeburn 1701: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1702: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1703: my $cid = $coursedom.'_'.$coursenum;
1704: $allmaps =
1705: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1706: $chome,$cid);
1707: $donechk = 1;
1708: }
1709: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1710: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1711: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1712: $importuploaded = 1;
1713: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1714: next if ($allmaps->{$url});
1715: }
1716: }
1.344 bisitz 1717: if (!$residx
1.329 droeschl 1718: || defined($LONCAPA::map::zombies[$residx])) {
1719: $residx = &LONCAPA::map::getresidx($url,$residx);
1720: push(@LONCAPA::map::order, $residx);
1721: }
1722: my $ext = 'false';
1723: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1724: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1725: my $filepath = $1;
1.675 raeburn 1726: my $fname;
1727: if ($name eq '') {
1728: $name = &mt('Web Page');
1.534 raeburn 1729: $fname = 'web';
1730: } else {
1.675 raeburn 1731: $fname = $name;
1732: $fname=&Apache::lonnet::clean_filename($fname);
1733: if ($fname eq '') {
1734: $fname = 'web';
1735: } elsif (length($fname) > 15) {
1736: $fname = substr($fname,0,14);
1737: }
1.534 raeburn 1738: }
1.675 raeburn 1739: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1740: my $initialtext = &mt('Replace with your own content.');
1741: my $newhtml = <<END;
1.545 raeburn 1742: <html>
1.534 raeburn 1743: <head>
1.675 raeburn 1744: <title>$title</title>
1.534 raeburn 1745: </head>
1746: <body bgcolor="#ffffff">
1747: $initialtext
1748: </body>
1749: </html>
1750: END
1751: $env{'form.output'}=$newhtml;
1.630 raeburn 1752: my $result =
1.534 raeburn 1753: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1754: 'output',
1755: "$filepath/$residx/$fname.html");
1756: if ($result =~ m{^/uploaded/}) {
1757: $url = $result;
1758: if ($filepath =~ /^supplemental/) {
1759: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1760: $env{'user.domain'}.'___&&&___'.$name;
1761: }
1762: } else {
1763: return (&mt('Failed to save new web page.'),1);
1764: }
1765: }
1.675 raeburn 1766: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1767: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1768: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1769: join(':', ($name, $url, $ext, 'normal', 'res'));
1770: }
1771: }
1.529 raeburn 1772: if ($importuploaded) {
1773: my %import_errors;
1774: my %updated = (
1775: removefrommap => \%removefrommap,
1776: removeparam => \%removeparam,
1777: );
1.533 raeburn 1778: my ($result,$msgsarray,$lockerror) =
1779: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1780: if (keys(%import_errors) > 0) {
1.530 raeburn 1781: $fixuperrors =
1.529 raeburn 1782: '<p span class="LC_warning">'."\n".
1783: &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".
1784: '<ul>'."\n";
1785: foreach my $key (sort(keys(%import_errors))) {
1786: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1787: }
1788: $fixuperrors .= '</ul></p>'."\n";
1789: }
1.533 raeburn 1790: if (ref($msgsarray) eq 'ARRAY') {
1791: if (@{$msgsarray} > 0) {
1792: $fixuperrors .= '<p class="LC_info">'.
1793: join('<br />',@{$msgsarray}).
1794: '</p>';
1795: }
1796: }
1797: if ($lockerror) {
1798: $fixuperrors .= '<p class="LC_error">'.
1799: $lockerror.
1800: '</p>';
1801: }
1.529 raeburn 1802: }
1803: my ($errtext,$fatal) =
1804: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1805: unless ($fatal) {
1806: if ($folder =~ /^supplemental/) {
1.561 raeburn 1807: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1808: $folder.'.'.$container);
1.557 raeburn 1809: }
1810: }
1.529 raeburn 1811: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1812: }
1813:
1814: sub log_docs {
1.494 raeburn 1815: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1816: }
1817:
1818: {
1819: my @oldresources=();
1820: my @oldorder=();
1821: my $parmidx;
1822: my %parmaction=();
1823: my %parmvalue=();
1824: my $changedflag;
1825:
1826: sub snapshotbefore {
1827: @oldresources=@LONCAPA::map::resources;
1828: @oldorder=@LONCAPA::map::order;
1829: $parmidx=undef;
1830: %parmaction=();
1831: %parmvalue=();
1832: $changedflag=0;
1833: }
1834:
1835: sub remember_parms {
1836: my ($idx,$parameter,$action,$value)=@_;
1837: $parmidx=$idx;
1838: $parmaction{$parameter}=$action;
1839: $parmvalue{$parameter}=$value;
1840: $changedflag=1;
1841: }
1842:
1843: sub log_differences {
1844: my ($plain)=@_;
1845: my %storehash=('folder' => $plain,
1846: 'currentfolder' => $env{'form.folder'});
1847: if ($parmidx) {
1848: $storehash{'parameter_res'}=$oldresources[$parmidx];
1849: foreach my $parm (keys(%parmaction)) {
1850: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1851: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1852: }
1853: }
1854: my $maxidx=$#oldresources;
1855: if ($#LONCAPA::map::resources>$#oldresources) {
1856: $maxidx=$#LONCAPA::map::resources;
1857: }
1858: for (my $idx=0; $idx<=$maxidx; $idx++) {
1859: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1860: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1861: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1862: $changedflag=1;
1863: }
1864: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1865: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1866: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1867: $changedflag=1;
1868: }
1869: }
1870: $storehash{'maxidx'}=$maxidx;
1871: if ($changedflag) { &log_docs(\%storehash); }
1872: }
1873: }
1874:
1875: sub docs_change_log {
1.611 raeburn 1876: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1877: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1878: my $navmap;
1.483 raeburn 1879: my $js = '<script type="text/javascript">'."\n".
1880: '// <![CDATA['."\n".
1881: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1882: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1883: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1884: &history_tab_js()."\n".
1.484 raeburn 1885: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1886: '// ]]>'."\n".
1887: '</script>'."\n";
1.484 raeburn 1888: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1889: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1890: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1891: my %orderhash;
1892: my $container='sequence';
1893: my $pathitem;
1.519 raeburn 1894: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1895: $container='page';
1896: }
1.519 raeburn 1897: my $folderpath=$env{'form.folderpath'};
1898: if ($folderpath eq '') {
1.617 raeburn 1899: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1900: }
1.617 raeburn 1901: undef($navmap);
1.519 raeburn 1902: $pathitem = '<input type="hidden" name="folderpath" value="'.
1903: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1904: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1905: my $jumpto = $readfile;
1906: $jumpto =~ s{^/}{};
1907: my $tid = 1;
1.489 raeburn 1908: if ($supplementalflag) {
1909: $tid = 2;
1910: }
1.630 raeburn 1911: my ($breadcrumbtrail) =
1.509 raeburn 1912: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1913: $r->print($breadcrumbtrail.
1914: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1915: $readfile));
1.329 droeschl 1916: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1917: $env{'course.'.$env{'request.course.id'}.'.domain'},
1918: $env{'course.'.$env{'request.course.id'}.'.num'});
1919:
1920: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1921:
1922: my %saveable_parameters = ('show' => 'scalar',);
1923: &Apache::loncommon::store_course_settings('docs_log',
1924: \%saveable_parameters);
1925: &Apache::loncommon::restore_course_settings('docs_log',
1926: \%saveable_parameters);
1927: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1928: # FIXME: internationalization seems wrong here
1.329 droeschl 1929: my %lt=('hiddenresource' => 'Resources hidden',
1930: 'encrypturl' => 'URL hidden',
1931: 'randompick' => 'Randomly pick',
1932: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1933: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1934: 'set' => 'set to',
1935: 'del' => 'deleted');
1.484 raeburn 1936: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1937: $pathitem."\n".
1938: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1939: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1940: $r->print('<div class="LC_left_float">'.
1941: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1942: &makedocslogform($filter,1).
1943: '</fieldset></div><br clear="all" />');
1.329 droeschl 1944: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1945: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1946: &mt('After').'</th>'.
1947: &Apache::loncommon::end_data_table_header_row());
1948: my $shown=0;
1949: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1950: if ($env{'form.displayfilter'} eq 'currentfolder') {
1951: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1952: }
1953: my @changes=keys(%{$docslog{$id}{'logentry'}});
1954: if ($env{'form.displayfilter'} eq 'containing') {
1955: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1956: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1957: foreach my $key (@changes) {
1958: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1959: }
1.344 bisitz 1960: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1961: }
1962: my $count = 0;
1963: my $time =
1964: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1965: my $plainname =
1966: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1967: $docslog{$id}{'exe_udom'});
1968: my $about_me_link =
1969: &Apache::loncommon::aboutmewrapper($plainname,
1970: $docslog{$id}{'exe_uname'},
1971: $docslog{$id}{'exe_udom'});
1972: my $send_msg_link='';
1973: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1974: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1975: $send_msg_link ='<br />'.
1976: &Apache::loncommon::messagewrapper(&mt('Send message'),
1977: $docslog{$id}{'exe_uname'},
1978: $docslog{$id}{'exe_udom'});
1979: }
1980: $r->print(&Apache::loncommon::start_data_table_row());
1981: $r->print('<td>'.$time.'</td>
1982: <td>'.$about_me_link.
1983: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1984: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1985: $send_msg_link.'</td><td>'.
1986: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1987: my $is_supp = 0;
1988: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1989: $is_supp = 1;
1990: }
1.329 droeschl 1991: # Before
1992: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1993: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1994: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1995: if ($oldname ne $newname) {
1.488 raeburn 1996: my $shown = &LONCAPA::map::qtescape($oldname);
1997: if ($is_supp) {
1998: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1999: }
2000: $r->print($shown);
1.329 droeschl 2001: }
2002: }
2003: $r->print('<ul>');
2004: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2005: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 2006: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
2007: if ($is_supp) {
2008: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2009: }
2010: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2011: }
2012: }
2013: $r->print('</ul>');
2014: # After
2015: $r->print('</td><td>');
2016:
2017: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2018: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2019: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2020: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 2021: my $shown = &LONCAPA::map::qtescape($newname);
2022: if ($is_supp) {
2023: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
2024: }
2025: $r->print($shown);
1.329 droeschl 2026: }
1.364 bisitz 2027: }
1.329 droeschl 2028: $r->print('<ul>');
2029: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2030: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 2031: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
2032: if ($is_supp) {
2033: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2034: }
2035: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2036: }
2037: }
2038: $r->print('</ul>');
2039: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 2040: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
2041: if ($title eq '') {
2042: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 2043: } elsif ($is_supp) {
2044: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 2045: }
2046: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 2047: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 2048: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 2049: # FIXME: internationalization seems wrong here
1.329 droeschl 2050: $r->print('<li>'.
2051: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
2052: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
2053: .'</li>');
2054: }
2055: }
2056: $r->print('</ul>');
2057: }
2058: # End
2059: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2060: $shown++;
2061: if (!($env{'form.show'} eq &mt('all')
2062: || $shown<=$env{'form.show'})) { last; }
2063: }
1.484 raeburn 2064: $r->print(&Apache::loncommon::end_data_table()."\n".
2065: &makesimpleeditform($pathitem)."\n".
2066: '</div></div>');
2067: $r->print(&endContentScreen());
1.329 droeschl 2068: }
2069:
2070: sub update_paste_buffer {
1.492 raeburn 2071: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 2072: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 2073: if ($env{'form.multiremove'}) {
2074: $env{'form.multiremove'} =~ s/,$//;
2075: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
2076: }
2077: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
2078: if ($env{'form.multicut'}) {
2079: $env{'form.multicut'} =~ s/,$//;
2080: foreach my $item (split(/,/,$env{'form.multicut'})) {
2081: unless ($removals{$item}) {
2082: $cuts{$item} = 1;
2083: push(@possibles,$item.':cut');
2084: }
2085: }
2086: }
2087: if ($env{'form.multicopy'}) {
2088: $env{'form.multicopy'} =~ s/,$//;
2089: foreach my $item (split(/,/,$env{'form.multicopy'})) {
2090: unless ($removals{$item} || $cuts{$item}) {
2091: push(@possibles,$item.':copy');
2092: }
2093: }
2094: }
2095: } elsif ($env{'form.markcopy'}) {
2096: @possibles = split(/,/,$env{'form.markcopy'});
2097: }
1.329 droeschl 2098:
1.538 raeburn 2099: return if (@possibles == 0);
1.329 droeschl 2100: return if (!defined($env{'form.copyfolder'}));
2101:
2102: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2103: $env{'form.copyfolder'});
1.538 raeburn 2104: return if ($fatal);
2105:
2106: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 2107:
1.538 raeburn 2108: # Retrieve current paste buffer suffixes.
2109: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2110: my (%pasteurls,@newpaste);
2111:
2112: # Construct identifiers for current contents of user's paste buffer
2113: if (@currpaste) {
2114: foreach my $suffix (@currpaste) {
1.667 raeburn 2115: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2116: my $url = $env{'docs.markedcopy_url_'.$suffix};
2117: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
2118: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
2119: ($url ne '')) {
2120: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2121: $pasteurls{$cid.'_'.$mapidx} = 1;
2122: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2123: $pasteurls{$url} = 1;
2124: } else {
1.669 raeburn 2125: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 2126: }
2127: }
1.538 raeburn 2128: }
2129: }
2130:
2131: # Mark items for copying (skip any items already in user's paste buffer)
2132: my %addtoenv;
1.597 raeburn 2133:
2134: my @pathitems = split(/\&/,$env{'form.folderpath'});
2135: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 2136: my $ispage = $folderconf[5];
1.597 raeburn 2137:
1.538 raeburn 2138: foreach my $item (@possibles) {
2139: my ($orderidx,$cmd) = split(/:/,$item);
2140: next if ($orderidx =~ /\D/);
2141: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 2142: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 2143: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
2144: my %denied = &action_restrictions($coursenum,$coursedom,
2145: &LONCAPA::map::qtescape($url),
2146: $env{'form.folderpath'},\%curr_groups);
2147: next if ($denied{'copy'});
2148: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 2149: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2150: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
2151: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2152: next if (exists($pasteurls{$url}));
2153: } else {
2154: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
2155: }
1.538 raeburn 2156: my ($suffix,$errortxt,$locknotfreed) =
2157: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 2158: if ($suffix ne '') {
2159: push(@newpaste,$suffix);
2160: } else {
2161: if ($locknotfreed) {
2162: return $locknotfreed;
2163: }
1.538 raeburn 2164: }
2165: if (&is_supplemental_title($title)) {
2166: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
2167: ($title) = &Apache::loncommon::parse_supplemental_title($title);
2168: }
1.329 droeschl 2169:
1.538 raeburn 2170: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
2171: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
2172: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
2173: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 2174: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 2175: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
2176: my $prefix = $1;
2177: my $subdir =$2;
2178: if ($subdir eq '') {
2179: $subdir = $prefix;
1.492 raeburn 2180: }
1.538 raeburn 2181: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 2182: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
2183: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 2184: if (ref($hierarchy{$url}) eq 'HASH') {
2185: my ($nested,$nestednames);
2186: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
2187: $nested =~ s/\&$//;
2188: $nestednames =~ s/\Q___&&&___\E$//;
2189: if ($nested ne '') {
2190: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
2191: }
2192: if ($nestednames ne '') {
2193: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
2194: }
1.492 raeburn 2195: }
2196: }
1.591 raeburn 2197: if ($locknotfreed) {
2198: $output = $locknotfreed;
2199: last;
2200: }
1.492 raeburn 2201: }
1.538 raeburn 2202: if (@newpaste) {
2203: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
2204: }
1.492 raeburn 2205: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 2206: delete($env{'form.markcopy'});
1.591 raeburn 2207: return $output;
1.329 droeschl 2208: }
2209:
1.492 raeburn 2210: sub recurse_uploaded_maps {
2211: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2212: if (ref($hierarchy->{$url}) eq 'HASH') {
2213: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2214: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2215: my (@uploaded,@names,%shorter);
2216: for (my $i=0; $i<@maps; $i++) {
2217: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2218: if ($inner ne '') {
2219: push(@uploaded,$inner);
2220: push(@names,&escape($titles[$i]));
2221: $shorter{$maps[$i]} = $inner;
2222: }
2223: }
2224: $$nestref .= "$dir:".join(',',@uploaded).'&';
2225: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2226: foreach my $map (@maps) {
2227: if ($shorter{$map} ne '') {
2228: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2229: }
2230: }
2231: }
2232: return;
2233: }
2234:
1.329 droeschl 2235: sub print_paste_buffer {
1.492 raeburn 2236: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2237: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2238:
1.538 raeburn 2239: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2240: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2241: }
2242:
1.538 raeburn 2243: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2244: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2245: my $clipboardcount = 0;
1.488 raeburn 2246:
1.538 raeburn 2247: # Construct identifiers for current contents of user's paste buffer
2248: foreach my $suffix (@currpaste) {
2249: next if ($suffix =~ /\D/);
2250: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2251: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2252: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2253: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2254: ($url ne '')) {
1.575 raeburn 2255: $clipboardcount ++;
1.538 raeburn 2256: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2257: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2258: $toolcnum,$marker);
1.538 raeburn 2259: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2260: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2261: $is_external = 1;
1.704 raeburn 2262: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2263: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2264: $is_exttool = 1;
1.538 raeburn 2265: }
2266: if ($folder =~ /^supplemental/) {
2267: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2268: unless ($canpaste) {
2269: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2270: }
2271: } else {
2272: $canpaste = 1;
2273: }
2274: if ($canpaste) {
2275: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2276: my $srcdom = $1;
2277: my $srcnum = $2;
2278: my $rem = $3;
2279: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2280: $othercourse = 1;
2281: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2282: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2283: } else {
2284: $canpaste = 0;
2285: $nopaste = &mt('Paste from another course unavailable.');
2286: }
2287: }
2288: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2289: my $prefix = $1;
2290: $parent = $2;
2291: if ($folder !~ /^\Q$prefix\E/) {
2292: $areachange = 1;
2293: }
2294: $is_uploaded_map = 1;
1.492 raeburn 2295: }
1.597 raeburn 2296: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2297: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2298: if ($cid ne $env{'request.course.id'}) {
2299: my ($srcdom,$srcnum) = split(/_/,$cid);
2300: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2301: if ($is_exttool) {
2302: if ($toolcdom ne $coursedom) {
2303: $canpaste = 0;
2304: $nopaste = &mt('Paste from another domain unavailable.');
2305: } elsif ($toolcnum ne $coursenum) {
2306: my %toolsettings =
2307: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2308: my %tooltypes = &Apache::loncommon::usable_exttools();
2309: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2310: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2311: $canpaste = 0;
2312: $nopaste = &mt('Paste from another course unavailable.');
2313: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2314: unless ($checkedsameinst) {
2315: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2316: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2317: if ($intdom ne '') {
2318: my $internet_names =
2319: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2320: if (ref($internet_names) eq 'ARRAY') {
2321: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2322: $same_institution = 1;
2323: }
2324: }
2325: }
2326: $checkedsameinst = 1;
2327: }
2328: if ($same_institution) {
2329: $othercrs = '<br />'.&mt('(from another course)');
2330: } else {
2331: $nopaste = &mt('Paste from another course unavailable.');
2332: }
2333: } else {
2334: $othercrs = '<br />'.&mt('(from another course)');
2335: }
2336: }
1.627 raeburn 2337: }
1.596 raeburn 2338: } else {
2339: $canpaste = 0;
2340: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2341: }
1.596 raeburn 2342: }
1.703 raeburn 2343: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2344: my ($audom,$auname) = ($1,$2);
2345: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2346: if (&Apache::lonnet::is_course($audom,$auname)) {
2347: $canpaste = 0;
2348: $nopaste = &mt('Paste from another course unavailable.');
2349: }
2350: }
1.492 raeburn 2351: }
1.596 raeburn 2352: if ($canpaste) {
2353: push(@pasteable,$suffix);
1.629 raeburn 2354: }
1.538 raeburn 2355: }
2356: my $buffer;
1.627 raeburn 2357: if ($is_external) {
1.538 raeburn 2358: $buffer = &mt('External Resource').': '.
2359: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2360: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2361: } elsif ($is_exttool) {
2362: $buffer = &mt('External Tool').': '.
2363: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2364: } else {
2365: my $icon = &Apache::loncommon::icon($extension);
2366: if ($extension eq 'sequence' &&
2367: $url =~ m{/default_\d+\.sequence$}x) {
2368: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2369: $icon .= '/navmap.folder.closed.gif';
2370: }
1.589 raeburn 2371: my $title = $env{'docs.markedcopy_title_'.$suffix};
2372: if ($title eq '') {
2373: ($title) = ($url =~ m{/([^/]+)$});
2374: }
1.538 raeburn 2375: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
2376: ': '.
2377: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2378: &LONCAPA::map::qtescape($title));
1.538 raeburn 2379: }
2380: $pasteitems .= '<div class="LC_left_float">';
2381: my ($options,$onclick);
2382: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2383: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2384: if (($is_uploaded_map) ||
2385: ($url =~ /(bulletinboard|smppg)$/) ||
2386: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2387: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2388: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2389: }
2390: }
2391: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2392: if ($nopaste) {
1.681 raeburn 2393: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2394: } else {
2395: if ($othercrs) {
2396: $pasteitems .= $othercrs;
2397: }
2398: if ($options) {
2399: $pasteitems .= $options;
1.492 raeburn 2400: }
2401: }
1.538 raeburn 2402: $pasteitems .= '</div>';
2403: }
2404: }
2405: if ($pasteitems eq '') {
2406: &Apache::lonnet::delenv('docs.markedcopies');
2407: }
2408: my ($pasteform,$form_start,$buttons,$form_end);
2409: if ($pasteitems) {
2410: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2411: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2412: if (@pasteable) {
1.575 raeburn 2413: my $value = &mt('Paste to current folder');
2414: if ($container eq 'page') {
2415: $value = &mt('Paste to current page');
2416: }
2417: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2418: }
2419: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2420: if ($clipboardcount > 1) {
2421: $buttons .=
2422: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2423: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2424: (' 'x2).
2425: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2426: (' 'x2);
1.492 raeburn 2427: }
1.575 raeburn 2428: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2429: '</form>';
1.538 raeburn 2430: } else {
2431: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2432: }
1.538 raeburn 2433: $r->print($form_start
2434: .'<fieldset>'
2435: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2436: .$pasteitems
2437: .'</fieldset>'
2438: .$form_end);
2439: }
2440:
2441: sub paste_options {
2442: my ($suffix,$is_uploaded_map,$parent) = @_;
2443: my ($copytext,$movetext);
2444: if ($is_uploaded_map) {
2445: $copytext = &mt('Copy to new folder');
2446: $movetext = &mt('Move old');
2447: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2448: $copytext = &mt('Copy to new board');
2449: $movetext = &mt('Move (not posts)');
2450: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2451: $copytext = &mt('Copy to new page');
2452: $movetext = &mt('Move');
1.533 raeburn 2453: } else {
1.538 raeburn 2454: $copytext = &mt('Copy to new file');
2455: $movetext = &mt('Move');
2456: }
2457: my $output = '<br />'.
2458: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2459: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2460: '<label>'.
2461: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2462: $copytext.'</label></span>'.(' 'x2).' '.
2463: '<span class="LC_nobreak"><label>'.
2464: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2465: $movetext.'</label></span>';
2466: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2467: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2468: '</legend><table border="0">';
2469: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2470: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2471: my $lastdir = $parent;
2472: my %depths = (
2473: $lastdir => 0,
2474: );
2475: my (%display,%deps);
2476: for (my $i=0; $i<@pastemaps; $i++) {
2477: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2478: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2479: my @subfolders = split(/,/,$subfolderstr);
2480: $deps{$lastdir} = \@subfolders;
2481: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2482: my $depth = $depths{$lastdir} + 1;
2483: my $offset = int($depth * 4);
2484: my $indent = (' ' x $offset);
2485: for (my $j=0; $j<@subfolders; $j++) {
2486: $depths{$subfolders[$j]} = $depth;
2487: $display{$subfolders[$j]} =
2488: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2489: '<td><label>'.
2490: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2491: '<label>'.
2492: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2493: &mt('Move old').'</label>'.
2494: '</td></tr>';
2495: }
1.492 raeburn 2496: }
1.538 raeburn 2497: &recurse_print(\$output,$parent,\%deps,\%display);
2498: $output .= '</table></fieldset>';
1.329 droeschl 2499: }
1.538 raeburn 2500: $output .= '</div>';
2501: return $output;
1.488 raeburn 2502: }
2503:
1.492 raeburn 2504: sub recurse_print {
1.538 raeburn 2505: my ($outputref,$dir,$deps,$display) = @_;
2506: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2507: if (ref($deps->{$dir}) eq 'ARRAY') {
2508: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2509: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2510: }
2511: }
2512: }
2513:
1.488 raeburn 2514: sub supp_pasteable {
2515: my ($url) = @_;
2516: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2517: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2518: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2519: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2520: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2521: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2522: return 1;
2523: }
2524: return;
1.329 droeschl 2525: }
2526:
1.492 raeburn 2527: sub paste_popup_js {
1.594 damieng 2528: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2529: show => 'Show Options',
2530: hide => 'Hide Options',
1.594 damieng 2531: );
2532: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2533: none => 'No items selected from clipboard.',
1.492 raeburn 2534: );
1.594 damieng 2535: &html_escape(\%html_js_lt);
2536: &js_escape(\%html_js_lt);
2537: &js_escape(\%js_lt);
1.492 raeburn 2538: return <<"END";
2539:
1.538 raeburn 2540: function showPasteOptions(suffix) {
2541: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2542: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2543: return;
2544: }
2545:
1.538 raeburn 2546: function hidePasteOptions(suffix) {
2547: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2548: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2549: return;
2550: }
2551:
2552: function showOptions(caller,suffix) {
2553: if (document.getElementById('pasteoptionstext_'+suffix)) {
2554: if (caller.checked) {
1.594 damieng 2555: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2556: } else {
2557: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2558: }
2559: if (document.getElementById('pasteoptions_'+suffix)) {
2560: document.getElementById('pasteoptions_'+suffix).style.display='none';
2561: }
2562: }
1.492 raeburn 2563: return;
2564: }
2565:
1.541 raeburn 2566: function validateClipboard() {
2567: var numchk = 0;
2568: if (document.pasteform.pasting.length > 1) {
2569: for (var i=0; i<document.pasteform.pasting.length; i++) {
2570: if (document.pasteform.pasting[i].checked) {
2571: numchk ++;
2572: }
2573: }
2574: } else {
2575: if (document.pasteform.pasting.type == 'checkbox') {
2576: if (document.pasteform.pasting.checked) {
2577: numchk ++;
2578: }
2579: }
2580: }
2581: if (numchk > 0) {
2582: return true;
2583: } else {
1.594 damieng 2584: alert("$js_lt{'none'}");
1.541 raeburn 2585: return false;
2586: }
2587: }
2588:
1.575 raeburn 2589: function checkClipboard() {
2590: if (document.pasteform.pasting.length > 1) {
2591: for (var i=0; i<document.pasteform.pasting.length; i++) {
2592: document.pasteform.pasting[i].checked = true;
2593: }
2594: }
2595: return;
2596: }
2597:
2598: function uncheckClipboard() {
2599: if (document.pasteform.pasting.length >1) {
2600: for (var i=0; i<document.pasteform.pasting.length; i++) {
2601: document.pasteform.pasting[i].checked = false;
2602: }
2603: }
2604: return;
2605: }
2606:
1.492 raeburn 2607: END
2608:
2609: }
2610:
1.329 droeschl 2611: sub do_paste_from_buffer {
1.492 raeburn 2612: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2613:
1.538 raeburn 2614: # Array of items in paste buffer
2615: my (@currpaste,%pastebuffer,%allerrors);
2616: @currpaste = split(/,/,$env{'docs.markedcopies'});
2617:
1.492 raeburn 2618: # Early out if paste buffer is empty
1.538 raeburn 2619: if (@currpaste == 0) {
1.492 raeburn 2620: return ();
1.538 raeburn 2621: }
2622: map { $pastebuffer{$_} = 1; } @currpaste;
2623:
2624: # Array of items selected items to paste
2625: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2626:
2627: # Early out if nothing selected to paste
2628: if (@reqpaste == 0) {
2629: return();
2630: }
2631: my @topaste;
2632: foreach my $suffix (@reqpaste) {
2633: next if ($suffix =~ /\D/);
2634: next unless (exists($pastebuffer{$suffix}));
2635: push(@topaste,$suffix);
2636: }
2637:
2638: # Early out if nothing available to paste
2639: if (@topaste == 0) {
2640: return();
1.329 droeschl 2641: }
2642:
1.704 raeburn 2643: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2644: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2645: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2646: %currltititles,$currltimax,$gotcrsltitools);
2647: $currltimax = 0;
2648: $gotcrsltitools = 0;
1.538 raeburn 2649: foreach my $suffix (@topaste) {
2650: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2651: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2652: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2653: # Supplemental content may only include certain types of content
2654: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2655: if ($folder =~ /^supplemental/) {
2656: unless (&supp_pasteable($url)) {
2657: $notinsupp{$suffix} = 1;
2658: next;
2659: }
1.492 raeburn 2660: }
1.538 raeburn 2661: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2662: my $srcd = $1;
2663: my $srcn = $2;
1.492 raeburn 2664: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2665: # check for mdc privilege in the course from which the resource was pasted
2666: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2667: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2668: $notincrs{$suffix} = 1;
2669: next;
2670: }
1.491 raeburn 2671: }
1.538 raeburn 2672: $srcdom{$suffix} = $srcd;
2673: $srcnum{$suffix} = $srcn;
1.597 raeburn 2674: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2675: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2676: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2677: my ($srcd,$srcn) = split(/_/,$cid);
2678: # When paste buffer was populated using an active role in a different course
2679: # check for mdc privilege in the course from which the resource was pasted
2680: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2681: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2682: $notincrs{$suffix} = 1;
2683: next;
2684: }
2685: }
1.632 raeburn 2686: # When buffer was populated using an active role in a different course
1.704 raeburn 2687: # disallow pasting of External Tool if course is in a different domain,
2688: # or if External Tool use is not permitted in this course.
2689: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2690: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2691: if ($toolcdom ne $coursedom) {
2692: $notindom{$suffix} = 1;
2693: next;
2694: } elsif ($toolcnum ne $coursenum) {
2695: my %toolsettings =
2696: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2697: my %tooltypes = &Apache::loncommon::usable_exttools();
2698: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2699: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2700: $othcrstool{$suffix} = 1;
2701: next;
2702: }
2703: if ($toolsettings{'id'} =~ /^c\d+$/) {
2704: unless ($gotcrsltitools) {
2705: %currcrsltitools =
2706: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2707: foreach my $item (sort(keys(%currcrsltitools))) {
2708: if (ref($currcrsltitools{$item}) eq 'HASH') {
2709: $currltimax ++;
2710: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2711: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2712: } else {
2713: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2714: }
2715: }
2716: }
2717: $gotcrsltitools = 1;
2718: }
2719: }
2720: }
1.627 raeburn 2721: }
1.596 raeburn 2722: $srcdom{$suffix} = $srcd;
2723: $srcnum{$suffix} = $srcn;
1.703 raeburn 2724: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2725: my ($audom,$auname) = ($1,$2);
2726: # When buffer was populated using an active role in a different course
2727: # disallow pasting of published resources from Course Authoring Space
2728: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2729: if (&Apache::lonnet::is_course($audom,$auname)) {
2730: $othcrsres{$suffix} = 1;
2731: next;
2732: }
2733: }
1.491 raeburn 2734: }
1.597 raeburn 2735: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2736: push(@dopaste,$suffix);
2737: if ($url=~/\.(page|sequence)$/) {
2738: $is_map{$suffix} = 1;
2739: }
2740: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2741: my $oldprefix = $1;
1.492 raeburn 2742: # When pasting content from Main Content to Supplemental Content and vice versa
2743: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2744: # a folder/page or a document).
1.538 raeburn 2745: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2746: $prefixchg{$suffix} = 'docstosupp';
2747: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2748: $prefixchg{$suffix} = 'supptodocs';
2749: }
1.491 raeburn 2750:
1.492 raeburn 2751: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2752: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2753: my @nested;
2754: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2755: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2756: my @deps = map { /\d+:([\d,]+$)/ } @items;
2757: foreach my $dep (@deps) {
2758: if ($dep =~ /,/) {
2759: push(@nested,split(/,/,$dep));
2760: } else {
2761: push(@nested,$dep);
2762: }
1.492 raeburn 2763: }
1.538 raeburn 2764: foreach my $item (@nested) {
2765: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2766: push(@{$marktomove{$suffix}},$type.'_'.$item);
2767: }
1.492 raeburn 2768: }
2769: }
1.488 raeburn 2770: }
2771: }
2772:
1.538 raeburn 2773: # Early out if nothing available to paste
2774: if (@dopaste == 0) {
2775: return ();
2776: }
2777:
2778: # Populate message hash and hashes used for main content <=> supplemental content
2779: # changes
2780:
2781: %msgs = &Apache::lonlocal::texthash (
2782: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2783: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2784: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2785: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2786: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2787: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2788: );
2789:
2790: %before = (
2791: docstosupp => {
2792: map => 'default',
2793: doc => 'docs',
2794: },
2795: supptodocs => {
2796: map => 'supplemental',
2797: doc => 'supplemental',
2798: },
2799: );
2800:
2801: %after = (
2802: docstosupp => {
2803: map => 'supplemental',
2804: doc => 'supplemental'
2805: },
2806: supptodocs => {
2807: map => 'default',
2808: doc => 'docs',
2809: },
2810: );
2811:
2812: # Retrieve information about all course maps in main content area
2813:
2814: my $allmaps = {};
1.704 raeburn 2815: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2816: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2817: $same_institution);
1.538 raeburn 2818:
2819: # Loop over the items to paste
2820: foreach my $suffix (@dopaste) {
1.329 droeschl 2821: # Maps need to be copied first
1.538 raeburn 2822: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2823: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2824: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2825: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2826: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2827: }
2828: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2829: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2830: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2831: my $oldurl = $url;
2832: if ($is_map{$suffix}) {
1.491 raeburn 2833: # If pasting a map, check if map contains other maps
1.538 raeburn 2834: my (%hierarchy,%titles);
1.660 raeburn 2835: if (($folder =~ /^default/) && (!$donechk)) {
2836: $allmaps =
2837: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2838: $env{"course.$env{'request.course.id'}.home"},
2839: $env{'request.course.id'});
2840: $donechk = 1;
2841: }
1.627 raeburn 2842: &contained_map_check($url,$folder,$coursenum,$coursedom,
2843: \%removefrommap,\%removeparam,\%addedmaps,
2844: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2845: if ($url=~ m{^/uploaded/}) {
2846: my $newurl;
2847: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2848: ($newurl,my $error) =
2849: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2850: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2851: \$title,$allmaps,\%newurls);
2852: if ($error) {
2853: $allerrors{$suffix} = $error;
2854: next;
2855: }
2856: if ($newurl ne '') {
2857: if ($newurl ne $url) {
2858: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2859: $newsubdir{$url} = $1;
2860: }
2861: $mapchanges{$url} = 1;
1.492 raeburn 2862: }
1.538 raeburn 2863: }
2864: }
2865: if (($srcdom{$suffix} ne $coursedom) ||
2866: ($srcnum{$suffix} ne $coursenum) ||
2867: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2868: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2869: $coursedom,$coursenum,$srcdom{$suffix},
2870: $srcnum{$suffix},$allmaps,\%rewrites,
2871: \%retitles,\%copies,\%dbcopies,
2872: \%zombies,\%params,\%mapmoves,
2873: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2874: \%newurls,\%resdatacopy)) {
1.538 raeburn 2875: $mapmoves{$url} = 1;
2876: }
2877: $url = $newurl;
2878: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2879: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2880: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2881: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2882: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 2883: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 2884: }
2885: } elsif ($url=~m {^/res/}) {
1.597 raeburn 2886: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 2887: push(@toclear,$suffix);
2888: # if pasting published map (main content area only) check map not already in course
2889: if ($folder =~ /^default/) {
2890: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2891: $duplicate{$suffix} = 1;
2892: next;
1.492 raeburn 2893: }
1.491 raeburn 2894: }
2895: }
1.538 raeburn 2896: }
1.627 raeburn 2897: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2898: my $prefix = $1;
1.648 raeburn 2899: my $fromothercrs;
1.538 raeburn 2900: #need to copy the db contents to a new one, unless this is a move.
2901: my %info = (
2902: src => $url,
2903: cdom => $coursedom,
2904: cnum => $coursenum,
1.596 raeburn 2905: );
1.649 raeburn 2906: if ($prefix eq 'ext.tool') {
1.655 raeburn 2907: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2908: $info{'delgradable'} = 1;
2909: }
2910: }
1.596 raeburn 2911: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2912: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2913: $fromothercrs = 1;
2914: $info{'cdom'} = $srcdom{$suffix};
2915: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 2916: unless ($checkedsameinst) {
2917: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2918: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2919: if ($intdom ne '') {
2920: my $internet_names =
2921: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2922: if (ref($internet_names) eq 'ARRAY') {
2923: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2924: $same_institution = 1;
2925: }
2926: }
2927: }
2928: $checkedsameinst = 1;
2929: }
1.596 raeburn 2930: }
2931: }
2932: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2933: my (%lockerr,$msg);
1.538 raeburn 2934: my ($newurl,$result,$errtext) =
1.704 raeburn 2935: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2936: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 2937: if ($result eq 'ok') {
2938: $url = $newurl;
2939: $title=&mt('Copy of').' '.$title;
2940: } else {
2941: if ($prefix eq 'smppg') {
2942: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2943: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2944: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2945: } elsif ($prefix eq 'ext.tool') {
2946: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2947: }
2948: $results{$suffix} = $result;
2949: $msgerrs{$suffix} = $msg;
2950: $lockerrs{$suffix} = $lockerr{$prefix};
2951: next;
2952: }
2953: if ($lockerr{$prefix}) {
2954: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2955: }
1.489 raeburn 2956: }
2957: }
1.538 raeburn 2958: $title = &LONCAPA::map::qtunescape($title);
2959: my $ext='false';
2960: if ($url=~m{^http(|s)://}) { $ext='true'; }
2961: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2962: if ($folder !~ /^supplemental/) {
2963: (undef,undef,$title) =
2964: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2965: }
2966: } else {
2967: if ($folder=~/^supplemental/) {
2968: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2969: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2970: }
1.533 raeburn 2971: }
1.491 raeburn 2972:
2973: # For uploaded files (excluding pages/sequences) path in copied file is changed
2974: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2975: # courses.
2976:
1.538 raeburn 2977: unless ($is_map{$suffix}) {
2978: my $newidx;
1.492 raeburn 2979: # Now insert the URL at the bottom
1.538 raeburn 2980: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2981: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2982: my $relpath = $1;
2983: if ($relpath ne '') {
2984: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2985: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2986: my $newprefix = $newloc;
2987: if ($newloc eq 'default') {
2988: $newprefix = 'docs';
2989: }
2990: if ($newdocsdir eq '') {
2991: $newdocsdir = 'default';
2992: }
1.630 raeburn 2993: if (($prefixchg{$suffix}) ||
2994: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2995: ($srcnum{$suffix} ne $coursenum) ||
2996: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2997: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2998: $url =
2999: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
3000: &Apache::lonnet::getfile($oldurl));
3001: if ($url eq '/adm/notfound.html') {
3002: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
3003: next;
3004: } else {
3005: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
3006: $newsubpath =~ s{/+$}{/};
3007: $docmoves{$oldurl} = $newsubpath;
3008: }
1.491 raeburn 3009: }
3010: }
1.597 raeburn 3011: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3012: my $template = $1;
3013: if ($newidx) {
3014: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
3015: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
3016: }
1.649 raeburn 3017: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 3018: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 3019: my $marker = (split(m{/},$url))[4];
3020: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
3021: my $val = 'no';
3022: if ($toolsettings{'gradable'}) {
3023: $val = 'yes';
3024: }
3025: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
3026: 'string_yesno');
3027: &remember_parms($newidx,'gradable','set',$val);
3028: }
1.491 raeburn 3029: }
1.538 raeburn 3030: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3031: ':'.$ext.':normal:res';
3032: push(@LONCAPA::map::order,$newidx);
3033: # Store the result
3034: my ($errtext,$fatal) =
3035: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3036: if ($fatal) {
3037: $save_err .= $errtext;
3038: $allresult = 'fail';
3039: }
1.488 raeburn 3040: }
1.538 raeburn 3041:
1.597 raeburn 3042: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
3043: # resourcedata for simpleproblems copied from another course
1.538 raeburn 3044: unless ($allresult eq 'fail') {
3045: my %updated = (
3046: rewrites => \%rewrites,
3047: zombies => \%zombies,
3048: removefrommap => \%removefrommap,
3049: removeparam => \%removeparam,
3050: dbcopies => \%dbcopies,
1.597 raeburn 3051: resdatacopy => \%resdatacopy,
1.538 raeburn 3052: retitles => \%retitles,
3053: );
3054: my %info = (
3055: newsubdir => \%newsubdir,
3056: params => \%params,
3057: );
3058: if ($prefixchg{$suffix}) {
3059: $info{'before'} = $before{$prefixchg{$suffix}};
3060: $info{'after'} = $after{$prefixchg{$suffix}};
3061: }
3062: my %moves = (
3063: copies => \%copies,
3064: docmoves => \%docmoves,
3065: mapmoves => \%mapmoves,
3066: );
3067: (my $result,$msgs{$suffix},my $lockerror) =
3068: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
3069: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
3070: $url,'paste');
3071: $lockerrors .= $lockerror;
3072: if ($result eq 'ok') {
3073: if ($is_map{$suffix}) {
3074: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3075: $folder.'.'.$container);
3076: if ($fatal) {
3077: $allresult = 'failread';
3078: } else {
3079: if ($#LONCAPA::map::order<1) {
3080: my $idx=&LONCAPA::map::getresidx();
3081: if ($idx<=0) { $idx=1; }
3082: $LONCAPA::map::order[0]=$idx;
3083: $LONCAPA::map::resources[$idx]='';
3084: }
3085: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3086: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3087: ':'.$ext.':normal:res';
3088: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 3089:
3090: # Store the result
1.538 raeburn 3091: my ($errtext,$fatal) =
3092: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3093: if ($fatal) {
3094: $save_err .= $errtext;
3095: $allresult = 'failstore';
3096: }
3097: }
3098: }
3099: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
3100: push(@toclear,$suffix);
3101: }
3102: }
1.492 raeburn 3103: }
3104: }
1.704 raeburn 3105: if (($updatetoolscache) || (@updatetoolsenc)) {
3106: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
3107: \@updatetoolsenc);
3108: }
1.538 raeburn 3109: &clear_from_buffer(\@toclear,\@currpaste);
3110: my $msgsarray;
3111: foreach my $suffix (keys(%msgs)) {
3112: if (ref($msgs{$suffix}) eq 'ARRAY') {
3113: $msgsarray .= join(',',@{$msgs{$suffix}});
3114: }
3115: }
3116: return ($allresult,$save_err,$msgsarray,$lockerrors);
3117: }
1.533 raeburn 3118:
1.538 raeburn 3119: sub do_buffer_empty {
3120: my @currpaste = split(/,/,$env{'docs.markedcopies'});
3121: if (@currpaste == 0) {
3122: return &mt('Clipboard is already empty');
3123: }
3124: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
3125: if (@toclear == 0) {
3126: return &mt('Nothing selected to clear from clipboard');
3127: }
3128: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
3129: if ($numdel) {
3130: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
3131: } else {
3132: return &mt('Clipboard unchanged');
1.492 raeburn 3133: }
1.538 raeburn 3134: return;
3135: }
3136:
3137: sub clear_from_buffer {
3138: my ($toclear,$currpaste) = @_;
3139: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
3140: my %pastebuffer;
3141: map { $pastebuffer{$_} = 1; } @{$currpaste};
3142: my $numdel = 0;
3143: foreach my $suffix (@{$toclear}) {
3144: next if ($suffix =~ /\D/);
3145: next unless (exists($pastebuffer{$suffix}));
3146: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
3147: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
3148: delete($pastebuffer{$suffix});
3149: $numdel ++;
3150: }
3151: }
3152: my $newbuffer = join(',',sort(keys(%pastebuffer)));
3153: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
3154: return $numdel;
1.492 raeburn 3155: }
3156:
1.704 raeburn 3157: sub update_ltitools_caches {
3158: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
3159: my $hashid=$coursedom.'_'.$coursenum;
3160: if ($updatetoolscache) {
3161: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3162: }
3163: if ((ref($updatetoolsenc) eq 'ARRAY') &&
3164: (@{$updatetoolsenc})) {
3165: my @ids=&Apache::lonnet::current_machine_ids();
3166: my $updatedone;
3167: foreach my $lonhost (@{$updatetoolsenc}) {
3168: if (grep(/^\Q$lonhost\E$/,@ids)) {
3169: unless ($updatedone) {
3170: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3171: }
3172: $updatedone = 1;
3173: } else {
3174: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
3175: }
3176: }
3177: }
3178: return;
3179: }
3180:
1.492 raeburn 3181: sub get_newmap_url {
3182: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
3183: $titleref,$allmaps,$newurls) = @_;
3184: my $newurl;
3185: if ($url=~ m{^/uploaded/}) {
3186: $$titleref=&mt('Copy of').' '.$$titleref;
3187: }
3188: my $now = time;
3189: my $suffix=$$.int(rand(100)).$now;
3190: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
3191: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
3192: my $path = $1;
3193: my $prefix = $2;
3194: my $ancestor = $3;
3195: if (length($ancestor) > 10) {
3196: $ancestor = substr($ancestor,-10,10);
3197: }
3198: my $newid;
3199: if ($prefixchg) {
3200: if ($folder =~ /^supplemental/) {
3201: $prefix =~ s/^default/supplemental/;
3202: } else {
3203: $prefix =~ s/^supplemental/default/;
3204: }
3205: }
3206: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3207: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3208: } else {
3209: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3210: }
3211: my $counter = 0;
3212: my $is_unique = &uniqueness_check($newurl);
3213: if ($folder =~ /^default/) {
3214: if ($allmaps->{$newurl}) {
3215: $is_unique = 0;
3216: }
3217: }
3218: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3219: $counter ++;
3220: $suffix ++;
3221: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3222: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3223: } else {
3224: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3225: }
3226: $is_unique = &uniqueness_check($newurl);
3227: }
3228: if ($is_unique) {
3229: $newurls->{$newurl} = 1;
3230: } else {
3231: if ($url=~/\.page$/) {
3232: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3233: } else {
3234: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3235: }
3236: }
1.329 droeschl 3237: }
1.492 raeburn 3238: return ($newurl);
1.329 droeschl 3239: }
3240:
1.488 raeburn 3241: sub dbcopy {
1.704 raeburn 3242: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3243: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3244: my ($url,$result,$errtext);
3245: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3246: $url = $dbref->{'src'};
1.627 raeburn 3247: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3248: my $prefix = $1;
1.627 raeburn 3249: if ($prefix eq 'ext.tool') {
3250: $prefix = 'exttool';
3251: }
1.533 raeburn 3252: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3253: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3254: my $db_name;
3255: my $marker = (split(m{/},$url))[4];
3256: $marker=~s/\D//g;
3257: if ($dbref->{'src'} =~ m{/smppg$}) {
3258: $db_name =
3259: &Apache::lonsimplepage::get_db_name($url,$marker,
3260: $dbref->{'cdom'},
3261: $dbref->{'cnum'});
1.627 raeburn 3262: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3263: $db_name = 'exttool_'.$marker;
1.533 raeburn 3264: } else {
3265: $db_name = 'bulletinpage_'.$marker;
3266: }
3267: my ($suffix,$freedlock,$error) =
3268: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3269: $coursedom,$coursenum,
3270: 'concat');
3271: if (!$suffix) {
3272: if ($prefix eq 'smppg') {
3273: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3274: } elsif ($prefix eq 'exttool') {
3275: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3276: } else {
1.565 bisitz 3277: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3278: }
3279: if ($error) {
3280: $errtext .= '<br />'.$error;
3281: }
3282: } else {
3283: #need to copy the db contents to a new one.
3284: my %contents=&Apache::lonnet::dump($db_name,
3285: $dbref->{'cdom'},
3286: $dbref->{'cnum'});
1.704 raeburn 3287: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3288: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3289: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3290: $oldtoolid = $2;
3291: if ($1 eq 'c') {
3292: $defincrs = 1;
3293: %toolinfo =
3294: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3295: } else {
3296: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3297: }
3298: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3299: if ($toolinfo{$oldtoolid}{'passback'}) {
3300: $toolpassback = 1;
3301: }
3302: if ($toolinfo{$oldtoolid}{'roster'}) {
3303: $toolroster = 1;
3304: }
3305: } else {
3306: $toolcopyerror = 1;
3307: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3308: }
3309: }
3310: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3311: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3312: if ($contents{'crstitle'} ne '') {
3313: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3314: }
3315: if (($defincrs) && (!$toolcopyerror)) {
3316: my %newtool;
3317: my $oldcdom = $dbref->{'cdom'};
3318: my $oldcnum = $dbref->{'cnum'};
3319: my $title = $toolinfo{$oldtoolid}{'title'};
3320: if (ref($currltititles) eq 'HASH') {
3321: if (exists($currltititles->{$title})) {
3322: $title .= ' (copied from another course)';
3323: }
3324: }
3325: my ($newid,$iderror) =
3326: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3327: if ($newid =~ /^\d+$/) {
3328: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3329: $newtool{$newid}{'title'} = $title;
3330: if (ref($currltimax)) {
3331: $newtool{$newid}{'order'} = $$currltimax;
3332: }
3333: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3334: my $fname = $1;
3335: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3336: if ($content eq '-1') {
3337: delete($newtool{$newid}{'image'});
3338: } else {
3339: $env{'form.'.$suffix.'.image'} = $content;
3340: my $newlogo =
3341: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3342: delete($env{'form.'.$suffix.'.image'});
3343: if ($newlogo =~ m{^/uploaded/}) {
3344: $newtool{$newid}{'image'} = $newlogo;
3345: } else {
3346: delete($newtool{$newid}{'image'});
3347: }
3348: }
3349: }
3350: my $newusable;
3351: if ($same_institution) {
3352: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3353: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3354: my %newtoolsenc;
3355: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3356: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3357: if ($putres eq 'ok') {
3358: if (ref($updatetoolsenc) eq 'ARRAY') {
3359: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3360: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3361: push(@{$updatetoolsenc},$newhome);
3362: }
3363: }
3364: $newusable = 1;
3365: }
3366: }
3367: }
3368: if ($newtool{$newid}{'usable'}) {
3369: unless ($newusable) {
3370: delete($newtool{$newid}{'usable'});
3371: }
3372: }
3373: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3374: if ($putres eq 'ok') {
3375: $contents{'id'} = "c$newid";
3376: if (ref($updatetoolscache)) {
3377: $$updatetoolscache ++;
3378: }
3379: if (ref($currltititles->{$title}) eq 'ARRAY') {
3380: push(@{$currltititles->{$title}},$newid);
3381: } else {
3382: $currltititles->{$title} = [$newid];
3383: }
3384: if (ref($currltimax)) {
3385: $$currltimax ++;
3386: }
3387: } else {
3388: $toolcopyerror = 1;
3389: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3390: }
3391: } else {
3392: $toolcopyerror = 1;
3393: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3394: }
3395: }
3396: }
3397: }
1.533 raeburn 3398: if (exists($contents{'uploaded.photourl'})) {
3399: my $photo = $contents{'uploaded.photourl'};
3400: my ($subdir,$fname) =
3401: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3402: my $newphoto;
1.533 raeburn 3403: if ($fname ne '') {
3404: my $content = &Apache::lonnet::getfile($photo);
3405: unless ($content eq '-1') {
3406: $env{'form.'.$suffix.'.photourl'} = $content;
3407: $newphoto =
3408: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3409: delete($env{'form.'.$suffix.'.photourl'});
3410: }
3411: }
3412: if ($newphoto =~ m{^/uploaded/}) {
3413: $contents{'uploaded.photourl'} = $newphoto;
3414: }
3415: }
3416: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3417: if ($prefix eq 'exttool') {
3418: unless ($toolcopyerror) {
3419: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3420: if (exists($contents{$key})) {
3421: delete($contents{$key});
3422: }
3423: }
3424: if ($dbref->{'delgradable'}) {
3425: if (exists($contents{'gradable'})) {
3426: delete($contents{'gradable'});
3427: }
3428: }
3429: if ($toolpassback) {
3430: if ($contents{'gradable'}) {
3431: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3432: $contents{'gradesecret'} = $gradesecret;
3433: $contents{'gradesecretdate'} = time;
3434: }
3435: }
3436: if ($toolroster) {
3437: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3438: $contents{'rostersecret'} = $rostersecret;
3439: $contents{'rostersecretdate'} = time;
3440: }
3441: }
1.649 raeburn 3442: }
1.704 raeburn 3443: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3444: $result = 'error';
3445: } else {
3446: $result=&Apache::lonnet::put($db_name,\%contents,
3447: $coursedom,$coursenum);
3448: if ($result eq 'ok') {
3449: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3450: }
1.533 raeburn 3451: }
3452: }
3453: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3454: $lockerrorsref->{$prefix} =
1.533 raeburn 3455: '<div class="LC_error">'.
3456: &mt('There was a problem removing a lockfile.');
3457: if ($prefix eq 'smppg') {
1.560 raeburn 3458: $lockerrorsref->{$prefix} .=
1.559 raeburn 3459: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3460: } elsif ($prefix eq 'exttool') {
3461: $lockerrorsref->{$prefix} .=
3462: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3463: } else {
1.565 bisitz 3464: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3465: }
1.560 raeburn 3466: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3467: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3468: '</div>';
1.533 raeburn 3469: }
3470: }
3471: } elsif ($url =~ m{/syllabus$}) {
3472: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3473: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3474: if (($dbref->{'cdom'} ne $coursedom) ||
3475: ($dbref->{'cnum'} ne $coursenum)) {
3476: my %contents=&Apache::lonnet::dump('syllabus',
3477: $dbref->{'cdom'},
3478: $dbref->{'cnum'});
3479: $result=&Apache::lonnet::put('syllabus',\%contents,
3480: $coursedom,$coursenum);
3481: }
3482: }
1.488 raeburn 3483: }
3484: }
1.533 raeburn 3485: return ($url,$result,$errtext);
1.488 raeburn 3486: }
3487:
1.597 raeburn 3488: sub copy_templated_files {
3489: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3490: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3491: my $srccontainer = 'sequence';
3492: if ($srcwaspage) {
3493: $srccontainer = 'page';
3494: }
3495: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3496: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3497: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3498: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3499: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3500: $template.'.problem';
3501: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3502: if ($template eq 'simpleproblem') {
3503: $srcprefix .= '.0.';
3504: my $weightprefix = $newprefix;
3505: $newprefix .= '.0.';
3506: my @simpleprobqtypes = qw(radio option string essay numerical);
3507: my $qtype=$srcparms{$srcprefix.'questiontype'};
3508: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3509: my %newdata = (
3510: $newprefix.'questiontype' => $qtype,
3511: );
1.597 raeburn 3512: foreach my $type (@simpleprobqtypes) {
3513: if ($type eq $qtype) {
3514: $newdata{"$weightprefix.$type.weight"}=1;
3515: } else {
3516: $newdata{"$weightprefix.$type.weight"}=0;
3517: }
3518: }
3519: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3520: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3521: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3522: if ($qtype eq 'numerical') {
3523: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3524: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3525: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3526: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3527: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3528: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3529: unless (defined($maxfoils)) { $maxfoils=10; }
3530: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3531: if ($maxfoils<=0) { $maxfoils=10; }
3532: my $randomize=$srcparms{$srcprefix.'randomize'};
3533: unless (defined($randomize)) { $randomize='yes'; }
3534: unless ($randomize eq 'no') { $randomize='yes'; }
3535: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3536: $newdata{$newprefix.'randomize'} = $randomize;
3537: if ($qtype eq 'option') {
3538: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3539: }
3540: for (my $i=1; $i<=10; $i++) {
3541: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3542: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3543: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3544: }
3545:
3546: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3547: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3548: unless (defined($maxfoils)) { $maxfoils=10; }
3549: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3550: if ($maxfoils<=0) { $maxfoils=10; }
3551: my $randomize=$srcparms{$srcprefix.'randomize'};
3552: unless (defined($randomize)) { $randomize='yes'; }
3553: unless ($randomize eq 'no') { $randomize='yes'; }
3554: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3555: $newdata{$newprefix.'randomize'} = $randomize;
3556: if ($qtype eq 'option') {
3557: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3558: }
3559: for (my $i=1; $i<=10; $i++) {
3560: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3561: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3562: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3563: }
3564: } elsif ($qtype eq 'string') {
3565: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3566: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3567: }
3568: if (keys(%newdata)) {
3569: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3570: $coursenum);
3571: if ($putres eq 'ok') {
3572: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3573: }
3574: }
3575: }
3576: }
3577: }
3578:
1.329 droeschl 3579: sub uniqueness_check {
3580: my ($newurl) = @_;
3581: my $unique = 1;
3582: foreach my $res (@LONCAPA::map::order) {
3583: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3584: $url=&LONCAPA::map::qtescape($url);
3585: if ($newurl eq $url) {
3586: $unique = 0;
1.344 bisitz 3587: last;
1.329 droeschl 3588: }
3589: }
3590: return $unique;
3591: }
3592:
1.488 raeburn 3593: sub contained_map_check {
1.627 raeburn 3594: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3595: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3596: my $content = &Apache::lonnet::getfile($url);
3597: unless ($content eq '-1') {
3598: my $parser = HTML::TokeParser->new(\$content);
3599: $parser->attr_encoded(1);
3600: while (my $token = $parser->get_token) {
3601: next if ($token->[0] ne 'S');
3602: if ($token->[1] eq 'resource') {
3603: next if ($token->[2]->{'type'} eq 'zombie');
3604: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3605: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3606: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3607: unless ($srcdom eq $coursedom) {
3608: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3609: next;
3610: }
1.704 raeburn 3611: unless ($srcnum eq $coursenum) {
3612: my %toolsettings =
3613: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3614: my %tooltypes = &Apache::loncommon::usable_exttools();
3615: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3616: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3617: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3618: next;
3619: }
3620: }
1.627 raeburn 3621: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3622: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3623: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3624: next;
3625: }
3626: }
1.703 raeburn 3627: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3628: my ($srcdom,$srcnum) = ($1,$2);
3629: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3630: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3631: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3632: next;
3633: }
3634: }
3635: }
1.492 raeburn 3636: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3637: if ($1 eq 'uploaded') {
3638: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3639: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3640: } else {
1.492 raeburn 3641: if ($allmaps->{$ressrc}) {
1.529 raeburn 3642: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3643: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3644: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3645: } else {
3646: $addedmaps->{$ressrc} = [$url];
3647: }
1.488 raeburn 3648: }
1.627 raeburn 3649: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3650: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3651: }
1.492 raeburn 3652: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3653: if ($folder =~ /^supplemental/) {
1.492 raeburn 3654: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3655: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3656: } else {
3657: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3658: }
1.488 raeburn 3659: }
3660: }
3661: }
3662: }
3663: return;
3664: }
3665:
3666: sub url_paste_fixups {
1.533 raeburn 3667: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3668: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3669: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3670: my $checktitle;
3671: if (($prefixchg) &&
1.492 raeburn 3672: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3673: $checktitle = 1;
3674: }
1.492 raeburn 3675: my $skip;
3676: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3677: my $mapid = $1.$2;
3678: if ($tomove->{$mapid}) {
3679: $skip = 1;
3680: }
3681: }
1.491 raeburn 3682: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3683: return if ($file eq '-1');
3684: my $parser = HTML::TokeParser->new(\$file);
3685: $parser->attr_encoded(1);
1.491 raeburn 3686: my $changed = 0;
1.488 raeburn 3687: while (my $token = $parser->get_token) {
3688: next if ($token->[0] ne 'S');
3689: if ($token->[1] eq 'resource') {
3690: my $ressrc = $token->[2]->{'src'};
3691: next if ($ressrc eq '');
1.491 raeburn 3692: my $id = $token->[2]->{'id'};
1.492 raeburn 3693: my $title = $token->[2]->{'title'};
1.491 raeburn 3694: if ($checktitle) {
3695: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3696: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3697: }
3698: }
1.488 raeburn 3699: next if ($token->[2]->{'type'} eq 'external');
3700: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3701: next if ($skip);
1.532 raeburn 3702: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3703: $changed = 1;
3704: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3705: my $srcdom = $1;
3706: my $srcnum = $2;
1.488 raeburn 3707: my $rem = $3;
1.492 raeburn 3708: my $newurl;
3709: my $mapname;
3710: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3711: my $prefix = $1;
3712: $mapname = $prefix.$2;
3713: if ($tomove->{$mapname}) {
1.533 raeburn 3714: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3715: $srcdom,$srcnum,$allmaps,$rewrites,
3716: $retitles,$copies,$dbcopies,$zombies,
3717: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3718: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3719: next;
3720: } else {
3721: ($newurl,my $error) =
3722: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3723: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3724: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3725: $newsubdir->{$ressrc} = $1;
3726: }
3727: if ($error) {
3728: next;
3729: }
3730: }
3731: }
3732: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3733: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3734:
1.488 raeburn 3735: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3736: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3737: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3738: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3739: $cnum,$srcdom,$srcnum,$allmaps,
3740: $rewrites,$retitles,$copies,$dbcopies,
3741: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3742: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3743: $mapmoves->{$ressrc} = 1;
3744: }
3745: $changed = 1;
1.488 raeburn 3746: } else {
1.532 raeburn 3747: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3748: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3749: $changed = 1;
1.488 raeburn 3750: }
3751: }
1.649 raeburn 3752: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3753: next if ($skip);
1.492 raeburn 3754: my $srcdom = $1;
3755: my $srcnum = $2;
1.649 raeburn 3756: my $rem = $3;
3757: my ($is_exttool,$exttoolchg);
3758: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3759: $is_exttool = 1;
1.649 raeburn 3760: }
1.492 raeburn 3761: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3762: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3763: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3764: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3765: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3766: $changed = 1;
1.649 raeburn 3767: if ($is_exttool) {
3768: $exttoolchg = 1;
3769: }
1.700 raeburn 3770: } elsif (($is_exttool) &&
1.649 raeburn 3771: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3772: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3773: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3774: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3775: $changed = 1;
3776: $exttoolchg = 1;
3777: }
3778: if (($is_exttool) && ($prefixchg)) {
3779: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3780: if ($exttoolchg) {
3781: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3782: }
3783: }
1.533 raeburn 3784: }
3785: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3786: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3787: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3788: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3789: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3790: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3791: $changed = 1;
1.488 raeburn 3792: }
1.597 raeburn 3793: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3794: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3795: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3796: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3797: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3798: }
1.488 raeburn 3799: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3800: next if ($skip);
3801: my $srcdom = $1;
3802: my $srcnum = $2;
3803: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3804: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3805: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3806: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3807: $changed = 1;
1.488 raeburn 3808: }
3809: }
3810: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3811: next if ($skip);
1.488 raeburn 3812: my $to = $token->[2]->{'to'};
3813: if ($to ne '') {
3814: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3815: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3816: } else {
3817: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3818: }
3819: }
3820: }
3821: }
1.491 raeburn 3822: return $changed;
1.488 raeburn 3823: }
3824:
3825: sub apply_fixups {
1.529 raeburn 3826: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3827: $oldurl,$url,$caller) = @_;
3828: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3829: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3830: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3831: %currltititles,$currltimax);
3832: $currltimax = 0;
1.529 raeburn 3833: if (ref($updated) eq 'HASH') {
3834: if (ref($updated->{'rewrites'}) eq 'HASH') {
3835: %rewrites = %{$updated->{'rewrites'}};
3836: }
3837: if (ref($updated->{'zombies'}) eq 'HASH') {
3838: %zombies = %{$updated->{'zombies'}};
3839: }
3840: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3841: %removefrommap = %{$updated->{'removefrommap'}};
3842: }
3843: if (ref($updated->{'removeparam'}) eq 'HASH') {
3844: %removeparam = %{$updated->{'removeparam'}};
3845: }
3846: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3847: %dbcopies = %{$updated->{'dbcopies'}};
3848: }
3849: if (ref($updated->{'retitles'}) eq 'HASH') {
3850: %retitles = %{$updated->{'retitles'}};
3851: }
1.597 raeburn 3852: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3853: %resdatacopy = %{$updated->{'resdatacopy'}};
3854: }
1.529 raeburn 3855: }
3856: if (ref($info) eq 'HASH') {
3857: if (ref($info->{'newsubdir'}) eq 'HASH') {
3858: %newsubdir = %{$info->{'newsubdir'}};
3859: }
3860: if (ref($info->{'params'}) eq 'HASH') {
3861: %params = %{$info->{'params'}};
3862: }
3863: if (ref($info->{'before'}) eq 'HASH') {
3864: %before = %{$info->{'before'}};
3865: }
3866: if (ref($info->{'after'}) eq 'HASH') {
3867: %after = %{$info->{'after'}};
3868: }
3869: }
3870: if (ref($moves) eq 'HASH') {
3871: if (ref($moves->{'copies'}) eq 'HASH') {
3872: %copies = %{$moves->{'copies'}};
3873: }
3874: if (ref($moves->{'docmoves'}) eq 'HASH') {
3875: %docmoves = %{$moves->{'docmoves'}};
3876: }
3877: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3878: %mapmoves = %{$moves->{'mapmoves'}};
3879: }
3880: }
3881: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 3882: my @allcopies;
1.529 raeburn 3883: if (exists($copies{$key})) {
3884: if (ref($copies{$key}) eq 'HASH') {
3885: my %added;
3886: foreach my $innerkey (keys(%{$copies{$key}})) {
3887: if (($innerkey ne '') && (!$added{$innerkey})) {
3888: push(@allcopies,$innerkey);
3889: $added{$innerkey} = 1;
3890: }
1.491 raeburn 3891: }
1.529 raeburn 3892: undef(%added);
1.491 raeburn 3893: }
3894: }
3895: if ($key eq $oldurl) {
1.529 raeburn 3896: if ((exists($docmoves{$key}))) {
1.532 raeburn 3897: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 3898: push(@allcopies,$oldurl);
3899: }
3900: }
3901: }
3902: if (@allcopies > 0) {
3903: foreach my $item (@allcopies) {
1.492 raeburn 3904: my ($relpath,$oldsubdir,$fname) =
3905: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 3906: if ($fname ne '') {
3907: my $content = &Apache::lonnet::getfile($item);
3908: unless ($content eq '-1') {
3909: my $storefn;
1.529 raeburn 3910: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3911: $storefn = $docmoves{$key};
1.491 raeburn 3912: } else {
3913: $storefn = $relpath;
3914: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3915: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3916: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 3917: }
1.529 raeburn 3918: if ($newsubdir{$key}) {
1.532 raeburn 3919: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 3920: }
3921: }
3922: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3923: my $copyurl =
3924: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3925: $storefn.$fname,$content);
3926: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 3927: if (exists($docmoves{$oldurl})) {
1.491 raeburn 3928: return &mt('Paste failed: an error occurred copying the file.');
3929: } elsif (ref($errors) eq 'HASH') {
3930: $errors->{$item} = 1;
1.489 raeburn 3931: }
3932: }
1.488 raeburn 3933: }
3934: }
1.491 raeburn 3935: }
3936: }
3937: }
1.529 raeburn 3938: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 3939: my $storefn=$key;
3940: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3941: if ($prefixchg && $before{'map'} && $after{'map'}) {
3942: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3943: }
1.529 raeburn 3944: if ($newsubdir{$key}) {
3945: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3946: }
1.491 raeburn 3947: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 3948: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3949: ($after{'map'} eq 'default') &&
3950: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3951: $mapcontent = '<map>'."\n".
3952: '<resource id="1" src="" type="start" />'."\n".
3953: '<link from="1" to="2" index="1" />'."\n".
3954: '<resource id="2" src="" type="finish" />'."\n".
3955: '</map>';
3956: }
1.491 raeburn 3957: if ($mapcontent eq '-1') {
3958: if (ref($errors) eq 'HASH') {
3959: $errors->{$key} = 1;
3960: }
3961: } else {
3962: my $newmap =
3963: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3964: $mapcontent);
3965: if ($newmap eq '/adm/notfound.html') {
3966: if (ref($errors) eq 'HASH') {
3967: $errors->{$key} = 1;
1.489 raeburn 3968: }
1.488 raeburn 3969: }
3970: }
3971: }
1.491 raeburn 3972: my %updates;
3973: if ($is_map) {
1.529 raeburn 3974: if (ref($updated) eq 'HASH') {
3975: foreach my $type (keys(%{$updated})) {
3976: if (ref($updated->{$type}) eq 'HASH') {
3977: foreach my $key (keys(%{$updated->{$type}})) {
3978: $updates{$key} = 1;
3979: }
3980: }
3981: }
1.491 raeburn 3982: }
1.704 raeburn 3983: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 3984: foreach my $key (keys(%updates)) {
1.492 raeburn 3985: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 3986: if (ref($rewrites{$key}) eq 'HASH') {
3987: %torewrite = %{$rewrites{$key}};
1.491 raeburn 3988: }
1.529 raeburn 3989: if (ref($retitles{$key}) eq 'HASH') {
3990: %toretitle = %{$retitles{$key}};
1.491 raeburn 3991: }
1.529 raeburn 3992: if (ref($removefrommap{$key}) eq 'HASH') {
3993: %toremove = %{$removefrommap{$key}};
1.491 raeburn 3994: }
1.529 raeburn 3995: if (ref($removeparam{$key}) eq 'HASH') {
3996: %remparam = %{$removeparam{$key}};
1.492 raeburn 3997: }
1.529 raeburn 3998: if (ref($zombies{$key}) eq 'HASH') {
3999: %zombie = %{$zombies{$key}};
1.491 raeburn 4000: }
1.529 raeburn 4001: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 4002: foreach my $idx (keys(%{$dbcopies{$key}})) {
4003: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 4004: my $oldurl = $dbcopies{$key}{$idx}{'src'};
4005: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
4006: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
4007: my $oldmarker;
4008: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
4009: $oldmarker = $1;
4010: unless (($gotcrsltitools) ||
4011: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
4012: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
4013: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
4014: unless ($gotcrsltitools) {
4015: %currcrsltitools =
4016: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
4017: foreach my $item (sort(keys(%currcrsltitools))) {
4018: if (ref($currcrsltitools{$item}) eq 'HASH') {
4019: $currltimax ++;
4020: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
4021: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
4022: } else {
4023: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
4024: }
4025: }
4026: }
4027: $gotcrsltitools = 1;
4028: }
4029: unless ($checkedsameinst) {
4030: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
4031: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4032: if ($intdom ne '') {
4033: my $internet_names =
4034: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4035: if (ref($internet_names) eq 'ARRAY') {
4036: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4037: $same_institution = 1;
4038: }
4039: }
4040: }
4041: $checkedsameinst = 1;
4042: }
4043: }
4044: }
4045: }
1.533 raeburn 4046: my ($newurl,$result,$errtext) =
1.704 raeburn 4047: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
4048: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 4049: if ($result eq 'ok') {
4050: $newdb{$idx} = $newurl;
1.704 raeburn 4051: if ($newurl =~ /ext\.tool$/) {
4052: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
4053: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
4054: my $newmarker = $1;
4055: unless ($oldmarker eq $newmarker) {
4056: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
4057: }
4058: }
4059: }
4060: }
1.533 raeburn 4061: } elsif (ref($errors) eq 'HASH') {
4062: $errors->{$key} = 1;
4063: }
4064: push(@msgs,$errtext);
4065: }
1.491 raeburn 4066: }
4067: }
1.597 raeburn 4068: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 4069: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 4070: foreach my $idx (keys(%{$resdatacopy{$key}})) {
4071: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
4072: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
4073: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
4074: my $template = $1;
4075: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
4076: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
4077: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
4078: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 4079: unless ($gotnewmapname) {
4080: ($newmapname) = ($key =~ m{/([^/]+)$});
4081: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
4082: if ($newsubdir{$key}) {
4083: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
4084: }
4085: $gotnewmapname = 1;
4086: }
1.597 raeburn 4087: my $srcmapinfo = $srcfolder.':'.$idx;
4088: if ($srccontainer eq 'page') {
4089: $srcmapinfo .= ':1';
4090: }
4091: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
4092: $cnum,$template,$idx,$newmapname);
4093: }
4094: }
4095: }
4096: }
4097: }
1.529 raeburn 4098: if (ref($params{$key}) eq 'HASH') {
4099: %currparam = %{$params{$key}};
1.492 raeburn 4100: }
4101: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
4102: if ($fatal) {
1.533 raeburn 4103: return ($errtext);
1.492 raeburn 4104: }
4105: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
4106: if (defined($LONCAPA::map::zombies[$i])) {
4107: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 4108: if ($zombie{$i} eq $src) {
1.492 raeburn 4109: undef($LONCAPA::map::zombies[$i]);
4110: }
4111: }
4112: }
1.646 raeburn 4113: my $total = scalar(@LONCAPA::map::order) - 1;
4114: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 4115: my $idx = $LONCAPA::map::order[$i];
4116: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 4117: my $changed;
1.529 raeburn 4118: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 4119: if ((exists($toremove{$idx})) &&
4120: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 4121: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 4122: if (ref($currparam{$idx}) eq 'ARRAY') {
4123: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 4124: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 4125: }
4126: }
4127: next;
4128: }
4129: my $origsrc = $src;
1.532 raeburn 4130: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 4131: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
4132: $changed = 1;
1.491 raeburn 4133: }
1.492 raeburn 4134: }
1.532 raeburn 4135: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 4136: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
4137: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 4138: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 4139: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 4140: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 4141: } else {
1.529 raeburn 4142: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 4143: }
1.491 raeburn 4144: }
1.532 raeburn 4145: if ($origsrc =~ /\.(page|sequence)$/) {
4146: if ($newsubdir{$origsrc}) {
1.529 raeburn 4147: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 4148: }
1.532 raeburn 4149: } elsif ($newsubdir{$key}) {
4150: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 4151: }
4152: }
1.492 raeburn 4153: $changed = 1;
1.533 raeburn 4154: } elsif ($newdb{$idx} ne '') {
4155: $src = $newdb{$idx};
1.492 raeburn 4156: $changed = 1;
4157: }
4158: if ($changed) {
1.538 raeburn 4159: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 4160: }
4161: }
4162: }
4163: foreach my $idx (keys(%remparam)) {
4164: if (ref($remparam{$idx}) eq 'ARRAY') {
4165: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 4166: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 4167: }
4168: }
4169: }
1.533 raeburn 4170: if (values(%lockerrors) > 0) {
4171: $lockmsg = join('<br />',values(%lockerrors));
4172: }
1.491 raeburn 4173: my $storefn;
4174: if ($key eq $oldurl) {
4175: $storefn = $url;
4176: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
4177: } else {
4178: $storefn = $key;
4179: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4180: if ($prefixchg && $before{'map'} && $after{'map'}) {
4181: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4182: }
1.529 raeburn 4183: if ($newsubdir{$key}) {
4184: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4185: }
1.491 raeburn 4186: }
1.492 raeburn 4187: my $report;
4188: if ($folder !~ /^supplemental/) {
4189: $report = 1;
4190: }
1.527 raeburn 4191: (my $outtext,$errtext) =
1.492 raeburn 4192: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
4193: if ($errtext) {
1.529 raeburn 4194: if ($caller eq 'paste') {
1.533 raeburn 4195: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 4196: }
1.491 raeburn 4197: }
4198: }
1.704 raeburn 4199: if (($updatetoolscache) || (@updatetoolsenc)) {
4200: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
4201: \@updatetoolsenc);
4202: }
1.491 raeburn 4203: }
1.533 raeburn 4204: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 4205: }
4206:
4207: sub copy_dependencies {
4208: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4209: my $content;
4210: if (ref($contentref)) {
4211: $content = $$contentref;
4212: } else {
4213: $content = &Apache::lonnet::getfile($item);
4214: }
4215: unless ($content eq '-1') {
4216: my $mm = new File::MMagic;
4217: my $mimetype = $mm->checktype_contents($content);
4218: if ($mimetype eq 'text/html') {
4219: my (%allfiles,%codebase,$state);
4220: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4221: if ($res eq 'ok') {
4222: my ($numexisting,$numpathchanges,$existing);
4223: (undef,$numexisting,$numpathchanges,$existing) =
4224: &Apache::loncommon::ask_for_embedded_content(
4225: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4226: {'error_on_invalid_names' => 1,
4227: 'ignore_remote_references' => 1,
4228: 'docs_url' => $item,
4229: 'context' => 'paste'});
4230: if ($numexisting > 0) {
4231: if (ref($existing) eq 'HASH') {
4232: foreach my $dep (keys(%{$existing})) {
4233: my $depfile = $dep;
4234: unless ($depfile =~ m{^\Q$relpath\E}) {
4235: $depfile = $relpath.$dep;
4236: }
4237: my $depcontent = &Apache::lonnet::getfile($depfile);
4238: unless ($depcontent eq '-1') {
4239: my $storedep = $dep;
4240: $storedep =~ s{^\Q$relpath\E}{};
4241: my $dep_url =
4242: &Apache::lonclonecourse::writefile(
4243: $env{'request.course.id'},
4244: $storefn.$storedep,$depcontent);
4245: if ($dep_url eq '/adm/notfound.html') {
4246: if (ref($errors) eq 'HASH') {
4247: $errors->{$depfile} = 1;
4248: }
4249: } else {
4250: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4251: }
4252: }
4253: }
1.488 raeburn 4254: }
4255: }
4256: }
4257: }
4258: }
4259: return;
4260: }
4261:
1.329 droeschl 4262: my %parameter_type = ( 'randompick' => 'int_pos',
4263: 'hiddenresource' => 'string_yesno',
4264: 'encrypturl' => 'string_yesno',
4265: 'randomorder' => 'string_yesno',);
4266: my $valid_parameters_re = join('|',keys(%parameter_type));
4267: # set parameters
4268: sub update_parameter {
1.537 raeburn 4269: if ($env{'form.changeparms'} eq 'all') {
4270: my (@allidx,@allmapidx,%allchecked,%currchecked);
4271: %allchecked = (
4272: 'hiddenresource' => {},
4273: 'encrypturl' => {},
4274: 'randompick' => {},
4275: 'randomorder' => {},
4276: );
4277: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4278: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4279: if ($which eq 'randompick') {
4280: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4281: my ($res,$value) = split(/:/,$item);
4282: if ($value =~ /^\d+$/) {
4283: $allchecked{$which}{$res} = $value;
4284: }
4285: }
4286: } else {
1.539 raeburn 4287: if ($env{'form.all'.$which}) {
4288: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4289: }
1.537 raeburn 4290: }
4291: }
4292: my $haschanges = 0;
4293: foreach my $res (@LONCAPA::map::order) {
4294: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4295: $name=&LONCAPA::map::qtescape($name);
4296: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4297: next unless $url;
1.537 raeburn 4298: my $is_map;
4299: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4300: $is_map = 1;
4301: }
4302: foreach my $which (keys(%allchecked)) {
4303: if (($which eq 'randompick' || $which eq 'randomorder')) {
4304: next if (!$is_map);
4305: }
4306: my $oldvalue = 0;
4307: my $newvalue = 0;
4308: if ($allchecked{$which}{$res}) {
4309: $newvalue = $allchecked{$which}{$res};
4310: }
4311: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4312: if ($which eq 'randompick') {
4313: if ($current =~ /^(\d+)$/) {
4314: $oldvalue = $1;
4315: }
4316: } else {
4317: if ($current =~ /^yes$/i) {
4318: $oldvalue = 1;
4319: }
4320: }
4321: if ($oldvalue ne $newvalue) {
4322: $haschanges = 1;
4323: if ($newvalue) {
4324: my $storeval = 'yes';
4325: if ($which eq 'randompick') {
4326: $storeval = $newvalue;
4327: }
4328: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4329: $storeval,
4330: $parameter_type{$which});
4331: &remember_parms($res,$which,'set',$storeval);
4332: } elsif ($oldvalue) {
4333: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4334: &remember_parms($res,$which,'del');
4335: }
4336: }
4337: }
4338: }
4339: return $haschanges;
4340: } else {
1.588 raeburn 4341: my $haschanges = 0;
4342: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4343:
1.537 raeburn 4344: my $which = $env{'form.changeparms'};
4345: my $idx = $env{'form.setparms'};
1.588 raeburn 4346: my $oldvalue = 0;
4347: my $newvalue = 0;
4348: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4349: if ($which eq 'randompick') {
4350: if ($current =~ /^(\d+)$/) {
4351: $oldvalue = $1;
4352: }
4353: } elsif ($current =~ /^yes$/i) {
4354: $oldvalue = 1;
4355: }
1.537 raeburn 4356: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4357: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4358: : 1;
4359: }
4360: if ($oldvalue ne $newvalue) {
4361: $haschanges = 1;
4362: if ($newvalue) {
4363: my $storeval = 'yes';
4364: if ($which eq 'randompick') {
4365: $storeval = $newvalue;
4366: }
4367: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4368: $parameter_type{$which});
4369: &remember_parms($idx,$which,'set',$storeval);
4370: } else {
4371: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4372: &remember_parms($idx,$which,'del');
4373: }
1.537 raeburn 4374: }
1.588 raeburn 4375: return $haschanges;
1.329 droeschl 4376: }
4377: }
4378:
4379: sub handle_edit_cmd {
4380: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4381: my $haschanges = 0;
1.543 raeburn 4382: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4383: return $haschanges;
1.543 raeburn 4384: }
1.329 droeschl 4385: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4386:
4387: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4388: my ($title, $url, @rrest) = split(':', $ratstr);
4389:
1.538 raeburn 4390: if ($cmd eq 'remove') {
1.329 droeschl 4391: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4392: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4393: &Apache::lonnet::removeuploadedurl($url);
4394: } else {
4395: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4396: }
4397: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4398: $haschanges = 1;
1.329 droeschl 4399: } elsif ($cmd eq 'cut') {
4400: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4401: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4402: $haschanges = 1;
1.344 bisitz 4403: } elsif ($cmd eq 'up'
1.329 droeschl 4404: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4405: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4406: $haschanges = 1;
1.329 droeschl 4407: } elsif ($cmd eq 'down'
4408: && defined($LONCAPA::map::order[$idx+1])) {
4409: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4410: $haschanges = 1;
1.329 droeschl 4411: } elsif ($cmd eq 'rename') {
4412: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4413: if ($comment=~/\S/) {
4414: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4415: $comment.':'.join(':', $url, @rrest);
4416: }
4417: # Devalidate title cache
4418: my $renamed_url=&LONCAPA::map::qtescape($url);
4419: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4420: $haschanges = 1;
4421: } elsif ($cmd eq 'setalias') {
4422: my $newvalue = $env{'form.alias'};
4423: if ($newvalue ne '') {
4424: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4425: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4426: 'string');
4427: &remember_parms($idx,'mapalias','set',$newvalue);
4428: $haschanges = 1;
4429: }
4430: }
4431: } elsif ($cmd eq 'delalias') {
4432: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4433: if ($current ne '') {
4434: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4435: &remember_parms($idx,'mapalias','del');
4436: $haschanges = 1;
4437: }
1.329 droeschl 4438: }
1.633 raeburn 4439: return $haschanges;
1.329 droeschl 4440: }
4441:
4442: sub editor {
1.458 raeburn 4443: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4444: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4445: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4446: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4447: if ($allowed) {
1.519 raeburn 4448: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4449: $is_random_order,$container) =
1.510 raeburn 4450: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4451: $r->print($breadcrumbtrail);
1.519 raeburn 4452: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4453: $container = 'page';
4454: } else {
4455: $container = 'sequence';
1.510 raeburn 4456: }
1.484 raeburn 4457:
1.525 raeburn 4458: my $jumpto;
4459:
4460: unless ($supplementalflag) {
1.546 raeburn 4461: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4462: }
1.484 raeburn 4463:
4464: unless ($allowed) {
4465: $randompick = -1;
4466: }
4467:
1.615 raeburn 4468: my ($errtext,$fatal);
4469: if (($folder eq '') && (!$supplementalflag)) {
4470: if (@LONCAPA::map::order) {
4471: undef(@LONCAPA::map::order);
4472: undef(@LONCAPA::map::resources);
4473: undef(@LONCAPA::map::resparms);
4474: undef(@LONCAPA::map::zombies);
4475: }
4476: $folder = 'default';
4477: $container = 'sequence';
4478: } else {
4479: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4480: $folder.'.'.$container);
4481: return $errtext if ($fatal);
4482: }
1.329 droeschl 4483:
4484: if ($#LONCAPA::map::order<1) {
4485: my $idx=&LONCAPA::map::getresidx();
4486: if ($idx<=0) { $idx=1; }
4487: $LONCAPA::map::order[0]=$idx;
4488: $LONCAPA::map::resources[$idx]='';
4489: }
1.364 bisitz 4490:
1.329 droeschl 4491: # ------------------------------------------------------------ Process commands
4492:
4493: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4494: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4495: # set parameters and change order
4496: &snapshotbefore();
4497:
4498: if (&update_parameter()) {
1.588 raeburn 4499: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4500: return $errtext if ($fatal);
4501: }
4502:
4503: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4504: # change order
4505: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4506: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4507:
4508: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4509: return $errtext if ($fatal);
4510: }
1.364 bisitz 4511:
1.329 droeschl 4512: if ($env{'form.pastemarked'}) {
1.491 raeburn 4513: my %paste_errors;
1.533 raeburn 4514: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4515: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4516: \%paste_errors);
1.541 raeburn 4517: if (ref($pastemsgarray) eq 'ARRAY') {
4518: if (@{$pastemsgarray} > 0) {
4519: $r->print('<p class="LC_info">'.
4520: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4521: '</p>');
4522: }
1.541 raeburn 4523: }
4524: if ($lockerror) {
4525: $r->print('<p class="LC_error">'.
4526: $lockerror.
4527: '</p>');
4528: }
4529: if ($save_error ne '') {
4530: return $save_error;
4531: }
4532: if ($paste_res) {
4533: my %errortext = &Apache::lonlocal::texthash (
4534: fail => 'Storage of folder contents failed',
4535: failread => 'Reading folder contents failed',
4536: failstore => 'Storage of folder contents failed',
4537: );
4538: if ($errortext{$paste_res}) {
4539: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4540: }
1.329 droeschl 4541: }
1.491 raeburn 4542: if (keys(%paste_errors) > 0) {
1.538 raeburn 4543: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4544: &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".
4545: '<ul>'."\n");
4546: foreach my $key (sort(keys(%paste_errors))) {
4547: $r->print('<li>'.$key.'</li>'."\n");
4548: }
4549: $r->print('</ul></p>'."\n");
4550: }
1.538 raeburn 4551: } elsif ($env{'form.clearmarked'}) {
4552: my $output = &do_buffer_empty();
4553: if ($output) {
4554: $r->print('<p class="LC_info">'.$output.'</p>');
4555: }
4556: }
1.329 droeschl 4557:
4558: $r->print($upload_output);
4559:
1.538 raeburn 4560: # Rename, cut, copy or remove a single resource
1.602 raeburn 4561: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4562: my $contentchg;
1.633 raeburn 4563: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4564: $contentchg = 1;
4565: }
4566: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4567: return $errtext if ($fatal);
4568: }
1.538 raeburn 4569:
4570: # Cut, copy and/or remove multiple resources
4571: if ($env{'form.multichange'}) {
4572: my %allchecked = (
4573: cut => {},
4574: remove => {},
4575: );
4576: my $needsupdate;
4577: foreach my $which (keys(%allchecked)) {
4578: $env{'form.multi'.$which} =~ s/,$//;
4579: if ($env{'form.multi'.$which}) {
4580: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4581: if (ref($allchecked{$which}) eq 'HASH') {
4582: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4583: }
4584: }
4585: }
4586: if ($needsupdate) {
4587: my $haschanges = 0;
4588: my %curr_groups = &Apache::longroup::coursegroups();
4589: my $total = scalar(@LONCAPA::map::order) - 1;
4590: for (my $i=$total; $i>=0; $i--) {
4591: my $res = $LONCAPA::map::order[$i];
4592: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4593: $name=&LONCAPA::map::qtescape($name);
4594: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4595: next unless $url;
1.538 raeburn 4596: my %denied =
4597: &action_restrictions($coursenum,$coursedom,$url,
4598: $env{'form.folderpath'},\%curr_groups);
4599: foreach my $which (keys(%allchecked)) {
4600: next if ($denied{$which});
4601: next unless ($allchecked{$which}{$res});
4602: if ($which eq 'remove') {
4603: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4604: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4605: &Apache::lonnet::removeuploadedurl($url);
4606: } else {
4607: &LONCAPA::map::makezombie($res);
4608: }
4609: splice(@LONCAPA::map::order,$i,1);
4610: $haschanges ++;
4611: } elsif ($which eq 'cut') {
4612: &LONCAPA::map::makezombie($res);
4613: splice(@LONCAPA::map::order,$i,1);
4614: $haschanges ++;
4615: }
4616: }
4617: }
4618: if ($haschanges) {
4619: ($errtext,$fatal) =
4620: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4621: return $errtext if ($fatal);
4622: }
4623: }
4624: }
4625:
1.329 droeschl 4626: # Group import/search
4627: if ($env{'form.importdetail'}) {
4628: my @imports;
4629: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4630: if (defined($item)) {
4631: my ($name,$url,$residx)=
1.533 raeburn 4632: map { &unescape($_); } split(/\=/,$item);
4633: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4634: my ($suffix,$errortxt,$locknotfreed) =
4635: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4636: if ($locknotfreed) {
4637: $r->print($locknotfreed);
4638: }
4639: if ($suffix) {
4640: $url =~ s/_new\./_$suffix./;
4641: } else {
4642: return $errortxt;
4643: }
1.533 raeburn 4644: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4645: my $type = $1;
4646: my ($suffix,$errortxt,$locknotfreed) =
4647: &new_timebased_suffix($coursedom,$coursenum,$type);
4648: if ($locknotfreed) {
4649: $r->print($locknotfreed);
4650: }
4651: if ($suffix) {
4652: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4653: } else {
4654: return $errortxt;
4655: }
1.626 raeburn 4656: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4657: my ($suffix,$errortxt,$locknotfreed) =
4658: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4659: if ($locknotfreed) {
4660: $r->print($locknotfreed);
4661: }
4662: if ($suffix) {
4663: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4664: } else {
4665: return $errortxt;
4666: }
1.534 raeburn 4667: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4668: if ($supplementalflag) {
4669: next unless ($1 eq 'supplemental');
4670: if ($folder eq 'supplemental') {
4671: next unless ($2 eq 'default');
4672: } else {
4673: next unless ($folder eq 'supplemental_'.$2);
4674: }
4675: } else {
4676: next unless ($1 eq 'docs');
4677: if ($folder eq 'default') {
4678: next unless ($2 eq 'default');
4679: } else {
4680: next unless ($folder eq 'default_'.$2);
4681: }
4682: }
1.504 raeburn 4683: }
1.329 droeschl 4684: push(@imports, [$name, $url, $residx]);
4685: }
4686: }
1.530 raeburn 4687: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4688: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4689: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4690: return $errtext if ($fatal);
1.529 raeburn 4691: if ($fixuperrors) {
4692: $r->print($fixuperrors);
4693: }
1.329 droeschl 4694: }
4695: # Loading a complete map
4696: if ($env{'form.loadmap'}) {
4697: if ($env{'form.importmap'}=~/\w/) {
4698: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4699: my ($title,$url,$ext,$type)=split(/\:/,$res);
4700: my $idx=&LONCAPA::map::getresidx($url);
4701: $LONCAPA::map::resources[$idx]=$res;
4702: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4703: }
4704: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4705: $folder.'.'.$container,1);
1.329 droeschl 4706: return $errtext if ($fatal);
4707: } else {
4708: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4709:
1.329 droeschl 4710: }
4711: }
4712: &log_differences($plain);
4713: }
4714: # ---------------------------------------------------------------- End commands
4715: # ---------------------------------------------------------------- Print screen
4716: my $idx=0;
4717: my $shown=0;
4718: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4719: $r->print('<div class="LC_Box">'.
1.432 raeburn 4720: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4721: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4722: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4723: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4724: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4725: '</ol>');
1.381 bisitz 4726: if ($randompick>=0) {
4727: $r->print('<p class="LC_warning">'
4728: .&mt('Caution: this folder is set to randomly pick a subset'
4729: .' of resources. Adding or removing resources from this'
4730: .' folder will change the set of resources that the'
4731: .' students see, resulting in spurious or missing credit'
4732: .' for completed problems, not limited to ones you'
4733: .' modify. Do not modify the contents of this folder if'
4734: .' it is in active student use.')
4735: .'</p>'
4736: );
4737: }
4738: if ($is_random_order) {
4739: $r->print('<p class="LC_warning">'
4740: .&mt('Caution: this folder is set to randomly order its'
4741: .' contents. Adding or removing resources from this folder'
4742: .' will change the order of resources shown.')
4743: .'</p>'
4744: );
4745: }
4746: $r->print('</div>');
1.364 bisitz 4747: }
1.381 bisitz 4748:
1.685 raeburn 4749: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4750: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4751: if (ref($supplemental) eq 'HASH') {
4752: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4753: (ref($supplemental->{'ids'}) eq 'HASH')) {
4754: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4755: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4756: if ($supplemental->{'hidden'}->{$mapnum}) {
4757: $ishidden = 1;
4758: }
4759: }
4760: }
4761: }
4762: }
4763:
1.538 raeburn 4764: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4765: %filters = (
1.543 raeburn 4766: canremove => [],
4767: cancut => [],
4768: cancopy => [],
4769: hiddenresource => [],
4770: encrypturl => [],
4771: randomorder => [],
4772: randompick => [],
1.538 raeburn 4773: );
4774: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4775: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4776: foreach my $res (@LONCAPA::map::order) {
4777: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4778: $name=&LONCAPA::map::qtescape($name);
4779: $url=&LONCAPA::map::qtescape($url);
4780: unless ($name) { $name=(split(/\//,$url))[-1]; }
4781: unless ($name) { $idx++; next; }
1.537 raeburn 4782: push(@allidx,$res);
4783: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4784: push(@allmapidx,$res);
4785: }
1.617 raeburn 4786:
1.682 raeburn 4787: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4788: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4789: $idx++;
4790: next;
4791: }
1.682 raeburn 4792: }
1.381 bisitz 4793: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4794: $coursenum,$coursedom,$crstype,
1.538 raeburn 4795: $pathitem,$supplementalflag,$container,
1.620 raeburn 4796: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4797: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4798: $idx++;
4799: $shown++;
1.329 droeschl 4800: }
1.424 onken 4801: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4802:
1.538 raeburn 4803: my $need_save;
1.611 raeburn 4804: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4805: my $toolslink;
1.682 raeburn 4806: if ($allowed || $canedit) {
4807: my $helpitem = 'Navigation_Screen';
4808: if (!$allowed) {
4809: $helpitem = 'Supplemental_Navigation';
4810: }
1.544 raeburn 4811: $toolslink = '<table><tr><td>'
1.520 raeburn 4812: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4813: $helpitem,undef,'RAT')
1.520 raeburn 4814: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4815: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4816: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4817: .'id="LC_content_toolbar_edittoplevel" '
4818: .'class="LC_toolbarItem" '
4819: .'title="'.&mt('Supplemental Content Editor').'">'
4820: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4821: }
1.510 raeburn 4822: if ($shown) {
4823: if ($allowed) {
4824: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4825: .&Apache::loncommon::start_data_table(undef,'contentlist')
4826: .&Apache::loncommon::start_data_table_header_row()
4827: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4828: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4829: .'<th>'.&mt('Document').'</th>'
4830: .'<th colspan="2">'.&mt('Settings').'</th>'
4831: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4832: if ($folder !~ /^supplemental/) {
1.538 raeburn 4833: $lists{'canhide'} = join(',',@allidx);
4834: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4835: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4836: 'randomorder','randompick');
4837: foreach my $item (@possfilters) {
1.538 raeburn 4838: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4839: if (@{$filters{$item}} > 0) {
4840: $lists{$item} = join(',',@{$filters{$item}});
4841: }
1.538 raeburn 4842: }
4843: }
1.537 raeburn 4844: if (@allidx > 0) {
4845: my $path;
4846: if ($env{'form.folderpath'}) {
1.630 raeburn 4847: $path =
1.537 raeburn 4848: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4849: }
1.538 raeburn 4850: if (@allidx > 1) {
1.630 raeburn 4851: $to_show .=
1.538 raeburn 4852: &Apache::loncommon::continue_data_table_row().
4853: '<td colspan="2"> </td>'.
4854: '<td>'.
1.611 raeburn 4855: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4856: '</td>'.
1.633 raeburn 4857: '<td colspan="3"> </td>'.
4858: '<td colspan="2">'.
1.611 raeburn 4859: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4860: '</td>'.
4861: &Apache::loncommon::end_data_table_row();
4862: $need_save = 1;
4863: }
1.537 raeburn 4864: }
4865: }
4866: $to_show .= $output.' '
1.510 raeburn 4867: .&Apache::loncommon::end_data_table()
4868: .'<br style="line-height:2px;" />'
4869: .&Apache::loncommon::end_scrollbox();
4870: } else {
1.520 raeburn 4871: $to_show .= $toolslink
1.510 raeburn 4872: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4873: .$output.' '
4874: .&Apache::loncommon::end_data_table();
1.393 raeburn 4875: }
1.510 raeburn 4876: } else {
1.520 raeburn 4877: if (!$allowed) {
4878: $to_show .= $toolslink;
4879: }
1.615 raeburn 4880: my $noresmsg;
4881: if ($allowed && $hiddentop && !$supplementalflag) {
4882: $noresmsg = &mt('Main Content Hidden');
4883: } else {
4884: $noresmsg = &mt('Currently empty');
4885: }
1.510 raeburn 4886: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4887: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 4888: .$noresmsg
1.510 raeburn 4889: .'</div>'
4890: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4891: }
4892: } else {
1.510 raeburn 4893: if ($shown) {
4894: $to_show = '<div>'
4895: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4896: .$output
4897: .&Apache::loncommon::end_data_table()
4898: .'</div>';
4899: } else {
4900: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 4901: .&mt('Currently empty')
1.510 raeburn 4902: .'</div>'
4903: }
1.458 raeburn 4904: }
4905: my $tid = 1;
4906: if ($supplementalflag) {
4907: $tid = 2;
1.329 droeschl 4908: }
4909: if ($allowed) {
1.484 raeburn 4910: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 4911: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 4912: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4913: if ($canedit) {
4914: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4915: }
1.460 raeburn 4916: } else {
4917: $r->print($to_show);
1.329 droeschl 4918: }
4919: return;
4920: }
4921:
1.538 raeburn 4922: sub multiple_check_form {
1.611 raeburn 4923: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 4924: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 4925: my $disabled;
4926: unless ($canedit) {
1.700 raeburn 4927: $disabled = ' disabled="disabled"';
1.611 raeburn 4928: }
1.538 raeburn 4929: my $output =
4930: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4931: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4932: '<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>'.
4933: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4934: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4935: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4936: if ($caller eq 'settings') {
4937: $output .=
4938: '<table><tr>'.
4939: '<td class="LC_docs_entry_parameter">'.
4940: '<span class="LC_nobreak"><label>'.
1.611 raeburn 4941: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 4942: '</label></span></td>'.
4943: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4944: '<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 4945: '</span></td>'.
4946: '</tr>'."\n".
4947: '<tr>'.
4948: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4949: '<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 4950: '</label></span>'.
4951: '</td></tr></table>'."\n";
4952: } else {
4953: $output .=
4954: '<table><tr>'.
4955: '<td class="LC_docs_entry_parameter">'.
4956: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 4957: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 4958: '</label></span></td>'.
4959: '<td class="LC_docs_entry_parameter">'.
4960: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 4961: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 4962: '</label></span></td>'."\n".
4963: '<td class="LC_docs_entry_parameter">'.
4964: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 4965: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 4966: '</label></span></td>'.
4967: '</tr></table>'."\n";
4968: }
4969: $output .=
4970: '</fieldset>'.
4971: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4972: if ($caller eq 'settings') {
4973: $output .=
1.543 raeburn 4974: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4975: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4976: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4977: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4978: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 4979: } elsif ($caller eq 'actions') {
4980: $output .=
4981: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4982: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4983: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4984: }
4985: $output .=
4986: '</form>'.
4987: '</div>';
4988: return $output;
4989: }
4990:
1.329 droeschl 4991: sub process_file_upload {
1.552 raeburn 4992: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4993: # upload a file, if present
1.552 raeburn 4994: my $filesize = length($env{'form.uploaddoc'});
4995: if (!$filesize) {
4996: $$upload_output = '<div class="LC_error">'.
4997: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4998: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4999: $filesize).'<br />'.
5000: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
5001: '</div>';
5002: return;
5003: }
5004: my $quotatype = 'unofficial';
5005: if ($crstype eq 'Community') {
1.601 raeburn 5006: $quotatype = 'community';
5007: } elsif ($crstype eq 'Placement') {
5008: $quotatype = 'placement';
1.580 raeburn 5009: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 5010: $quotatype = 'official';
1.573 raeburn 5011: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5012: $quotatype = 'textbook';
1.552 raeburn 5013: }
5014: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
5015: $filesize = int($filesize/1000); #expressed in kb
5016: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 5017: $env{'form.uploaddoc.filename'},$filesize,
5018: 'upload',$quotatype);
1.552 raeburn 5019: return if ($$upload_output);
5020: }
1.440 raeburn 5021: my ($parseaction,$showupload,$nextphase,$mimetype);
5022: if ($env{'form.parserflag'}) {
1.329 droeschl 5023: $parseaction = 'parse';
5024: }
5025: my $folder=$env{'form.folder'};
5026: if ($folder eq '') {
5027: $folder='default';
5028: }
5029: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
5030: my $errtext='';
5031: my $fatal=0;
5032: my $container='sequence';
1.519 raeburn 5033: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 5034: $container='page';
5035: }
5036: ($errtext,$fatal)=
1.534 raeburn 5037: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 5038: if ($#LONCAPA::map::order<1) {
5039: $LONCAPA::map::order[0]=1;
5040: $LONCAPA::map::resources[1]='';
5041: }
5042: my $destination = 'docs/';
5043: if ($folder =~ /^supplemental/) {
5044: $destination = 'supplemental/';
5045: }
5046: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5047: $destination .= 'default/';
5048: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5049: $destination .= $2.'/';
5050: }
1.534 raeburn 5051: if ($fatal) {
5052: $$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>';
5053: return;
5054: }
1.440 raeburn 5055: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 5056: my $newidx=&LONCAPA::map::getresidx();
5057: $destination .= $newidx;
1.439 raeburn 5058: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 5059: $parseaction,$allfiles,
1.440 raeburn 5060: $codebase,undef,undef,undef,undef,
5061: undef,undef,\$mimetype);
5062: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
5063: my $stored = $1;
5064: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
5065: $stored.'</span>').'</p>';
5066: } else {
5067: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
5068:
1.457 raeburn 5069: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 5070: return;
5071: }
1.329 droeschl 5072: my $ext='false';
5073: if ($url=~m{^http://}) { $ext='true'; }
5074: $url = &LONCAPA::map::qtunescape($url);
5075: my $comment=$env{'form.comment'};
5076: $comment = &LONCAPA::map::qtunescape($comment);
5077: if ($folder=~/^supplemental/) {
5078: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
5079: $env{'user.domain'}.'___&&&___'.$comment;
5080: }
5081:
5082: $LONCAPA::map::resources[$newidx]=
5083: $comment.':'.$url.':'.$ext.':normal:res';
5084: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
5085: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 5086: $folder.'.'.$container,1);
1.329 droeschl 5087: if ($fatal) {
1.457 raeburn 5088: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 5089: return;
1.329 droeschl 5090: } else {
1.440 raeburn 5091: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
5092: $$upload_output = $showupload;
1.384 raeburn 5093: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 5094: if ($total_embedded > 0) {
1.440 raeburn 5095: my $uploadphase = 'upload_embedded';
5096: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
5097: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 5098: my ($embedded,$num) =
1.440 raeburn 5099: &Apache::loncommon::ask_for_embedded_content(
5100: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
5101: if ($embedded) {
5102: if ($num) {
5103: $$upload_output .=
5104: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
5105: $nextphase = $uploadphase;
5106: } else {
5107: $$upload_output .= $embedded;
5108: }
5109: } else {
5110: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
5111: }
1.329 droeschl 5112: } else {
1.440 raeburn 5113: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 5114: }
1.457 raeburn 5115: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 5116: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
5117: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 5118: $nextphase = 'decompress_uploaded';
5119: my $position = scalar(@LONCAPA::map::order)-1;
5120: my $noextract = &return_to_editor();
5121: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
5122: my %archiveitems = (
5123: folderpath => $env{'form.folderpath'},
5124: cmd => $nextphase,
5125: newidx => $newidx,
5126: position => $position,
5127: phase => $nextphase,
1.477 raeburn 5128: comment => $comment,
1.480 raeburn 5129: );
5130: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
5131: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 5132: $$upload_output = $showupload.
5133: &Apache::loncommon::decompress_form($mimetype,
5134: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 5135: \%archiveitems,\@current);
1.329 droeschl 5136: }
5137: }
5138: }
1.440 raeburn 5139: return $nextphase;
1.329 droeschl 5140: }
5141:
1.480 raeburn 5142: sub get_dir_list {
5143: my ($url,$coursenum,$coursedom,$newidx) = @_;
5144: my ($destination,$dir_root) = &embedded_destination();
5145: my ($dirlistref,$listerror) =
5146: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
5147: my @dir_lines;
5148: my $dirptr=16384;
5149: if (ref($dirlistref) eq 'ARRAY') {
5150: foreach my $dir_line (sort
5151: {
5152: my ($afile)=split('&',$a,2);
5153: my ($bfile)=split('&',$b,2);
5154: return (lc($afile) cmp lc($bfile));
5155: } (@{$dirlistref})) {
5156: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
5157: $filename =~ s/\s+$//;
5158: next if ($filename =~ /^\.\.?$/);
5159: my $isdir = 0;
5160: if ($dirptr&$testdir) {
5161: $isdir = 1;
5162: }
5163: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
5164: }
5165: }
5166: return @dir_lines;
5167: }
5168:
1.329 droeschl 5169: sub is_supplemental_title {
5170: my ($title) = @_;
5171: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
5172: }
5173:
5174: # --------------------------------------------------------------- An entry line
5175:
5176: sub entryline {
1.501 raeburn 5177: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 5178: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 5179: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 5180: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 5181: if (&is_supplemental_title($title)) {
1.488 raeburn 5182: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 5183: $encodedtitle=$title;
1.329 droeschl 5184: } else {
5185: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 5186: $encodedtitle=$title;
1.329 droeschl 5187: $renametitle=$title;
5188: $foldertitle=$title;
5189: }
5190:
1.611 raeburn 5191: my ($disabled,$readonly,$js_lt);
5192: unless ($canedit) {
5193: $disabled = 'disabled="disabled"';
5194: $readonly = 1;
5195: }
5196:
1.329 droeschl 5197: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 5198:
1.329 droeschl 5199: $renametitle=~s/\\/\\\\/g;
5200: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 5201: $renametitle=~s/"/%22/g;
1.581 raeburn 5202: $renametitle=~s/ /%20/g;
5203: $oldtitle = $renametitle;
1.576 raeburn 5204: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 5205: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 5206: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5207: # Edit commands
1.679 raeburn 5208: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5209: if ($env{'form.folderpath'}) {
5210: $esc_path=&escape($env{'form.folderpath'});
5211: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5212: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5213: }
1.505 raeburn 5214: my $isexternal;
1.510 raeburn 5215: if ($residx) {
1.501 raeburn 5216: my $currurl = $url;
5217: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5218: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5219: $isexternal = 1;
5220: }
1.510 raeburn 5221: if (!$supplementalflag) {
5222: my $path = 'uploaded/'.
5223: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5224: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5225: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5226: $residx,
5227: &Apache::lonnet::declutter($currurl));
5228: }
1.501 raeburn 5229: }
1.538 raeburn 5230: my ($renamelink,%lt,$ishash);
5231: if (ref($filtersref) eq 'HASH') {
5232: $ishash = 1;
5233: }
5234:
1.329 droeschl 5235: if ($allowed) {
1.538 raeburn 5236: $form_start = '
5237: <form action="/adm/coursedocs" method="post">
5238: ';
5239: $form_common=(<<END);
5240: <input type="hidden" name="folderpath" value="$path" />
5241: <input type="hidden" name="symb" value="$symb" />
5242: END
5243: $form_param=(<<END);
5244: <input type="hidden" name="setparms" value="$orderidx" />
5245: <input type="hidden" name="changeparms" value="0" />
5246: END
5247: $form_end = '</form>';
5248:
1.329 droeschl 5249: my $incindex=$index+1;
5250: my $selectbox='';
1.471 raeburn 5251: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5252: ((split(/\:/,
1.344 bisitz 5253: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5254: ne '') &&
1.329 droeschl 5255: ((split(/\:/,
1.344 bisitz 5256: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5257: ne '')) {
5258: $selectbox=
5259: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5260: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5261: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5262: if ($i==$incindex) {
1.358 bisitz 5263: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5264: } else {
5265: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5266: }
5267: }
5268: $selectbox.='</select>';
5269: }
1.501 raeburn 5270: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5271: 'up' => 'Move Up',
5272: 'dw' => 'Move Down',
5273: 'rm' => 'Remove',
5274: 'ct' => 'Cut',
5275: 'rn' => 'Rename',
1.501 raeburn 5276: 'cp' => 'Copy',
1.633 raeburn 5277: 'da' => 'Unset alias',
5278: 'sa' => 'Set alias',
1.501 raeburn 5279: 'ex' => 'External Resource',
1.598 raeburn 5280: 'et' => 'External Tool',
1.501 raeburn 5281: 'ed' => 'Edit',
5282: 'pr' => 'Preview',
5283: 'sv' => 'Save',
5284: 'ul' => 'URL',
1.611 raeburn 5285: 'ti' => 'Title',
1.618 raeburn 5286: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5287: );
1.538 raeburn 5288: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5289: $env{'form.folderpath'},
5290: $currgroups);
1.517 raeburn 5291: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5292: my $skip_confirm = 0;
1.603 raeburn 5293: my $confirm_removal = 0;
1.329 droeschl 5294: if ( $folder =~ /^supplemental/
5295: || ($url =~ m{( /smppg$
5296: |/syllabus$
5297: |/aboutme$
5298: |/navmaps$
5299: |/bulletinboard$
1.626 raeburn 5300: |/ext\.tool$
1.505 raeburn 5301: |\.html$)}x)
5302: || $isexternal) {
1.329 droeschl 5303: $skip_confirm = 1;
5304: }
1.603 raeburn 5305: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5306: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5307: $confirm_removal = 1;
5308: }
1.633 raeburn 5309: if ($url =~ /$LONCAPA::assess_re/) {
5310: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5311: }
1.329 droeschl 5312:
1.538 raeburn 5313: if ($denied{'copy'}) {
1.543 raeburn 5314: $copylink=(<<ENDCOPY)
1.507 raeburn 5315: <span style="visibility: hidden;">$lt{'cp'}</span>
5316: ENDCOPY
5317: } else {
1.538 raeburn 5318: my $formname = 'edit_copy_'.$orderidx;
5319: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5320: $copylink=(<<ENDCOPY);
1.538 raeburn 5321: <form name="$formname" method="post" action="/adm/coursedocs">
5322: $form_common
1.611 raeburn 5323: <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 5324: $form_end
1.329 droeschl 5325: ENDCOPY
1.538 raeburn 5326: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5327: push(@{$filtersref->{'cancopy'}},$orderidx);
5328: }
1.329 droeschl 5329: }
1.538 raeburn 5330: if ($denied{'cut'}) {
1.507 raeburn 5331: $cutlink=(<<ENDCUT);
5332: <span style="visibility: hidden;">$lt{'ct'}</span>
5333: ENDCUT
5334: } else {
1.538 raeburn 5335: my $formname = 'edit_cut_'.$orderidx;
5336: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5337: $cutlink=(<<ENDCUT);
1.538 raeburn 5338: <form name="$formname" method="post" action="/adm/coursedocs">
5339: $form_common
1.542 raeburn 5340: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 5341: <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 5342: $form_end
1.329 droeschl 5343: ENDCUT
1.538 raeburn 5344: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5345: push(@{$filtersref->{'cancut'}},$orderidx);
5346: }
1.329 droeschl 5347: }
1.538 raeburn 5348: if ($denied{'remove'}) {
1.507 raeburn 5349: $removelink=(<<ENDREM);
5350: <span style="visibility: hidden;">$lt{'rm'}</a>
5351: ENDREM
5352: } else {
1.538 raeburn 5353: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5354: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5355: $removelink=(<<ENDREM);
1.538 raeburn 5356: <form name="$formname" method="post" action="/adm/coursedocs">
5357: $form_common
1.542 raeburn 5358: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5359: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 5360: <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 5361: $form_end
1.497 raeburn 5362: ENDREM
1.538 raeburn 5363: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5364: push(@{$filtersref->{'canremove'}},$orderidx);
5365: }
1.497 raeburn 5366: }
1.551 raeburn 5367: $renamelink=(<<ENDREN);
1.581 raeburn 5368: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5369: ENDREN
1.611 raeburn 5370: my ($uplink,$downlink);
5371: if ($canedit) {
5372: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5373: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5374: } else {
5375: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5376: $downlink = $uplink;
5377: }
1.329 droeschl 5378: $line.=(<<END);
5379: <td>
1.379 bisitz 5380: <div class="LC_docs_entry_move">
1.611 raeburn 5381: <a href="$uplink">
1.501 raeburn 5382: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5383: </a>
5384: </div>
5385: <div class="LC_docs_entry_move">
1.611 raeburn 5386: <a href="$downlink">
1.501 raeburn 5387: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5388: </a>
5389: </div>
1.329 droeschl 5390: </td>
5391: <td>
5392: $form_start
1.538 raeburn 5393: $form_param
1.478 raeburn 5394: $form_common
1.329 droeschl 5395: $selectbox
5396: $form_end
5397: </td>
1.540 raeburn 5398: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5399: $removelink
1.329 droeschl 5400: $cutlink
5401: $copylink
5402: </td>
5403: END
5404: }
5405: # Figure out what kind of a resource this is
5406: my ($extension)=($url=~/\.(\w+)$/);
5407: my $uploaded=($url=~/^\/*uploaded\//);
5408: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5409: my $isfolder;
5410: my $ispage;
5411: my $containerarg;
1.615 raeburn 5412: my $folderurl;
1.685 raeburn 5413: my $plainurl;
1.329 droeschl 5414: if ($uploaded) {
1.472 raeburn 5415: if (($extension eq 'sequence') || ($extension eq 'page')) {
5416: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5417: $containerarg = $1;
1.472 raeburn 5418: if ($extension eq 'sequence') {
5419: $icon=$iconpath.'navmap.folder.closed.gif';
5420: $isfolder=1;
5421: } else {
5422: $icon=$iconpath.'page.gif';
5423: $ispage=1;
5424: }
1.615 raeburn 5425: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5426: if ($allowed) {
5427: $url='/adm/coursedocs?';
5428: } else {
5429: $url='/adm/supplemental?';
5430: }
1.329 droeschl 5431: } else {
1.685 raeburn 5432: $plainurl = $url;
1.329 droeschl 5433: }
5434: }
1.364 bisitz 5435:
1.621 raeburn 5436: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5437: my $orig_url = $url;
1.340 raeburn 5438: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5439: if ($container eq 'page') {
5440: $url=~s{^http(|s)(:|:)//}{/ext/};
5441: } else {
5442: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5443: }
1.501 raeburn 5444: if (!$supplementalflag && $residx && $symb) {
5445: if ((!$isfolder) && (!$ispage)) {
5446: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5447: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5448: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5449: } else {
5450: $url=&Apache::lonnet::clutter($url);
5451: }
1.501 raeburn 5452: if ($url=~/^\/*uploaded\//) {
5453: $url=~/\.(\w+)$/;
5454: my $embstyle=&Apache::loncommon::fileembstyle($1);
5455: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5456: $url='/adm/wrapper'.$url;
5457: } elsif ($embstyle eq 'ssi') {
5458: #do nothing with these
5459: } elsif ($url!~/\.(sequence|page)$/) {
5460: $url='/adm/coursedocs/showdoc'.$url;
5461: }
1.623 raeburn 5462: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5463: my $wrapped = $1;
5464: my $exturl = $2;
1.668 raeburn 5465: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5466: $url='/adm/wrapper'.$url;
5467: }
5468: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5469: $nomodal = 1;
5470: }
1.626 raeburn 5471: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5472: $url='/adm/wrapper'.$url;
1.621 raeburn 5473: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5474: if (($ENV{'SERVER_PORT'} == 443) &&
5475: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5476: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5477: $url .= '?usehttp=1';
5478: }
1.621 raeburn 5479: $nomodal = 1;
5480: }
1.598 raeburn 5481: }
1.696 raeburn 5482: my $checkencrypt;
1.680 raeburn 5483: if (!$env{'request.role.adv'}) {
1.615 raeburn 5484: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5485: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5486: $checkencrypt = 1;
1.620 raeburn 5487: } elsif (ref($navmapref)) {
1.615 raeburn 5488: unless (ref($$navmapref)) {
5489: $$navmapref = Apache::lonnavmaps::navmap->new();
5490: }
5491: if (ref($$navmapref)) {
5492: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5493: $checkencrypt = 1;
1.615 raeburn 5494: }
5495: }
5496: }
1.680 raeburn 5497: }
5498: if ($checkencrypt) {
5499: my $currenc = $env{'request.enc'};
5500: $env{'request.enc'} = 1;
5501: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5502: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5503: if (&Apache::lonnet::symbverify($symb,$url)) {
5504: $url = $shownurl;
5505: } else {
5506: $url = '';
5507: }
5508: $env{'request.enc'} = $currenc;
5509: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5510: $shownsymb = $symb;
5511: if ($isexternal) {
5512: $url =~ s/\#[^#]+$//;
5513: if ($container eq 'page') {
5514: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5515: }
1.612 raeburn 5516: }
1.696 raeburn 5517: } else {
5518: $url = '';
1.680 raeburn 5519: }
5520: unless ($env{'request.role.adv'}) {
5521: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5522: $url = '';
5523: }
5524: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5525: $url = '';
5526: $hiddenres = 1;
5527: }
5528: }
1.696 raeburn 5529: if (($url ne '') && ($shownsymb ne '')) {
5530: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5531: }
1.329 droeschl 5532: }
1.621 raeburn 5533: } elsif ($supplementalflag) {
1.610 raeburn 5534: if ($isexternal) {
5535: if ($url =~ /^([^#]+)#([^#]+)$/) {
5536: $url = $1;
5537: $anchor = $2;
1.623 raeburn 5538: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5539: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5540: if ($hostname ne '') {
5541: $url = 'http://'.$hostname.$url;
5542: }
5543: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5544: }
5545: $nomodal = 1;
5546: }
1.610 raeburn 5547: }
1.621 raeburn 5548: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5549: if (($ENV{'SERVER_PORT'} == 443) &&
5550: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5551: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5552: if ($hostname ne '') {
5553: $url = 'http://'.$hostname.$url;
5554: }
5555: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5556: }
1.621 raeburn 5557: $nomodal = 1;
5558: }
1.705 raeburn 5559: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5560: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5561: unless ($embstyle eq 'ssi') {
5562: if (($embstyle eq 'img')
5563: || ($embstyle eq 'emb')
5564: || ($embstyle eq 'wrp')) {
5565: $url='/adm/wrapper'.$url;
5566: } elsif ($url !~ /\.(sequence|page)$/) {
5567: $url='/adm/coursedocs/showdoc'.$url;
5568: }
5569: }
1.610 raeburn 5570: }
1.685 raeburn 5571: unless ($allowed && $env{'request.role.adv'}) {
5572: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5573: $hiddenres = 1;
5574: }
5575: }
1.329 droeschl 5576: }
1.615 raeburn 5577: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5578: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5579: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5580: my $foldername=&escape($foldertitle);
5581: my $folderpath=$env{'form.folderpath'};
5582: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5583: if (!$allowed && $supplementalflag) {
1.519 raeburn 5584: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5585: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5586: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5587: $hiddenfolder = 1;
1.682 raeburn 5588: }
1.510 raeburn 5589: } else {
1.617 raeburn 5590: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5591: 'parameter_randompick'))[0];
5592: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5593: 'parameter_randomorder'))[0]=~/^yes$/i);
5594: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5595: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5596: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5597: 'parameter_encrypturl'))[0]=~/^yes$/i);
5598: unless ($hiddenmap) {
1.620 raeburn 5599: if (ref($navmapref)) {
5600: unless (ref($$navmapref)) {
5601: $$navmapref = Apache::lonnavmaps::navmap->new();
5602: }
5603: if (ref($$navmapref)) {
5604: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5605: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5606: unless (@resources) {
5607: $hiddenmap = 1;
5608: unless ($env{'request.role.adv'}) {
5609: $url = '';
5610: $hiddenfolder = 1;
5611: }
1.617 raeburn 5612: }
1.615 raeburn 5613: }
5614: }
5615: }
5616: }
1.617 raeburn 5617: unless ($encryptmap) {
1.620 raeburn 5618: if ((ref($navmapref)) && (ref($$navmapref))) {
5619: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5620: $encryptmap = 1;
5621: }
1.617 raeburn 5622: }
5623: }
1.630 raeburn 5624:
1.617 raeburn 5625: # Append randompick number, hidden, and encrypted with ":" to foldername,
5626: # so it gets transferred between levels
5627: $folderpath.=$containerarg.'&'.$foldername.
5628: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5629: unless ($url eq '') {
1.612 raeburn 5630: $url.='folderpath='.&escape($folderpath);
5631: }
1.510 raeburn 5632: my $rpckchk;
5633: if ($rpicknum) {
5634: $rpckchk = ' checked="checked"';
1.543 raeburn 5635: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5636: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5637: }
1.510 raeburn 5638: }
1.537 raeburn 5639: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5640: $rand_pick_text =
1.478 raeburn 5641: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5642: $form_param."\n".
1.478 raeburn 5643: $form_common."\n".
1.611 raeburn 5644: '<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 5645: if ($rpicknum ne '') {
5646: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5647: }
1.537 raeburn 5648: $rand_pick_text .= '</span></span>'.
5649: $form_end;
1.543 raeburn 5650: my $ro_set;
1.617 raeburn 5651: if ($randorder) {
1.543 raeburn 5652: $ro_set = 'checked="checked"';
5653: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5654: push(@{$filtersref->{'randomorder'}},$orderidx);
5655: }
5656: }
1.564 raeburn 5657: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5658: $rand_order_text =
1.537 raeburn 5659: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5660: $form_param."\n".
1.537 raeburn 5661: $form_common."\n".
1.611 raeburn 5662: '<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 5663: $form_end;
1.510 raeburn 5664: }
1.705 raeburn 5665: } elsif ($supplementalflag) {
1.598 raeburn 5666: my $isexttool;
1.626 raeburn 5667: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5668: $url='/adm/wrapper'.$url;
5669: $isexttool = 1;
5670: }
1.510 raeburn 5671: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5672: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5673: if ($title) {
1.687 raeburn 5674: $url .= '&title='.$encodedtitle;
1.510 raeburn 5675: }
1.598 raeburn 5676: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5677: $url .= '&idx='.$orderidx;
5678: }
1.610 raeburn 5679: if ($anchor ne '') {
5680: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5681: }
1.329 droeschl 5682: }
1.519 raeburn 5683: my ($tdalign,$tdwidth);
1.501 raeburn 5684: if ($allowed) {
1.630 raeburn 5685: my $fileloc =
1.501 raeburn 5686: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5687: if ($isexternal) {
1.630 raeburn 5688: ($editlink,$extresform) =
1.611 raeburn 5689: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5690: undef,undef,undef,undef,undef,undef,
5691: undef,$disabled);
1.626 raeburn 5692: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5693: ($editlink,$extresform) =
5694: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5695: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5696: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5697: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5698: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5699: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5700: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5701: my $suppanchor;
5702: if ($supplementalflag) {
5703: $suppanchor = $anchor;
5704: }
1.630 raeburn 5705: my $jscall =
1.501 raeburn 5706: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5707: $switchserver,
1.503 raeburn 5708: $forceedit,
1.679 raeburn 5709: undef,$symb,$shownsymb,
1.511 raeburn 5710: &escape($env{'form.folderpath'}),
1.622 raeburn 5711: $renametitle,$hostname,
5712: '','',1,$suppanchor);
1.501 raeburn 5713: if ($jscall) {
1.518 raeburn 5714: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5715: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5716: }
5717: }
5718: }
1.519 raeburn 5719: $tdalign = ' align="right" valign="top"';
5720: $tdwidth = ' width="80%"';
1.329 droeschl 5721: }
1.408 raeburn 5722: my $reinit;
5723: if ($crstype eq 'Community') {
5724: $reinit = &mt('(re-initialize community to access)');
5725: } else {
5726: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5727: }
1.702 raeburn 5728: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5729: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5730: $line.= '<br />';
5731: if ($curralias ne '') {
5732: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5733: $lt{'da'}.'</a></span>';
5734: } else {
5735: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5736: $lt{'sa'}.'</a></span>';
5737: }
5738: }
1.701 raeburn 5739: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5740: my ($link,$nolink);
1.472 raeburn 5741: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5742: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5743: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5744: $nolink = 1;
5745: }
5746: }
5747: if ($nolink) {
5748: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5749: } else {
5750: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5751: }
1.469 www 5752: } elsif ($url) {
1.610 raeburn 5753: if ($anchor ne '') {
5754: if ($supplementalflag) {
5755: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5756: } else {
5757: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5758: }
5759: }
1.705 raeburn 5760: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5761: $link = 'http://'.$hostname.$url;
5762: } else {
5763: $link = $url;
5764: }
1.705 raeburn 5765: my $inhibitmenu;
5766: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5767: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5768: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5769: $inhibitmenu = 'only_body=1';
5770: } else {
5771: $inhibitmenu = 'inhibitmenu=yes';
5772: }
5773: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5774: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5775: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5776: $nolink = 1;
5777: }
5778: }
5779: if ($nolink) {
5780: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5781: } elsif ($nomodal) {
1.621 raeburn 5782: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5783: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5784: } else {
5785: $line.=&Apache::loncommon::modal_link($link,
5786: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5787: }
1.469 www 5788: } else {
5789: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5790: }
1.519 raeburn 5791: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5792: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5793: if ($nolink) {
5794: $line.=$title;
5795: } else {
5796: $line.='<a href="'.$url.'">'.$title.'</a>';
5797: }
1.682 raeburn 5798: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5799: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5800: my $editurl = $url;
5801: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5802: $line .= ' '.'<a href="'.$editurl.'">'.
5803: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5804: '</a>';
5805: }
5806: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5807: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5808: }
1.469 www 5809: } elsif ($url) {
1.685 raeburn 5810: if ($nolink) {
5811: $line.=$title;
5812: } elsif ($nomodal) {
1.621 raeburn 5813: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5814: $title.'</a>';
5815: } else {
5816: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5817: }
1.617 raeburn 5818: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5819: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5820: } else {
5821: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5822: }
1.633 raeburn 5823: if (($allowed) && ($curralias ne '')) {
5824: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5825: } else {
5826: $line .= $extresform;
5827: }
5828: $line .= '</td>';
1.478 raeburn 5829: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5830: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5831: if ($uploaded && $url && !$isfolder && !$ispage) {
5832: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5833: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5834: }
5835: }
1.682 raeburn 5836: if ($allowed) {
5837: my %lt=&Apache::lonlocal::texthash(
5838: 'hd' => 'Hidden',
5839: 'ec' => 'URL hidden');
5840: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5841: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5842: $hidtext = ' checked="checked"';
1.694 raeburn 5843: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5844: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5845: }
5846: }
1.682 raeburn 5847: $formhidden = 'edit_hiddenresource_'.$orderidx;
5848: $line.=(<<ENDPARMS);
1.329 droeschl 5849: <td class="LC_docs_entry_parameter">
1.537 raeburn 5850: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5851: $form_param
1.478 raeburn 5852: $form_common
1.611 raeburn 5853: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5854: $form_end
1.682 raeburn 5855: ENDPARMS
5856: if ($folder =~/^supplemental/) {
5857: $line.= "\n <td>";
5858: } else {
5859: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5860: $enctext = ' checked="checked"';
5861: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5862: push(@{$filtersref->{'encrypturl'}},$orderidx);
5863: }
5864: }
5865: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5866: $line.=(<<ENDPARMS);
1.458 raeburn 5867: <br />
1.537 raeburn 5868: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5869: $form_param
1.478 raeburn 5870: $form_common
1.611 raeburn 5871: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5872: $form_end
5873: </td>
1.478 raeburn 5874: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5875: $rand_order_text</td>
1.329 droeschl 5876: ENDPARMS
1.682 raeburn 5877: }
1.329 droeschl 5878: }
1.379 bisitz 5879: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 5880: return $line;
5881: }
5882:
1.538 raeburn 5883: sub action_restrictions {
5884: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5885: my %denied = (
5886: cut => 0,
5887: copy => 0,
5888: remove => 0,
5889: );
5890: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5891: # no copy for published maps
5892: $denied{'copy'} = 1;
1.597 raeburn 5893: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5894: unless ($1 eq 'simpleproblem') {
5895: $denied{'copy'} = 1;
5896: }
5897: $denied{'cut'} = 1;
1.538 raeburn 5898: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5899: if ($folderpath =~ /^default&[^\&]+$/) {
5900: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5901: $denied{'remove'} = 1;
5902: }
5903: $denied{'cut'} = 1;
5904: $denied{'copy'} = 1;
5905: }
5906: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5907: my $group = $1;
5908: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5909: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5910: $denied{'remove'} = 1;
5911: }
5912: }
5913: $denied{'cut'} = 1;
5914: $denied{'copy'} = 1;
5915: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5916: my $group = $1;
5917: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5918: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5919: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5920: if (keys(%groupsettings) > 0) {
5921: $denied{'remove'} = 1;
5922: }
5923: $denied{'cut'} = 1;
5924: $denied{'copy'} = 1;
5925: }
5926: }
5927: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5928: my $group = $1;
5929: if ($url =~ /group_boards_\Q$group\E/) {
5930: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5931: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5932: if (keys(%groupsettings) > 0) {
5933: if (ref($groupsettings{'functions'}) eq 'HASH') {
5934: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5935: $denied{'remove'} = 1;
5936: }
5937: }
5938: }
5939: $denied{'cut'} = 1;
5940: $denied{'copy'} = 1;
5941: }
5942: }
5943: }
5944: return %denied;
5945: }
5946:
1.533 raeburn 5947: sub new_timebased_suffix {
1.538 raeburn 5948: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 5949: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 5950: if ($type eq 'paste') {
5951: $prefix = $type;
5952: $namespace = 'courseeditor';
1.587 raeburn 5953: $idtype = 'addcode';
1.538 raeburn 5954: } elsif ($type eq 'map') {
1.533 raeburn 5955: $prefix = 'docs';
5956: if ($area eq 'supplemental') {
5957: $prefix = 'supp';
5958: }
5959: $prefix .= $container;
5960: $namespace = 'uploadedmaps';
5961: } else {
5962: $prefix = $type;
5963: $namespace = 'templated';
1.504 raeburn 5964: }
5965: my ($suffix,$freedlock,$error) =
1.587 raeburn 5966: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 5967: if (!$suffix) {
1.538 raeburn 5968: if ($type eq 'paste') {
5969: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5970: } elsif ($type eq 'map') {
1.533 raeburn 5971: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5972: } elsif ($type eq 'smppg') {
5973: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 5974: } elsif ($type eq 'exttool') {
5975: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 5976: } else {
1.565 bisitz 5977: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 5978: }
1.504 raeburn 5979: if ($error) {
5980: $errtext .= '<br />'.$error;
5981: }
5982: }
5983: if ($freedlock ne 'ok') {
1.630 raeburn 5984: $locknotfreed =
1.533 raeburn 5985: '<div class="LC_error">'.
5986: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 5987: if ($type eq 'paste') {
1.591 raeburn 5988: if ($freedlock eq 'nolock') {
5989: $locknotfreed =
5990: '<div class="LC_error">'.
5991: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5992:
1.593 droeschl 5993: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 5994: } else {
5995: $locknotfreed .=
5996: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5997: }
1.538 raeburn 5998: } elsif ($type eq 'map') {
1.591 raeburn 5999: $locknotfreed .=
6000: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 6001: } elsif ($type eq 'smppg') {
6002: $locknotfreed .=
6003: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 6004: } elsif ($type eq 'exttool') {
6005: $locknotfreed .=
6006: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 6007: } else {
6008: $locknotfreed .=
1.565 bisitz 6009: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 6010: }
1.538 raeburn 6011: unless ($type eq 'paste') {
6012: $locknotfreed .=
1.560 raeburn 6013: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
6014: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 6015: }
6016: $locknotfreed .= '</div>';
1.504 raeburn 6017: }
6018: return ($suffix,$errtext,$locknotfreed);
6019: }
6020:
1.329 droeschl 6021: =pod
6022:
6023: =item tiehash()
6024:
6025: tie the hash
6026:
6027: =cut
6028:
6029: sub tiehash {
6030: my ($mode)=@_;
6031: $hashtied=0;
6032: if ($env{'request.course.fn'}) {
6033: if ($mode eq 'write') {
6034: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6035: &GDBM_WRCREAT(),0640)) {
6036: $hashtied=2;
6037: }
6038: } else {
6039: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6040: &GDBM_READER(),0640)) {
6041: $hashtied=1;
6042: }
6043: }
1.364 bisitz 6044: }
1.329 droeschl 6045: }
6046:
6047: sub untiehash {
6048: if ($hashtied) { untie %hash; }
6049: $hashtied=0;
6050: return OK;
6051: }
6052:
6053:
6054:
6055:
6056: sub checkonthis {
1.637 raeburn 6057: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 6058: $url=&unescape($url);
6059: $alreadyseen{$url}=1;
6060: $r->rflush();
6061: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
6062: $r->print("\n<br />");
6063: if ($level==0) {
6064: $r->print("<br />");
6065: }
6066: for (my $i=0;$i<=$level*5;$i++) {
6067: $r->print(' ');
6068: }
6069: $r->print('<a href="'.$url.'" target="cat">'.
6070: ($title?$title:$url).'</a> ');
6071: if ($url=~/^\/res\//) {
1.637 raeburn 6072: my $updated;
6073: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
6074: ($url !~ /\.\d+\.\w+$/)) {
6075: $updated = &Apache::lonnet::remove_stale_resfile($url);
6076: }
1.329 droeschl 6077: my $result=&Apache::lonnet::repcopy(
6078: &Apache::lonnet::filelocation('',$url));
6079: if ($result eq 'ok') {
6080: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 6081: if ($updated) {
6082: $r->print('<br />');
6083: for (my $i=0;$i<=$level*5;$i++) {
6084: $r->print(' ');
6085: }
6086: $r->print('- '.&mt('Outdated copy removed'));
6087: }
1.329 droeschl 6088: $r->rflush();
6089: &Apache::lonnet::countacc($url);
6090: $url=~/\.(\w+)$/;
6091: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
6092: $r->print('<br />');
6093: $r->rflush();
6094: for (my $i=0;$i<=$level*5;$i++) {
6095: $r->print(' ');
6096: }
6097: $r->print('- '.&mt('Rendering:').' ');
6098: my ($errorcount,$warningcount)=split(/:/,
6099: &Apache::lonnet::ssi_body($url,
6100: ('grade_target'=>'web',
6101: 'return_only_error_and_warning_counts' => 1)));
6102: if (($errorcount) ||
6103: ($warningcount)) {
6104: if ($errorcount) {
1.369 bisitz 6105: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 6106: &mt('[quant,_1,error]',$errorcount).'</span>');
6107: }
6108: if ($warningcount) {
6109: $r->print('<span class="LC_warning">'.
6110: &mt('[quant,_1,warning]',$warningcount).'</span>');
6111: }
6112: } else {
6113: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
6114: }
6115: $r->rflush();
6116: }
6117: my $dependencies=
6118: &Apache::lonnet::metadata($url,'dependencies');
6119: foreach my $dep (split(/\,/,$dependencies)) {
6120: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 6121: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 6122: }
6123: }
6124: } elsif ($result eq 'unavailable') {
6125: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
6126: } elsif ($result eq 'not_found') {
6127: unless ($url=~/\$/) {
1.521 bisitz 6128: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 6129: } else {
1.366 bisitz 6130: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 6131: }
6132: } else {
6133: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
6134: }
1.637 raeburn 6135: if (($updated) && ($result ne 'ok')) {
6136: $r->print('<br />'.&mt('Outdated copy removed'));
6137: }
1.329 droeschl 6138: }
6139: }
6140: }
6141:
6142:
6143:
6144: =pod
6145:
6146: =item list_symbs()
6147:
1.485 raeburn 6148: List Content Identifiers
1.329 droeschl 6149:
6150: =cut
6151:
6152: sub list_symbs {
6153: my ($r) = @_;
6154:
1.408 raeburn 6155: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6156: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
6157: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
6158: $r->print(&startContentScreen('tools'));
1.329 droeschl 6159: my $navmap = Apache::lonnavmaps::navmap->new();
6160: if (!defined($navmap)) {
6161: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
6162: '<div class="LC_error">'.
6163: &mt('Unable to retrieve information about course contents').
6164: '</div>');
1.408 raeburn 6165: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 6166: } else {
1.484 raeburn 6167: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
6168: &Apache::loncommon::start_data_table().
6169: &Apache::loncommon::start_data_table_header_row().
6170: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
6171: &Apache::loncommon::end_data_table_header_row()."\n");
6172: my $count;
1.329 droeschl 6173: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 6174: $r->print(&Apache::loncommon::start_data_table_row().
6175: '<td>'.$res->compTitle().'</td>'.
6176: '<td>'.$res->symb().'</td>'.
1.521 bisitz 6177: &Apache::loncommon::end_data_table_row());
1.484 raeburn 6178: $count ++;
6179: }
6180: if (!$count) {
6181: $r->print(&Apache::loncommon::start_data_table_row().
6182: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
6183: &Apache::loncommon::end_data_table_row());
1.329 droeschl 6184: }
1.484 raeburn 6185: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 6186: }
1.521 bisitz 6187: $r->print(&endContentScreen());
1.329 droeschl 6188: }
6189:
1.651 raeburn 6190: sub short_urls {
6191: my ($r,$canedit) = @_;
6192: my $crstype = &Apache::loncommon::course_type();
6193: my $formname = 'shortenurl';
6194: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
6195: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
6196: $r->print(&startContentScreen('tools'));
6197: my ($navmap,$errormsg) =
6198: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
6199: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6200: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6201: my (%maps,%resources,%titles);
6202: if (!ref($navmap)) {
6203: $r->print($errormsg.
6204: &endContentScreen());
6205: return '';
6206: } else {
1.652 raeburn 6207: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6208: $r->rflush();
6209: my $readonly;
6210: if ($canedit) {
1.671 raeburn 6211: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6212: if ($numnew) {
6213: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6214: }
6215: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6216: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6217: foreach my $error (@{$errors}) {
6218: $r->print('<li>'.$error.'</li>');
6219: }
6220: $r->print('</ul><br />');
6221: }
6222: } else {
6223: $readonly = 1;
6224: }
6225: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6226: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6227: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6228: }
6229: $r->print(&endContentScreen());
6230: }
6231:
1.637 raeburn 6232: sub contentverifyform {
6233: my ($r) = @_;
6234: my $crstype = &Apache::loncommon::course_type();
6235: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6236: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6237: $r->print(&startContentScreen('tools'));
6238: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6239: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6240: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6241: ' <span class="LC_nobreak">'.
6242: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6243: &mt('No').'</label>'.(' 'x2).
6244: '<label><input type="radio" name="checkstale" value="1" />'.
6245: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6246: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6247: '<input type="hidden" value="1" name="tools" />'.
6248: '<input type="hidden" value="1" name="verify" /></p></form>');
6249: $r->print(&endContentScreen());
6250: return;
6251: }
1.329 droeschl 6252:
6253: sub verifycontent {
1.637 raeburn 6254: my ($r,$checkstale) = @_;
1.408 raeburn 6255: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6256: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6257: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6258: $r->print(&startContentScreen('tools'));
6259: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6260: $hashtied=0;
6261: undef %alreadyseen;
6262: %alreadyseen=();
6263: &tiehash();
1.484 raeburn 6264:
1.329 droeschl 6265: foreach my $key (keys(%hash)) {
6266: if ($hash{$key}=~/\.(page|sequence)$/) {
6267: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6268: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6269: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6270: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6271: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6272: }
6273: }
6274: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6275: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6276: }
6277: }
6278: &untiehash();
1.442 www 6279: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6280: $r->print(&endContentScreen());
1.329 droeschl 6281: }
6282:
6283: sub devalidateversioncache {
6284: my $src=shift;
6285: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6286: &Apache::lonnet::clutter($src));
6287: }
6288:
6289: sub checkversions {
1.611 raeburn 6290: my ($r,$canedit) = @_;
1.408 raeburn 6291: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6292: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6293: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6294: $r->print(&startContentScreen('tools'));
1.442 www 6295:
1.329 droeschl 6296: my $header='';
6297: my $startsel='';
6298: my $monthsel='';
6299: my $weeksel='';
6300: my $daysel='';
6301: my $allsel='';
6302: my %changes=();
6303: my $starttime=0;
6304: my $haschanged=0;
6305: my %setversions=&Apache::lonnet::dump('resourceversions',
6306: $env{'course.'.$env{'request.course.id'}.'.domain'},
6307: $env{'course.'.$env{'request.course.id'}.'.num'});
6308:
6309: $hashtied=0;
6310: &tiehash();
1.611 raeburn 6311: if ($canedit) {
6312: my %newsetversions=();
6313: if ($env{'form.setmostrecent'}) {
6314: $haschanged=1;
6315: foreach my $key (keys(%hash)) {
6316: if ($key=~/^ids\_(\/res\/.+)$/) {
6317: $newsetversions{$1}='mostrecent';
6318: &devalidateversioncache($1);
6319: }
6320: }
6321: } elsif ($env{'form.setcurrent'}) {
6322: $haschanged=1;
6323: foreach my $key (keys(%hash)) {
6324: if ($key=~/^ids\_(\/res\/.+)$/) {
6325: my $getvers=&Apache::lonnet::getversion($1);
6326: if ($getvers>0) {
6327: $newsetversions{$1}=$getvers;
6328: &devalidateversioncache($1);
6329: }
6330: }
1.329 droeschl 6331: }
1.611 raeburn 6332: } elsif ($env{'form.setversions'}) {
6333: $haschanged=1;
6334: foreach my $key (keys(%env)) {
6335: if ($key=~/^form\.set_version_(.+)$/) {
6336: my $src=$1;
6337: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6338: $newsetversions{$src}=$env{$key};
6339: &devalidateversioncache($src);
6340: }
6341: }
1.329 droeschl 6342: }
1.611 raeburn 6343: }
6344: if ($haschanged) {
6345: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6346: $env{'course.'.$env{'request.course.id'}.'.domain'},
6347: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6348: $r->print(&Apache::loncommon::confirmwrapper(
6349: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6350: } else {
6351: $r->print(&Apache::loncommon::confirmwrapper(
6352: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6353: }
1.611 raeburn 6354: &mark_hash_old();
6355: }
6356: &changewarning($r,'');
1.329 droeschl 6357: }
6358: if ($env{'form.timerange'} eq 'all') {
6359: # show all documents
1.549 raeburn 6360: $header=&mt('All content in '.$crstype);
1.521 bisitz 6361: $allsel=' selected="selected"';
1.329 droeschl 6362: foreach my $key (keys(%hash)) {
6363: if ($key=~/^ids\_(\/res\/.+)$/) {
6364: my $src=$1;
6365: $changes{$src}=1;
6366: }
6367: }
6368: } else {
6369: # show documents which changed
6370: %changes=&Apache::lonnet::dump
6371: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6372: $env{'course.'.$env{'request.course.id'}.'.num'});
6373: my $firstkey=(keys(%changes))[0];
6374: unless ($firstkey=~/^error\:/) {
6375: unless ($env{'form.timerange'}) {
6376: $env{'form.timerange'}=604800;
6377: }
6378: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6379: .&mt('seconds');
6380: if ($env{'form.timerange'}==-1) {
6381: $seltext='since start of course';
1.521 bisitz 6382: $startsel=' selected="selected"';
1.329 droeschl 6383: $env{'form.timerange'}=time;
6384: }
6385: $starttime=time-$env{'form.timerange'};
6386: if ($env{'form.timerange'}==2592000) {
6387: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6388: $monthsel=' selected="selected"';
1.329 droeschl 6389: } elsif ($env{'form.timerange'}==604800) {
6390: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6391: $weeksel=' selected="selected"';
1.329 droeschl 6392: } elsif ($env{'form.timerange'}==86400) {
6393: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6394: $daysel=' selected="selected"';
1.329 droeschl 6395: }
6396: $header=&mt('Content changed').' '.$seltext;
6397: } else {
6398: $header=&mt('No content modifications yet.');
6399: }
6400: }
6401: %setversions=&Apache::lonnet::dump('resourceversions',
6402: $env{'course.'.$env{'request.course.id'}.'.domain'},
6403: $env{'course.'.$env{'request.course.id'}.'.num'});
6404: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6405: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6406: 'lm' => 'Version changes since last Month',
6407: 'lw' => 'Version changes since last Week',
6408: 'sy' => 'Version changes since Yesterday',
6409: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6410: 'cd' => 'Change display',
1.329 droeschl 6411: 'sd' => 'Display',
6412: 'fi' => 'File',
6413: 'md' => 'Modification Date',
6414: 'mr' => 'Most recently published Version',
1.408 raeburn 6415: 've' => 'Version used in '.$crstype,
6416: 'vu' => 'Set Version to be used in '.$crstype,
6417: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6418: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6419: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6420: 'di' => 'Differences',
1.484 raeburn 6421: 'save' => 'Save changes',
6422: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6423: 'act' => 'Actions');
1.611 raeburn 6424: my ($disabled,$readonly);
6425: unless ($canedit) {
6426: $disabled = 'disabled="disabled"';
6427: $readonly = 1;
6428: }
1.329 droeschl 6429: $r->print(<<ENDHEADERS);
1.484 raeburn 6430: <h4 class="LC_info">$header</h4>
1.329 droeschl 6431: <form action="/adm/coursedocs" method="post">
6432: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6433: <div class="LC_left_float">
1.479 golterma 6434: <fieldset>
1.484 raeburn 6435: <legend>$lt{'cd'}</legend>
1.329 droeschl 6436: <select name="timerange">
1.521 bisitz 6437: <option value='all'$allsel>$lt{'al'}</option>
6438: <option value="-1"$startsel>$lt{'st'}</option>
6439: <option value="2592000"$monthsel>$lt{'lm'}</option>
6440: <option value="604800"$weeksel>$lt{'lw'}</option>
6441: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6442: </select>
6443: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6444: </fieldset>
6445: </div>
6446: <div class="LC_left_float">
6447: <fieldset>
6448: <legend>$lt{'act'}</legend>
1.611 raeburn 6449: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6450: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6451: </fieldset>
6452: </div>
6453: <br clear="all" />
6454: <hr />
6455: <h4>$lt{'vers'}</h4>
1.329 droeschl 6456: ENDHEADERS
1.479 golterma 6457: #number of columns for version history
1.571 raeburn 6458: my %changedbytime;
6459: foreach my $key (keys(%changes)) {
6460: #excludes not versionable problems from resource version history:
6461: next if ($key =~ /^\/res\/lib\/templates/);
6462: my $chg;
6463: if ($env{'form.timerange'} eq 'all') {
6464: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6465: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6466: } else {
6467: $chg = $changes{$key};
6468: next if ($chg < $starttime);
6469: }
6470: push(@{$changedbytime{$chg}},$key);
6471: }
6472: if (keys(%changedbytime) == 0) {
6473: &untiehash();
6474: $r->print(&mt('No content changes in imported content in specified time frame').
6475: &endContentScreen());
6476: return;
6477: }
1.479 golterma 6478: $r->print(
1.611 raeburn 6479: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6480: &Apache::loncommon::start_data_table().
6481: &Apache::loncommon::start_data_table_header_row().
6482: '<th>'.&mt('Resources').'</th>'.
6483: "<th>$lt{'mr'}</th>".
6484: "<th>$lt{'ve'}</th>".
6485: "<th>$lt{'vu'}</th>".
6486: '<th>'.&mt('History').'</th>'.
6487: &Apache::loncommon::end_data_table_header_row()
6488: );
1.571 raeburn 6489: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6490: foreach my $key (sort(@{$changedbytime{$chg}})) {
6491: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6492: my $currentversion=&Apache::lonnet::getversion($key);
6493: if ($currentversion<0) {
6494: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6495: }
6496: my $linkurl=&Apache::lonnet::clutter($key);
6497: $r->print(
6498: &Apache::loncommon::start_data_table_row().
6499: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6500: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6501: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6502: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6503: '<td align="right">'
6504: );
6505: # Used in course
6506: my $usedversion=$hash{'version_'.$linkurl};
6507: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6508: if ($usedversion != $currentversion) {
1.479 golterma 6509: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6510: } else {
1.479 golterma 6511: $r->print($usedversion);
6512: }
1.329 droeschl 6513: } else {
1.521 bisitz 6514: $r->print($currentversion);
1.329 droeschl 6515: }
1.571 raeburn 6516: $r->print('</td><td title="'.$lt{'vu'}.'">');
6517: # Set version
6518: $r->print(&Apache::loncommon::select_form(
6519: $setversions{$linkurl},
6520: 'set_version_'.$linkurl,
6521: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6522: '' => '',
6523: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6524: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6525: my $lastold=1;
6526: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6527: my $url=$root.'.'.$prevvers.'.'.$extension;
6528: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6529: $lastold=$prevvers;
6530: }
6531: }
6532: $r->print('</td>');
6533: # List all available versions
6534: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6535: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6536: my $url=$root.'.'.$prevvers.'.'.$extension;
6537: $r->print(
6538: '<span class="LC_nobreak">'
6539: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6540: .&mt('Version [_1]',$prevvers).'</a>'
6541: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6542: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6543: .')');
6544: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6545: $r->print(
6546: ' <a href="/adm/diff?filename='.
6547: &Apache::lonnet::clutter($root.'.'.$extension).
6548: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6549: '" target="diffs">'.&mt('Diffs').'</a>');
6550: }
6551: $r->print('</span><br />');
1.329 droeschl 6552: }
1.571 raeburn 6553: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6554: }
1.329 droeschl 6555: }
1.521 bisitz 6556: $r->print(
6557: &Apache::loncommon::end_data_table().
1.611 raeburn 6558: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6559: '</form>'
6560: );
1.329 droeschl 6561:
6562: &untiehash();
1.521 bisitz 6563: $r->print(&endContentScreen());
1.571 raeburn 6564: return;
1.329 droeschl 6565: }
6566:
6567: sub mark_hash_old {
6568: my $retie_hash=0;
6569: if ($hashtied) {
6570: $retie_hash=1;
6571: &untiehash();
6572: }
6573: &tiehash('write');
6574: $hash{'old'}=1;
6575: &untiehash();
6576: if ($retie_hash) { &tiehash(); }
6577: }
6578:
6579: sub is_hash_old {
6580: my $untie_hash=0;
6581: if (!$hashtied) {
6582: $untie_hash=1;
6583: &tiehash();
6584: }
6585: my $return=$hash{'old'};
6586: if ($untie_hash) { &untiehash(); }
6587: return $return;
6588: }
6589:
6590: sub changewarning {
6591: my ($r,$postexec,$message,$url)=@_;
6592: if (!&is_hash_old()) { return; }
6593: my $pathvar='folderpath';
6594: my $path=&escape($env{'form.folderpath'});
6595: if (!defined($url)) {
6596: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6597: }
6598: my $course_type = &Apache::loncommon::course_type();
6599: if (!defined($message)) {
6600: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6601: }
1.653 raeburn 6602: my $windowname = 'loncapaclient';
6603: if ($env{'request.lti.login'}) {
6604: $windowname .= 'lti';
6605: }
1.329 droeschl 6606: $r->print("\n\n".
1.372 bisitz 6607: '<script type="text/javascript">'."\n".
6608: '// <![CDATA['."\n".
6609: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6610: '// ]]>'."\n".
1.369 bisitz 6611: '</script>'."\n".
1.653 raeburn 6612: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6613: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6614: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6615: &mt($message,' <input type="hidden" name="'.
6616: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6617: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6618: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6619: }
6620:
6621:
6622: sub init_breadcrumbs {
1.571 raeburn 6623: my ($form,$text,$help)=@_;
1.329 droeschl 6624: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6625: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6626: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6627: faq=>273,
6628: bug=>'Instructor Interface',
1.571 raeburn 6629: help => $help});
1.329 droeschl 6630: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6631: text=>$text,
6632: faq=>273,
6633: bug=>'Instructor Interface'});
6634: }
6635:
1.441 www 6636: # subroutine to list form elements
6637: sub create_list_elements {
6638: my @formarr = @_;
6639: my $list = '';
1.501 raeburn 6640: foreach my $button (@formarr){
6641: foreach my $picture (keys(%{$button})) {
6642: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6643: }
6644: }
6645: return $list;
6646: }
1.329 droeschl 6647:
1.441 www 6648: # subroutine to create ul from list elements
6649: sub create_form_ul {
6650: my $list = shift;
6651: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6652: return $ul;
6653: }
1.329 droeschl 6654:
1.442 www 6655: #
6656: # Start tabs
6657: #
6658:
6659: sub startContentScreen {
1.484 raeburn 6660: my ($mode) = @_;
6661: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6662: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6663: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6664: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6665: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6666: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6667: } else {
1.549 raeburn 6668: $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 6669: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6670: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6671: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6672: }
6673: $output .= "\n".'</ul>'."\n";
6674: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6675: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6676: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6677: return $output;
1.442 www 6678: }
6679:
6680: #
6681: # End tabs
6682: #
6683:
6684: sub endContentScreen {
1.484 raeburn 6685: return '</div></div></div>';
1.442 www 6686: }
1.329 droeschl 6687:
1.446 www 6688: sub supplemental_base {
1.548 raeburn 6689: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6690: }
6691:
1.329 droeschl 6692: sub handler {
6693: my $r = shift;
6694: &Apache::loncommon::content_type($r,'text/html');
6695: $r->send_http_header;
6696: return OK if $r->header_only;
1.484 raeburn 6697:
6698: # get course data
1.408 raeburn 6699: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6700: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6701: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6702: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6703:
1.606 raeburn 6704: # get docroot
6705: my $londocroot = $r->dir_config('lonDocRoot');
6706:
1.484 raeburn 6707: # graphics settings
6708: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6709:
1.443 www 6710: #
1.329 droeschl 6711: # --------------------------------------------- Initialize help topics for this
6712: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6713: 'Adding_External_Resource','Adding_External_Tool',
6714: 'Navigate_Content','Adding_Folders','Docs_Overview',
6715: 'Load_Map','Supplemental','Score_Upload_Form',
6716: 'Adding_Pages','Importing_LON-CAPA_Resource',
6717: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6718: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6719: 'Standard_Problem','Course_Resources',
6720: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6721: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6722: }
6723: # Composite help files
6724: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6725: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6726: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6727: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6728: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6729: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6730: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6731: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6732: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6733: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6734:
1.611 raeburn 6735: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6736: # does this user have privileges to modify content.
6737: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6738: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6739: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6740: $allowed = 1;
1.682 raeburn 6741: }
6742: $canedit = 1;
6743: $canview = 1;
6744: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6745: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6746: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6747: $allowed = 1;
6748: }
1.682 raeburn 6749: $canview = 1;
1.611 raeburn 6750: }
6751: unless ($canedit) {
6752: $disabled = ' disabled="disabled"';
1.472 raeburn 6753: }
1.582 raeburn 6754: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6755: if ($env{'form.inhibitmenu'}) {
6756: unless ($env{'form.inhibitmenu'} eq 'yes') {
6757: delete($env{'form.inhibitmenu'});
6758: }
6759: }
6760:
1.582 raeburn 6761: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6762: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6763: if (!$canedit) {
6764: &verifycontent($r);
6765: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6766: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6767: text=>'Results',
6768: faq=>273,
6769: bug=>'Instructor Interface'});
6770: &verifycontent($r,$env{'form.checkstale'});
6771: } else {
6772: &contentverifyform($r);
6773: }
1.329 droeschl 6774: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6775: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6776: &list_symbs($r);
1.651 raeburn 6777: } elsif ($allowed && $env{'form.shorturls'}) {
6778: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6779: &short_urls($r,$canedit);
1.329 droeschl 6780: } elsif ($allowed && $env{'form.docslog'}) {
6781: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6782: my $folder = $env{'form.folder'};
6783: if ($folder eq '') {
6784: $folder='default';
6785: }
1.611 raeburn 6786: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6787: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6788: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6789: &checkversions($r,$canedit);
6790: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6791: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6792: &dumpcourse($r);
1.712 raeburn 6793: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
6794: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
6795: my $readonly;
6796: if (!$canedit) {
6797: $readonly = 1;
6798: }
6799: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6800: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6801: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6802: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6803: } else {
1.611 raeburn 6804: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6805: $noendpage = 1;
6806: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6807: if ($redirect) {
6808: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6809: my $container = 'sequence';
6810: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6811: $is_random_order,$container) =
6812: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6813: my (@folders)=split('&',$env{'form.folderpath'});
6814: $env{'form.foldername'}=&unescape(pop(@folders));
6815: my $folder=pop(@folders);
6816: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6817: $folder.'.'.$container);
6818: my $warning;
6819: if ($fatal) {
6820: if ($container eq 'page') {
6821: $warning = &mt('An error occurred retrieving the contents of the current page.');
6822: } else {
6823: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6824: }
6825: } else {
6826: my $url = $redirect;
6827: my $srcfile = $londocroot.$url;
6828: $url =~ s{^/priv/}{/res/};
6829: my $targetfile = $londocroot.$url;
6830: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6831: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6832: $env{'form.folder'} = $folder;
6833: &snapshotbefore();
6834: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6835: my $ext = 'false';
6836: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6837: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6838: ':'.$ext.':normal:res';
6839: push(@LONCAPA::map::order,$newidx);
6840: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6841: 'string_yesno');
6842: &remember_parms($newidx,'hiddenresource','set','yes');
6843: ($errtext,$fatal) =
6844: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6845: &log_differences($plain);
6846: &mark_hash_old();
6847: $r->internal_redirect($redirect);
6848: return OK;
6849: }
1.654 raeburn 6850: } else {
6851: $r->internal_redirect($redirect);
1.606 raeburn 6852: }
6853: }
6854: }
1.445 www 6855: #
6856: # Done catching special calls
1.484 raeburn 6857: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6858: # Get the parameters that may be needed
6859: #
6860: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6861: ['folderpath','title',
1.519 raeburn 6862: 'forcesupplement','forcestandard',
1.510 raeburn 6863: 'tools','symb','command','supppath']);
1.445 www 6864:
1.635 raeburn 6865: foreach my $item ('forcesupplement','forcestandard','tools') {
6866: next if ($env{'form.'.$item} eq '');
6867: unless ($env{'form.'.$item} eq '1') {
6868: delete($env{'form.'.$item});
6869: }
6870: }
6871:
6872: if ($env{'form.command'}) {
6873: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6874: delete($env{'form.command'});
6875: }
6876: }
6877:
6878: if ($env{'form.symb'}) {
6879: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6880: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6881: delete($env{'form.symb'});
6882: }
6883: }
6884:
1.445 www 6885: # standard=1: this is a "new-style" course with an uploaded map as top level
6886: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 6887:
6888: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 6889:
1.484 raeburn 6890: # Decide whether this should display supplemental or main content or utilities
1.445 www 6891: # supplementalflag=1: show supplemental documents
6892: # supplementalflag=0: show standard documents
1.484 raeburn 6893: # toolsflag=1: show utilities
1.445 www 6894:
1.561 raeburn 6895: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6896: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6897: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 6898: $supplementalflag=0;
6899: }
6900: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6901: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 6902: unless (($supplementalflag) ||
6903: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
6904: unless ($allowed) { $supplementalflag=1; }
6905: unless ($standard) { $supplementalflag=1; }
6906: }
1.484 raeburn 6907: my $toolsflag=0;
6908: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 6909:
1.635 raeburn 6910: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6911: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 6912: }
6913:
1.685 raeburn 6914: my $backto_supppath;
1.635 raeburn 6915: if ($env{'form.supppath'} ne '') {
1.685 raeburn 6916: if ($supplementalflag && $allowed) {
6917: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6918: }
1.635 raeburn 6919: }
6920:
1.329 droeschl 6921: my $script='';
6922: my $showdoc=0;
1.457 raeburn 6923: my $addentries = {};
1.475 raeburn 6924: my $container;
1.329 droeschl 6925: my $containertag;
1.508 raeburn 6926: my $pathitem;
1.598 raeburn 6927: my %ltitools;
1.699 raeburn 6928: my $posslti;
1.617 raeburn 6929: my $hiddentop;
1.615 raeburn 6930: my $navmap;
1.617 raeburn 6931: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 6932:
1.464 www 6933: # Do we directly jump somewhere?
1.525 raeburn 6934: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 6935: if ($env{'form.symb'} ne '') {
1.522 raeburn 6936: $env{'form.folderpath'}=
1.617 raeburn 6937: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 6938: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 6939: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 6940: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 6941: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 6942: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 6943: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 6944: }
1.472 raeburn 6945: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 6946: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 6947: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 6948: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 6949: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 6950: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6951: } elsif ($env{'form.command'} eq 'contents') {
6952: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6953: } elsif ($env{'form.command'} eq 'home') {
6954: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 6955: }
6956:
1.525 raeburn 6957:
1.445 www 6958: # Where do we store these for when we come back?
6959: my $stored_folderpath='docs_folderpath';
6960: if ($supplementalflag) {
6961: $stored_folderpath='docs_sup_folderpath';
6962: }
1.464 www 6963:
1.519 raeburn 6964: # No folderpath, and in edit mode, see if we have something stored
6965: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6966: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 6967: {'folderpath' => 'scalar'});
1.615 raeburn 6968:
6969: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6970: if ($supplementalflag) {
6971: undef($env{'form.folderpath'}) if ($1 eq 'default');
6972: } else {
6973: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6974: }
6975: } else {
1.523 raeburn 6976: undef($env{'form.folderpath'});
6977: }
1.677 raeburn 6978: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6979: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 6980: }
1.329 droeschl 6981: }
1.706 raeburn 6982:
6983: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 6984: if ((!$allowed) && ($supplementalflag)) {
1.446 www 6985: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6986: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6987: }
6988: }
1.446 www 6989: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6990: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6991: $env{'form.folderpath'} = &supplemental_base()
6992: .'&'.
1.329 droeschl 6993: $env{'form.folderpath'};
6994: }
1.685 raeburn 6995: # If allowed and user's role is not advanced check folderpath is not hidden
6996: my $hidden_and_empty;
1.687 raeburn 6997: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 6998: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 6999: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 7000: my $folder = $pathitems[-2];
7001: if ($folder eq '') {
7002: undef($env{'form.folderpath'});
7003: } else {
7004: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 7005: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 7006: $folderurl .= '.page';
7007: } else {
7008: $folderurl .= '.sequence';
7009: }
1.685 raeburn 7010: if ($supplementalflag) {
7011: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
7012: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 7013: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 7014: if (ref($supplemental) eq 'HASH') {
7015: my ($suppmap,$suppmapnum);
7016: if ($folder eq 'supplemental') {
7017: $suppmap = 'default';
7018: $suppmapnum = 0;
7019: } elsif ($folder =~ /^supplemental_(\d+)$/) {
7020: $suppmap = $1;
7021: $suppmapnum = $suppmap;
7022: }
7023: if ($hiddenfolder) {
7024: my $hascontent;
7025: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
7026: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
7027: $hascontent = 1;
7028: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
7029: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
7030: if ($id =~ /^$suppmapnum\:/) {
7031: $hascontent = 1;
7032: last;
7033: }
7034: }
7035: }
7036: last if ($hascontent);
7037: }
7038: unless ($hascontent) {
7039: if ($foldername ne '') {
7040: $hidden_and_empty = $foldername;
7041: } else {
7042: $hidden_and_empty = $folder;
7043: }
7044: }
7045: }
7046: }
7047: } else {
7048: unless (ref($navmap)) {
7049: $navmap = Apache::lonnavmaps::navmap->new();
7050: }
7051: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
7052: $foldername = &HTML::Entities::decode(&unescape($foldername));
7053: if (ref($navmap)) {
7054: if ($hiddenfolder ||
7055: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
7056: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
7057: unless (@resources) {
7058: if ($foldername ne '') {
7059: $hidden_and_empty = $foldername;
7060: } else {
7061: $hidden_and_empty = $folder;
7062: }
7063: }
7064: }
7065: }
1.617 raeburn 7066: }
1.685 raeburn 7067: if ($hidden_and_empty ne '') {
7068: splice(@pathitems,-2);
7069: if (@pathitems) {
7070: $env{'form.folderpath'} = join('&',@pathitems);
7071: } else {
7072: undef($env{'form.folderpath'});
1.615 raeburn 7073: }
7074: }
7075: }
7076: }
7077:
1.446 www 7078: # If after all of this, we still don't have any paths, make them
1.519 raeburn 7079: unless ($env{'form.folderpath'}) {
1.446 www 7080: if ($supplementalflag) {
7081: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 7082: } elsif ($allowed) {
7083: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 7084: }
1.472 raeburn 7085: }
1.446 www 7086:
1.445 www 7087: # Store this
1.484 raeburn 7088: unless ($toolsflag) {
1.615 raeburn 7089: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 7090: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 7091: {'folderpath' => 'scalar'});
1.510 raeburn 7092: }
1.519 raeburn 7093: my $folderpath;
1.484 raeburn 7094: if ($env{'form.folderpath'}) {
1.519 raeburn 7095: $folderpath = $env{'form.folderpath'};
7096: my (@folders)=split('&',$env{'form.folderpath'});
7097: $env{'form.foldername'}=&unescape(pop(@folders));
7098: if ($env{'form.foldername'} =~ /\:1$/) {
7099: $container = 'page';
7100: } else {
7101: $container = 'sequence';
7102: }
7103: $env{'form.folder'}=pop(@folders);
1.484 raeburn 7104: } else {
1.519 raeburn 7105: if ($env{'form.folder'} eq '' ||
7106: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 7107: if ($env{'form.folder'} eq 'supplemental') {
7108: $folderpath=&supplemental_base();
7109: } elsif (!$hiddentop) {
7110: $folderpath='default&'.
7111: &escape(&mt('Main Content').':::::');
7112: }
1.484 raeburn 7113: }
7114: }
1.519 raeburn 7115: $containertag = '<input type="hidden" name="folderpath" value="" />';
7116: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 7117: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
7118: $showdoc='/'.$1;
7119: }
7120: if ($showdoc) { # got called in sequence from course
7121: $allowed=0;
7122: } else {
1.611 raeburn 7123: if ($canedit) {
1.484 raeburn 7124: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
7125: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 7126: }
7127: }
1.329 droeschl 7128: }
7129:
1.344 bisitz 7130: # get personal data
1.329 droeschl 7131: my $uname=$env{'user.name'};
7132: my $udom=$env{'user.domain'};
7133: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
7134:
7135: if ($allowed) {
1.484 raeburn 7136: if ($toolsflag) {
7137: $script .= &inject_data_js();
7138: my ($home,$other,%outhash)=&authorhosts();
7139: if (!$home && $other) {
7140: my @hosts;
7141: foreach my $aurole (keys(%outhash)) {
7142: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7143: push(@hosts,$outhash{$aurole});
7144: }
7145: }
7146: $script .= &dump_switchserver_js(@hosts);
7147: }
1.458 raeburn 7148: } else {
1.570 raeburn 7149: my $tid = 1;
1.484 raeburn 7150: my @tabids;
7151: if ($supplementalflag) {
1.655 raeburn 7152: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 7153: $tid = 2;
1.484 raeburn 7154: } else {
7155: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 7156: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 7157: unshift(@tabids,'001');
7158: push(@tabids,('dd1','ee1'));
7159: }
1.458 raeburn 7160: }
1.484 raeburn 7161: my $tabidstr = join("','",@tabids);
1.699 raeburn 7162: my (%domtools,%crstools);
7163: my %tooltypes = &Apache::loncommon::usable_exttools();
7164: if ($tooltypes{'dom'}) {
7165: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
7166: }
7167: if ($tooltypes{'crs'}) {
7168: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
7169: }
7170: %ltitools = (
7171: dom => \%domtools,
7172: crs => \%crstools,
7173: );
7174: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 7175: my $hostname = $r->hostname();
1.606 raeburn 7176: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 7177: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 7178: &history_tab_js().
7179: &inject_data_js().
1.570 raeburn 7180: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 7181: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 7182: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
7183: if ($hidden_and_empty ne '') {
7184: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
7185: $hidden_and_empty);
7186: $onload .= "javascript:alert('".&js_escape($alert)."');";
7187: }
1.484 raeburn 7188: $addentries = {
1.685 raeburn 7189: onload => $onload,
1.484 raeburn 7190: };
1.458 raeburn 7191: }
1.538 raeburn 7192: $script .= &paste_popup_js();
1.501 raeburn 7193: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
7194: &mt('Switch server?');
7195:
7196:
1.329 droeschl 7197: }
7198: # -------------------------------------------------------------------- Body tag
1.369 bisitz 7199: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 7200: .'// <![CDATA['."\n"
7201: .$script."\n"
7202: .'// ]]>'."\n"
1.595 musolffc 7203: .'</script>'."\n"
7204: .'<script type="text/javascript"
7205: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 7206:
7207: # Breadcrumbs
7208: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7209:
7210: if ($showdoc) {
1.682 raeburn 7211: my $args;
7212: if ($supplementalflag) {
1.687 raeburn 7213: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7214: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7215: $args = {'bread_crumbs' => $brcrum,
7216: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7217: } else {
7218: $args = {'force_register' => $showdoc};
7219: }
7220: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7221: } elsif ($toolsflag) {
1.611 raeburn 7222: my ($breadtext,$breadtitle);
1.617 raeburn 7223: $breadtext = "$crstype Editor";
1.611 raeburn 7224: if ($canedit) {
7225: $breadtitle = 'Editing '.$crstype.' Contents';
7226: } else {
7227: $breadtext .= ' (View-only mode)';
7228: $breadtitle = 'Viewing '.$crstype.' Contents';
7229: }
1.571 raeburn 7230: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7231: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7232: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7233: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7234: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7235: $breadtitle)
1.571 raeburn 7236: );
1.510 raeburn 7237: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7238: unless ($env{'request.role.adv'}) {
7239: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7240: $r->internal_redirect('/adm/navmaps');
7241: return OK;
7242: }
7243: }
1.510 raeburn 7244: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7245: my $args = {'bread_crumbs' => $brcrum};
7246: unless (($env{'form.folderpath'} eq '') ||
7247: ($env{'form.folder'} eq 'supplemental')) {
7248: $args->{'bread_crumbs_nomenu'} = 1;
7249: }
1.510 raeburn 7250: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7251: $args));
1.510 raeburn 7252: } else {
1.611 raeburn 7253: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7254: $breadtext = "$crstype Editor";
1.611 raeburn 7255: if ($canedit) {
7256: $breadtitle = 'Editing '.$crstype.' Contents';
7257: $helpitem = 'Docs_Adding_Course_Doc';
7258: } else {
7259: $breadtext .= ' (View-only mode)';
7260: $breadtitle = 'Viewing '.$crstype.' Contents';
7261: $helpitem = 'Docs_Viewing_Course_Doc';
7262: }
1.392 raeburn 7263: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7264: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7265: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7266: {'add_entries' => $addentries}
7267: )
1.392 raeburn 7268: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7269: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7270: $breadtitle,
7271: $helpitem)
1.392 raeburn 7272: );
7273: }
1.364 bisitz 7274:
1.329 droeschl 7275: my %allfiles = ();
7276: my %codebase = ();
1.440 raeburn 7277: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7278: if ($canedit) {
1.684 raeburn 7279: undef($suppchanges);
1.329 droeschl 7280: if (($env{'form.uploaddoc.filename'}) &&
7281: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7282: my $context = $1;
7283: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7284: undef($hadchanges);
1.440 raeburn 7285: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7286: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7287: undef($navmap);
1.329 droeschl 7288: if ($hadchanges) {
7289: &mark_hash_old();
7290: }
1.684 raeburn 7291: if ($suppchanges) {
7292: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7293: undef($suppchanges);
7294: }
1.440 raeburn 7295: $r->print($upload_output);
7296: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7297: # Process file upload - phase two - upload embedded objects
7298: $uploadphase = 'check_embedded';
7299: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7300: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7301: $env{'form.newidx'});
7302: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7303: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7304: my ($destination,$dir_root) = &embedded_destination();
7305: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7306: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7307: my ($result,$flag) =
1.440 raeburn 7308: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7309: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7310: $actionurl);
7311: $r->print($result.&return_to_editor());
7312: } elsif ($env{'form.phase'} eq 'check_embedded') {
7313: # Process file upload - phase three - modify references in HTML file
7314: $uploadphase = 'modified_orightml';
7315: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7316: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7317: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7318: my $result =
1.482 raeburn 7319: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7320: $docuname,$docudom,undef,
7321: $dir_root);
1.630 raeburn 7322: $r->print($result.&return_to_editor());
1.476 raeburn 7323: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7324: $uploadphase = 'decompress_phase_one';
7325: $r->print(&decompression_phase_one().
7326: &return_to_editor());
7327: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7328: $uploadphase = 'decompress_phase_two';
7329: $r->print(&decompression_phase_two().
7330: &return_to_editor());
1.329 droeschl 7331: }
7332: }
7333:
1.484 raeburn 7334: if ($allowed && $toolsflag) {
7335: $r->print(&startContentScreen('tools'));
1.708 raeburn 7336: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7337: $r->print(&endContentScreen());
7338: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7339: # -----------------------------------------------------------------------------
7340: my %lt=&Apache::lonlocal::texthash(
7341: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7342: 'upfi' => 'Upload File',
1.553 raeburn 7343: 'upld' => 'Upload Content',
1.706 raeburn 7344: 'srch' => 'Search Repository',
7345: 'impo' => 'Import from Repository',
1.487 raeburn 7346: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7347: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7348: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7349: 'extr' => 'External Resource',
7350: 'extt' => 'External Tool',
1.329 droeschl 7351: 'selm' => 'Select Map',
7352: 'load' => 'Load Map',
7353: 'newf' => 'New Folder',
7354: 'newp' => 'New Composite Page',
7355: 'syll' => 'Syllabus',
1.425 raeburn 7356: 'navc' => 'Table of Contents',
1.343 biermanm 7357: 'sipa' => 'Simple Course Page',
1.329 droeschl 7358: 'sipr' => 'Simple Problem',
1.630 raeburn 7359: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7360: 'stpr' => 'Standard Problem',
7361: 'news' => 'New sub-directory',
7362: 'crpr' => 'Create Problem',
1.689 raeburn 7363: 'swit' => 'Switch Server',
1.329 droeschl 7364: 'drbx' => 'Drop Box',
1.451 www 7365: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7366: 'bull' => 'Discussion Board',
1.347 weissno 7367: 'mypi' => 'My Personal Information Page',
1.353 weissno 7368: 'grpo' => 'Group Portfolio',
1.329 droeschl 7369: 'rost' => 'Course Roster',
1.528 raeburn 7370: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7371: 'imsf' => 'IMS Upload',
7372: 'imsl' => 'Upload IMS package',
1.501 raeburn 7373: 'cms' => 'Origin of IMS package',
7374: 'se' => 'Select',
1.329 droeschl 7375: 'file' => 'File',
7376: 'title' => 'Title',
1.606 raeburn 7377: 'addp' => 'Add Placeholder to course?',
7378: 'uste' => 'Use Template?',
7379: 'fnam' => 'File Name:',
7380: 'loca' => 'Location:',
7381: 'dire' => 'Directory:',
7382: 'cate' => 'Category:',
7383: 'tmpl' => 'Template:',
1.698 raeburn 7384: 'empd' => 'No resources found',
1.329 droeschl 7385: 'comment' => 'Comment',
1.403 raeburn 7386: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7387: 'bb5' => 'Blackboard 5',
7388: 'bb6' => 'Blackboard 6',
7389: 'angel5' => 'ANGEL 5.5',
7390: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7391: 'yes' => 'Yes',
7392: 'no' => 'No',
1.618 raeburn 7393: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7394: );
1.329 droeschl 7395: # -----------------------------------------------------------------------------
1.595 musolffc 7396:
7397: # Calculate free quota space for a user or course. A javascript function checks
7398: # file size to determine if upload should be allowed.
7399: my $quotatype = 'unofficial';
7400: if ($crstype eq 'Community') {
1.601 raeburn 7401: $quotatype = 'community';
7402: } elsif ($crstype eq 'Placement') {
7403: $quotatype = 'placement';
1.595 musolffc 7404: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7405: $quotatype = 'official';
7406: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7407: $quotatype = 'textbook';
7408: }
7409: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7410: 'course',$quotatype); # expressed in MB
7411: my $current_disk_usage = 0;
7412: foreach my $subdir ('docs','supplemental') {
7413: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7414: "userfiles/$subdir",1); # expressed in kB
7415: }
7416: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7417: my $usage = $current_disk_usage/1024; # in MB
7418: my $quota = $disk_quota;
7419: my $percent;
7420: if ($disk_quota == 0) {
7421: $percent = 100.0;
7422: } else {
1.619 raeburn 7423: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7424: }
7425: $usage = sprintf("%.2f",$usage);
7426: $quota = sprintf("%.2f",$quota);
7427: $percent = sprintf("%.0f",$percent);
7428: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7429: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7430:
1.329 droeschl 7431: my $fileupload=(<<FIUP);
1.605 raeburn 7432: $quotainfo
1.329 droeschl 7433: $lt{'file'}:<br />
7434: FIUP
7435: my $checkbox=(<<CHBO);
7436: <!-- <label>$lt{'parse'}?
7437: <input type="checkbox" name="parserflag" />
7438: </label> -->
7439: <label>
1.611 raeburn 7440: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7441: </label>
7442: CHBO
1.501 raeburn 7443: my $imsfolder = $env{'form.folder'};
7444: if ($imsfolder eq '') {
7445: $imsfolder = 'default';
7446: }
7447: my $imspform=(<<IMSFORM);
7448: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7449: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7450: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7451: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7452: <legend>$lt{'imsf'}</legend>
7453: $fileupload
1.702 raeburn 7454: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7455: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7456: <br />
7457: <p>
7458: $lt{'cms'}:
1.611 raeburn 7459: <select name="source" $disabled>
1.501 raeburn 7460: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7461: <option value="bb5">$lt{'bb5'}</option>
7462: <option value="bb6">$lt{'bb6'}</option>
7463: <option value="angel5">$lt{'angel5'}</option>
7464: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7465: </select>
7466: <input type="hidden" name="folder" value="$imsfolder" />
7467: </p>
7468: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7469: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7470: </fieldset>
7471: </form>
7472: IMSFORM
1.329 droeschl 7473:
7474: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7475: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7476: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7477: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7478: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7479: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7480: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7481: $fileupload
1.702 raeburn 7482: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7483: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7484: <br />
7485: $lt{'title'}:<br />
1.611 raeburn 7486: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7487: $pathitem
1.329 droeschl 7488: <input type="hidden" name="cmd" value="upload_default" />
7489: <br />
1.458 raeburn 7490: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7491: $checkbox
7492: </span>
1.501 raeburn 7493: <br clear="all" />
1.611 raeburn 7494: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7495: </fieldset>
7496: </form>
1.383 tempelho 7497: FUFORM
1.329 droeschl 7498:
1.611 raeburn 7499: my $mapimportjs;
7500: if ($canedit) {
7501: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7502: } else {
7503: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7504: }
1.502 raeburn 7505: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7506: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7507: $lt{'impm'}</a>$help{'Load_Map'}
7508: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7509: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7510: <legend>$lt{'impm'}</legend>
1.371 tempelho 7511: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7512: $lt{'copm'}<br />
7513: <span class="LC_nobreak">
7514: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7515: onfocus="this.blur();$mapimportjs" $disabled />
7516: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7517: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7518: </fieldset>
7519: </form>
7520:
1.383 tempelho 7521: SEDFFORM
1.706 raeburn 7522: my ($importcrsresform,$checkcrsres);
7523: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7524: $checkcrsres = 1;
7525: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7526: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7527: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7528: unless (($type eq 'community') || ($type eq 'placement')) {
7529: $type = 'unofficial';
7530: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7531: $type = 'official';
7532: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7533: $type = 'textbook';
7534: } else {
7535: $type = 'unofficial';
7536: }
7537: }
7538: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7539: $checkcrsres = 1;
7540: }
7541: }
7542: if ($checkcrsres) {
7543: my ($numdirs,$pickfile) =
7544: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7545: "resize_scrollbox('contentscroll','1','0');",
7546: undef,'res');
7547: if ($pickfile) {
7548: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7549: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7550: $lt{'imcr'}</a>$help{'Course_Resources'}
7551: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7552: <fieldset id="importcrsresform" style="display: none;">
7553: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7554: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7555: <input type="hidden" name="active" value="bb" />
7556: $pickfile
7557: <p>
1.699 raeburn 7558: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7559: </p>
7560: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7561: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7562: </div>
7563: <div id="importcrsresempty" style="display: none;">
7564: <p>
7565: $lt{'empd'}
7566: </p>
7567: </div>
1.606 raeburn 7568: </fieldset>
7569: </form>
7570: CRSFORM
1.706 raeburn 7571: }
1.606 raeburn 7572: }
7573:
1.611 raeburn 7574: my $fromstoredjs;
7575: if ($canedit) {
7576: $fromstoredjs = 'open_StoredLinks_Import()';
7577: } else {
7578: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7579: }
7580:
1.502 raeburn 7581: my @importpubforma = (
1.706 raeburn 7582: { '<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 7583: { '<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 7584: { '<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 7585: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7586: );
1.706 raeburn 7587: if ($importcrsresform) {
7588: 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 7589: }
1.502 raeburn 7590: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7591: my $extresourcesform =
7592: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7593: $help{'Adding_External_Resource'},
7594: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7595: my $exttoolform =
7596: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7597: $help{'Adding_External_Tool'},undef,
7598: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7599: \%ltitools,$disabled);
1.329 droeschl 7600: if ($allowed) {
1.492 raeburn 7601: my $folder = $env{'form.folder'};
7602: if ($folder eq '') {
7603: $folder='default';
7604: }
1.615 raeburn 7605: if ($canedit) {
7606: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7607: if ($output) {
7608: $r->print($output);
7609: }
1.538 raeburn 7610: }
1.337 ehlerst 7611: $r->print(<<HIDDENFORM);
7612: <form name="renameform" method="post" action="/adm/coursedocs">
7613: <input type="hidden" name="title" />
7614: <input type="hidden" name="cmd" />
7615: <input type="hidden" name="markcopy" />
7616: <input type="hidden" name="copyfolder" />
7617: $containertag
7618: </form>
1.633 raeburn 7619: <form name="aliasform" method="post" action="/adm/coursedocs">
7620: <input type="hidden" name="alias" />
7621: <input type="hidden" name="cmd" />
7622: $containertag
7623: </form>
1.484 raeburn 7624:
1.337 ehlerst 7625: HIDDENFORM
1.508 raeburn 7626: $r->print(&makesimpleeditform($pathitem)."\n".
7627: &makedocslogform($pathitem."\n".
1.484 raeburn 7628: '<input type="hidden" name="folder" value="'.
7629: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7630: }
1.442 www 7631:
7632: # Generate the tabs
1.510 raeburn 7633: my ($mode,$needs_end);
1.472 raeburn 7634: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7635: my @folders = split('&',$env{'form.folderpath'});
7636: unless (@folders > 2) {
7637: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7638: $needs_end = 1;
7639: }
1.472 raeburn 7640: } else {
1.484 raeburn 7641: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7642: $needs_end = 1;
1.472 raeburn 7643: }
1.443 www 7644:
1.442 www 7645: #
1.622 raeburn 7646: my $hostname = $r->hostname();
1.442 www 7647: my $savefolderpath;
7648:
1.395 raeburn 7649: if ($allowed) {
1.329 droeschl 7650: my $folder=$env{'form.folder'};
1.615 raeburn 7651: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7652: $folder='default';
1.356 tempelho 7653: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7654: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7655: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7656: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7657: }
7658: my $postexec='';
7659: if ($folder eq 'default') {
1.653 raeburn 7660: my $windowname = 'loncapaclient';
7661: if ($env{'request.lti.login'}) {
7662: $windowname .= 'lti';
7663: }
1.372 bisitz 7664: $r->print('<script type="text/javascript">'."\n"
7665: .'// <![CDATA['."\n"
1.653 raeburn 7666: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7667: .'// ]]>'."\n"
7668: .'</script>'."\n"
1.369 bisitz 7669: );
1.329 droeschl 7670: } else {
7671: #$postexec='self.close();';
7672: }
1.504 raeburn 7673: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7674: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7675: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7676:
7677: my $newnavform=(<<NNFORM);
7678: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7679: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7680: $pathitem
1.329 droeschl 7681: <input type="hidden" name="importdetail"
7682: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7683: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7684: $help{'Navigate_Content'}
7685: </form>
7686: NNFORM
7687: my $newsmppageform=(<<NSPFORM);
7688: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7689: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7690: $pathitem
1.329 droeschl 7691: <input type="hidden" name="importdetail" value="" />
1.423 onken 7692: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7693: $help{'Simple Page'}
1.329 droeschl 7694: </form>
7695: NSPFORM
7696:
7697: my $newsmpproblemform=(<<NSPROBFORM);
7698: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7699: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7700: $pathitem
1.329 droeschl 7701: <input type="hidden" name="importdetail" value="" />
1.423 onken 7702: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7703: $help{'Simple_Problem'}
1.329 droeschl 7704: </form>
7705:
7706: NSPROBFORM
7707:
7708: my $newdropboxform=(<<NDBFORM);
7709: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7710: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7711: $pathitem
1.329 droeschl 7712: <input type="hidden" name="importdetail" value="" />
1.423 onken 7713: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7714: $help{'Dropbox'}
1.344 bisitz 7715: </form>
1.329 droeschl 7716: NDBFORM
7717:
7718: my $newexuploadform=(<<NEXUFORM);
7719: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7720: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7721: $pathitem
1.329 droeschl 7722: <input type="hidden" name="importdetail" value="" />
1.423 onken 7723: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7724: $help{'Score_Upload_Form'}
7725: </form>
7726: NEXUFORM
7727:
7728: my $newbulform=(<<NBFORM);
7729: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7730: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7731: $pathitem
1.329 droeschl 7732: <input type="hidden" name="importdetail" value="" />
1.423 onken 7733: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7734: $help{'Bulletin Board'}
7735: </form>
7736: NBFORM
7737:
7738: my $newaboutmeform=(<<NAMFORM);
7739: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7740: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7741: $pathitem
1.329 droeschl 7742: <input type="hidden" name="importdetail"
7743: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7744: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7745: $help{'My Personal Information Page'}
1.329 droeschl 7746: </form>
7747: NAMFORM
7748:
7749: my $newaboutsomeoneform=(<<NASOFORM);
7750: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7751: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7752: $pathitem
1.329 droeschl 7753: <input type="hidden" name="importdetail" value="" />
1.423 onken 7754: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7755: </form>
7756: NASOFORM
7757:
7758: my $newrosterform=(<<NROSTFORM);
7759: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7760: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7761: $pathitem
1.329 droeschl 7762: <input type="hidden" name="importdetail"
7763: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7764: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7765: $help{'Course_Roster'}
1.329 droeschl 7766: </form>
7767: NROSTFORM
7768:
1.534 raeburn 7769: my $newwebpage;
7770: if ($folder =~ /^default_?(\d*)$/) {
7771: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7772: if ($1) {
7773: $newwebpage .= $1;
7774: } else {
7775: $newwebpage .= 'default';
7776: }
7777: $newwebpage .= '/new.html';
7778: }
7779: my $newwebpageform =(<<NWEBFORM);
7780: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7781: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7782: $pathitem
7783: <input type="hidden" name="importdetail" value="$newwebpage" />
7784: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7785: $help{'Web_Page'}
1.534 raeburn 7786: </form>
7787: NWEBFORM
1.701 raeburn 7788: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7789: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7790: my $machines_str = "'".join("','",@ids)."'";
7791: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7792: if ($env{'user.author'}) {
7793: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7794: $is_home{'author'} = 1;
1.606 raeburn 7795: }
1.691 raeburn 7796: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7797: }
7798: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7799: ['active'],['ca','aa']);
1.691 raeburn 7800: my %by_roletype;
1.606 raeburn 7801: if (keys(%roleshash)) {
7802: foreach my $entry (keys(%roleshash)) {
7803: my ($auname,$audom,$roletype) = split(/:/,$entry);
7804: my $key = $entry;
7805: $key =~ s/:/___/g;
1.691 raeburn 7806: my $author = $auname.'___'.$audom;
7807: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7808: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7809: $toppath{$author} = "/priv/$audom/$auname";
7810: if (grep(/^\Q$rolehome\E$/,@ids)) {
7811: $is_home{$author} = 1;
1.606 raeburn 7812: }
1.691 raeburn 7813: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7814: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7815: }
1.691 raeburn 7816: }
7817: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7818: if (grep(/^\Q$crshome\E$/,@ids)) {
7819: $is_home{'course'} = 1;
7820: }
7821: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7822: my $pickdir = $lt{'loca'}.
7823: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7824: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7825: if ($env{'user.author'}) {
7826: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7827: }
7828: if (keys(%by_roletype)) {
7829: foreach my $possrole ('ca','aa') {
7830: if (ref($by_roletype{$possrole}) eq 'HASH') {
7831: my $roletitle = &Apache::lonnet::plaintext($possrole);
7832: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7833: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7834: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7835: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7836: }
7837: }
7838: }
7839: }
1.706 raeburn 7840: if ($checkcrsres) {
7841: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7842: }
7843: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7844: $lt{'dire'}.
7845: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7846: '<option value=""></option>'.
7847: '</select><br />'."\n";
1.606 raeburn 7848: my %seltemplate_menus;
7849: my @files = &Apache::lonhomework::get_template_list('problem');
7850: my @noexamplelink = ('blank.problem','blank.library','script.library');
7851: my $currentcategory = '';
7852: my @ordered = ('');
7853: my %templatehelp;
7854: my $defcategory = '';
7855: my @catorder = ($defcategory);
7856: $seltemplate_menus{$defcategory}->{'order'} = [''];
7857: $seltemplate_menus{$defcategory}->{'text'} = '';
7858: foreach my $file (@files) {
7859: if (ref($file) eq 'ARRAY') {
7860: my ($path,$title,$category,$help) = @{$file};
7861: next if ($title !~ /\S/);
7862: if (&js_escape($category) ne $currentcategory) {
7863: $currentcategory = &js_escape($category);
7864: push(@catorder,&js_escape($currentcategory));
7865: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7866: $seltemplate_menus{$currentcategory}->{'default'} = '';
7867: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7868: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7869: }
7870: if ($path) {
7871: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7872: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7873: if ($help) {
7874: $templatehelp{$path} = $help;
7875: }
7876: }
7877: }
7878: }
7879:
7880: my $templates = $lt{'cate'}.' '.
7881: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7882: $defcategory,'tempcategory','template',
7883: \%seltemplate_menus,\@catorder,
7884: "resize_scrollbox('contentscroll','1','0');",
7885: "toggleExampleText();",'template').'<br />';
7886: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 7887: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 7888: my $crsresform;
7889: if (($env{'user.author'}) || ($checkcrsres)) {
7890: $crsresform=(<<RESFORM);
1.691 raeburn 7891: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 7892: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 7893: <form action="/adm/coursedocs" method="post" name="courseresform">
7894: <fieldset id="crsresform" style="display:none;">
7895: <legend>$lt{'stpr'}</legend>
1.655 raeburn 7896: <input type="hidden" name="active" value="bb" />
1.606 raeburn 7897: <p>
7898: $pickdir
1.701 raeburn 7899: </p>
1.691 raeburn 7900: <div id="newstdproblem" style="display:none;">
1.701 raeburn 7901: <p>
1.606 raeburn 7902: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 7903: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 7904:
1.611 raeburn 7905: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 7906: </span><span id="newsubdir"></span>
7907: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 7908: </p>
1.699 raeburn 7909: </div>
1.606 raeburn 7910: $lt{'fnam'}
1.611 raeburn 7911: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 7912: <div id="newresource" style="display:none">
1.606 raeburn 7913: <p>
7914: $lt{'addp'}
1.611 raeburn 7915: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7916: $lt{'no'}</label>
1.611 raeburn 7917: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7918: $lt{'yes'}</label>
7919: <span id="newrestitle"></span>
1.611 raeburn 7920: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 7921: </p>
1.606 raeburn 7922: </div>
7923: <p>
7924: $lt{'uste'}
1.611 raeburn 7925: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7926: $lt{'no'}</label>
1.611 raeburn 7927: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7928: $lt{'yes'}</label>
1.701 raeburn 7929: </p>
1.606 raeburn 7930: <div id="newrestemplate" style="display:none">
7931: $templates
7932: $templatepreview
7933: </div>
7934: <span class="LC_nobreak">
1.701 raeburn 7935: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 7936: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 7937: </span>
1.691 raeburn 7938: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 7939: $rolehomes
7940: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7941: </div>
1.606 raeburn 7942: </fieldset>
7943: </form>
7944:
7945: RESFORM
1.706 raeburn 7946: }
1.534 raeburn 7947:
1.342 ehlerst 7948: my $specialdocumentsform;
1.383 tempelho 7949: my @specialdocumentsforma;
1.451 www 7950: my $gradingform;
7951: my @gradingforma;
7952: my $communityform;
7953: my @communityforma;
1.351 ehlerst 7954: my $newfolderform;
1.390 tempelho 7955: my $newfolderb;
1.342 ehlerst 7956:
1.451 www 7957: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 7958:
1.329 droeschl 7959: my $newpageform=(<<NPFORM);
7960: <form action="/adm/coursedocs" method="post" name="newpage">
7961: <input type="hidden" name="folderpath" value="$path" />
7962: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7963: <input type="hidden" name="active" value="ee" />
1.423 onken 7964: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 7965: $help{'Adding_Pages'}
1.329 droeschl 7966: </form>
7967: NPFORM
1.390 tempelho 7968:
7969:
1.351 ehlerst 7970: $newfolderform=(<<NFFORM);
1.329 droeschl 7971: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 7972: $pathitem
1.329 droeschl 7973: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7974: <input type="hidden" name="active" value="" />
1.422 onken 7975: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 7976: </form>
7977: NFFORM
7978:
7979: my $newsylform=(<<NSYLFORM);
7980: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 7981: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7982: $pathitem
1.329 droeschl 7983: <input type="hidden" name="importdetail"
7984: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7985: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 7986: $help{'Syllabus'}
1.383 tempelho 7987:
1.329 droeschl 7988: </form>
7989: NSYLFORM
1.364 bisitz 7990:
1.329 droeschl 7991: my $newgroupfileform=(<<NGFFORM);
7992: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 7993: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7994: $pathitem
1.329 droeschl 7995: <input type="hidden" name="importdetail"
7996: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 7997: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 7998: $help{'Group Portfolio'}
1.329 droeschl 7999: </form>
8000: NGFFORM
1.672 raeburn 8001: if ($container eq 'page') {
8002: @specialdocumentsforma=(
8003: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
8004: );
8005: } else {
8006: @specialdocumentsforma=(
1.421 onken 8007: {'<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 8008: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 8009: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 8010: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 8011: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 8012: );
8013: }
1.451 www 8014: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
8015:
1.655 raeburn 8016: my @external = (
8017: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 8018: );
1.699 raeburn 8019: if ($posslti) {
1.655 raeburn 8020: push(@external,
8021: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
8022: );
1.598 raeburn 8023: }
1.655 raeburn 8024: my $externalform = &create_form_ul(&create_list_elements(@external));
8025:
8026: my @importdoc = ();
1.519 raeburn 8027: unless ($container eq 'page') {
8028: push(@importdoc,
8029: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
8030: );
8031: }
8032: push(@importdoc,
1.558 raeburn 8033: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 8034: );
1.501 raeburn 8035: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 8036:
1.451 www 8037: @gradingforma=(
8038: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
8039: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 8040: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 8041: );
1.706 raeburn 8042: if ($crsresform) {
8043: push(@gradingforma,
8044: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
8045: );
8046: }
1.451 www 8047: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
8048:
8049: @communityforma=(
8050: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
8051: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
8052: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 8053: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
8054: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 8055: );
8056: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 8057:
1.330 tempelho 8058: my %orderhash = (
1.553 raeburn 8059: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 8060: 'bb' => ['External',$externalform],
8061: 'cc' => ['Import',$importpubform],
1.701 raeburn 8062: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 8063: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 8064: );
1.519 raeburn 8065: unless ($container eq 'page') {
1.434 raeburn 8066: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 8067: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 8068: }
8069:
1.341 ehlerst 8070: $hadchanges=0;
1.484 raeburn 8071: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 8072: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 8073: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 8074: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 8075: undef($navmap);
1.443 www 8076: if ($error) {
8077: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8078: }
1.639 raeburn 8079: if ($hadchanges) {
8080: unless (&is_hash_old()) {
1.638 raeburn 8081: &mark_hash_old();
8082: }
8083: }
1.341 ehlerst 8084:
1.443 www 8085: &changewarning($r,'');
8086: }
1.458 raeburn 8087: }
1.442 www 8088:
1.443 www 8089: # Supplemental documents start here
8090:
1.329 droeschl 8091: my $folder=$env{'form.folder'};
1.443 www 8092: unless ($supplementalflag) {
1.329 droeschl 8093: $folder='supplemental';
8094: }
1.685 raeburn 8095: if (($folder eq 'supplemental') &&
1.329 droeschl 8096: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 8097: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 8098: } elsif ($allowed) {
1.356 tempelho 8099: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 8100: }
1.508 raeburn 8101: $pathitem = '<input type="hidden" name="folderpath" value="'.
8102: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 8103: if ($allowed) {
8104: my $folderseq=
1.504 raeburn 8105: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 8106:
8107: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 8108: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
8109: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 8110: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 8111: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 8112: <legend>$lt{'upfi'}</legend>
1.630 raeburn 8113: <input type="hidden" name="active" value="ee" />
1.329 droeschl 8114: $fileupload
1.702 raeburn 8115: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
8116: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 8117: <br />
8118: <br />
8119: <span class="LC_nobreak">
8120: $checkbox
8121: </span>
8122: <br /><br />
8123: $lt{'comment'}:<br />
1.383 tempelho 8124: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 8125: <br />
1.508 raeburn 8126: $pathitem
1.329 droeschl 8127: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 8128: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 8129: </fieldset>
1.501 raeburn 8130: </form>
1.329 droeschl 8131: SUPDOCFORM
8132:
8133: my $supnewfolderform=(<<SNFFORM);
8134: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 8135: <input type="hidden" name="active" value="" />
1.508 raeburn 8136: $pathitem
1.329 droeschl 8137: <input type="hidden" name="importdetail" value="" />
1.423 onken 8138: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 8139: $help{'Adding_Folders'}
1.329 droeschl 8140: </form>
8141: SNFFORM
1.383 tempelho 8142:
1.510 raeburn 8143: my $supextform =
8144: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 8145: $help{'Adding_External_Resource'},
8146: undef,undef,undef,undef,undef,undef,
8147: $disabled);
1.329 droeschl 8148:
1.598 raeburn 8149: my $supexttoolform =
8150: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
8151: $help{'Adding_External_Tool'},
8152: undef,undef,'tool',$coursedom,
1.611 raeburn 8153: $coursenum,\%ltitools,$disabled);
1.598 raeburn 8154:
1.329 droeschl 8155: my $supnewsylform=(<<SNSFORM);
8156: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 8157: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8158: $pathitem
1.329 droeschl 8159: <input type="hidden" name="importdetail"
8160: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8161: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 8162: $help{'Syllabus'}
8163: </form>
8164: SNSFORM
8165:
8166: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 8167: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 8168: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8169: $pathitem
1.329 droeschl 8170: <input type="hidden" name="importdetail"
8171: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 8172: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 8173: $help{'My Personal Information Page'}
1.329 droeschl 8174: </form>
8175: SNAMFORM
8176:
1.534 raeburn 8177: my $supwebpage;
8178: if ($folder =~ /^supplemental_?(\d*)$/) {
8179: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
8180: if ($1) {
8181: $supwebpage .= $1;
8182: } else {
8183: $supwebpage .= 'default';
8184: }
8185: $supwebpage .= '/new.html';
8186: }
8187: my $supwebpageform =(<<SWEBFORM);
8188: <form action="/adm/coursedocs" method="post" name="supwebpage">
8189: <input type="hidden" name="active" value="cc" />
8190: $pathitem
8191: <input type="hidden" name="importdetail" value="$supwebpage" />
8192: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 8193: $help{'Web_Page'}
1.534 raeburn 8194: </form>
8195: SWEBFORM
8196:
1.333 muellerd 8197:
1.383 tempelho 8198: my @specialdocs = (
1.618 raeburn 8199: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 8200: =>$supnewsylform},
1.611 raeburn 8201: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 8202: =>$supnewaboutmeform},
1.534 raeburn 8203: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
8204:
1.383 tempelho 8205: );
1.655 raeburn 8206: my @supexternal = (
8207: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8208: =>$supextform});
1.699 raeburn 8209: if ($posslti) {
1.655 raeburn 8210: push(@supexternal,
8211: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8212: =>$supexttoolform});
8213: }
1.655 raeburn 8214: my @supimportdoc = (
1.598 raeburn 8215: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8216: =>$supupdocform},
1.598 raeburn 8217: );
1.501 raeburn 8218:
8219: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8220: my %suporderhash = (
1.390 tempelho 8221: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8222: 'dd' => ['Upload',$supupdocform],
8223: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8224: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8225: );
1.443 www 8226: if ($supplementalflag) {
1.682 raeburn 8227: $suppchanges = 0;
8228: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8229: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8230: \%ltitools,$canedit,$hostname);
8231: if ($error) {
8232: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8233: }
8234: if ($suppchanges) {
1.684 raeburn 8235: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8236: undef($suppchanges);
8237: }
1.393 raeburn 8238: }
1.443 www 8239: } elsif ($supplementalflag) {
1.458 raeburn 8240: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8241: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8242: $hostname);
1.393 raeburn 8243: if ($error) {
8244: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8245: }
1.393 raeburn 8246: }
1.389 tempelho 8247:
1.510 raeburn 8248: if ($needs_end) {
8249: $r->print(&endContentScreen());
8250: }
1.383 tempelho 8251:
1.329 droeschl 8252: if ($allowed) {
8253: $r->print('
8254: <form method="post" name="extimport" action="/adm/coursedocs">
8255: <input type="hidden" name="title" />
8256: <input type="hidden" name="url" />
8257: <input type="hidden" name="useform" />
8258: <input type="hidden" name="residx" />
8259: </form>');
8260: }
1.484 raeburn 8261: } elsif ($showdoc) {
1.329 droeschl 8262: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8263: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8264: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8265: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8266: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8267: }
8268: }
1.630 raeburn 8269: unless ($noendpage) {
1.606 raeburn 8270: $r->print(&Apache::loncommon::end_page());
8271: }
1.329 droeschl 8272: return OK;
1.364 bisitz 8273: }
1.329 droeschl 8274:
1.440 raeburn 8275: sub embedded_form_elems {
8276: my ($phase,$primaryurl,$newidx) = @_;
8277: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8278: $newidx =~s /\D+//g;
1.440 raeburn 8279: return <<STATE;
8280: <input type="hidden" name="folderpath" value="$folderpath" />
8281: <input type="hidden" name="cmd" value="upload_embedded" />
8282: <input type="hidden" name="newidx" value="$newidx" />
8283: <input type="hidden" name="phase" value="$phase" />
8284: <input type="hidden" name="primaryurl" value="$primaryurl" />
8285: STATE
8286: }
8287:
8288: sub embedded_destination {
8289: my $folder=$env{'form.folder'};
8290: my $destination = 'docs/';
8291: if ($folder =~ /^supplemental/) {
8292: $destination = 'supplemental/';
8293: }
8294: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8295: $destination .= 'default/';
8296: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8297: $destination .= $2.'/';
8298: }
1.634 raeburn 8299: my $newidx = $env{'form.newidx'};
8300: $newidx =~s /\D+//g;
8301: if ($newidx) {
8302: $destination .= $newidx;
8303: }
1.440 raeburn 8304: my $dir_root = '/userfiles';
8305: return ($destination,$dir_root);
8306: }
8307:
8308: sub return_to_editor {
8309: my $actionurl = '/adm/coursedocs';
8310: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8311: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8312: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8313: '</a></p>';
8314: }
8315:
1.476 raeburn 8316: sub decompression_info {
8317: my ($destination,$dir_root) = &embedded_destination();
8318: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8319: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8320: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8321: my $container='sequence';
1.480 raeburn 8322: my ($pathitem,$hiddenelem);
1.583 raeburn 8323: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8324: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8325: $container='page';
8326: }
1.480 raeburn 8327: unshift(@hiddens,$pathitem);
8328: foreach my $item (@hiddens) {
1.634 raeburn 8329: if ($item eq 'newidx') {
8330: next if ($env{'form.'.$item} =~ /\D/);
8331: }
1.480 raeburn 8332: if ($env{'form.'.$item}) {
8333: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8334: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8335: }
1.477 raeburn 8336: }
1.476 raeburn 8337: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8338: $hiddenelem);
8339: }
8340:
8341: sub decompression_phase_one {
8342: my ($dir,$file,$warning,$error,$output);
8343: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8344: &decompression_info();
1.490 raeburn 8345: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8346: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8347: } else {
8348: my $file = $1;
1.630 raeburn 8349: $output =
1.481 raeburn 8350: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8351: $destination,$dir_root,
8352: $hiddenelem);
8353: if ($env{'form.autoextract_camtasia'}) {
8354: $output .= &remove_archive($docudom,$docuname,$container);
8355: }
1.476 raeburn 8356: }
8357: if ($error) {
8358: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8359: $error.'</p>'."\n";
8360: }
8361: if ($warning) {
8362: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8363: }
8364: return $output;
8365: }
8366:
8367: sub decompression_phase_two {
8368: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8369: &decompression_info();
1.481 raeburn 8370: my $output;
1.480 raeburn 8371: if ($env{'form.archivedelete'}) {
1.481 raeburn 8372: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8373: }
8374: $output .=
1.481 raeburn 8375: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8376: $destination,$dir_root,$hiddenelem);
8377: return $output;
8378: }
8379:
1.480 raeburn 8380: sub remove_archive {
8381: my ($docudom,$docuname,$container) = @_;
8382: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8383: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8384: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8385: if ($fatal) {
8386: if ($container eq 'page') {
8387: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8388: } else {
8389: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8390: }
1.583 raeburn 8391: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8392: } else {
8393: my $currcmd = $env{'form.cmd'};
8394: my $position = $env{'form.position'};
1.583 raeburn 8395: my $archiveidx = $position;
1.563 raeburn 8396: if ($position > 0) {
1.583 raeburn 8397: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8398: $archiveidx = $position-1;
8399: }
8400: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8401: my ($title,$url,@rrest) =
1.583 raeburn 8402: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8403: if ($url eq $env{'form.archiveurl'}) {
8404: if (&handle_edit_cmd($docuname,$docudom)) {
8405: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8406: if ($suppchanges) {
8407: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8408: undef($suppchanges);
8409: }
1.583 raeburn 8410: if ($fatal) {
8411: if ($container eq 'page') {
8412: $delwarning = &mt('An error occurred updating the contents of the current page.');
8413: } else {
8414: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8415: }
1.480 raeburn 8416: } else {
1.583 raeburn 8417: $delresult = &mt('Archive file removed.');
1.480 raeburn 8418: }
8419: }
1.583 raeburn 8420: } else {
8421: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8422: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8423: }
8424: }
8425: $env{'form.cmd'} = $currcmd;
8426: }
8427: if ($delwarning) {
8428: $output = '<p class="LC_warning">'.
8429: $delwarning.
8430: '</p>';
8431: }
8432: if ($delresult) {
8433: $output .= '<p class="LC_info">'.
8434: $delresult.
8435: '</p>';
8436: }
1.481 raeburn 8437: return $output;
1.480 raeburn 8438: }
8439:
1.484 raeburn 8440: sub generate_admin_menu {
1.708 raeburn 8441: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8442: my $lc_crstype = lc($crstype);
8443: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8444: my %lt= ( # do not translate here
1.484 raeburn 8445: 'vc' => 'Verify Content',
8446: 'cv' => 'Check/Set Resource Versions',
8447: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8448: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8449: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8450: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8451: 'dcd' => 'Copy uploaded content to Authoring Space',
8452: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8453: );
1.712 raeburn 8454: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8455: if ($home + $other > 0) {
8456: $candump = 'F';
8457: if ($home) {
8458: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8459: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8460: } else {
8461: my @hosts;
8462: foreach my $aurole (keys(%outhash)) {
8463: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8464: push(@hosts,$outhash{$aurole});
1.538 raeburn 8465: }
1.484 raeburn 8466: }
8467: if (@hosts == 1) {
8468: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8469: '&role='.
8470: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8471: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8472: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8473: $exportcrsurl = $dumpurl;
1.484 raeburn 8474: } else {
8475: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8476: $exportcrsurl = $dumpurl;
1.484 raeburn 8477: }
8478: }
8479: }
8480: my @menu=
8481: ({ categorytitle=>'Administration',
8482: items =>[
8483: { linktext => $lt{'vc'},
8484: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8485: permission => 'F',
1.571 raeburn 8486: help => 'Docs_Verify_Content',
1.484 raeburn 8487: icon => 'verify.png',
8488: linktitle => 'Verify contents can be retrieved/rendered',
8489: },
8490: { linktext => $lt{'cv'},
8491: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8492: permission => 'F',
1.571 raeburn 8493: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8494: icon => 'resversion.png',
8495: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8496: },
8497: { linktext => $lt{'ls'},
8498: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8499: permission => 'F',
8500: #help => '',
8501: icon => 'symbs.png',
8502: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8503: },
1.651 raeburn 8504: { linktext => $lt{'ct'},
8505: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8506: permission => 'F',
8507: help => 'Docs_Short_URLs',
8508: icon => 'shorturls.png',
8509: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8510: },
1.484 raeburn 8511: ]
1.611 raeburn 8512: });
8513: if ($canedit) {
1.708 raeburn 8514: my ($crsauname,$crsaudom,$crshome);
8515: if (($coursenum ne '') && ($coursedom ne '')) {
8516: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8517: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8518: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8519: my @ids=&Apache::lonnet::current_machine_ids();
8520: my $linkurl;
8521: if (grep(/^\Q$crshome\E$/,@ids)) {
8522: $linkurl = $crsauthorurl;
8523: } else {
8524: $linkurl =
8525: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8526: }
8527: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
8528: push(@{$menu[0]->{items}},
8529: { linktext => $lt{'ca'},
8530: url => $linkurl,
8531: permission => 'F',
8532: help => 'Docs_Course_Authorspace',
8533: icon => 'impcrsau.png',
8534: linktitle => $lt{'ca'},
8535: });
8536: }
8537: }
8538: }
1.611 raeburn 8539: push(@menu,
1.484 raeburn 8540: { categorytitle=>'Export',
8541: items =>[
8542: { linktext => $lt{'imse'},
8543: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8544: permission => 'F',
8545: help => 'Docs_Export_Course_Docs',
8546: icon => 'imsexport.png',
8547: linktitle => $lt{'imse'},
8548: },
8549: { linktext => $lt{'dcd'},
8550: url => $dumpurl,
8551: permission => $candump,
1.571 raeburn 8552: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8553: icon => 'dump.png',
8554: linktitle => $lt{'dcd'},
8555: },
8556: ]
8557: });
1.712 raeburn 8558: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8559: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8560: push(@{$menu[1]->{items}},
8561: { linktext => $lt{'cpc'},
8562: url => $exportcrsurl,
8563: permission => 'F',
8564: help => 'Docs_Export_Course_Author',
8565: icon => 'res.png',
8566: linktitle => $lt{'cpc'},
8567: });
8568: }
8569: }
1.611 raeburn 8570: }
1.484 raeburn 8571: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8572: '<input type="hidden" id="dummy" />'."\n".
8573: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8574: '</form>';
1.329 droeschl 8575: }
8576:
8577: sub generate_edit_table {
1.538 raeburn 8578: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8579: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8580: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8581: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8582: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8583: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8584: $activetab = $env{'form.active'};
8585: }
1.611 raeburn 8586: unless ($canedit) {
8587: $disabled = ' disabled="disabled"';
8588: }
1.472 raeburn 8589: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8590: my $backtext = &mt('Exit Editor');
1.458 raeburn 8591: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8592: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8593: '<li class="goback">'.
1.546 raeburn 8594: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8595: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8596: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8597: '<li>'.
8598: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8599: &mt('Undo Delete').'</a></li>'."\n";
8600: if ($env{'form.docslog'}) {
8601: $form .= '<li class="active">';
8602: } else {
8603: $form .= '<li>';
8604: }
8605: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8606: &mt('History').'</a></li>'."\n";
8607: if ($env{'form.docslog'}) {
8608: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8609: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8610: }
1.458 raeburn 8611: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8612: if($name ne '00'){
1.371 tempelho 8613: if($activetab eq '' || $activetab ne $name){
8614: $active = '';
8615: }elsif($activetab eq $name){
8616: $active = 'class="active"';
8617: }
1.458 raeburn 8618: $form .= '<li style="float:right" '.$active
1.484 raeburn 8619: .' 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 8620: } else {
1.570 raeburn 8621: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8622:
8623: }
1.329 droeschl 8624: }
1.484 raeburn 8625: $form .= '</ul>'."\n";
8626: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8627:
8628: if ($to_show ne '') {
1.538 raeburn 8629: my $saveform;
8630: if ($need_save) {
8631: my $button = &mt('Make changes');
8632: my $path;
8633: if ($env{'form.folderpath'}) {
8634: $path =
8635: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8636: }
8637: $saveform = <<"END";
8638: <div id="multisave" style="display:none; clear:both;" >
8639: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8640: <input type="hidden" name="folderpath" value="$path" />
8641: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8642: <input type="hidden" name="allhiddenresource" value="" />
8643: <input type="hidden" name="allencrypturl" value="" />
8644: <input type="hidden" name="allrandompick" value="" />
8645: <input type="hidden" name="allrandomorder" value="" />
8646: <input type="hidden" name="changeparms" value="" />
8647: <input type="hidden" name="multiremove" value="" />
8648: <input type="hidden" name="multicut" value="" />
8649: <input type="hidden" name="multicopy" value="" />
8650: <input type="hidden" name="multichange" value="" />
8651: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8652: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8653: </form>
8654: </div>
8655: END
8656: }
8657: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8658: }
1.363 ehlerst 8659: foreach my $field (keys(%orderhash)){
1.390 tempelho 8660: if($field ne '00'){
1.422 onken 8661: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8662: $active = 'style="display: none;float:left"';
1.422 onken 8663: }elsif($activetab eq $field){
1.458 raeburn 8664: $active = 'style="display:block;float:left"';
1.422 onken 8665: }
8666: $form .= '<div id="'.$field.$tid.'"'
8667: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8668: .'</div>'."\n";
1.363 ehlerst 8669: }
8670: }
1.484 raeburn 8671: unless ($env{'form.docslog'}) {
8672: $form .= '</div></div>'."\n";
8673: }
1.329 droeschl 8674: return $form;
8675: }
8676:
8677: sub editing_js {
1.622 raeburn 8678: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8679: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8680: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8681: p_mnf => 'Name of New Folder',
8682: t_mnf => 'New Folder',
8683: p_mnp => 'Name of New Page',
8684: t_mnp => 'New Page',
1.451 www 8685: p_mxu => 'Title for the External Score',
1.349 biermanm 8686: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8687: p_msb => 'Title for the Problem',
8688: p_mdb => 'Title for the Drop Box',
1.336 schafran 8689: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8690: p_mwp => 'Title for Web Page',
1.606 raeburn 8691: p_mnr => 'Title for the Resource',
1.348 weissno 8692: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8693: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8694: p_mab_alrt1 => 'Not a valid user:domain',
8695: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8696: p_chn => 'New Title',
8697: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8698: p_rmr2a => 'Remove',
8699: p_rmr2b => '?',
8700: p_rmr3a => 'Remove those',
8701: p_rmr3b => 'items?',
8702: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8703: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8704: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8705: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8706: p_ctr2a => 'Cut',
8707: p_ctr2b => '?',
8708: p_ctr3a => 'Cut those',
8709: p_ctr3b => 'items?',
1.633 raeburn 8710: setal => 'Enter a (unique) alias',
8711: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8712: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8713: imsfile => 'You must choose an IMS package for import',
8714: imscms => 'You must select which Course Management System was the source of the IMS package',
8715: invurl => 'Invalid URL',
8716: titbl => 'Title is blank',
1.538 raeburn 8717: more => '(More ...)',
8718: less => '(Less ...)',
1.543 raeburn 8719: noor => 'No actions selected or changes to settings specified.',
8720: noch => 'No changes to settings specified.',
8721: noac => 'No actions selected.',
1.606 raeburn 8722: nofi => 'No file selected',
8723: tinc => 'Title in course',
8724: sunm => 'Sub-directory name',
1.618 raeburn 8725: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8726: sele => 'Select',
8727: swit => 'Switch server required',
1.329 droeschl 8728: );
1.594 damieng 8729: &js_escape(\%js_lt);
1.433 raeburn 8730: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8731: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8732: my $main_container_page;
1.519 raeburn 8733: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8734: $main_container_page = 1;
1.434 raeburn 8735: }
1.617 raeburn 8736: my $backtourl;
8737: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8738: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8739: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8740: my @ids=&Apache::lonnet::current_machine_ids();
8741: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8742: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8743: my $caller = $1;
1.525 raeburn 8744: if ($caller =~ /^supplemental/) {
8745: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8746: } else {
8747: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8748: $res = &Apache::lonnet::clutter($res);
8749: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8750: my ($url,$anchor);
8751: if ($res =~ /^([^#]+)#([^#]+)$/) {
8752: $url = $1;
8753: $anchor = $2;
8754: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8755: $caller = $1.&escape('#').$anchor;
8756: }
1.614 raeburn 8757: } else {
8758: $url = $res;
1.609 raeburn 8759: }
1.640 raeburn 8760: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8761: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8762: $backtourl .= '?navmap=1';
8763: } else {
8764: $backtourl .= '?symb='.
8765: &HTML::Entities::encode($caller,'<>&"');
8766: }
1.622 raeburn 8767: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8768: if (($ENV{'SERVER_PORT'} == 443) &&
8769: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8770: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8771: if ($hostname ne '') {
8772: $backtourl = 'http://'.$hostname.$backtourl;
8773: }
8774: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8775: }
8776: }
1.623 raeburn 8777: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8778: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8779: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8780: if ($hostname ne '') {
8781: $backtourl = 'http://'.$hostname.$backtourl;
8782: }
8783: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8784: }
1.623 raeburn 8785: }
1.622 raeburn 8786: }
1.609 raeburn 8787: if ($anchor ne '') {
8788: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8789: }
1.590 raeburn 8790: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8791: } else {
8792: $backtourl = '/adm/navmaps';
1.525 raeburn 8793: }
8794: }
8795: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8796: $backtourl = '/adm/menu';
8797: } elsif ($supplementalflag) {
1.682 raeburn 8798: if (($env{'request.role.adv'}) ||
8799: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8800: $backtourl = '/adm/supplemental';
8801: } else {
8802: $backtourl = '/adm/navmaps';
8803: }
1.525 raeburn 8804: } else {
8805: $backtourl = '/adm/navmaps';
1.472 raeburn 8806: }
8807:
1.655 raeburn 8808: my $fieldsets = "'doc'";
1.519 raeburn 8809: unless ($main_container_page) {
8810: $fieldsets .=",'ims'";
8811: }
1.655 raeburn 8812: my $extfieldsets = "'ext'";
8813: if ($posslti) {
8814: $extfieldsets .= ",'tool'";
8815: }
1.501 raeburn 8816: if ($supplementalflag) {
1.655 raeburn 8817: $fieldsets = "'suppdoc'";
8818: $extfieldsets = "'suppext'";
1.600 raeburn 8819: if ($posslti) {
1.655 raeburn 8820: $extfieldsets .= ",'supptool'";
1.600 raeburn 8821: }
1.501 raeburn 8822: }
1.655 raeburn 8823:
1.611 raeburn 8824: my $jsmakefunctions;
8825: if ($canedit) {
8826: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8827: function makenewfolder(targetform,folderseq) {
1.594 damieng 8828: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8829: if (foldername) {
1.676 raeburn 8830: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8831: targetform.submit();
8832: }
8833: }
8834:
8835: function makenewpage(targetform,folderseq) {
1.594 damieng 8836: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8837: if (pagename) {
1.676 raeburn 8838: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8839: targetform.submit();
8840: }
8841: }
8842:
8843: function makeexamupload() {
1.594 damieng 8844: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8845: if (title) {
1.329 droeschl 8846: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8847: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8848: this.document.forms.newexamupload.submit();
8849: }
8850: }
8851:
8852: function makesmppage() {
1.594 damieng 8853: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8854: if (title) {
1.329 droeschl 8855: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8856: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8857: this.document.forms.newsmppg.submit();
8858: }
8859: }
8860:
1.534 raeburn 8861: function makewebpage(type) {
1.594 damieng 8862: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8863: var formname;
8864: if (type == 'supp') {
8865: formname = this.document.forms.supwebpage;
8866: } else {
8867: formname = this.document.forms.newwebpage;
8868: }
8869: if (title) {
8870: var webpage = formname.importdetail.value;
1.675 raeburn 8871: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8872: formname.submit();
8873: }
8874: }
8875:
1.329 droeschl 8876: function makesmpproblem() {
1.594 damieng 8877: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 8878: if (title) {
1.329 droeschl 8879: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 8880: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 8881: this.document.forms.newsmpproblem.submit();
8882: }
8883: }
8884:
8885: function makedropbox() {
1.594 damieng 8886: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 8887: if (title) {
1.329 droeschl 8888: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 8889: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 8890: this.document.forms.newdropbox.submit();
8891: }
8892: }
8893:
8894: function makebulboard() {
1.594 damieng 8895: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 8896: if (title) {
8897: this.document.forms.newbul.importdetail.value=
1.676 raeburn 8898: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 8899: this.document.forms.newbul.submit();
8900: }
8901: }
8902:
8903: function makeabout() {
1.594 damieng 8904: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 8905: if (user) {
8906: var comp=new Array();
8907: comp=user.split(':');
8908: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
8909: if ((comp[0]) && (comp[1])) {
8910: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 8911: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 8912: this.document.forms.newaboutsomeone.submit();
8913: } else {
8914: alert("$js_lt{'p_mab_alrt1'}");
8915: }
8916: } else {
8917: alert("$js_lt{'p_mab_alrt2'}");
8918: }
8919: }
8920: }
8921:
8922: function makenew(targetform) {
8923: targetform.submit();
8924: }
8925:
8926: function changename(folderpath,index,oldtitle) {
8927: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8928: if (title) {
8929: this.document.forms.renameform.markcopy.value='';
8930: this.document.forms.renameform.title.value=title;
8931: this.document.forms.renameform.cmd.value='rename_'+index;
8932: this.document.forms.renameform.folderpath.value=folderpath;
8933: this.document.forms.renameform.submit();
8934: }
8935: }
8936:
1.633 raeburn 8937: function setalias(folderpath,index) {
8938: var alias = prompt('$js_lt{"setal"}');
8939: if ((alias != null) && (alias != '')) {
8940: this.document.forms.aliasform.alias.value=alias;
8941: this.document.forms.aliasform.cmd.value='setalias_'+index;
8942: this.document.forms.aliasform.folderpath.value=folderpath;
8943: this.document.forms.aliasform.submit();
8944: }
8945: }
8946:
8947: function delalias(folderpath,index) {
8948: if (confirm('$js_lt{"delal"}')) {
8949: this.document.forms.aliasform.cmd.value='delalias_'+index;
8950: this.document.forms.aliasform.folderpath.value=folderpath;
8951: this.document.forms.aliasform.submit();
8952: }
8953: }
8954:
1.611 raeburn 8955: ENDNEWSCRIPT
8956: } else {
8957: $jsmakefunctions = <<ENDNEWSCRIPT;
8958:
8959: function makenewfolder() {
8960: alert("$js_lt{'edri'}");
8961: }
8962:
8963: function makenewpage() {
8964: alert("$js_lt{'edri'}");
8965: }
8966:
8967: function makeexamupload() {
8968: alert("$js_lt{'edri'}");
8969: }
8970:
8971: function makesmppage() {
8972: alert("$js_lt{'edri'}");
8973: }
8974:
8975: function makewebpage(type) {
8976: alert("$js_lt{'edri'}");
8977: }
8978:
8979: function makesmpproblem() {
8980: alert("$js_lt{'edri'}");
8981: }
8982:
8983: function makedropbox() {
8984: alert("$js_lt{'edri'}");
8985: }
8986:
8987: function makebulboard() {
8988: alert("$js_lt{'edri'}");
8989: }
8990:
8991: function makeabout() {
8992: alert("$js_lt{'edri'}");
8993: }
8994:
8995: function changename() {
8996: alert("$js_lt{'edri'}");
8997: }
8998:
1.633 raeburn 8999: function setalias() {
9000: alert("$js_lt{'edri'}");
9001: }
9002:
9003: function delalias() {
9004: alert("$js_lt{'edri'}");
9005: }
9006:
1.611 raeburn 9007: function makenew() {
9008: alert("$js_lt{'edri'}");
9009: }
9010:
9011: function groupimport() {
9012: alert("$js_lt{'edri'}");
1.335 ehlerst 9013: }
1.611 raeburn 9014:
9015: function groupsearch() {
9016: alert("$js_lt{'edri'}");
1.335 ehlerst 9017: }
1.611 raeburn 9018:
9019: function groupopen(url,recover) {
9020: var options="scrollbars=1,resizable=1,menubar=0";
9021: idxflag=1;
9022: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
9023: idx.focus();
1.329 droeschl 9024: }
9025:
1.611 raeburn 9026: ENDNEWSCRIPT
9027:
9028: }
9029: return <<ENDSCRIPT;
9030:
9031: $jsmakefunctions
9032:
1.501 raeburn 9033: function toggleUpload(caller) {
9034: var blocks = Array($fieldsets);
9035: for (var i=0; i<blocks.length; i++) {
9036: var disp = 'none';
9037: if (caller == blocks[i]) {
9038: var curr = document.getElementById('upload'+caller+'form').style.display;
9039: if (curr == 'none') {
9040: disp='block';
9041: }
9042: }
9043: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 9044: }
9045: resize_scrollbox('contentscroll','1','1');
9046: return;
9047: }
9048:
9049: function toggleExternal(caller) {
9050: var blocks = Array($extfieldsets);
9051: for (var i=0; i<blocks.length; i++) {
9052: var disp = 'none';
9053: if (caller == blocks[i]) {
9054: var curr = document.getElementById('external'+caller+'form').style.display;
9055: if (curr == 'none') {
9056: disp='block';
9057: }
9058: }
9059: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 9060: if ((caller == 'tool') || (caller == 'supptool')) {
9061: if (disp == 'block') {
1.655 raeburn 9062: if (document.getElementById('LC_exttoolid')) {
9063: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 9064: var suppflag = 0;
9065: if (caller == 'supptool') {
9066: suppflag = 1;
9067: }
9068: currForm = document.getElementById('new'+caller);
1.655 raeburn 9069: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 9070: }
9071: }
9072: }
1.501 raeburn 9073: }
1.502 raeburn 9074: resize_scrollbox('contentscroll','1','1');
9075: return;
9076: }
9077:
1.514 raeburn 9078: function toggleMap(caller) {
1.502 raeburn 9079: var disp = 'none';
1.510 raeburn 9080: if (document.getElementById('importmapform')) {
1.514 raeburn 9081: if (caller == 'map') {
9082: var curr = document.getElementById('importmapform').style.display;
9083: if (curr == 'none') {
9084: disp='block';
9085: }
1.510 raeburn 9086: }
9087: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 9088: if (disp == 'block') {
9089: if (document.getElementById('importcrsresform')) {
9090: if (document.getElementById('importcrsresform').style.display == 'block') {
9091: document.getElementById('importcrsresform').style.display = 'none';
9092: }
9093: }
9094: }
1.510 raeburn 9095: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 9096: }
1.501 raeburn 9097: return;
1.329 droeschl 9098: }
9099:
1.691 raeburn 9100: function toggleCrsRes(caller) {
1.606 raeburn 9101: var disp = 'none';
9102: if (document.getElementById('crsresform')) {
9103: if (caller == 'res') {
1.691 raeburn 9104: var form = document.getElementById('crsresform');
9105: var curr = form.style.display;
1.606 raeburn 9106: if (curr == 'none') {
9107: disp='block';
1.691 raeburn 9108: document.courseresform.authorrole.selectedIndex = 0;
9109: document.courseresform.authorpath.selectedIndex = 0;
9110: document.courseresform.newresourceadd.selectedIndex = 0;
9111: populateDirSelects(form,'authorrole','authorpath',1,0,0);
9112: toggleNewInCourse(document.courseresform);
9113: if (document.getElementById('newresource')) {
9114: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 9115: }
9116: if (document.courseresform.newresusetemp.length) {
9117: document.courseresform.newresusetemp[0].checked = true;
9118: toggleWithTemplate(document.courseresform);
9119: }
9120: document.courseresform.newresourcename.value = '';
9121: }
9122: }
9123: if (document.courseresform.newsubdir.length) {
9124: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
9125: if (document.courseresform.newsubdir[j].value == 0) {
9126: document.courseresform.newsubdir[j].checked = true;
9127: }
9128: break;
9129: }
9130: if (document.getElementById('newsubdirname')) {
9131: document.getElementById('newsubdirname').type = "hidden";
9132: document.getElementById('newsubdirname').value = "";
9133: }
9134: if (document.getElementById('newsubdir')) {
9135: document.getElementById('newsubdir').innerHTML = "";
9136: }
9137: }
9138: document.getElementById('crsresform').style.display=disp;
9139: resize_scrollbox('contentscroll','1','0');
9140: }
9141: return;
9142: }
9143:
9144: function toggleNewsubdir(form) {
9145: if (form.newsubdir.length) {
9146: for (var j=0; j<form.newsubdir.length; j++) {
9147: if (form.newsubdir[j].checked) {
9148: if (document.getElementById('newsubdirname')) {
9149: if (form.newsubdir[j].value == '1') {
9150: document.getElementById('newsubdirname').type = "text";
9151: if (document.getElementById('newsubdir')) {
9152: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
9153: }
9154: } else {
9155: document.getElementById('newsubdirname').type = "hidden";
9156: document.getElementById('newsubdirname').value = "";
9157: document.getElementById('newsubdir').innerHTML = "";
9158: }
9159: }
9160: break;
9161: }
9162: }
9163: }
9164: }
9165:
9166: function toggleCrsResTitle() {
9167: if (document.getElementById('newresource')) {
1.691 raeburn 9168: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9169: if (selloc == 'course') {
1.606 raeburn 9170: document.getElementById('newresource').style.display = 'inline';
9171: document.courseresform.newresourceadd[0].checked = true;
9172: toggleNewInCourse(document.courseresform);
9173: } else {
9174: document.getElementById('newresource').style.display = 'none';
9175: }
1.689 raeburn 9176: }
9177: if (document.getElementById('newstdproblem')) {
9178: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9179: document.getElementById('newstdproblem').style.display = 'none';
9180: if (document.getElementById('stdprobswitch')) {
9181: document.getElementById('stdprobswitch').style.display = 'block';
9182: }
9183: } else {
9184: document.getElementById('newstdproblem').style.display = 'block';
9185: if (document.getElementById('stdprobswitch')) {
9186: document.getElementById('stdprobswitch').style.display = 'none';
9187: }
9188: }
9189: }
1.606 raeburn 9190: }
9191:
9192: function toggleNewInCourse(form) {
9193: if (form.newresourceadd.length) {
9194: for (var i=0; i<form.newresourceadd.length; i++) {
9195: if (form.newresourceadd[i].checked) {
9196: if (document.getElementById('newresourcetitle')) {
9197: if (form.newresourceadd[i].value == '1') {
9198: document.getElementById('newresourcetitle').type = 'text';
9199: if (document.getElementById('newrestitle')) {
9200: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
9201: }
9202: } else {
9203: document.getElementById('newresourcetitle').type = 'hidden';
9204: document.getElementById('newresourcetitle').value = '';
9205: if (document.getElementById('newrestitle')) {
9206: document.getElementById('newrestitle').innerHTML = '';
9207: }
9208: }
9209: }
9210: break;
9211: }
9212: }
9213: }
9214: }
9215:
9216: function toggleWithTemplate(form) {
9217: if (form.newresusetemp.length) {
9218: for (var i=0; i<form.newresusetemp.length; i++) {
9219: if (form.newresusetemp[i].checked) {
9220: if (document.getElementById('newrestemplate')) {
9221: if (form.newresusetemp[i].value == '1') {
9222: document.getElementById('newrestemplate').style.display = 'inline';
9223: toggleExampleText();
9224: } else {
9225: form.tempcategory.selectedIndex = 0;
9226: select1template_changed();
9227: document.getElementById('newrestemplate').style.display = 'none';
9228: }
9229: }
9230: }
9231: }
9232: }
9233: }
9234:
9235: function toggleExampleText() {
9236: if (document.getElementById('newresexample')) {
9237: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9238: if (url == '') {
9239: document.getElementById('newresexample').style.fontWeight = 'normal';
9240: } else {
9241: document.getElementById('newresexample').style.fontWeight = 'bold';
9242: }
9243: }
9244: }
9245:
9246: function getExample(width,height,scrolling,transparency) {
9247: var url;
9248: if (document.courseresform.newresusetemp.length) {
9249: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9250: if (document.courseresform.newresusetemp[i].checked) {
9251: if (document.courseresform.newresusetemp[i].value == '1') {
9252: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9253: if (url == '') {
9254: alert('Pick a category and template');
9255: } else {
9256: url = url.replace("$londocroot","");
9257: url += '?inhibitmenu=yes';
9258: }
9259: }
9260: break;
9261: }
9262: }
9263: }
9264: if (url != '') {
9265: openMyModal(url,width,height,scrolling,transparency,'');
9266: }
9267: }
9268:
1.690 raeburn 9269: function toggleImportCrsres(caller) {
1.606 raeburn 9270: var disp = 'none';
9271: if (document.getElementById('importcrsresform')) {
9272: if (caller == 'res') {
9273: var curr = document.getElementById('importcrsresform').style.display;
9274: if (curr == 'none') {
9275: disp='block';
1.698 raeburn 9276: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9277: if ((document.getElementById('importcrsrescontent')) &&
9278: (document.getElementById('importcrsresempty'))) {
9279: var selelem = document.crsresimportform.elements['coursepath'];
9280: var numdirs = 0;
9281: if (selelem.options.length) {
9282: numdirs = selelem.options.length - 1;
9283: }
9284: if (numdirs) {
9285: document.getElementById('importcrsrescontent').style.display='block';
9286: document.getElementById('importcrsresempty').style.display='none';
9287: } else {
9288: document.getElementById('importcrsrescontent').style.display='none';
9289: document.getElementById('importcrsresempty').style.display='block';
9290: }
9291: }
1.606 raeburn 9292: }
9293: }
9294: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9295: if (disp == 'block') {
9296: if (document.getElementById('importmapform')) {
9297: if (document.getElementById('importmapform').style.display == 'block') {
9298: document.getElementById('importmapform').style.display = 'none';
9299: }
9300: }
9301: }
1.606 raeburn 9302: resize_scrollbox('contentscroll','1','0');
9303: }
9304: return;
9305: }
9306:
1.690 raeburn 9307: $showfile_js
9308:
1.691 raeburn 9309: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9310: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9311: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9312: var selelem = form.elements[dirsel];
9313: var i, numfiles = selelem.options.length -1;
9314: if (numfiles >=0) {
9315: for (i = numfiles; i >= 0; i--) {
9316: selelem.remove(i);
9317: }
9318: }
9319: if ((location == '') || (location == null) || (location == 'undefined')) {
9320: if (selelem.options.length == 0) {
9321: selelem.options[selelem.options.length] = new Option('','');
9322: selelem.selectedIndex = 0;
9323: }
9324: if (document.getElementById('newstdproblem')) {
9325: document.getElementById('newstdproblem').style.display = 'none';
9326: }
9327: return;
9328: }
9329: var machineIds = new Array($machines_str);
9330: var athome = 0;
9331: var role = location;
9332: if ((location == 'author') || (location == 'course')) {
9333: if (document.getElementById('rolehome_'+location)) {
9334: var currhome = document.getElementById('rolehome_'+location).value;
9335: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9336: if (machineIds.includes(currhome)) {
9337: athome = 1;
9338: }
9339: }
9340: }
9341: } else {
9342: const roleinfo = location.split('___');
9343: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9344: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9345: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9346: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9347: if (machineIds.includes(currhome)) {
9348: athome = 1;
9349: }
9350: }
9351: }
9352: }
1.706 raeburn 9353: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9354: if (athome) {
9355: if (document.getElementById('stdprobswitch')) {
9356: document.getElementById('stdprobswitch').style.display = 'none';
9357: }
9358: if (document.getElementById('newstdproblem')) {
9359: document.getElementById('newstdproblem').style.display = 'none';
9360: }
1.706 raeburn 9361: var canedit = '$canedit';
9362: if (canedit) {
9363: if (templateradio.length > 1) {
9364: for (var i=0; i<templateradio.length; i++) {
9365: templateradio[i].disabled = false;
9366: }
9367: }
9368: document.courseresform.newresourcename.disabled = false;
9369: document.courseresform.newcrs.disabled = false;
9370: }
1.691 raeburn 9371: var http = new XMLHttpRequest();
9372: var url = "/adm/courseauthor";
1.698 raeburn 9373: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9374: http.open("POST", url, true);
9375: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9376: http.onreadystatechange = function() {
9377: if (http.readyState == 4 && http.status == 200) {
9378: var data = JSON.parse(http.responseText);
9379: if (Array.isArray(data.dirs)) {
9380: var len = data.dirs.length;
9381: if (len) {
9382: if (len > 1) {
9383: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9384: }
9385: }
9386: if (len) {
9387: var j;
9388: for (j = 0; j < len; j++) {
9389: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9390: }
9391: selelem.selectedIndex = 0;
1.697 raeburn 9392: if (len == 1) {
9393: toggleCrsResTitle();
9394: }
1.691 raeburn 9395: }
9396: }
9397: }
9398: }
9399: http.send(params);
9400: } else {
9401: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9402: selelem.selectedIndex = 0;
9403: if (document.getElementById('stdprobswitch')) {
9404: document.getElementById('stdprobswitch').style.display = 'block';
9405: }
9406: if (document.getElementById('newstdproblem')) {
9407: document.getElementById('newstdproblem').style.display = 'none';
9408: }
1.706 raeburn 9409: if (templateradio.length > 1) {
9410: for (var i=0; i<templateradio.length; i++) {
9411: templateradio[i].disabled = true;
9412: }
9413: }
9414: document.courseresform.newresourcename.disabled = true;
9415: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9416: }
9417: }
9418: return;
9419: }
9420:
1.689 raeburn 9421: function switchForProb() {
9422: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9423: var url = '/adm/switchserver?otherserver=';
9424: var newhostid = '';
9425: var role = '';
9426: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9427: if (selloc == 'author') {
9428: newhostid = document.courseresform.rolehome_author.value;
9429: role = "au./&js_escape($env{'user.domain'})/";
9430: } else if (selloc == 'course') {
9431: newhostid = document.courseresform.rolehome_course.value;
9432: role = "&js_escape($env{'request.role'})";
9433: } else {
9434: var items = new Array();
9435: items = selloc.split('___');
9436: var len = document.courseresform.rolehome_coauthor.length;
9437: if (null == len) {
9438: var currval = document.courseresform.rolehome_coauthor.value;
9439: if (null != currval) {
9440: var info = new Array();
9441: info = currval.split('=');
9442: newhostid = info[2];
9443: role = info[0]+'./'+info[1];
9444: }
9445: } else {
9446: for (var i=0; i<len; i++) {
9447: var currval = document.courseresform.rolehome_coauthor[i].value;
9448: if (null != currval) {
9449: var info = new Array();
9450: info = currval.split('=');
9451: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9452: newhostid = info[2];
9453: role = info[0]+'./'+info[1];
9454: break;
9455: }
9456: }
9457: }
9458: }
9459: }
9460: if (newhostid != '') {
9461: url += newhostid;
9462: if (role != '') {
9463: url += '&role='+role;
9464: }
9465: document.location.href = url;
9466: }
9467: }
9468: return;
9469: }
9470:
1.501 raeburn 9471: function makeims(imsform) {
9472: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9473: alert("$js_lt{'imsfile'}");
1.501 raeburn 9474: return;
9475: }
9476: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9477: alert("$js_lt{'imscms'}");
1.501 raeburn 9478: return;
9479: }
9480: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9481: imsform.submit();
9482: }
9483:
1.478 raeburn 9484: function updatePick(targetform,index,caller) {
1.537 raeburn 9485: var pickitem;
9486: var picknumitem;
9487: var picknumtext;
9488: if (index == 'all') {
9489: pickitem = document.getElementById('randompickall');
9490: picknumitem = document.getElementById('rpicknumall');
9491: picknumtext = document.getElementById('rpicktextall');
9492: } else {
9493: pickitem = document.getElementById('randompick_'+index);
9494: picknumitem = document.getElementById('rpicknum_'+index);
9495: picknumtext = document.getElementById('randompicknum_'+index);
9496: }
1.478 raeburn 9497: if (pickitem.checked) {
1.594 damieng 9498: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9499: if (picknum == '' || picknum == null) {
9500: if (caller == 'check') {
9501: pickitem.checked=false;
1.537 raeburn 9502: if (index == 'all') {
9503: picknumtext.innerHTML = '';
9504: if (caller == 'link') {
9505: propagateState(targetform,'rpicknum');
9506: }
9507: } else {
1.538 raeburn 9508: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9509: }
1.478 raeburn 9510: }
9511: } else {
9512: picknum.toString();
9513: var regexdigit=/^\\d+\$/;
9514: if (regexdigit.test(picknum)) {
9515: picknumitem.value = picknum;
1.537 raeburn 9516: if (index == 'all') {
1.538 raeburn 9517: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9518: if (caller == 'link') {
9519: propagateState(targetform,'rpicknum');
9520: }
9521: } else {
9522: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9523: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9524: }
1.478 raeburn 9525: } else {
9526: if (caller == 'check') {
1.537 raeburn 9527: if (index == 'all') {
9528: picknumtext.innerHTML = '';
9529: if (caller == 'link') {
9530: propagateState(targetform,'rpicknum');
9531: }
9532: } else {
9533: pickitem.checked=false;
1.538 raeburn 9534: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9535: }
1.478 raeburn 9536: }
9537: return;
9538: }
9539: }
9540: } else {
1.537 raeburn 9541: picknumitem.value = '';
9542: picknumtext.innerHTML = '';
9543: if (index == 'all') {
9544: if (caller == 'link') {
9545: propagateState(targetform,'rpicknum');
9546: }
9547: } else {
1.538 raeburn 9548: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9549: }
9550: }
9551: }
9552:
9553: function propagateState(form,param) {
9554: if (document.getElementById(param+'all')) {
9555: var setcheck = 0;
9556: var rpick = 0;
9557: if (param == 'rpicknum') {
9558: if (document.getElementById('randompickall')) {
9559: if (document.getElementById('randompickall').checked) {
9560: if (document.getElementById('rpicknumall')) {
9561: rpick = document.getElementById('rpicknumall').value;
9562: }
9563: }
9564: }
9565: } else {
9566: if (document.getElementById(param+'all').checked) {
9567: setcheck = 1;
9568: }
9569: }
1.538 raeburn 9570: var allidxlist;
9571: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9572: if (document.getElementById('all'+param+'idx')) {
9573: allidxlist = document.getElementById('all'+param+'idx').value;
9574: }
9575: var actions = new Array ('remove','cut','copy');
9576: for (var i=0; i<actions.length; i++) {
9577: if (actions[i] != param) {
9578: if (document.getElementById(actions[i]+'all')) {
9579: document.getElementById(actions[i]+'all').checked = false;
9580: }
9581: }
9582: }
9583: }
1.537 raeburn 9584: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9585: allidxlist = form.allidx.value;
9586: }
9587: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9588: allidxlist = form.allmapidx.value;
9589: }
9590: if ((allidxlist != '') && (allidxlist != null)) {
9591: var allidxs = allidxlist.split(',');
9592: if (allidxs.length > 1) {
9593: for (var i=0; i<allidxs.length; i++) {
9594: if (document.getElementById(param+'_'+allidxs[i])) {
9595: if (param == 'rpicknum') {
9596: if (document.getElementById('randompick_'+allidxs[i])) {
9597: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9598: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9599: if (rpick > 0) {
9600: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9601: } else {
9602: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9603: }
9604: }
9605: }
9606: } else {
1.537 raeburn 9607: if (setcheck == 1) {
9608: document.getElementById(param+'_'+allidxs[i]).checked = true;
9609: } else {
9610: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9611: if (param == 'randompick') {
9612: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9613: }
1.537 raeburn 9614: }
9615: }
9616: }
9617: }
1.538 raeburn 9618: if (setcheck == 1) {
9619: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9620: var actions = new Array('copy','cut','remove');
9621: for (var i=0; i<actions.length; i++) {
9622: var otheractions;
9623: var otheridxs;
9624: if (actions[i] === param) {
9625: continue;
9626: } else {
9627: if (document.getElementById('all'+actions[i]+'idx')) {
9628: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9629: otheridxs = otheractions.split(',');
9630: if (otheridxs.length > 1) {
9631: for (var j=0; j<otheridxs.length; j++) {
9632: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9633: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9634: }
1.537 raeburn 9635: }
9636: }
9637: }
1.538 raeburn 9638: }
9639: }
9640: }
9641: }
9642: }
9643: }
9644: }
9645: return;
9646: }
9647:
1.603 raeburn 9648: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9649: var canedit = '$canedit';
9650: if (canedit == '') {
9651: alert("$js_lt{'edri'}");
9652: return;
9653: }
1.539 raeburn 9654: var dosettings;
9655: var doaction;
1.538 raeburn 9656: var control = document.togglemultsettings;
9657: if (context == 'actions') {
9658: control = document.togglemultactions;
1.539 raeburn 9659: doaction = 1;
9660: } else {
9661: dosettings = 1;
1.538 raeburn 9662: }
1.539 raeburn 9663: if (control) {
9664: if (control.showmultpick.length) {
9665: for (var i=0; i<control.showmultpick.length; i++) {
9666: if (control.showmultpick[i].checked) {
9667: if (control.showmultpick[i].value == 1) {
9668: if (context == 'settings') {
9669: dosettings = 0;
9670: } else {
9671: doaction = 0;
1.538 raeburn 9672: }
9673: }
9674: }
1.537 raeburn 9675: }
9676: }
1.539 raeburn 9677: }
9678: if (context == 'settings') {
9679: if (dosettings == 1) {
1.538 raeburn 9680: targetform.changeparms.value=param;
9681: targetform.submit();
9682: }
1.537 raeburn 9683: }
1.539 raeburn 9684: if (context == 'actions') {
9685: if (doaction == 1) {
9686: targetform.cmd.value=param+'_'+index;
9687: targetform.folderpath.value=folderpath;
9688: targetform.markcopy.value=idx+':'+param;
9689: targetform.copyfolder.value=folder+'.'+container;
9690: if (param == 'remove') {
1.603 raeburn 9691: var doremove = 0;
9692: if (skip_confirm) {
9693: if (confirm_removal) {
9694: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9695: doremove = 1;
9696: }
9697: } else {
9698: doremove = 1;
9699: }
9700: } else {
9701: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9702: doremove = 1;
9703: }
9704: }
9705: if (doremove) {
1.539 raeburn 9706: targetform.markcopy.value='';
9707: targetform.copyfolder.value='';
9708: targetform.submit();
9709: }
9710: }
9711: if (param == 'cut') {
1.594 damieng 9712: 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 9713: targetform.submit();
9714: return;
9715: }
9716: }
9717: if (param == 'copy') {
9718: targetform.submit();
9719: return;
9720: }
9721: targetform.markcopy.value='';
9722: targetform.copyfolder.value='';
9723: targetform.cmd.value='';
9724: targetform.folderpath.value='';
9725: return;
9726: } else {
9727: if (document.getElementById(param+'_'+idx)) {
9728: item = document.getElementById(param+'_'+idx);
9729: if (item.type == 'checkbox') {
9730: if (item.checked) {
9731: item.checked = false;
9732: } else {
9733: item.checked = true;
9734: singleCheck(item,idx,param);
9735: }
9736: }
9737: }
9738: }
9739: }
1.537 raeburn 9740: return;
9741: }
9742:
1.538 raeburn 9743: function singleCheck(caller,idx,action) {
9744: actions = new Array('cut','copy','remove');
9745: if (caller.checked) {
9746: for (var i=0; i<actions.length; i++) {
9747: if (actions[i] != action) {
9748: if (document.getElementById(actions[i]+'_'+idx)) {
9749: if (document.getElementById(actions[i]+'_'+idx).checked) {
9750: document.getElementById(actions[i]+'_'+idx).checked = false;
9751: }
1.537 raeburn 9752: }
9753: }
9754: }
1.478 raeburn 9755: }
1.537 raeburn 9756: return;
1.478 raeburn 9757: }
9758:
1.334 muellerd 9759: function unselectInactive(nav) {
1.335 ehlerst 9760: currentNav = document.getElementById(nav);
9761: currentLis = currentNav.getElementsByTagName('LI');
9762: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9763: if (currentLis[i].className == 'goback') {
9764: currentLis[i].className = 'goback';
9765: } else {
9766: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9767: currentLis[i].className = 'right';
1.472 raeburn 9768: } else {
1.374 tempelho 9769: currentLis[i].className = 'i';
1.472 raeburn 9770: }
9771: }
1.335 ehlerst 9772: }
1.332 tempelho 9773: }
9774:
1.334 muellerd 9775: function hideAll(current, nav, data) {
1.335 ehlerst 9776: unselectInactive(nav);
1.570 raeburn 9777: if (current) {
9778: if (current.className == 'right'){
9779: current.className = 'right active'
9780: } else {
9781: current.className = 'active';
9782: }
1.374 tempelho 9783: }
1.335 ehlerst 9784: currentData = document.getElementById(data);
9785: currentDivs = currentData.getElementsByTagName('DIV');
9786: for (i = 0; i < currentDivs.length; i++) {
9787: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9788: currentDivs[i].style.display = 'none';
1.330 tempelho 9789: }
9790: }
1.335 ehlerst 9791: }
1.330 tempelho 9792:
1.374 tempelho 9793: function openTabs(pageId) {
9794: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9795: if(tabnav.length > 2 ){
1.389 tempelho 9796: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9797: currentLis = currentNav.getElementsByTagName('LI');
9798: for(i = 0; i< currentLis.length; i++){
9799: if(currentLis[i].className == 'active') {
1.375 tempelho 9800: funcString = currentLis[i].onclick.toString();
9801: tab = funcString.split('"');
1.420 onken 9802: if(tab.length < 2) {
9803: tab = funcString.split("'");
9804: }
1.375 tempelho 9805: currentData = document.getElementById(tab[1]);
9806: currentData.style.display = 'block';
1.374 tempelho 9807: }
9808: }
9809: }
9810: }
9811:
1.334 muellerd 9812: function showPage(current, pageId, nav, data) {
1.570 raeburn 9813: currstate = current.className;
1.334 muellerd 9814: hideAll(current, nav, data);
1.375 tempelho 9815: openTabs(pageId);
1.334 muellerd 9816: unselectInactive(nav);
1.570 raeburn 9817: if ((currstate == 'active') || (currstate == 'right active')) {
9818: if (currstate == 'active') {
9819: current.className = '';
9820: } else {
9821: current.className = 'right';
9822: }
9823: activeTab = '';
1.656 raeburn 9824: toggleExternal();
1.570 raeburn 9825: toggleUpload();
9826: toggleMap();
1.606 raeburn 9827: toggleCrsRes();
9828: toggleImportCrsres();
1.570 raeburn 9829: resize_scrollbox('contentscroll','1','0');
9830: return;
9831: } else {
9832: current.className = 'active';
9833: }
1.330 tempelho 9834: currentData = document.getElementById(pageId);
9835: currentData.style.display = 'block';
1.458 raeburn 9836: activeTab = pageId;
1.656 raeburn 9837: toggleExternal();
1.501 raeburn 9838: toggleUpload();
1.503 raeburn 9839: toggleMap();
1.606 raeburn 9840: toggleCrsRes();
9841: toggleImportCrsres();
1.433 raeburn 9842: if (nav == 'mainnav') {
9843: var storedpath = "$docs_folderpath";
1.434 raeburn 9844: var storedpage = "$main_container_page";
1.433 raeburn 9845: var reg = new RegExp("^supplemental");
9846: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9847: if (storedpage == 1) {
9848: document.simpleedit.folderpath.value = '';
9849: document.uploaddocument.folderpath.value = '';
9850: } else {
9851: if (reg.test(storedpath)) {
9852: document.simpleedit.folderpath.value = '$toplevelmain';
9853: document.uploaddocument.folderpath.value = '$toplevelmain';
9854: document.newext.folderpath.value = '$toplevelmain';
9855: } else {
9856: document.simpleedit.folderpath.value = storedpath;
9857: document.uploaddocument.folderpath.value = storedpath;
9858: document.newext.folderpath.value = storedpath;
9859: }
1.433 raeburn 9860: }
9861: } else {
1.434 raeburn 9862: if (reg.test(storedpath)) {
9863: document.simpleedit.folderpath.value = storedpath;
9864: document.supuploaddocument.folderpath.value = storedpath;
9865: document.supnewext.folderpath.value = storedpath;
9866: } else {
1.433 raeburn 9867: document.simpleedit.folderpath.value = '$toplevelsupp';
9868: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9869: document.supnewext.folderpath.value = '$toplevelsupp';
9870: }
9871: }
9872: }
1.485 raeburn 9873: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9874: return false;
9875: }
1.329 droeschl 9876:
1.472 raeburn 9877: function toContents(jumpto) {
9878: var newurl = '$backtourl';
1.525 raeburn 9879: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 9880: newurl = newurl+'?postdata='+jumpto;
9881: }
9882: location.href=newurl;
9883: }
9884:
1.538 raeburn 9885: function togglePick(caller,value) {
9886: var disp = 'none';
9887: if (document.getElementById('multi'+caller)) {
9888: var curr = document.getElementById('multi'+caller).style.display;
9889: if (value == 1) {
9890: disp='block';
9891: }
9892: if (curr == disp) {
9893: return;
9894: }
9895: document.getElementById('multi'+caller).style.display=disp;
9896: if (value == 1) {
1.594 damieng 9897: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9898: } else {
9899: document.getElementById('more'+caller).innerHTML = '';
9900: }
9901: if (caller == 'actions') {
9902: setClass(value);
9903: setBoxes(value);
9904: }
9905: }
9906: var showButton = multiSettings();
9907: if (showButton != 1) {
9908: showButton = multiActions();
9909: }
9910: if (document.getElementById('multisave')) {
9911: if (showButton == 1) {
9912: document.getElementById('multisave').style.display='block';
9913: } else {
9914: document.getElementById('multisave').style.display='none';
9915: }
9916: }
9917: resize_scrollbox('contentscroll','1','1');
9918: return;
9919: }
9920:
9921: function toggleCheckUncheck(caller,more) {
9922: if (more == 1) {
1.594 damieng 9923: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 9924: document.getElementById('allfields'+caller).style.display='block';
9925: } else {
1.594 damieng 9926: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9927: document.getElementById('allfields'+caller).style.display='none';
9928: }
9929: resize_scrollbox('contentscroll','1','1');
9930: }
9931:
9932: function multiSettings() {
9933: var inuse = 0;
9934: var settingsform = document.togglemultsettings;
9935: if (settingsform.showmultpick.length > 1) {
9936: for (var i=0; i<settingsform.showmultpick.length; i++) {
9937: if (settingsform.showmultpick[i].checked) {
9938: if (settingsform.showmultpick[i].value == 1) {
9939: inuse = 1;
9940: }
9941: }
9942: }
9943: }
9944: return inuse;
9945: }
9946:
9947: function multiActions() {
9948: var inuse = 0;
9949: var actionsform = document.togglemultactions;
9950: if (actionsform.showmultpick.length > 1) {
9951: for (var i=0; i<actionsform.showmultpick.length; i++) {
9952: if (actionsform.showmultpick[i].checked) {
9953: if (actionsform.showmultpick[i].value == 1) {
9954: inuse = 1;
9955: }
9956: }
9957: }
9958: }
9959: return inuse;
9960: }
9961:
9962: function checkSubmits() {
9963: var numchanges = 0;
9964: var form = document.saveactions;
9965: var doactions = multiActions();
1.542 raeburn 9966: var cutwarnings = 0;
9967: var remwarnings = 0;
1.603 raeburn 9968: var removalinfo = 0;
1.538 raeburn 9969: if (doactions == 1) {
9970: var remidxlist = document.cumulativeactions.allremoveidx.value;
9971: if ((remidxlist != '') && (remidxlist != null)) {
9972: var remidxs = remidxlist.split(',');
9973: for (var i=0; i<remidxs.length; i++) {
9974: if (document.getElementById('remove_'+remidxs[i])) {
9975: if (document.getElementById('remove_'+remidxs[i]).checked) {
9976: form.multiremove.value += remidxs[i]+',';
9977: numchanges ++;
1.542 raeburn 9978: if (document.getElementById('skip_remove_'+remidxs[i])) {
9979: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9980: remwarnings ++;
9981: }
9982: }
1.603 raeburn 9983: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9984: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9985: removalinfo ++;
9986: }
9987: }
1.537 raeburn 9988: }
9989: }
1.538 raeburn 9990: }
9991: }
9992: var cutidxlist = document.cumulativeactions.allcutidx.value;
9993: if ((cutidxlist != '') && (cutidxlist != null)) {
9994: var cutidxs = cutidxlist.split(',');
9995: for (var i=0; i<cutidxs.length; i++) {
9996: if (document.getElementById('cut_'+cutidxs[i])) {
9997: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9998: form.multicut.value += cutidxs[i]+',';
9999: numchanges ++;
1.542 raeburn 10000: if (document.getElementById('skip_cut_'+cutidxs[i])) {
10001: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
10002: cutwarnings ++;
10003: }
10004: }
1.537 raeburn 10005: }
10006: }
10007: }
10008: }
1.538 raeburn 10009: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10010: if ((copyidxlist != '') && (copyidxlist != null)) {
10011: var copyidxs = copyidxlist.split(',');
10012: for (var i=0; i<copyidxs.length; i++) {
10013: if (document.getElementById('copy_'+copyidxs[i])) {
10014: if (document.getElementById('copy_'+copyidxs[i]).checked) {
10015: form.multicopy.value += copyidxs[i]+',';
10016: numchanges ++;
10017: }
10018: }
10019: }
10020: }
10021: if (numchanges > 0) {
10022: form.multichange.value = numchanges;
10023: }
1.537 raeburn 10024: }
1.538 raeburn 10025: var dosettings = multiSettings();
1.543 raeburn 10026: var haschanges = 0;
1.538 raeburn 10027: if (dosettings == 1) {
10028: form.allencrypturl.value = '';
10029: form.allhiddenresource.value = '';
1.543 raeburn 10030: form.changeparms.value = 'all';
10031: var patt=new RegExp(",\$");
1.538 raeburn 10032: var allidxlist = document.cumulativesettings.allidx.value;
10033: if ((allidxlist != '') && (allidxlist != null)) {
10034: var allidxs = allidxlist.split(',');
10035: if (allidxs.length > 1) {
10036: for (var i=0; i<allidxs.length; i++) {
10037: if (document.getElementById('hiddenresource_'+allidxs[i])) {
10038: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
10039: form.allhiddenresource.value += allidxs[i]+',';
10040: }
10041: }
10042: if (document.getElementById('encrypturl_'+allidxs[i])) {
10043: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
10044: form.allencrypturl.value += allidxs[i]+',';
10045: }
10046: }
10047: }
1.543 raeburn 10048: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
10049: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 10050: }
1.538 raeburn 10051: }
10052: form.allrandompick.value = '';
10053: form.allrandomorder.value = '';
10054: var allmapidxlist = document.cumulativesettings.allmapidx.value;
10055: if ((allmapidxlist != '') && (allmapidxlist != null)) {
10056: var allmapidxs = allmapidxlist.split(',');
10057: for (var i=0; i<allmapidxs.length; i++) {
10058: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
10059: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
10060: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
10061: if ((randompick.checked) && (rpicknum.value != '')) {
10062: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
10063: }
10064: if (randorder.checked) {
10065: form.allrandomorder.value += allmapidxs[i]+',';
10066: }
1.537 raeburn 10067: }
1.543 raeburn 10068: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
10069: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
10070: }
10071: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
10072: haschanges = 1;
10073: }
10074: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
10075: haschanges = 1;
10076: }
10077: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
10078: haschanges = 1;
10079: }
10080: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
10081: haschanges = 1;
1.537 raeburn 10082: }
10083: }
1.543 raeburn 10084: if (doactions == 1) {
1.542 raeburn 10085: if (numchanges > 0) {
1.603 raeburn 10086: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 10087: if (remwarnings > 0) {
1.594 damieng 10088: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 10089: return false;
10090: }
10091: }
1.603 raeburn 10092: if (removalinfo > 0) {
10093: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
10094: return false;
10095: }
10096: }
1.542 raeburn 10097: if (cutwarnings > 0) {
1.594 damieng 10098: 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 10099: return false;
10100: }
10101: }
10102: }
10103: form.submit();
10104: return true;
1.543 raeburn 10105: }
10106: }
10107: if (dosettings == 1) {
10108: if (haschanges == 1) {
1.542 raeburn 10109: form.submit();
10110: return true;
10111: }
1.543 raeburn 10112: }
10113: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 10114: alert("$js_lt{'noor'}");
1.543 raeburn 10115: } else {
10116: if (dosettings == 1) {
1.594 damieng 10117: alert("$js_lt{'noch'}");
1.543 raeburn 10118: } else {
1.594 damieng 10119: alert("$js_lt{'noac'}");
1.543 raeburn 10120: }
10121: }
1.538 raeburn 10122: return false;
10123: }
10124:
10125: function setClass(value) {
10126: var cutclass = 'LC_docs_cut';
10127: var copyclass = 'LC_docs_copy';
10128: var removeclass = 'LC_docs_remove';
10129: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
10130: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
10131: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
10132: var links = document.getElementsByTagName('a');
10133: for (var i=0; i<links.length; i++) {
10134: var classes = links[i].className;
10135: if (cutreg.test(classes)) {
10136: links[i].className = cutclass;
10137: if (value == 1) {
10138: links[i].className += " LC_menubuttons_link";
10139: }
10140: } else {
10141: if (copyreg.test(classes)) {
10142: links[i].className = copyclass;
10143: if (value == 1) {
10144: links[i].className += " LC_menubuttons_link";
10145: }
10146: } else {
10147: if (removereg.test(classes)) {
10148: links[i].className = removeclass;
10149: if (value == 1) {
10150: links[i].className += " LC_menubuttons_link";
10151: }
10152: }
10153: }
10154: }
10155: }
10156: return;
1.537 raeburn 10157: }
10158:
1.538 raeburn 10159: function setBoxes(value) {
10160: var remidxlist = document.cumulativeactions.allremoveidx.value;
10161: if ((remidxlist != '') && (remidxlist != null)) {
10162: var remidxs = remidxlist.split(',');
10163: for (var i=0; i<remidxs.length; i++) {
10164: if (document.getElementById('remove_'+remidxs[i])) {
10165: var item = document.getElementById('remove_'+remidxs[i]);
10166: if (value == 1) {
10167: item.className = 'LC_docs_remove';
10168: } else {
10169: item.className = 'LC_hidden';
10170: }
10171: }
10172: }
10173: }
10174: var cutidxlist = document.cumulativeactions.allcutidx.value;
10175: if ((cutidxlist != '') && (cutidxlist != null)) {
10176: var cutidxs = cutidxlist.split(',');
10177: for (var i=0; i<cutidxs.length; i++) {
10178: if (document.getElementById('cut_'+cutidxs[i])) {
10179: var item = document.getElementById('cut_'+cutidxs[i]);
10180: if (value == 1) {
10181: item.className = 'LC_docs_cut';
10182: } else {
10183: item.className = 'LC_hidden';
10184: }
10185: }
1.537 raeburn 10186: }
10187: }
1.538 raeburn 10188: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10189: if ((copyidxlist != '') && (copyidxlist != null)) {
10190: var copyidxs = copyidxlist.split(',');
10191: for (var i=0; i<copyidxs.length; i++) {
10192: if (document.getElementById('copy_'+copyidxs[i])) {
10193: var item = document.getElementById('copy_'+copyidxs[i]);
10194: if (value == 1) {
10195: item.className = 'LC_docs_copy';
10196: } else {
10197: item.className = 'LC_hidden';
10198: }
10199: }
1.537 raeburn 10200: }
10201: }
10202: return;
10203: }
10204:
1.606 raeburn 10205: function validImportCrsRes() {
10206: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10207: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10208: if ((fname == '') || (fname == null)) {
10209: alert("$js_lt{'nofi'}");
10210: return false;
10211: }
10212: var url = '/res/$coursedom/$coursenum/';
10213: if (path && path != '/') {
10214: url += path+'/';
10215: }
10216: if (fname != '') {
10217: url += fname;
10218: }
10219: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10220: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10221: return true;
10222: }
10223:
10224: function validateNewRes(caller) {
10225: if (caller == 'single') {
10226: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10227: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10228: var resname = document.courseresform.newresourcename.value;
10229: }
10230: }
10231:
1.611 raeburn 10232: ENDSCRIPT
1.329 droeschl 10233: }
1.457 raeburn 10234:
1.483 raeburn 10235: sub history_tab_js {
10236: return <<"ENDHIST";
10237: function toggleHistoryDisp(choice) {
10238: document.docslogform.docslog.value = choice;
10239: document.docslogform.submit();
10240: return;
10241: }
10242:
10243: ENDHIST
10244: }
10245:
1.484 raeburn 10246: sub inject_data_js {
10247: return <<ENDINJECT;
10248:
10249: function injectData(current, hiddenField, name, value) {
10250: currentElement = document.getElementById(hiddenField);
10251: currentElement.name = name;
10252: currentElement.value = value;
10253: current.submit();
10254: }
10255:
10256: ENDINJECT
10257: }
10258:
10259: sub dump_switchserver_js {
10260: my @hosts = @_;
1.594 damieng 10261: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10262: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10263: swit => 'Switch server?',
1.594 damieng 10264: );
10265: my %html_js_lt = &Apache::lonlocal::texthash(
10266: swit => 'Switch server?',
1.709 raeburn 10267: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10268: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10269: chos => 'Choose server',
10270: );
1.594 damieng 10271: &js_escape(\%js_lt);
10272: &html_escape(\%html_js_lt);
10273: &js_escape(\%html_js_lt);
1.484 raeburn 10274: my $role = $env{'request.role'};
10275: my $js = <<"ENDSWJS";
10276: <script type="text/javascript">
10277: function write_switchserver() {
10278: var server;
10279: if (document.setserver.posshosts.length > 0) {
10280: for (var i=0; i<document.setserver.posshosts.length; i++) {
10281: if (document.setserver.posshosts[i].checked) {
10282: server = document.setserver.posshosts[i].value;
10283: }
10284: }
10285: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10286: }
10287: window.close();
10288: }
10289: </script>
10290:
10291: ENDSWJS
10292:
10293: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10294: {'only_body' => 1,
10295: 'js_ready' => 1,});
10296: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10297:
10298: my $hostpicker;
10299: my $count = 0;
10300: foreach my $host (sort(@hosts)) {
10301: my $checked;
10302: if ($count == 0) {
10303: $checked = ' checked="checked"';
10304: }
10305: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10306: $host.'"'.$checked.' />'.$host.'</label> ';
10307: $count++;
10308: }
10309:
10310: return <<"ENDSWITCHJS";
10311:
10312: function dump_needs_switchserver(url) {
10313: if (url!='' && url!= null) {
1.594 damieng 10314: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10315: go(url);
10316: }
10317: }
10318: return;
10319: }
10320:
10321: function choose_switchserver_window() {
10322: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10323: newWindow.document.open();
10324: newWindow.document.writeln('$startpage');
1.594 damieng 10325: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10326: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10327: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10328: '<form name="setserver" method="post" action="" \\/>\\n'+
10329: '$hostpicker\\n'+
10330: '<br \\/><br \\/>\\n'+
1.594 damieng 10331: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10332: 'onclick="write_switchserver();" \\/>\\n'+
10333: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10334: newWindow.document.writeln('$endpage');
10335: newWindow.document.close();
10336: newWindow.focus();
10337: }
10338:
10339: ENDSWITCHJS
10340: }
10341:
10342: sub makedocslogform {
10343: my ($formelems,$docslog) = @_;
10344: return <<"LOGSFORM";
10345: <form action="/adm/coursedocs" method="post" name="docslogform">
10346: <input type="hidden" name="docslog" value="$docslog" />
10347: $formelems
10348: </form>
10349: LOGSFORM
10350: }
10351:
10352: sub makesimpleeditform {
10353: my ($formelems) = @_;
10354: return <<"SIMPFORM";
10355: <form name="simpleedit" method="post" action="/adm/coursedocs">
10356: <input type="hidden" name="importdetail" value="" />
10357: $formelems
10358: </form>
10359: SIMPFORM
10360: }
10361:
1.606 raeburn 10362: sub makenewproblem {
10363: my ($r,$coursedom,$coursenum) = @_;
10364: # Creating a new problem
10365: my ($redirect,$error);
10366: if ($env{'form.authorrole'}) {
10367: my ($newsubdir,$filename);
10368: if ($env{'form.newsubdir'}) {
10369: if ($env{'form.newsubdirname'} ne '') {
10370: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10371: }
1.606 raeburn 10372: }
10373: if ($env{'form.newresourcename'}) {
10374: $filename = $env{'form.newresourcename'};
10375: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10376: $filename =~ s/`//g;
10377: $filename =~ s{/\.\./}{_}g;
10378: $filename =~ s/\.+/./g;
10379: $filename =~ s{/+}{_}g;
10380: if ($filename ne '') {
10381: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10382: if (($ext) && ($ext ne '.problem')) {
10383: $filename = $name.'.problem';
10384: } elsif ($ext eq '') {
10385: $filename .= '.problem';
10386: }
10387: my $docroot = $r->dir_config('lonDocRoot');
10388: my @ids=&Apache::lonnet::current_machine_ids();
10389: if ($env{'form.authorrole'} eq 'author') {
10390: if ($env{'user.author'}) {
10391: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10392: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10393: my $path = $docroot.$url;
10394: my $subdir = $env{'form.authorpath'};
10395: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10396: }
10397: }
10398: } elsif ($env{'form.authorrole'} eq 'course') {
10399: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10400: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10401: my $url = "/priv/$coursedom/$coursenum";
10402: my $path=$docroot.$url;
10403: my $subdir = $env{'form.authorpath'};
10404: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10405: if ($redirect) {
10406: my $rightsfile = 'default.rights';
10407: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10408: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10409: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10410: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10411: if (!-e "$docroot/res/$coursedom") {
10412: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10413: }
1.654 raeburn 10414: if (!-e "$docroot/res/$coursedom/$coursenum") {
10415: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10416: }
10417: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10418: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10419: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10420: }
10421: }
1.654 raeburn 10422: my $source = $docroot.$redirect;
10423: if (!-e "$source.meta") {
10424: my $cid = $coursedom.'_'.$coursenum;
10425: my $now = time;
10426: if (open(my $fh,">$source.meta")) {
10427: my $author=$env{'environment.firstname'}.' '.
10428: $env{'environment.middlename'}.' '.
10429: $env{'environment.lastname'}.' '.
10430: $env{'environment.generation'};
10431: $author =~ s/\s+$//;
10432: my $title = $env{'form.newresourcetitle'};
10433: $title =~ s/^\s+|\s+$//g;
10434: print $fh <<END;
1.606 raeburn 10435:
10436: <abstract></abstract>
10437: <author>$author</author>
10438: <authorspace>$coursenum:$coursedom</authorspace>
10439: <copyright>custom</copyright>
10440: <creationdate>$now</creationdate>
10441: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10442: <dependencies></dependencies>
10443: <domain>$coursedom</domain>
10444: <highestgradelevel>0</highestgradelevel>
10445: <keywords></keywords>
10446: <language>notset </language>
10447: <lastrevisiondate>$now</lastrevisiondate>
10448: <lowestgradelevel>0</lowestgradelevel>
10449: <mime>problem</mime>
10450: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10451: <notes></notes>
10452: <obsolete></obsolete>
10453: <obsoletereplacement></obsoletereplacement>
10454: <owner>$coursenum:$coursedom</owner>
10455: <sourceavail></sourceavail>
10456: <standards></standards>
10457: <subject></subject>
10458: <title>$title</title>
10459: END
1.654 raeburn 10460: close($fh);
1.606 raeburn 10461: }
10462: }
10463: }
10464: }
10465: } else {
10466: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10467: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10468: if (grep(/^\Q$rolehome\E$/,@ids)) {
10469: my $now = time;
10470: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10471: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10472: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10473: my $url = "/priv/$audom/$auname";
10474: my $path = $r->dir_config('lonDocRoot').$url;
10475: my $subdir = $env{'form.authorpath'};
10476: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10477: }
10478: }
10479: }
10480: }
10481: }
10482: }
10483: }
10484: return ($redirect,$error);
10485: }
10486:
10487: sub finishnewprob {
1.654 raeburn 10488: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10489: unless (-d $path) {
10490: unless (mkdir($path,02770)) {
10491: return;
10492: }
10493: }
1.606 raeburn 10494: my $redirect;
10495: if ($subdir ne '/') {
10496: $subdir = &cleandir($subdir);
10497: if (($subdir ne '') && (-d "$path/$subdir")) {
10498: $path .= "/$subdir";
10499: $url .= "/$subdir";
10500: }
10501: }
10502: my $dest;
10503: if ($newsubdir ne '') {
10504: $newsubdir = &cleandir($newsubdir);
10505: }
10506: if ($newsubdir ne '') {
10507: if (-d "$path/$newsubdir") {
10508: $dest = "$path/$newsubdir/$filename";
10509: } else {
10510: my $dirok;
10511: unless (-e "$path/$newsubdir") {
10512: if (mkdir("$path/$newsubdir",02770)) {
10513: if (chmod(02770,"$path/$newsubdir")) {
10514: $dirok = 1;
10515: }
10516: }
10517: }
10518: if ($dirok) {
10519: $dest = "$path/$newsubdir/$filename";
10520: }
10521: }
10522: if (($dest ne '') && (!-e $dest)) {
10523: $redirect = "$url/$newsubdir/$filename";
10524: }
10525: } else {
10526: $dest = "$path/$filename";
10527: if (($dest ne '') && (!-e $dest)) {
10528: $redirect = "$url/$filename";
10529: }
10530: }
1.654 raeburn 10531: if ((!-e $dest) && ($context ne 'upload')) {
10532: my $template = $env{'form.template'};
10533: my $copyfrom;
10534: if ($template ne '') {
10535: my %templates;
10536: my @files = &Apache::lonhomework::get_template_list('problem');
10537: foreach my $poss (@files) {
10538: if (ref($poss) eq 'ARRAY') {
10539: if ($template eq $poss->[0]) {
10540: $templates{$template} = 1;
10541: last;
10542: }
10543: }
10544: }
10545: if ($templates{$template}) {
10546: $copyfrom = $template;
10547: }
10548: }
10549: if ($filename =~ /\.problem$/) {
10550: unless ($copyfrom) {
10551: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10552: }
10553: &File::Copy::copy($copyfrom,$dest);
10554: }
10555: }
1.606 raeburn 10556: return $redirect;
10557: }
10558:
10559: sub cleandir {
10560: my ($dir) = @_;
10561: $dir =~ s/^\s+//;
10562: $dir =~ s/\s+$//;
10563: $dir =~ s/\.+//g;
10564: $dir =~ s/[\#\?&%\":]//g;
10565: return $dir;
10566: }
10567:
1.329 droeschl 10568: 1;
10569: __END__
10570:
10571:
10572: =head1 NAME
10573:
10574: Apache::londocs.pm
10575:
10576: =head1 SYNOPSIS
10577:
10578: This is part of the LearningOnline Network with CAPA project
10579: described at http://www.lon-capa.org.
10580:
10581: =head1 SUBROUTINES
10582:
10583: =over
10584:
10585: =item %help=()
10586:
10587: Available help topics
10588:
10589: =item mapread()
10590:
1.344 bisitz 10591: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10592: @order and @resources, determines status
10593: sets @order - pointer to resources in right order
10594: sets @resources - array with the resources with correct idx
10595:
10596: =item authorhosts()
10597:
10598: Return hash with valid author names
10599:
10600: =item clean()
10601:
10602: =item dumpcourse()
10603:
10604: Actually dump course
10605:
10606: =item group_import()
10607:
10608: Imports the given (name, url) resources into the course
10609: coursenum, coursedom, and folder must precede the list
10610:
10611: =item breadcrumbs()
10612:
10613: =item log_docs()
10614:
10615: =item docs_change_log()
10616:
10617: =item update_paste_buffer()
10618:
10619: =item print_paste_buffer()
10620:
10621: =item do_paste_from_buffer()
10622:
1.538 raeburn 10623: =item do_buffer_empty()
10624:
10625: =item clear_from_buffer()
10626:
1.492 raeburn 10627: =item get_newmap_url()
10628:
10629: =item dbcopy()
10630:
10631: =item uniqueness_check()
10632:
10633: =item contained_map_check()
10634:
10635: =item url_paste_fixups()
10636:
10637: =item apply_fixups()
10638:
10639: =item copy_dependencies()
10640:
1.329 droeschl 10641: =item update_parameter()
10642:
10643: =item handle_edit_cmd()
10644:
10645: =item editor()
10646:
10647: =item process_file_upload()
10648:
10649: =item process_secondary_uploads()
10650:
10651: =item is_supplemental_title()
10652:
10653: =item entryline()
10654:
10655: =item tiehash()
10656:
10657: =item untiehash()
10658:
10659: =item checkonthis()
10660:
10661: check on this
10662:
10663: =item verifycontent()
10664:
10665: Verify Content
10666:
1.636 raeburn 10667: =item devalidateversioncache()
10668:
10669: =item checkversions()
1.329 droeschl 10670:
10671: Check Versions
10672:
10673: =item mark_hash_old()
10674:
10675: =item is_hash_old()
10676:
10677: =item changewarning()
10678:
10679: =item init_breadcrumbs()
10680:
10681: Breadcrumbs for special functions
10682:
1.484 raeburn 10683: =item create_list_elements()
10684:
10685: =item create_form_ul()
10686:
10687: =item startContentScreen()
10688:
10689: =item endContentScreen()
10690:
10691: =item supplemental_base()
10692:
10693: =item embedded_form_elems()
10694:
10695: =item embedded_destination()
10696:
10697: =item return_to_editor()
10698:
10699: =item decompression_info()
10700:
10701: =item decompression_phase_one()
10702:
10703: =item decompression_phase_two()
10704:
10705: =item remove_archive()
10706:
10707: =item generate_admin_menu()
10708:
10709: =item generate_edit_table()
10710:
10711: =item editing_js()
10712:
10713: =item history_tab_js()
10714:
10715: =item inject_data_js()
10716:
10717: =item dump_switchserver_js()
10718:
1.485 raeburn 10719: =item resize_scrollbox_js()
1.484 raeburn 10720:
10721: =item makedocslogform()
10722:
1.485 raeburn 10723: =item makesimpleeditform()
10724:
1.329 droeschl 10725: =back
10726:
10727: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>