Annotation of loncom/interface/londocs.pm, revision 1.717
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.717 ! raeburn 4: # $Id: londocs.pm,v 1.716 2025/01/03 02:10: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: }
1.716 raeburn 732: }
1.715 raeburn 733: return true;
734: }
735:
736: function init_copycrs_form() {
737: document.$formname.authorspace.selectedIndex = "0";
738: document.$formname.authorfolder.value = '$title';
739: document.$formname.copyright.selectedIndex = "0";
740: }
741:
742: // ]]>
743: </script>
744:
745: ENDJS
746: } elsif ($home) {
747: $js = <<"ENDJS";
748: <script type="text/javascript">
749: // <![CDATA[
750:
751: function init_copycrs_form() {
752: document.$formname.authorfolder.value = '$title';
753: document.$formname.copyright.selectedIndex = "0";
754: }
755:
756: // ]]>
757: </script>
758:
759: ENDJS
760: }
761: $js .= <<"ENDJS";
1.712 raeburn 762: <script type="text/javascript">
763: // <![CDATA[
764:
765: function hide_searching() {
766: if (document.getElementById('searching')) {
767: document.getElementById('searching').style.display = 'none';
768: }
769: return;
770: }
771:
1.715 raeburn 772: function showHideCustom(caller,divid) {
773: if (document.getElementById(divid)) {
774: if (caller.options[caller.selectedIndex].value == 'custom') {
775: document.getElementById(divid).style.display="inline-block";
776: } else {
777: document.getElementById(divid).style.display="none";
778: }
779: }
780: return;
781: }
782:
1.712 raeburn 783: // ]]>
784: </script>
785: ENDJS
1.715 raeburn 786:
787: $js .= "\n".&Apache::lonhtmlcommon::scripttag(&Apache::loncommon::browser_and_searcher_javascript())."\n";
1.712 raeburn 788: $starthash = {
1.715 raeburn 789: add_entries => {'onload' => "hide_searching(); init_copycrs_form();"},
1.712 raeburn 790: };
791: }
792: $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
793: &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
794: $r->print(&startContentScreen('tools'));
795: unless ($home) {
796: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
797: $r->print(&endContentScreen());
798: return '';
799: }
1.715 raeburn 800: my $docroot = $r->dir_config('lonDocRoot');
1.714 raeburn 801: my $is_course_home;
802: my @ids=&Apache::lonnet::current_machine_ids();
803: if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
804: $is_course_home = 1;
805: }
1.712 raeburn 806: my $exclude = &Apache::lonnet::priv_exclude();
807: my $srcurl = "/priv/$coursedom/$coursenum";
1.715 raeburn 808: my $srctop = $docroot.$srcurl;
809: my $resurl = "/res/$coursedom/$coursenum";
810: my $res_exclude = &Apache::lonnet::res_exclude();
1.712 raeburn 811: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
812: $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
813: if ($readonly) {
814: $r->print('<p class="LC_info">'.
815: &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
816: '</p>'.
817: &endContentScreen());
818: return '';
819: }
820: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
821: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
822: &endContentScreen());
823: return '';
824: }
825: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
826: my $desturl = "/priv/$cd/$ca";
1.715 raeburn 827: my $destresurl = "/res/$cd/$ca";
828: my $desttop = $docroot.$desturl;
1.712 raeburn 829: my $subdir = &clean($env{'form.authorfolder'});
830: $subdir = &cleandir($subdir);
831: if ($subdir eq '') {
832: $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
833: &endContentScreen());
834: return '';
835: } elsif ($subdir =~/^_+$/) {
836: $r->print('<p class="LC_info">'.&mt('After replacement of non-alphanumeric characters with _ in target sub-directory name, nothing but underscores was left.').'</p>'.
837: &endContentScreen());
838: return '';
839: }
840: my (%tocopy,%dirs_to_make,%files_to_copy);
841: map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
842: if (keys(%tocopy)) {
843: my (%subdirs,%files);
1.714 raeburn 844: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1.712 raeburn 845: foreach my $possible (sort(keys(%tocopy))) {
846: if ($possible =~ m{/$}) {
847: my $possdir = $possible;
848: $possdir =~ s{^/+|/+$}{}g;
849: if (exists($subdirs{$possdir})) {
850: $dirs_to_make{$possdir} = 1;
851: } else {
852: delete($tocopy{$possible});
853: }
854: } else {
855: my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
856: my $found = 0;
857: if ($path eq '/') {
858: if (ref($files{$path}) eq 'HASH') {
859: if (exists($files{$path}{$fname})) {
860: $found = 1;
861: $files_to_copy{$fname} = 1;
862: }
863: }
864: } else {
865: $path =~ s{^/+|/+$}{}g;
866: if (ref($files{$path}) eq 'HASH') {
867: if (exists($files{$path}{$fname})) {
868: $dirs_to_make{$path} = 1;
869: $files_to_copy{"$path/$fname"} = 1;
870: $found = 1;
871: }
872: }
873: }
874: unless ($found) {
875: delete($tocopy{$possible});
876: }
877: }
878: }
879: } else {
880: $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
881: $r->print(&endContentScreen());
882: return '';
883: }
884: if (keys(%tocopy)) {
1.714 raeburn 885: my (%resdirs,%resfiles);
886: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.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 '')) {
1.717 ! raeburn 998: my $ressrc = $docroot.$resurl.'/'.$file;
! 999: my $ressrcmeta = $ressrc.'.meta';
! 1000: my ($ext) = ($file =~ /\.(\w+)$/);
! 1001: my $embstyle=&Apache::loncommon::fileembstyle($ext);
! 1002: my ($getres,$getresmeta);
! 1003: if ($respublish) {
! 1004: if ($path eq '') {
! 1005: if ((ref($resfiles{'/'}) eq 'HASH') &&
! 1006: (exists($resfiles{'/'}{$fname}))) {
! 1007: $getres = 1;
! 1008: $getresmeta = 1;
! 1009: }
! 1010: } elsif ((ref($resfiles{$path}) eq 'HASH') &&
! 1011: (exists($resfiles{$path}{$fname}))) {
! 1012: $getres = 1;
! 1013: $getresmeta = 1;
1.714 raeburn 1014: }
1015: }
1.717 ! raeburn 1016: if ($is_course_home) {
! 1017: my ($needpriv,$needprivmeta);
! 1018: if ($respublish) {
! 1019: if ($getres) {
! 1020: if (&Apache::londiff::are_different_files($src,$ressrc)) {
! 1021: $needpriv = 1;
! 1022: if (&File::Copy::copy($ressrc,$dest)) {
! 1023: if ($embstyle eq 'ssi') {
! 1024: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
! 1025: }
! 1026: }
! 1027: } else {
! 1028: if (&File::Copy::copy($src,$dest)) {
! 1029: $newfile{$file} = 1;
! 1030: if ($embstyle eq 'ssi') {
! 1031: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
! 1032: }
! 1033: }
1.714 raeburn 1034: }
1.717 ! raeburn 1035: } else {
! 1036: $needpriv = 1;
1.714 raeburn 1037: }
1.717 ! raeburn 1038: if ($getresmeta) {
! 1039: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
! 1040: if (&Apache::londiff::are_different_files($src.'.meta',$ressrc.'.meta')) {
! 1041: if (&File::Copy::copy($ressrc.'.meta',$dest.'.meta')) {
! 1042: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
! 1043: $customdistfile,$sourceavail,\%checkdeps);
1.715 raeburn 1044: }
1.717 ! raeburn 1045: $needprivmeta = 1;
! 1046: } else {
! 1047: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
! 1048: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
! 1049: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1050: }
1051: }
1.712 raeburn 1052: }
1.717 ! raeburn 1053: }
! 1054: if ($getres) {
! 1055: my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
! 1056: if (-e $dest) {
! 1057: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.714 raeburn 1058: }
1.712 raeburn 1059: }
1.717 ! raeburn 1060: } else {
! 1061: $needpriv = 1;
! 1062: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
! 1063: $needprivmeta = 1;
! 1064: }
! 1065: }
! 1066: if ($needpriv) {
! 1067: if (&File::Copy::copy($src,$dest)) {
! 1068: $newfile{$file} = 1;
! 1069: if ($embstyle eq 'ssi') {
! 1070: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
! 1071: }
! 1072: }
! 1073: }
! 1074: if ($needprivmeta) {
! 1075: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
! 1076: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
! 1077: $customdistfile,$sourceavail,\%checkdeps);
! 1078: }
1.714 raeburn 1079: }
1.717 ! raeburn 1080: } else {
! 1081: my ($needpriv,$needprivmeta);
! 1082: if ($respublish) {
! 1083: if ($getres) {
! 1084: &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file);
! 1085: }
! 1086: if ($getresmeta) {
! 1087: &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file.'.meta');
! 1088: }
! 1089: if (-e $docroot.$resurl.'/'.$file) {
! 1090: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
! 1091: if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file,$dest)) {
! 1092: $needpriv = 1;
! 1093: if (&File::Copy::copy($docroot.$resurl.'/'.$file,$dest)) {
! 1094: if ($embstyle eq 'ssi') {
! 1095: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
1.713 raeburn 1096: }
1.714 raeburn 1097: }
1.717 ! raeburn 1098: } else {
! 1099: if ($embstyle eq 'ssi') {
! 1100: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.714 raeburn 1101: }
1.717 ! raeburn 1102: $newfile{$file} = 1;
! 1103: }
! 1104: }
! 1105: } else {
! 1106: $needpriv = 1;
! 1107: }
! 1108: if (-e $docroot.$resurl.'/'.$file.'.meta') {
! 1109: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
! 1110: if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
! 1111: $needprivmeta = 1;
! 1112: if (&File::Copy::copy($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
! 1113: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
! 1114: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1115: }
1.714 raeburn 1116: } else {
1.717 ! raeburn 1117: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
! 1118: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1119: }
1120: }
1.717 ! raeburn 1121: } else {
! 1122: if (!-e $dest.'.meta') {
! 1123: $needprivmeta = 1;
! 1124: }
1.714 raeburn 1125: }
1.717 ! raeburn 1126: if ($getres) {
! 1127: my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
! 1128: if (-e $dest) {
! 1129: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
! 1130: #FIXME publish meta file also?
1.713 raeburn 1131: }
1.712 raeburn 1132: }
1.717 ! raeburn 1133: } else {
! 1134: $needpriv = 1;
! 1135: if (!-e $dest.'.meta') {
! 1136: $needprivmeta = 1;
! 1137: }
1.712 raeburn 1138: }
1.717 ! raeburn 1139: if ($needpriv) {
! 1140: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
! 1141: if ($embstyle eq 'ssi') {
! 1142: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.715 raeburn 1143: }
1.717 ! raeburn 1144: $newfile{$file} = 1;
! 1145: }
! 1146: }
! 1147: if ($needprivmeta) {
! 1148: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
! 1149: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
! 1150: $customdistfile,$sourceavail,\%checkdeps);
1.715 raeburn 1151: }
1152: }
1.712 raeburn 1153: }
1154: }
1155: }
1.714 raeburn 1156: } else {
1157: $notopdir = 1;
1.712 raeburn 1158: }
1159: }
1160: if ($notopdir) {
1161: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
1162: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
1163: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1164: '</span></p>'."\n");
1165: }
1166: if (keys(%newdir)) {
1167: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1168: '</p>'."\n".
1169: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
1170: }
1171: if (keys(%newfile)) {
1172: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1173: '</p>'."\n".
1174: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1175: }
1.713 raeburn 1176: if (keys(%checkdeps)) {
1177: my %missingdep;
1178: foreach my $depfile (sort(keys(%checkdeps))) {
1179: unless (-e "$desttop/$depfile") {
1180: $missingdep{$depfile} = 1;
1181: }
1182: }
1183: if (keys(%missingdep)) {
1184: $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
1185: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1186: '</p>'."\n".
1187: '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
1188: }
1189: }
1.712 raeburn 1190: } else {
1191: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
1192: $r->print(&endContentScreen());
1193: return '';
1194: }
1195: } else {
1196: my $chkname = 'copytouser';
1197: my $context = 'crsauthored';
1198: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714 raeburn 1199: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712 raeburn 1200: foreach my $key (keys(%subdirs)) {
1201: next if (($key eq '/') || ($key eq ''));
1202: my @items = split(/\//,$key);
1203: my $dir = pop(@items);
1204: my $depth = scalar(@items);
1205: my $path;
1206: if (!$depth) {
1207: $path = '/';
1208: } else {
1209: $path = join('/',@items);
1210: }
1211: $dirs_by_depth[$depth]{$path}{$dir} = 1;
1212: }
1213: foreach my $path (keys(%files)) {
1214: next if ($path eq '');
1215: my $depth;
1216: if ($path eq '/') {
1217: $depth = 0;
1218: } else {
1219: $depth = scalar(split(/\//,$path));
1220: }
1221: if (ref($files{$path}) eq 'HASH') {
1222: foreach my $file (keys(%{$files{$path}})) {
1.714 raeburn 1223: $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712 raeburn 1224: }
1225: }
1226: }
1227: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714 raeburn 1228: my (%resdirs,%resfiles);
1.715 raeburn 1229: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1230: my $numpub = 0;
1231: if (keys(%resfiles)) {
1232: foreach my $dir (keys(%resfiles)) {
1233: if (ref($resfiles{$dir}) eq 'HASH') {
1234: foreach my $file (keys(%{$resfiles{$dir}})) {
1235: if (exists($files{$dir}{$file})) {
1236: $numpub ++;
1237: }
1238: }
1239: }
1240: }
1241: }
1.712 raeburn 1242: if ($readonly) {
1243: $disabled = ' disabled="disabled"';
1244: }
1245: if ($disabled) {
1246: $togglebuttons = '<br />';
1247: } else {
1248: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1249: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1250: ' <input type="button" value="'.&mt('uncheck all').'"'.
1251: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1252: }
1.715 raeburn 1253: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
1254: &courseresource_options($formname,$numpub).
1255: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1256: my $display = '<form name="'.$formname.'" action="" method="post" onsubmit="return validCrsCopy();">'."\n".
1.712 raeburn 1257: $preamble."\n".
1258: '<div class="LC_float_left">'."\n".
1259: '<fieldset>'."\n".
1260: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
1261: '<span class="LC_fontsize_medium">'.
1262: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
1263: '</span><br /><br />'."\n";
1264: my $count = 0;
1265: my $startcount = 4 + $home;
1266: my $lastcontainer = $startcount;
1267: $display .= &Apache::loncommon::start_data_table()."\n".
1268: &Apache::loncommon::start_data_table_header_row().
1269: '<th>'.&mt('Copy?').'</th>'.
1.714 raeburn 1270: '<th>'.&mt('Name').'</th>'.
1271: '<th>'.&mt('Last modified').'</th>'.
1272: '<th>'.&mt('Published?').'</th>'.
1.712 raeburn 1273: &Apache::loncommon::end_data_table_header_row()."\n";
1274: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1275: $count,\$display,\%parent,\%children,$readonly,
1.714 raeburn 1276: $formname,$chkname,\$lastcontainer,\%resfiles);
1.712 raeburn 1277: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1278: unless ($readonly) {
1279: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1280: '<div>'.
1281: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1282: '</div>';
1283: }
1284: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1285: \%hierarchy,\@checked_maps,$home,$chkname);
1286: $r->print($display);
1287: }
1288: $r->print(&endContentScreen());
1289: }
1290:
1291: sub recurse_crsauthored {
1292: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714 raeburn 1293: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
1294: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
1295: (ref($resfilesref) eq 'HASH'));
1.712 raeburn 1296: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1297: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1298: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1299: $hasdirs = 1;
1300: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1301: map { $unique{$_} = 1; } keys(%dirs);
1302: }
1303: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1304: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1305: $hasfiles = 1;
1306: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1307: map { $unique{$_} = 1; } keys(%files);
1308: }
1309: if ($readonly) {
1310: $disabled = ' disabled="disabled"';
1311: }
1312: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1313: my $whitespace =
1314: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1315: $parent->{$currdepth} = $$lastcontainerref;
1316: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1317: next if ($item eq '');
1318: my $currelem;
1319: if ($hasdirs && exists($dirs{$item})) {
1320: $count ++;
1321: my $deeper = $currdepth+1;
1322: my ($newpath,$showpath);
1323: if ($currpath eq '/') {
1324: $newpath = $item;
1325: $showpath = $currpath.$item.'/';
1326: } else {
1327: $newpath = $currpath.'/'.$item;
1328: $showpath = '/'.$currpath.'/'.$item.'/';
1329: }
1330: $currelem = $count+$startcount;
1331: $$lastcontainerref = $currelem;
1332: $children->{$parent->{$currdepth}} .= $currelem.':';
1333: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1334: $$displayref .= &Apache::loncommon::start_data_table_row().
1335: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1336: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1337: $disabled.' /></td><td>';
1338: for (my $i=0; $i<$currdepth; $i++) {
1339: $$displayref .= "$whitespace\n";
1340: }
1.714 raeburn 1341: $$displayref .= '<img '.$icon.' /> '.$item.'</td><td> </td><td> </td>'.
1.712 raeburn 1342: &Apache::loncommon::end_data_table_row()."\n";
1343: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1344: $startcount,$count,$displayref,$parent,$children,
1.714 raeburn 1345: $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712 raeburn 1346: }
1347: if ($hasfiles && exists($files{$item})) {
1348: $count ++;
1349: $currelem = $count+$startcount;
1350: $children->{$parent->{$currdepth}} .= $currelem.':';
1351: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1352: my ($ext) = ($item =~ /\.([^.]+)$/);
1353: my $alttext;
1354: if (lc($ext) eq 'problem') {
1355: $alttext = ' alt="'.&mt('Problem Icon').'"';
1356: } elsif ($ext =~ /^x?html?$/i) {
1357: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1358: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1359: $alttext = ' alt="'.&mt('Image Icon').'"';
1360: } else {
1361: $alttext = ' alt="'.&mt('Resource Icon').'"';
1362: }
1363: my $showpath;
1364: if ($currpath eq '/') {
1365: $showpath = $currpath;
1366: } else {
1367: $showpath = "/$currpath/";
1368: }
1.714 raeburn 1369: my ($published,$lastmod);
1370: if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
1371: $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
1372: } else {
1373: $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
1374: }
1.712 raeburn 1375: $$displayref .= &Apache::loncommon::start_data_table_row().
1376: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1377: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1378: $disabled.' /></td><td>';
1379: for (my $i=0; $i<$currdepth; $i++) {
1380: $$displayref .= "$whitespace\n";
1381: }
1382: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1.714 raeburn 1383: '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
1384: '<td style="text-align: center;">'.$published.'</td>'.
1.712 raeburn 1385: &Apache::loncommon::end_data_table_row()."\n";
1386: }
1387: }
1388: $$lastcontainerref = $parent->{$currdepth};
1389: return $count;
1390: }
1391:
1.715 raeburn 1392: sub courseresource_options {
1393: my ($formname,$numpub) = @_;
1394: my %lt = &Apache::lonlocal::texthash(
1395: 'default' => 'System wide - can be used for any courses system wide',
1396: 'domain' => 'Domain only - use limited to courses in the domain',
1397: 'custom' => 'Customized right of use ...',
1398: 'public' => 'Public - no authentication or authorization required for use',
1399: 'closed' => 'Closed - XML source is closed to everyone',
1400: 'open' => 'Open - XML source is open to people who want to use it',
1401: 'sel' => 'Select',
1402: );
1403: my $output;
1404: if ($numpub) {
1405: $output .= '<div class="LC_left_float">'.
1406: '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
1407: &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
1408: $numpub).'</br />'.
1409: &mt('Publish copied files in selected Authoring Space?').': '."\n".
1410: '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
1411: &mt('Yes').'</label>'."\n".
1412: '<label><input type="radio" name="respublish" value="0" />'.
1413: &mt('No').'</label>'."\n".
1414: '</fieldset></div>'."\n";
1415: }
1416: $output .= '<div class="LC_left_float">'.
1417: '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
1418: &mt('Copyright').': '.
1419: '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
1420: '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
1421: '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
1422: '<option value="public">'.$lt{'public'}.'</option>'."\n".
1423: '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
1424: '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
1425: '<input type="text" name="customrights" size="60" value="" />'.
1426: '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
1427: $lt{'sel'}.'</a></div><br />'."\n".
1428: &mt('Source').' :'.
1429: '<select name="sourceavail">'."\n".
1430: '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
1431: '<option value="open">'.$lt{'open'}.'</option>'."\n".
1432: '</select><br />'."\n".
1433: '</fieldset></div>'."\n";
1434: return $output;
1435: }
1436:
1.717 ! raeburn 1437: sub crsres_fixup_meta {
! 1438: my ($dest,$coursenum,$coursedom,$ca,$cd,$copyright,$customdistfile,$sourceavail,$checkdeps) = @_;
! 1439: return unless (ref($checkdeps) eq 'HASH');
! 1440: if (open(my $fh,'<',$dest.'.meta')) {
! 1441: my ($output,$now,$setsourceavail);
! 1442: $now = time;
! 1443: if (($dest =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($dest =~ /$LONCAPA::assess_re/)) {
! 1444: $setsourceavail = 1;
! 1445: }
! 1446: while (my $line=<$fh>) {
! 1447: chomp($line);
! 1448: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
! 1449: $output .= "<authorspace>$ca:$cd</authorspace>\n";
! 1450: } elsif ($line eq '<copyright>custom</copyright>') {
! 1451: $output .= "<copyright>$copyright</copyright>\n";
! 1452: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
! 1453: $output .= "<creationdate>$now</creationdate>\n";
! 1454: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
! 1455: $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
! 1456: } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
! 1457: if ($setsourceavail) {
! 1458: $output .= "<sourceavail>$sourceavail</sourceavail>\n";
! 1459: }
! 1460: } elsif ($line eq "<domain>$coursedom</domain>") {
! 1461: $output .= "<domain>$cd</domain>\n";
! 1462: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
! 1463: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
! 1464: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
! 1465: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
! 1466: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
! 1467: $output .= "<owner>$ca:$cd</owner>\n";
! 1468: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
! 1469: my @deps = split(/\s*,\s*/,$1);
! 1470: my @newdeps;
! 1471: my $changed = 0;
! 1472: foreach my $dep (@deps) {
! 1473: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
! 1474: my $rest = $1;
! 1475: push(@newdeps,"/res/$cd/$ca/$rest");
! 1476: $checkdeps->{$rest} = 1;
! 1477: $changed ++;
! 1478: } else {
! 1479: push(@newdeps,$dep);
! 1480: }
! 1481: }
! 1482: if ($changed) {
! 1483: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
! 1484: }
! 1485: } else {
! 1486: $output .= "$line\n";
! 1487: }
! 1488: }
! 1489: close($fh);
! 1490: if (open(my $fh,'>',$dest.'.meta')) {
! 1491: print $fh $output;
! 1492: close($fh);
! 1493: }
! 1494: }
! 1495: }
! 1496:
! 1497: sub crsres_fixup {
! 1498: my ($dest,$coursenum,$coursedom,$ca,$cd,$subdir) = @_;
! 1499: my $outstring='';
! 1500: my $changes = 0;
! 1501: my @parser;
! 1502: $parser[0]=HTML::LCParser->new($dest);
! 1503: $parser[-1]->xml_mode(1);
! 1504: my $token;
! 1505: while (@parser) {
! 1506: while ($token=$parser[-1]->get_token) {
! 1507: if ($token->[0] eq 'S') {
! 1508: my $tag=$token->[1];
! 1509: my $lctag=lc($tag);
! 1510: my %parms=%{$token->[2]};
! 1511: foreach my $type ('src','href','background','bgimg') {
! 1512: foreach my $key (keys(%parms)) {
! 1513: if ($key =~ /^$type$/i) {
! 1514: next if (($lctag eq 'img') && ($type eq 'src') &&
! 1515: ($parms{$key} =~ m{^data\:image/gif;base64,}));
! 1516: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1517: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 1518: $changes ++;
! 1519: }
! 1520: }
! 1521: }
! 1522: }
! 1523: # probably a <randomlabel> image type <label>
! 1524: # or a <image> tag inside <imageresponse> or <drawimage>
! 1525: if (($lctag eq 'label' && defined($parms{'description'}))
! 1526: || ($lctag eq 'image') || ($lctag eq 'import')) {
! 1527: my $next_token=$parser[-1]->get_token();
! 1528: if ($next_token->[0] eq 'T') {
! 1529: $next_token->[1] =~ s/[\n\r\f]+//g;
! 1530: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1531: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 1532: $changes ++;
! 1533: }
! 1534: }
! 1535: $parser[-1]->unget_token($next_token);
! 1536: }
! 1537: if ($lctag eq 'applet') {
! 1538: my $havecodebase=0;
! 1539: foreach my $key (keys(%parms)) {
! 1540: if (lc($key) eq 'codebase') {
! 1541: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1542: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 1543: $changes ++;
! 1544: }
! 1545: $havecodebase = 1;
! 1546: }
! 1547: }
! 1548: unless ($havecodebase) {
! 1549: foreach my $key (keys(%parms)) {
! 1550: if ($key =~ /(archive|code|object)/i) {
! 1551: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1552: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
! 1553: $changes ++;
! 1554: }
! 1555: }
! 1556: }
! 1557: }
! 1558: }
! 1559: my $newparmstring='';
! 1560: my $endtag='';
! 1561: foreach my $parkey (keys(%parms)) {
! 1562: if ($parkey eq '/') {
! 1563: $endtag=' /';
! 1564: } else {
! 1565: my $quote=($parms{$parkey}=~/\"/?"'":'"');
! 1566: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
! 1567: }
! 1568: }
! 1569: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
! 1570: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
! 1571: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
! 1572: $lctag eq 'tex') {
! 1573: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1574: } elsif ($lctag eq 'script') {
! 1575: if ($parms{'type'} eq 'loncapa/perl') {
! 1576: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1577: } else {
! 1578: my $needsupdate;
! 1579: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1580: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
! 1581: my $src = $2;
! 1582: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1583: $needsupdate = 1;
! 1584: }
! 1585: }
! 1586: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
! 1587: my $scriptslist = $2;
! 1588: my @srcs = split(/\s*,\s*/,$scriptslist);
! 1589: foreach my $src (@srcs) {
! 1590: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
! 1591: my $quote = $1;
! 1592: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
! 1593: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1594: $needsupdate = 1;
! 1595: }
! 1596: }
! 1597: }
! 1598: }
! 1599: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
! 1600: my $src = $2;
! 1601: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1602: $needsupdate = 1;
! 1603: }
! 1604: }
! 1605: if ($needsupdate) {
! 1606: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
! 1607: $changes ++;
! 1608: }
! 1609: $outstring .= $script;
! 1610: }
! 1611: }
! 1612: } elsif ($token->[0] eq 'E') {
! 1613: if ($token->[2]) {
! 1614: unless ($token->[1] eq 'allow') {
! 1615: $outstring.='</'.$token->[1].'>';
! 1616: }
! 1617: }
! 1618: } else {
! 1619: $outstring.=$token->[1];
! 1620: }
! 1621: }
! 1622: pop(@parser);
! 1623: }
! 1624: if ($changes) {
! 1625: if (open(my $fh,'>',$dest)) {
! 1626: print $fh $outstring;
! 1627: close($fh);
! 1628: }
! 1629: }
! 1630: }
! 1631:
1.329 droeschl 1632: sub group_import {
1.598 raeburn 1633: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1634: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1635: %removeparam,$importuploaded,$fixuperrors);
1636: $allmaps = {};
1.329 droeschl 1637: while (@files) {
1638: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1639: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1640: && ($caller eq 'londocs')
1641: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1642:
1.329 droeschl 1643: my $errtext = '';
1644: my $fatal = 0;
1645: my $newmapstr = '<map>'."\n".
1646: '<resource id="1" src="" type="start"></resource>'."\n".
1647: '<link from="1" to="2" index="1"></link>'."\n".
1648: '<resource id="2" src="" type="finish"></resource>'."\n".
1649: '</map>';
1650: $env{'form.output'}=$newmapstr;
1651: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1652: 'output',$1.$2);
1.534 raeburn 1653: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1654: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1655: $fatal = 2;
1656: }
1657: if ($fatal) {
1658: return ($errtext,$fatal);
1659: }
1660: }
1661: if ($url) {
1.626 raeburn 1662: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1663: $url = $1;
1664: my $marker = $2;
1665: my $info = $3;
1.699 raeburn 1666: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1667: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1668: my @toolinfo = split(/:/,$info);
1669: if ($residx) {
1.604 raeburn 1670: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1671: $toolid = $toolsettings{'id'};
1672: } else {
1.604 raeburn 1673: $toolid = shift(@toolinfo);
1.598 raeburn 1674: }
1.699 raeburn 1675: if ($toolid =~ /^c/) {
1676: $tooltype = 'crs';
1677: $toolprefix = 'c';
1678: } else {
1679: $tooltype = 'dom';
1680: }
1.598 raeburn 1681: $toolid =~ s/\D//g;
1.604 raeburn 1682: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1683: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1684: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1685: foreach my $item (@extras) {
1686: $toolhash{$item} = &unescape($toolhash{$item});
1687: }
1.645 raeburn 1688: if ($folder =~ /^supplemental/) {
1.648 raeburn 1689: delete($toolhash{'gradable'});
1690: } else {
1691: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1692: }
1.598 raeburn 1693: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1694: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1695: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1696: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1697: my @deleted;
1698: $toolhash{'id'} = $toolprefix.$toolid;
1699: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1700: ($toolhash{'target'} eq 'window')) {
1701: if ($toolhash{'target'} eq 'window') {
1702: foreach my $item ('width','height') {
1703: $toolhash{$item} =~ s/^\s+//;
1704: $toolhash{$item} =~ s/\s+$//;
1705: if ($toolhash{$item} =~ /\D/) {
1706: delete($toolhash{$item});
1707: if ($residx) {
1708: if ($toolsettings{$item}) {
1709: push(@deleted,$item);
1710: }
1.624 raeburn 1711: }
1712: }
1713: }
1.604 raeburn 1714: }
1.699 raeburn 1715: } elsif ($residx) {
1716: $toolhash{'target'} = $toolsettings{'target'};
1717: if ($toolhash{'target'} eq 'window') {
1718: foreach my $item ('width','height') {
1719: $toolhash{$item} = $toolsettings{$item};
1720: }
1721: }
1722: } elsif (ref($tools{'display'}) eq 'HASH') {
1723: $toolhash{'target'} = $tools{'display'}{'target'};
1724: if ($toolhash{'target'} eq 'window') {
1725: $toolhash{'width'} = $tools{'display'}{'width'};
1726: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1727: }
1.604 raeburn 1728: }
1.699 raeburn 1729: if ($toolhash{'target'} eq 'iframe') {
1730: foreach my $item ('width','height','linktext','explanation') {
1731: delete($toolhash{$item});
1732: if ($residx) {
1733: if ($toolsettings{$item}) {
1734: push(@deleted,$item);
1735: }
1.624 raeburn 1736: }
1.604 raeburn 1737: }
1.699 raeburn 1738: } elsif ($toolhash{'target'} eq 'tab') {
1739: foreach my $item ('width','height') {
1740: delete($toolhash{$item});
1741: if ($residx) {
1742: if ($toolsettings{$item}) {
1743: push(@deleted,$item);
1744: }
1.628 raeburn 1745: }
1746: }
1747: }
1.699 raeburn 1748: if (ref($tools{'crsconf'}) eq 'HASH') {
1749: foreach my $item ('label','title','linktext','explanation') {
1750: my $crsitem;
1751: if (($item eq 'label') || ($item eq 'title')) {
1752: $crsitem = 'crs'.$item;
1753: } else {
1754: $crsitem = $item;
1755: }
1756: if ($tools{'crsconf'}{$item}) {
1757: $toolhash{$crsitem} =~ s/^\s+//;
1758: $toolhash{$crsitem} =~ s/\s+$//;
1759: if ($toolhash{$crsitem} eq '') {
1760: delete($toolhash{$crsitem});
1761: }
1762: } else {
1.624 raeburn 1763: delete($toolhash{$crsitem});
1.604 raeburn 1764: }
1.699 raeburn 1765: if (($residx) && (exists($toolsettings{$crsitem}))) {
1766: unless (exists($toolhash{$crsitem})) {
1767: push(@deleted,$crsitem);
1768: }
1769: }
1.604 raeburn 1770: }
1.699 raeburn 1771: }
1772: if ($toolhash{'passback'}) {
1773: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1774: $toolhash{'gradesecret'} = $gradesecret;
1775: $toolhash{'gradesecretdate'} = time;
1776: }
1777: if ($toolhash{'roster'}) {
1778: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1779: $toolhash{'rostersecret'} = $rostersecret;
1780: $toolhash{'rostersecretdate'} = time;
1781: }
1782: my $changegradable;
1783: if (($residx) && ($folder =~ /^default/)) {
1784: if ($toolsettings{'gradable'}) {
1785: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1786: push(@deleted,'gradable');
1787: $changegradable = 1;
1.604 raeburn 1788: }
1.699 raeburn 1789: } elsif ($toolhash{'gradable'}) {
1790: $changegradable = 1;
1.604 raeburn 1791: }
1.699 raeburn 1792: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1793: $changegradable = 1;
1.699 raeburn 1794: if ($toolsettings{'gradable'}) {
1795: $toolhash{'gradable'} = 1;
1796: }
1.645 raeburn 1797: }
1.648 raeburn 1798: }
1.699 raeburn 1799: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1800: if ($putres eq 'ok') {
1801: if (@deleted) {
1802: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1803: }
1.699 raeburn 1804: if (($changegradable) && ($folder =~ /^default/)) {
1805: my $val;
1806: if ($toolhash{'gradable'}) {
1807: $val = 'yes';
1808: } else {
1809: $val = 'no';
1810: }
1811: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1812: 'string_yesno');
1813: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1814: }
1.699 raeburn 1815: } else {
1816: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1817: }
1.604 raeburn 1818: }
1.598 raeburn 1819: }
1820: }
1821: }
1.529 raeburn 1822: if (($caller eq 'londocs') &&
1823: ($folder =~ /^default/)) {
1.534 raeburn 1824: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1825: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1826: my $cid = $coursedom.'_'.$coursenum;
1827: $allmaps =
1828: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1829: $chome,$cid);
1830: $donechk = 1;
1831: }
1832: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1833: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1834: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1835: $importuploaded = 1;
1836: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1837: next if ($allmaps->{$url});
1838: }
1839: }
1.344 bisitz 1840: if (!$residx
1.329 droeschl 1841: || defined($LONCAPA::map::zombies[$residx])) {
1842: $residx = &LONCAPA::map::getresidx($url,$residx);
1843: push(@LONCAPA::map::order, $residx);
1844: }
1845: my $ext = 'false';
1846: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1847: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1848: my $filepath = $1;
1.675 raeburn 1849: my $fname;
1850: if ($name eq '') {
1851: $name = &mt('Web Page');
1.534 raeburn 1852: $fname = 'web';
1853: } else {
1.675 raeburn 1854: $fname = $name;
1855: $fname=&Apache::lonnet::clean_filename($fname);
1856: if ($fname eq '') {
1857: $fname = 'web';
1858: } elsif (length($fname) > 15) {
1859: $fname = substr($fname,0,14);
1860: }
1.534 raeburn 1861: }
1.675 raeburn 1862: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1863: my $initialtext = &mt('Replace with your own content.');
1864: my $newhtml = <<END;
1.545 raeburn 1865: <html>
1.534 raeburn 1866: <head>
1.675 raeburn 1867: <title>$title</title>
1.534 raeburn 1868: </head>
1869: <body bgcolor="#ffffff">
1870: $initialtext
1871: </body>
1872: </html>
1873: END
1874: $env{'form.output'}=$newhtml;
1.630 raeburn 1875: my $result =
1.534 raeburn 1876: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1877: 'output',
1878: "$filepath/$residx/$fname.html");
1879: if ($result =~ m{^/uploaded/}) {
1880: $url = $result;
1881: if ($filepath =~ /^supplemental/) {
1882: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1883: $env{'user.domain'}.'___&&&___'.$name;
1884: }
1885: } else {
1886: return (&mt('Failed to save new web page.'),1);
1887: }
1888: }
1.675 raeburn 1889: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1890: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1891: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1892: join(':', ($name, $url, $ext, 'normal', 'res'));
1893: }
1894: }
1.529 raeburn 1895: if ($importuploaded) {
1896: my %import_errors;
1897: my %updated = (
1898: removefrommap => \%removefrommap,
1899: removeparam => \%removeparam,
1900: );
1.533 raeburn 1901: my ($result,$msgsarray,$lockerror) =
1902: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1903: if (keys(%import_errors) > 0) {
1.530 raeburn 1904: $fixuperrors =
1.529 raeburn 1905: '<p span class="LC_warning">'."\n".
1906: &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".
1907: '<ul>'."\n";
1908: foreach my $key (sort(keys(%import_errors))) {
1909: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1910: }
1911: $fixuperrors .= '</ul></p>'."\n";
1912: }
1.533 raeburn 1913: if (ref($msgsarray) eq 'ARRAY') {
1914: if (@{$msgsarray} > 0) {
1915: $fixuperrors .= '<p class="LC_info">'.
1916: join('<br />',@{$msgsarray}).
1917: '</p>';
1918: }
1919: }
1920: if ($lockerror) {
1921: $fixuperrors .= '<p class="LC_error">'.
1922: $lockerror.
1923: '</p>';
1924: }
1.529 raeburn 1925: }
1926: my ($errtext,$fatal) =
1927: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1928: unless ($fatal) {
1929: if ($folder =~ /^supplemental/) {
1.561 raeburn 1930: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1931: $folder.'.'.$container);
1.557 raeburn 1932: }
1933: }
1.529 raeburn 1934: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1935: }
1936:
1937: sub log_docs {
1.494 raeburn 1938: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1939: }
1940:
1941: {
1942: my @oldresources=();
1943: my @oldorder=();
1944: my $parmidx;
1945: my %parmaction=();
1946: my %parmvalue=();
1947: my $changedflag;
1948:
1949: sub snapshotbefore {
1950: @oldresources=@LONCAPA::map::resources;
1951: @oldorder=@LONCAPA::map::order;
1952: $parmidx=undef;
1953: %parmaction=();
1954: %parmvalue=();
1955: $changedflag=0;
1956: }
1957:
1958: sub remember_parms {
1959: my ($idx,$parameter,$action,$value)=@_;
1960: $parmidx=$idx;
1961: $parmaction{$parameter}=$action;
1962: $parmvalue{$parameter}=$value;
1963: $changedflag=1;
1964: }
1965:
1966: sub log_differences {
1967: my ($plain)=@_;
1968: my %storehash=('folder' => $plain,
1969: 'currentfolder' => $env{'form.folder'});
1970: if ($parmidx) {
1971: $storehash{'parameter_res'}=$oldresources[$parmidx];
1972: foreach my $parm (keys(%parmaction)) {
1973: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1974: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1975: }
1976: }
1977: my $maxidx=$#oldresources;
1978: if ($#LONCAPA::map::resources>$#oldresources) {
1979: $maxidx=$#LONCAPA::map::resources;
1980: }
1981: for (my $idx=0; $idx<=$maxidx; $idx++) {
1982: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1983: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1984: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1985: $changedflag=1;
1986: }
1987: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1988: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1989: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1990: $changedflag=1;
1991: }
1992: }
1993: $storehash{'maxidx'}=$maxidx;
1994: if ($changedflag) { &log_docs(\%storehash); }
1995: }
1996: }
1997:
1998: sub docs_change_log {
1.611 raeburn 1999: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 2000: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 2001: my $navmap;
1.483 raeburn 2002: my $js = '<script type="text/javascript">'."\n".
2003: '// <![CDATA['."\n".
2004: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 2005: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 2006: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 2007: &history_tab_js()."\n".
1.484 raeburn 2008: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 2009: '// ]]>'."\n".
2010: '</script>'."\n";
1.484 raeburn 2011: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
2012: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 2013: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 2014: my %orderhash;
2015: my $container='sequence';
2016: my $pathitem;
1.519 raeburn 2017: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 2018: $container='page';
2019: }
1.519 raeburn 2020: my $folderpath=$env{'form.folderpath'};
2021: if ($folderpath eq '') {
1.617 raeburn 2022: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 2023: }
1.617 raeburn 2024: undef($navmap);
1.519 raeburn 2025: $pathitem = '<input type="hidden" name="folderpath" value="'.
2026: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 2027: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
2028: my $jumpto = $readfile;
2029: $jumpto =~ s{^/}{};
2030: my $tid = 1;
1.489 raeburn 2031: if ($supplementalflag) {
2032: $tid = 2;
2033: }
1.630 raeburn 2034: my ($breadcrumbtrail) =
1.509 raeburn 2035: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 2036: $r->print($breadcrumbtrail.
2037: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
2038: $readfile));
1.329 droeschl 2039: my %docslog=&Apache::lonnet::dump('nohist_docslog',
2040: $env{'course.'.$env{'request.course.id'}.'.domain'},
2041: $env{'course.'.$env{'request.course.id'}.'.num'});
2042:
2043: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
2044:
2045: my %saveable_parameters = ('show' => 'scalar',);
2046: &Apache::loncommon::store_course_settings('docs_log',
2047: \%saveable_parameters);
2048: &Apache::loncommon::restore_course_settings('docs_log',
2049: \%saveable_parameters);
2050: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 2051: # FIXME: internationalization seems wrong here
1.329 droeschl 2052: my %lt=('hiddenresource' => 'Resources hidden',
2053: 'encrypturl' => 'URL hidden',
2054: 'randompick' => 'Randomly pick',
2055: 'randomorder' => 'Randomly ordered',
1.645 raeburn 2056: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 2057: 'set' => 'set to',
2058: 'del' => 'deleted');
1.484 raeburn 2059: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
2060: $pathitem."\n".
2061: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
2062: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
2063: $r->print('<div class="LC_left_float">'.
2064: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
2065: &makedocslogform($filter,1).
2066: '</fieldset></div><br clear="all" />');
1.329 droeschl 2067: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
2068: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
2069: &mt('After').'</th>'.
2070: &Apache::loncommon::end_data_table_header_row());
2071: my $shown=0;
2072: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
2073: if ($env{'form.displayfilter'} eq 'currentfolder') {
2074: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
2075: }
2076: my @changes=keys(%{$docslog{$id}{'logentry'}});
2077: if ($env{'form.displayfilter'} eq 'containing') {
2078: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
2079: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
2080: foreach my $key (@changes) {
2081: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
2082: }
1.344 bisitz 2083: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 2084: }
2085: my $count = 0;
2086: my $time =
2087: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
2088: my $plainname =
2089: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
2090: $docslog{$id}{'exe_udom'});
2091: my $about_me_link =
2092: &Apache::loncommon::aboutmewrapper($plainname,
2093: $docslog{$id}{'exe_uname'},
2094: $docslog{$id}{'exe_udom'});
2095: my $send_msg_link='';
2096: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
2097: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
2098: $send_msg_link ='<br />'.
2099: &Apache::loncommon::messagewrapper(&mt('Send message'),
2100: $docslog{$id}{'exe_uname'},
2101: $docslog{$id}{'exe_udom'});
2102: }
2103: $r->print(&Apache::loncommon::start_data_table_row());
2104: $r->print('<td>'.$time.'</td>
2105: <td>'.$about_me_link.
2106: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
2107: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
2108: $send_msg_link.'</td><td>'.
2109: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 2110: my $is_supp = 0;
2111: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
2112: $is_supp = 1;
2113: }
1.329 droeschl 2114: # Before
2115: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2116: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2117: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2118: if ($oldname ne $newname) {
1.488 raeburn 2119: my $shown = &LONCAPA::map::qtescape($oldname);
2120: if ($is_supp) {
2121: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2122: }
2123: $r->print($shown);
1.329 droeschl 2124: }
2125: }
2126: $r->print('<ul>');
2127: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2128: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 2129: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
2130: if ($is_supp) {
2131: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2132: }
2133: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2134: }
2135: }
2136: $r->print('</ul>');
2137: # After
2138: $r->print('</td><td>');
2139:
2140: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2141: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2142: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2143: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 2144: my $shown = &LONCAPA::map::qtescape($newname);
2145: if ($is_supp) {
2146: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
2147: }
2148: $r->print($shown);
1.329 droeschl 2149: }
1.364 bisitz 2150: }
1.329 droeschl 2151: $r->print('<ul>');
2152: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2153: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 2154: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
2155: if ($is_supp) {
2156: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2157: }
2158: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2159: }
2160: }
2161: $r->print('</ul>');
2162: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 2163: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
2164: if ($title eq '') {
2165: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 2166: } elsif ($is_supp) {
2167: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 2168: }
2169: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 2170: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 2171: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 2172: # FIXME: internationalization seems wrong here
1.329 droeschl 2173: $r->print('<li>'.
2174: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
2175: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
2176: .'</li>');
2177: }
2178: }
2179: $r->print('</ul>');
2180: }
2181: # End
2182: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2183: $shown++;
2184: if (!($env{'form.show'} eq &mt('all')
2185: || $shown<=$env{'form.show'})) { last; }
2186: }
1.484 raeburn 2187: $r->print(&Apache::loncommon::end_data_table()."\n".
2188: &makesimpleeditform($pathitem)."\n".
2189: '</div></div>');
2190: $r->print(&endContentScreen());
1.329 droeschl 2191: }
2192:
2193: sub update_paste_buffer {
1.492 raeburn 2194: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 2195: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 2196: if ($env{'form.multiremove'}) {
2197: $env{'form.multiremove'} =~ s/,$//;
2198: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
2199: }
2200: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
2201: if ($env{'form.multicut'}) {
2202: $env{'form.multicut'} =~ s/,$//;
2203: foreach my $item (split(/,/,$env{'form.multicut'})) {
2204: unless ($removals{$item}) {
2205: $cuts{$item} = 1;
2206: push(@possibles,$item.':cut');
2207: }
2208: }
2209: }
2210: if ($env{'form.multicopy'}) {
2211: $env{'form.multicopy'} =~ s/,$//;
2212: foreach my $item (split(/,/,$env{'form.multicopy'})) {
2213: unless ($removals{$item} || $cuts{$item}) {
2214: push(@possibles,$item.':copy');
2215: }
2216: }
2217: }
2218: } elsif ($env{'form.markcopy'}) {
2219: @possibles = split(/,/,$env{'form.markcopy'});
2220: }
1.329 droeschl 2221:
1.538 raeburn 2222: return if (@possibles == 0);
1.329 droeschl 2223: return if (!defined($env{'form.copyfolder'}));
2224:
2225: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2226: $env{'form.copyfolder'});
1.538 raeburn 2227: return if ($fatal);
2228:
2229: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 2230:
1.538 raeburn 2231: # Retrieve current paste buffer suffixes.
2232: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2233: my (%pasteurls,@newpaste);
2234:
2235: # Construct identifiers for current contents of user's paste buffer
2236: if (@currpaste) {
2237: foreach my $suffix (@currpaste) {
1.667 raeburn 2238: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2239: my $url = $env{'docs.markedcopy_url_'.$suffix};
2240: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
2241: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
2242: ($url ne '')) {
2243: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2244: $pasteurls{$cid.'_'.$mapidx} = 1;
2245: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2246: $pasteurls{$url} = 1;
2247: } else {
1.669 raeburn 2248: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 2249: }
2250: }
1.538 raeburn 2251: }
2252: }
2253:
2254: # Mark items for copying (skip any items already in user's paste buffer)
2255: my %addtoenv;
1.597 raeburn 2256:
2257: my @pathitems = split(/\&/,$env{'form.folderpath'});
2258: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 2259: my $ispage = $folderconf[5];
1.597 raeburn 2260:
1.538 raeburn 2261: foreach my $item (@possibles) {
2262: my ($orderidx,$cmd) = split(/:/,$item);
2263: next if ($orderidx =~ /\D/);
2264: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 2265: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 2266: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
2267: my %denied = &action_restrictions($coursenum,$coursedom,
2268: &LONCAPA::map::qtescape($url),
2269: $env{'form.folderpath'},\%curr_groups);
2270: next if ($denied{'copy'});
2271: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 2272: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2273: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
2274: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2275: next if (exists($pasteurls{$url}));
2276: } else {
2277: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
2278: }
1.538 raeburn 2279: my ($suffix,$errortxt,$locknotfreed) =
2280: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 2281: if ($suffix ne '') {
2282: push(@newpaste,$suffix);
2283: } else {
2284: if ($locknotfreed) {
2285: return $locknotfreed;
2286: }
1.538 raeburn 2287: }
2288: if (&is_supplemental_title($title)) {
2289: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
2290: ($title) = &Apache::loncommon::parse_supplemental_title($title);
2291: }
1.329 droeschl 2292:
1.538 raeburn 2293: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
2294: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
2295: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
2296: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 2297: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 2298: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
2299: my $prefix = $1;
2300: my $subdir =$2;
2301: if ($subdir eq '') {
2302: $subdir = $prefix;
1.492 raeburn 2303: }
1.538 raeburn 2304: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 2305: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
2306: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 2307: if (ref($hierarchy{$url}) eq 'HASH') {
2308: my ($nested,$nestednames);
2309: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
2310: $nested =~ s/\&$//;
2311: $nestednames =~ s/\Q___&&&___\E$//;
2312: if ($nested ne '') {
2313: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
2314: }
2315: if ($nestednames ne '') {
2316: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
2317: }
1.492 raeburn 2318: }
2319: }
1.591 raeburn 2320: if ($locknotfreed) {
2321: $output = $locknotfreed;
2322: last;
2323: }
1.492 raeburn 2324: }
1.538 raeburn 2325: if (@newpaste) {
2326: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
2327: }
1.492 raeburn 2328: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 2329: delete($env{'form.markcopy'});
1.591 raeburn 2330: return $output;
1.329 droeschl 2331: }
2332:
1.492 raeburn 2333: sub recurse_uploaded_maps {
2334: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2335: if (ref($hierarchy->{$url}) eq 'HASH') {
2336: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2337: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2338: my (@uploaded,@names,%shorter);
2339: for (my $i=0; $i<@maps; $i++) {
2340: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2341: if ($inner ne '') {
2342: push(@uploaded,$inner);
2343: push(@names,&escape($titles[$i]));
2344: $shorter{$maps[$i]} = $inner;
2345: }
2346: }
2347: $$nestref .= "$dir:".join(',',@uploaded).'&';
2348: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2349: foreach my $map (@maps) {
2350: if ($shorter{$map} ne '') {
2351: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2352: }
2353: }
2354: }
2355: return;
2356: }
2357:
1.329 droeschl 2358: sub print_paste_buffer {
1.492 raeburn 2359: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2360: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2361:
1.538 raeburn 2362: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2363: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2364: }
2365:
1.538 raeburn 2366: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2367: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2368: my $clipboardcount = 0;
1.488 raeburn 2369:
1.538 raeburn 2370: # Construct identifiers for current contents of user's paste buffer
2371: foreach my $suffix (@currpaste) {
2372: next if ($suffix =~ /\D/);
2373: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2374: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2375: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2376: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2377: ($url ne '')) {
1.575 raeburn 2378: $clipboardcount ++;
1.538 raeburn 2379: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2380: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2381: $toolcnum,$marker);
1.538 raeburn 2382: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2383: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2384: $is_external = 1;
1.704 raeburn 2385: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2386: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2387: $is_exttool = 1;
1.538 raeburn 2388: }
2389: if ($folder =~ /^supplemental/) {
2390: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2391: unless ($canpaste) {
2392: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2393: }
2394: } else {
2395: $canpaste = 1;
2396: }
2397: if ($canpaste) {
2398: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2399: my $srcdom = $1;
2400: my $srcnum = $2;
2401: my $rem = $3;
2402: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2403: $othercourse = 1;
2404: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2405: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2406: } else {
2407: $canpaste = 0;
2408: $nopaste = &mt('Paste from another course unavailable.');
2409: }
2410: }
2411: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2412: my $prefix = $1;
2413: $parent = $2;
2414: if ($folder !~ /^\Q$prefix\E/) {
2415: $areachange = 1;
2416: }
2417: $is_uploaded_map = 1;
1.492 raeburn 2418: }
1.597 raeburn 2419: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2420: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2421: if ($cid ne $env{'request.course.id'}) {
2422: my ($srcdom,$srcnum) = split(/_/,$cid);
2423: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2424: if ($is_exttool) {
2425: if ($toolcdom ne $coursedom) {
2426: $canpaste = 0;
2427: $nopaste = &mt('Paste from another domain unavailable.');
2428: } elsif ($toolcnum ne $coursenum) {
2429: my %toolsettings =
2430: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2431: my %tooltypes = &Apache::loncommon::usable_exttools();
2432: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2433: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2434: $canpaste = 0;
2435: $nopaste = &mt('Paste from another course unavailable.');
2436: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2437: unless ($checkedsameinst) {
2438: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2439: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2440: if ($intdom ne '') {
2441: my $internet_names =
2442: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2443: if (ref($internet_names) eq 'ARRAY') {
2444: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2445: $same_institution = 1;
2446: }
2447: }
2448: }
2449: $checkedsameinst = 1;
2450: }
2451: if ($same_institution) {
2452: $othercrs = '<br />'.&mt('(from another course)');
2453: } else {
2454: $nopaste = &mt('Paste from another course unavailable.');
2455: }
2456: } else {
2457: $othercrs = '<br />'.&mt('(from another course)');
2458: }
2459: }
1.627 raeburn 2460: }
1.596 raeburn 2461: } else {
2462: $canpaste = 0;
2463: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2464: }
1.596 raeburn 2465: }
1.703 raeburn 2466: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2467: my ($audom,$auname) = ($1,$2);
2468: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2469: if (&Apache::lonnet::is_course($audom,$auname)) {
2470: $canpaste = 0;
2471: $nopaste = &mt('Paste from another course unavailable.');
2472: }
2473: }
1.492 raeburn 2474: }
1.596 raeburn 2475: if ($canpaste) {
2476: push(@pasteable,$suffix);
1.629 raeburn 2477: }
1.538 raeburn 2478: }
2479: my $buffer;
1.627 raeburn 2480: if ($is_external) {
1.538 raeburn 2481: $buffer = &mt('External Resource').': '.
2482: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2483: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2484: } elsif ($is_exttool) {
2485: $buffer = &mt('External Tool').': '.
2486: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2487: } else {
2488: my $icon = &Apache::loncommon::icon($extension);
2489: if ($extension eq 'sequence' &&
2490: $url =~ m{/default_\d+\.sequence$}x) {
2491: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2492: $icon .= '/navmap.folder.closed.gif';
2493: }
1.589 raeburn 2494: my $title = $env{'docs.markedcopy_title_'.$suffix};
2495: if ($title eq '') {
2496: ($title) = ($url =~ m{/([^/]+)$});
2497: }
1.538 raeburn 2498: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
2499: ': '.
2500: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2501: &LONCAPA::map::qtescape($title));
1.538 raeburn 2502: }
2503: $pasteitems .= '<div class="LC_left_float">';
2504: my ($options,$onclick);
2505: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2506: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2507: if (($is_uploaded_map) ||
2508: ($url =~ /(bulletinboard|smppg)$/) ||
2509: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2510: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2511: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2512: }
2513: }
2514: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2515: if ($nopaste) {
1.681 raeburn 2516: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2517: } else {
2518: if ($othercrs) {
2519: $pasteitems .= $othercrs;
2520: }
2521: if ($options) {
2522: $pasteitems .= $options;
1.492 raeburn 2523: }
2524: }
1.538 raeburn 2525: $pasteitems .= '</div>';
2526: }
2527: }
2528: if ($pasteitems eq '') {
2529: &Apache::lonnet::delenv('docs.markedcopies');
2530: }
2531: my ($pasteform,$form_start,$buttons,$form_end);
2532: if ($pasteitems) {
2533: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2534: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2535: if (@pasteable) {
1.575 raeburn 2536: my $value = &mt('Paste to current folder');
2537: if ($container eq 'page') {
2538: $value = &mt('Paste to current page');
2539: }
2540: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2541: }
2542: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2543: if ($clipboardcount > 1) {
2544: $buttons .=
2545: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2546: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2547: (' 'x2).
2548: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2549: (' 'x2);
1.492 raeburn 2550: }
1.575 raeburn 2551: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2552: '</form>';
1.538 raeburn 2553: } else {
2554: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2555: }
1.538 raeburn 2556: $r->print($form_start
2557: .'<fieldset>'
2558: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2559: .$pasteitems
2560: .'</fieldset>'
2561: .$form_end);
2562: }
2563:
2564: sub paste_options {
2565: my ($suffix,$is_uploaded_map,$parent) = @_;
2566: my ($copytext,$movetext);
2567: if ($is_uploaded_map) {
2568: $copytext = &mt('Copy to new folder');
2569: $movetext = &mt('Move old');
2570: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2571: $copytext = &mt('Copy to new board');
2572: $movetext = &mt('Move (not posts)');
2573: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2574: $copytext = &mt('Copy to new page');
2575: $movetext = &mt('Move');
1.533 raeburn 2576: } else {
1.538 raeburn 2577: $copytext = &mt('Copy to new file');
2578: $movetext = &mt('Move');
2579: }
2580: my $output = '<br />'.
2581: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2582: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2583: '<label>'.
2584: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2585: $copytext.'</label></span>'.(' 'x2).' '.
2586: '<span class="LC_nobreak"><label>'.
2587: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2588: $movetext.'</label></span>';
2589: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2590: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2591: '</legend><table border="0">';
2592: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2593: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2594: my $lastdir = $parent;
2595: my %depths = (
2596: $lastdir => 0,
2597: );
2598: my (%display,%deps);
2599: for (my $i=0; $i<@pastemaps; $i++) {
2600: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2601: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2602: my @subfolders = split(/,/,$subfolderstr);
2603: $deps{$lastdir} = \@subfolders;
2604: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2605: my $depth = $depths{$lastdir} + 1;
2606: my $offset = int($depth * 4);
2607: my $indent = (' ' x $offset);
2608: for (my $j=0; $j<@subfolders; $j++) {
2609: $depths{$subfolders[$j]} = $depth;
2610: $display{$subfolders[$j]} =
2611: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2612: '<td><label>'.
2613: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2614: '<label>'.
2615: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2616: &mt('Move old').'</label>'.
2617: '</td></tr>';
2618: }
1.492 raeburn 2619: }
1.538 raeburn 2620: &recurse_print(\$output,$parent,\%deps,\%display);
2621: $output .= '</table></fieldset>';
1.329 droeschl 2622: }
1.538 raeburn 2623: $output .= '</div>';
2624: return $output;
1.488 raeburn 2625: }
2626:
1.492 raeburn 2627: sub recurse_print {
1.538 raeburn 2628: my ($outputref,$dir,$deps,$display) = @_;
2629: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2630: if (ref($deps->{$dir}) eq 'ARRAY') {
2631: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2632: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2633: }
2634: }
2635: }
2636:
1.488 raeburn 2637: sub supp_pasteable {
2638: my ($url) = @_;
2639: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2640: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2641: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2642: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2643: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2644: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2645: return 1;
2646: }
2647: return;
1.329 droeschl 2648: }
2649:
1.492 raeburn 2650: sub paste_popup_js {
1.594 damieng 2651: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2652: show => 'Show Options',
2653: hide => 'Hide Options',
1.594 damieng 2654: );
2655: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2656: none => 'No items selected from clipboard.',
1.492 raeburn 2657: );
1.594 damieng 2658: &html_escape(\%html_js_lt);
2659: &js_escape(\%html_js_lt);
2660: &js_escape(\%js_lt);
1.492 raeburn 2661: return <<"END";
2662:
1.538 raeburn 2663: function showPasteOptions(suffix) {
2664: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2665: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2666: return;
2667: }
2668:
1.538 raeburn 2669: function hidePasteOptions(suffix) {
2670: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2671: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2672: return;
2673: }
2674:
2675: function showOptions(caller,suffix) {
2676: if (document.getElementById('pasteoptionstext_'+suffix)) {
2677: if (caller.checked) {
1.594 damieng 2678: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2679: } else {
2680: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2681: }
2682: if (document.getElementById('pasteoptions_'+suffix)) {
2683: document.getElementById('pasteoptions_'+suffix).style.display='none';
2684: }
2685: }
1.492 raeburn 2686: return;
2687: }
2688:
1.541 raeburn 2689: function validateClipboard() {
2690: var numchk = 0;
2691: if (document.pasteform.pasting.length > 1) {
2692: for (var i=0; i<document.pasteform.pasting.length; i++) {
2693: if (document.pasteform.pasting[i].checked) {
2694: numchk ++;
2695: }
2696: }
2697: } else {
2698: if (document.pasteform.pasting.type == 'checkbox') {
2699: if (document.pasteform.pasting.checked) {
2700: numchk ++;
2701: }
2702: }
2703: }
2704: if (numchk > 0) {
2705: return true;
2706: } else {
1.594 damieng 2707: alert("$js_lt{'none'}");
1.541 raeburn 2708: return false;
2709: }
2710: }
2711:
1.575 raeburn 2712: function checkClipboard() {
2713: if (document.pasteform.pasting.length > 1) {
2714: for (var i=0; i<document.pasteform.pasting.length; i++) {
2715: document.pasteform.pasting[i].checked = true;
2716: }
2717: }
2718: return;
2719: }
2720:
2721: function uncheckClipboard() {
2722: if (document.pasteform.pasting.length >1) {
2723: for (var i=0; i<document.pasteform.pasting.length; i++) {
2724: document.pasteform.pasting[i].checked = false;
2725: }
2726: }
2727: return;
2728: }
2729:
1.492 raeburn 2730: END
2731:
2732: }
2733:
1.329 droeschl 2734: sub do_paste_from_buffer {
1.492 raeburn 2735: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2736:
1.538 raeburn 2737: # Array of items in paste buffer
2738: my (@currpaste,%pastebuffer,%allerrors);
2739: @currpaste = split(/,/,$env{'docs.markedcopies'});
2740:
1.492 raeburn 2741: # Early out if paste buffer is empty
1.538 raeburn 2742: if (@currpaste == 0) {
1.492 raeburn 2743: return ();
1.538 raeburn 2744: }
2745: map { $pastebuffer{$_} = 1; } @currpaste;
2746:
2747: # Array of items selected items to paste
2748: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2749:
2750: # Early out if nothing selected to paste
2751: if (@reqpaste == 0) {
2752: return();
2753: }
2754: my @topaste;
2755: foreach my $suffix (@reqpaste) {
2756: next if ($suffix =~ /\D/);
2757: next unless (exists($pastebuffer{$suffix}));
2758: push(@topaste,$suffix);
2759: }
2760:
2761: # Early out if nothing available to paste
2762: if (@topaste == 0) {
2763: return();
1.329 droeschl 2764: }
2765:
1.704 raeburn 2766: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2767: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2768: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2769: %currltititles,$currltimax,$gotcrsltitools);
2770: $currltimax = 0;
2771: $gotcrsltitools = 0;
1.538 raeburn 2772: foreach my $suffix (@topaste) {
2773: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2774: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2775: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2776: # Supplemental content may only include certain types of content
2777: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2778: if ($folder =~ /^supplemental/) {
2779: unless (&supp_pasteable($url)) {
2780: $notinsupp{$suffix} = 1;
2781: next;
2782: }
1.492 raeburn 2783: }
1.538 raeburn 2784: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2785: my $srcd = $1;
2786: my $srcn = $2;
1.492 raeburn 2787: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2788: # check for mdc privilege in the course from which the resource was pasted
2789: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2790: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2791: $notincrs{$suffix} = 1;
2792: next;
2793: }
1.491 raeburn 2794: }
1.538 raeburn 2795: $srcdom{$suffix} = $srcd;
2796: $srcnum{$suffix} = $srcn;
1.597 raeburn 2797: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2798: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2799: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2800: my ($srcd,$srcn) = split(/_/,$cid);
2801: # When paste buffer was populated using an active role in a different course
2802: # check for mdc privilege in the course from which the resource was pasted
2803: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2804: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2805: $notincrs{$suffix} = 1;
2806: next;
2807: }
2808: }
1.632 raeburn 2809: # When buffer was populated using an active role in a different course
1.704 raeburn 2810: # disallow pasting of External Tool if course is in a different domain,
2811: # or if External Tool use is not permitted in this course.
2812: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2813: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2814: if ($toolcdom ne $coursedom) {
2815: $notindom{$suffix} = 1;
2816: next;
2817: } elsif ($toolcnum ne $coursenum) {
2818: my %toolsettings =
2819: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2820: my %tooltypes = &Apache::loncommon::usable_exttools();
2821: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2822: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2823: $othcrstool{$suffix} = 1;
2824: next;
2825: }
2826: if ($toolsettings{'id'} =~ /^c\d+$/) {
2827: unless ($gotcrsltitools) {
2828: %currcrsltitools =
2829: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2830: foreach my $item (sort(keys(%currcrsltitools))) {
2831: if (ref($currcrsltitools{$item}) eq 'HASH') {
2832: $currltimax ++;
2833: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2834: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2835: } else {
2836: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2837: }
2838: }
2839: }
2840: $gotcrsltitools = 1;
2841: }
2842: }
2843: }
1.627 raeburn 2844: }
1.596 raeburn 2845: $srcdom{$suffix} = $srcd;
2846: $srcnum{$suffix} = $srcn;
1.703 raeburn 2847: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2848: my ($audom,$auname) = ($1,$2);
2849: # When buffer was populated using an active role in a different course
2850: # disallow pasting of published resources from Course Authoring Space
2851: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2852: if (&Apache::lonnet::is_course($audom,$auname)) {
2853: $othcrsres{$suffix} = 1;
2854: next;
2855: }
2856: }
1.491 raeburn 2857: }
1.597 raeburn 2858: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2859: push(@dopaste,$suffix);
2860: if ($url=~/\.(page|sequence)$/) {
2861: $is_map{$suffix} = 1;
2862: }
2863: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2864: my $oldprefix = $1;
1.492 raeburn 2865: # When pasting content from Main Content to Supplemental Content and vice versa
2866: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2867: # a folder/page or a document).
1.538 raeburn 2868: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2869: $prefixchg{$suffix} = 'docstosupp';
2870: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2871: $prefixchg{$suffix} = 'supptodocs';
2872: }
1.491 raeburn 2873:
1.492 raeburn 2874: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2875: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2876: my @nested;
2877: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2878: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2879: my @deps = map { /\d+:([\d,]+$)/ } @items;
2880: foreach my $dep (@deps) {
2881: if ($dep =~ /,/) {
2882: push(@nested,split(/,/,$dep));
2883: } else {
2884: push(@nested,$dep);
2885: }
1.492 raeburn 2886: }
1.538 raeburn 2887: foreach my $item (@nested) {
2888: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2889: push(@{$marktomove{$suffix}},$type.'_'.$item);
2890: }
1.492 raeburn 2891: }
2892: }
1.488 raeburn 2893: }
2894: }
2895:
1.538 raeburn 2896: # Early out if nothing available to paste
2897: if (@dopaste == 0) {
2898: return ();
2899: }
2900:
2901: # Populate message hash and hashes used for main content <=> supplemental content
2902: # changes
2903:
2904: %msgs = &Apache::lonlocal::texthash (
2905: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2906: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2907: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2908: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2909: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2910: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2911: );
2912:
2913: %before = (
2914: docstosupp => {
2915: map => 'default',
2916: doc => 'docs',
2917: },
2918: supptodocs => {
2919: map => 'supplemental',
2920: doc => 'supplemental',
2921: },
2922: );
2923:
2924: %after = (
2925: docstosupp => {
2926: map => 'supplemental',
2927: doc => 'supplemental'
2928: },
2929: supptodocs => {
2930: map => 'default',
2931: doc => 'docs',
2932: },
2933: );
2934:
2935: # Retrieve information about all course maps in main content area
2936:
2937: my $allmaps = {};
1.704 raeburn 2938: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2939: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2940: $same_institution);
1.538 raeburn 2941:
2942: # Loop over the items to paste
2943: foreach my $suffix (@dopaste) {
1.329 droeschl 2944: # Maps need to be copied first
1.538 raeburn 2945: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2946: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2947: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2948: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2949: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2950: }
2951: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2952: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2953: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2954: my $oldurl = $url;
2955: if ($is_map{$suffix}) {
1.491 raeburn 2956: # If pasting a map, check if map contains other maps
1.538 raeburn 2957: my (%hierarchy,%titles);
1.660 raeburn 2958: if (($folder =~ /^default/) && (!$donechk)) {
2959: $allmaps =
2960: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2961: $env{"course.$env{'request.course.id'}.home"},
2962: $env{'request.course.id'});
2963: $donechk = 1;
2964: }
1.627 raeburn 2965: &contained_map_check($url,$folder,$coursenum,$coursedom,
2966: \%removefrommap,\%removeparam,\%addedmaps,
2967: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2968: if ($url=~ m{^/uploaded/}) {
2969: my $newurl;
2970: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2971: ($newurl,my $error) =
2972: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2973: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2974: \$title,$allmaps,\%newurls);
2975: if ($error) {
2976: $allerrors{$suffix} = $error;
2977: next;
2978: }
2979: if ($newurl ne '') {
2980: if ($newurl ne $url) {
2981: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2982: $newsubdir{$url} = $1;
2983: }
2984: $mapchanges{$url} = 1;
1.492 raeburn 2985: }
1.538 raeburn 2986: }
2987: }
2988: if (($srcdom{$suffix} ne $coursedom) ||
2989: ($srcnum{$suffix} ne $coursenum) ||
2990: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2991: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2992: $coursedom,$coursenum,$srcdom{$suffix},
2993: $srcnum{$suffix},$allmaps,\%rewrites,
2994: \%retitles,\%copies,\%dbcopies,
2995: \%zombies,\%params,\%mapmoves,
2996: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2997: \%newurls,\%resdatacopy)) {
1.538 raeburn 2998: $mapmoves{$url} = 1;
2999: }
3000: $url = $newurl;
3001: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
3002: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
3003: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
3004: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
3005: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 3006: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 3007: }
3008: } elsif ($url=~m {^/res/}) {
1.597 raeburn 3009: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 3010: push(@toclear,$suffix);
3011: # if pasting published map (main content area only) check map not already in course
3012: if ($folder =~ /^default/) {
3013: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
3014: $duplicate{$suffix} = 1;
3015: next;
1.492 raeburn 3016: }
1.491 raeburn 3017: }
3018: }
1.538 raeburn 3019: }
1.627 raeburn 3020: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 3021: my $prefix = $1;
1.648 raeburn 3022: my $fromothercrs;
1.538 raeburn 3023: #need to copy the db contents to a new one, unless this is a move.
3024: my %info = (
3025: src => $url,
3026: cdom => $coursedom,
3027: cnum => $coursenum,
1.596 raeburn 3028: );
1.649 raeburn 3029: if ($prefix eq 'ext.tool') {
1.655 raeburn 3030: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 3031: $info{'delgradable'} = 1;
3032: }
3033: }
1.596 raeburn 3034: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
3035: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
3036: $fromothercrs = 1;
3037: $info{'cdom'} = $srcdom{$suffix};
3038: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 3039: unless ($checkedsameinst) {
3040: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
3041: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3042: if ($intdom ne '') {
3043: my $internet_names =
3044: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3045: if (ref($internet_names) eq 'ARRAY') {
3046: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3047: $same_institution = 1;
3048: }
3049: }
3050: }
3051: $checkedsameinst = 1;
3052: }
1.596 raeburn 3053: }
3054: }
3055: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 3056: my (%lockerr,$msg);
1.538 raeburn 3057: my ($newurl,$result,$errtext) =
1.704 raeburn 3058: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
3059: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 3060: if ($result eq 'ok') {
3061: $url = $newurl;
3062: $title=&mt('Copy of').' '.$title;
3063: } else {
3064: if ($prefix eq 'smppg') {
3065: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
3066: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 3067: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 3068: } elsif ($prefix eq 'ext.tool') {
3069: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 3070: }
3071: $results{$suffix} = $result;
3072: $msgerrs{$suffix} = $msg;
3073: $lockerrs{$suffix} = $lockerr{$prefix};
3074: next;
3075: }
3076: if ($lockerr{$prefix}) {
3077: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 3078: }
1.489 raeburn 3079: }
3080: }
1.538 raeburn 3081: $title = &LONCAPA::map::qtunescape($title);
3082: my $ext='false';
3083: if ($url=~m{^http(|s)://}) { $ext='true'; }
3084: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
3085: if ($folder !~ /^supplemental/) {
3086: (undef,undef,$title) =
3087: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
3088: }
3089: } else {
3090: if ($folder=~/^supplemental/) {
3091: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3092: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 3093: }
1.533 raeburn 3094: }
1.491 raeburn 3095:
3096: # For uploaded files (excluding pages/sequences) path in copied file is changed
3097: # if paste is from Main to Supplemental (or vice versa), or if pasting between
3098: # courses.
3099:
1.538 raeburn 3100: unless ($is_map{$suffix}) {
3101: my $newidx;
1.492 raeburn 3102: # Now insert the URL at the bottom
1.538 raeburn 3103: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3104: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
3105: my $relpath = $1;
3106: if ($relpath ne '') {
3107: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
3108: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
3109: my $newprefix = $newloc;
3110: if ($newloc eq 'default') {
3111: $newprefix = 'docs';
3112: }
3113: if ($newdocsdir eq '') {
3114: $newdocsdir = 'default';
3115: }
1.630 raeburn 3116: if (($prefixchg{$suffix}) ||
3117: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 3118: ($srcnum{$suffix} ne $coursenum) ||
3119: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
3120: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
3121: $url =
3122: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
3123: &Apache::lonnet::getfile($oldurl));
3124: if ($url eq '/adm/notfound.html') {
3125: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
3126: next;
3127: } else {
3128: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
3129: $newsubpath =~ s{/+$}{/};
3130: $docmoves{$oldurl} = $newsubpath;
3131: }
1.491 raeburn 3132: }
3133: }
1.597 raeburn 3134: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3135: my $template = $1;
3136: if ($newidx) {
3137: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
3138: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
3139: }
1.649 raeburn 3140: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 3141: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 3142: my $marker = (split(m{/},$url))[4];
3143: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
3144: my $val = 'no';
3145: if ($toolsettings{'gradable'}) {
3146: $val = 'yes';
3147: }
3148: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
3149: 'string_yesno');
3150: &remember_parms($newidx,'gradable','set',$val);
3151: }
1.491 raeburn 3152: }
1.538 raeburn 3153: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3154: ':'.$ext.':normal:res';
3155: push(@LONCAPA::map::order,$newidx);
3156: # Store the result
3157: my ($errtext,$fatal) =
3158: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3159: if ($fatal) {
3160: $save_err .= $errtext;
3161: $allresult = 'fail';
3162: }
1.488 raeburn 3163: }
1.538 raeburn 3164:
1.597 raeburn 3165: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
3166: # resourcedata for simpleproblems copied from another course
1.538 raeburn 3167: unless ($allresult eq 'fail') {
3168: my %updated = (
3169: rewrites => \%rewrites,
3170: zombies => \%zombies,
3171: removefrommap => \%removefrommap,
3172: removeparam => \%removeparam,
3173: dbcopies => \%dbcopies,
1.597 raeburn 3174: resdatacopy => \%resdatacopy,
1.538 raeburn 3175: retitles => \%retitles,
3176: );
3177: my %info = (
3178: newsubdir => \%newsubdir,
3179: params => \%params,
3180: );
3181: if ($prefixchg{$suffix}) {
3182: $info{'before'} = $before{$prefixchg{$suffix}};
3183: $info{'after'} = $after{$prefixchg{$suffix}};
3184: }
3185: my %moves = (
3186: copies => \%copies,
3187: docmoves => \%docmoves,
3188: mapmoves => \%mapmoves,
3189: );
3190: (my $result,$msgs{$suffix},my $lockerror) =
3191: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
3192: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
3193: $url,'paste');
3194: $lockerrors .= $lockerror;
3195: if ($result eq 'ok') {
3196: if ($is_map{$suffix}) {
3197: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3198: $folder.'.'.$container);
3199: if ($fatal) {
3200: $allresult = 'failread';
3201: } else {
3202: if ($#LONCAPA::map::order<1) {
3203: my $idx=&LONCAPA::map::getresidx();
3204: if ($idx<=0) { $idx=1; }
3205: $LONCAPA::map::order[0]=$idx;
3206: $LONCAPA::map::resources[$idx]='';
3207: }
3208: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3209: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3210: ':'.$ext.':normal:res';
3211: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 3212:
3213: # Store the result
1.538 raeburn 3214: my ($errtext,$fatal) =
3215: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3216: if ($fatal) {
3217: $save_err .= $errtext;
3218: $allresult = 'failstore';
3219: }
3220: }
3221: }
3222: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
3223: push(@toclear,$suffix);
3224: }
3225: }
1.492 raeburn 3226: }
3227: }
1.704 raeburn 3228: if (($updatetoolscache) || (@updatetoolsenc)) {
3229: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
3230: \@updatetoolsenc);
3231: }
1.538 raeburn 3232: &clear_from_buffer(\@toclear,\@currpaste);
3233: my $msgsarray;
3234: foreach my $suffix (keys(%msgs)) {
3235: if (ref($msgs{$suffix}) eq 'ARRAY') {
3236: $msgsarray .= join(',',@{$msgs{$suffix}});
3237: }
3238: }
3239: return ($allresult,$save_err,$msgsarray,$lockerrors);
3240: }
1.533 raeburn 3241:
1.538 raeburn 3242: sub do_buffer_empty {
3243: my @currpaste = split(/,/,$env{'docs.markedcopies'});
3244: if (@currpaste == 0) {
3245: return &mt('Clipboard is already empty');
3246: }
3247: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
3248: if (@toclear == 0) {
3249: return &mt('Nothing selected to clear from clipboard');
3250: }
3251: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
3252: if ($numdel) {
3253: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
3254: } else {
3255: return &mt('Clipboard unchanged');
1.492 raeburn 3256: }
1.538 raeburn 3257: return;
3258: }
3259:
3260: sub clear_from_buffer {
3261: my ($toclear,$currpaste) = @_;
3262: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
3263: my %pastebuffer;
3264: map { $pastebuffer{$_} = 1; } @{$currpaste};
3265: my $numdel = 0;
3266: foreach my $suffix (@{$toclear}) {
3267: next if ($suffix =~ /\D/);
3268: next unless (exists($pastebuffer{$suffix}));
3269: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
3270: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
3271: delete($pastebuffer{$suffix});
3272: $numdel ++;
3273: }
3274: }
3275: my $newbuffer = join(',',sort(keys(%pastebuffer)));
3276: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
3277: return $numdel;
1.492 raeburn 3278: }
3279:
1.704 raeburn 3280: sub update_ltitools_caches {
3281: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
3282: my $hashid=$coursedom.'_'.$coursenum;
3283: if ($updatetoolscache) {
3284: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3285: }
3286: if ((ref($updatetoolsenc) eq 'ARRAY') &&
3287: (@{$updatetoolsenc})) {
3288: my @ids=&Apache::lonnet::current_machine_ids();
3289: my $updatedone;
3290: foreach my $lonhost (@{$updatetoolsenc}) {
3291: if (grep(/^\Q$lonhost\E$/,@ids)) {
3292: unless ($updatedone) {
3293: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3294: }
3295: $updatedone = 1;
3296: } else {
3297: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
3298: }
3299: }
3300: }
3301: return;
3302: }
3303:
1.492 raeburn 3304: sub get_newmap_url {
3305: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
3306: $titleref,$allmaps,$newurls) = @_;
3307: my $newurl;
3308: if ($url=~ m{^/uploaded/}) {
3309: $$titleref=&mt('Copy of').' '.$$titleref;
3310: }
3311: my $now = time;
3312: my $suffix=$$.int(rand(100)).$now;
3313: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
3314: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
3315: my $path = $1;
3316: my $prefix = $2;
3317: my $ancestor = $3;
3318: if (length($ancestor) > 10) {
3319: $ancestor = substr($ancestor,-10,10);
3320: }
3321: my $newid;
3322: if ($prefixchg) {
3323: if ($folder =~ /^supplemental/) {
3324: $prefix =~ s/^default/supplemental/;
3325: } else {
3326: $prefix =~ s/^supplemental/default/;
3327: }
3328: }
3329: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3330: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3331: } else {
3332: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3333: }
3334: my $counter = 0;
3335: my $is_unique = &uniqueness_check($newurl);
3336: if ($folder =~ /^default/) {
3337: if ($allmaps->{$newurl}) {
3338: $is_unique = 0;
3339: }
3340: }
3341: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3342: $counter ++;
3343: $suffix ++;
3344: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3345: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3346: } else {
3347: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3348: }
3349: $is_unique = &uniqueness_check($newurl);
3350: }
3351: if ($is_unique) {
3352: $newurls->{$newurl} = 1;
3353: } else {
3354: if ($url=~/\.page$/) {
3355: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3356: } else {
3357: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3358: }
3359: }
1.329 droeschl 3360: }
1.492 raeburn 3361: return ($newurl);
1.329 droeschl 3362: }
3363:
1.488 raeburn 3364: sub dbcopy {
1.704 raeburn 3365: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3366: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3367: my ($url,$result,$errtext);
3368: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3369: $url = $dbref->{'src'};
1.627 raeburn 3370: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3371: my $prefix = $1;
1.627 raeburn 3372: if ($prefix eq 'ext.tool') {
3373: $prefix = 'exttool';
3374: }
1.533 raeburn 3375: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3376: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3377: my $db_name;
3378: my $marker = (split(m{/},$url))[4];
3379: $marker=~s/\D//g;
3380: if ($dbref->{'src'} =~ m{/smppg$}) {
3381: $db_name =
3382: &Apache::lonsimplepage::get_db_name($url,$marker,
3383: $dbref->{'cdom'},
3384: $dbref->{'cnum'});
1.627 raeburn 3385: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3386: $db_name = 'exttool_'.$marker;
1.533 raeburn 3387: } else {
3388: $db_name = 'bulletinpage_'.$marker;
3389: }
3390: my ($suffix,$freedlock,$error) =
3391: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3392: $coursedom,$coursenum,
3393: 'concat');
3394: if (!$suffix) {
3395: if ($prefix eq 'smppg') {
3396: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3397: } elsif ($prefix eq 'exttool') {
3398: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3399: } else {
1.565 bisitz 3400: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3401: }
3402: if ($error) {
3403: $errtext .= '<br />'.$error;
3404: }
3405: } else {
3406: #need to copy the db contents to a new one.
3407: my %contents=&Apache::lonnet::dump($db_name,
3408: $dbref->{'cdom'},
3409: $dbref->{'cnum'});
1.704 raeburn 3410: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3411: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3412: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3413: $oldtoolid = $2;
3414: if ($1 eq 'c') {
3415: $defincrs = 1;
3416: %toolinfo =
3417: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3418: } else {
3419: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3420: }
3421: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3422: if ($toolinfo{$oldtoolid}{'passback'}) {
3423: $toolpassback = 1;
3424: }
3425: if ($toolinfo{$oldtoolid}{'roster'}) {
3426: $toolroster = 1;
3427: }
3428: } else {
3429: $toolcopyerror = 1;
3430: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3431: }
3432: }
3433: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3434: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3435: if ($contents{'crstitle'} ne '') {
3436: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3437: }
3438: if (($defincrs) && (!$toolcopyerror)) {
3439: my %newtool;
3440: my $oldcdom = $dbref->{'cdom'};
3441: my $oldcnum = $dbref->{'cnum'};
3442: my $title = $toolinfo{$oldtoolid}{'title'};
3443: if (ref($currltititles) eq 'HASH') {
3444: if (exists($currltititles->{$title})) {
3445: $title .= ' (copied from another course)';
3446: }
3447: }
3448: my ($newid,$iderror) =
3449: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3450: if ($newid =~ /^\d+$/) {
3451: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3452: $newtool{$newid}{'title'} = $title;
3453: if (ref($currltimax)) {
3454: $newtool{$newid}{'order'} = $$currltimax;
3455: }
3456: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3457: my $fname = $1;
3458: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3459: if ($content eq '-1') {
3460: delete($newtool{$newid}{'image'});
3461: } else {
3462: $env{'form.'.$suffix.'.image'} = $content;
3463: my $newlogo =
3464: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3465: delete($env{'form.'.$suffix.'.image'});
3466: if ($newlogo =~ m{^/uploaded/}) {
3467: $newtool{$newid}{'image'} = $newlogo;
3468: } else {
3469: delete($newtool{$newid}{'image'});
3470: }
3471: }
3472: }
3473: my $newusable;
3474: if ($same_institution) {
3475: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3476: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3477: my %newtoolsenc;
3478: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3479: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3480: if ($putres eq 'ok') {
3481: if (ref($updatetoolsenc) eq 'ARRAY') {
3482: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3483: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3484: push(@{$updatetoolsenc},$newhome);
3485: }
3486: }
3487: $newusable = 1;
3488: }
3489: }
3490: }
3491: if ($newtool{$newid}{'usable'}) {
3492: unless ($newusable) {
3493: delete($newtool{$newid}{'usable'});
3494: }
3495: }
3496: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3497: if ($putres eq 'ok') {
3498: $contents{'id'} = "c$newid";
3499: if (ref($updatetoolscache)) {
3500: $$updatetoolscache ++;
3501: }
3502: if (ref($currltititles->{$title}) eq 'ARRAY') {
3503: push(@{$currltititles->{$title}},$newid);
3504: } else {
3505: $currltititles->{$title} = [$newid];
3506: }
3507: if (ref($currltimax)) {
3508: $$currltimax ++;
3509: }
3510: } else {
3511: $toolcopyerror = 1;
3512: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3513: }
3514: } else {
3515: $toolcopyerror = 1;
3516: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3517: }
3518: }
3519: }
3520: }
1.533 raeburn 3521: if (exists($contents{'uploaded.photourl'})) {
3522: my $photo = $contents{'uploaded.photourl'};
3523: my ($subdir,$fname) =
3524: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3525: my $newphoto;
1.533 raeburn 3526: if ($fname ne '') {
3527: my $content = &Apache::lonnet::getfile($photo);
3528: unless ($content eq '-1') {
3529: $env{'form.'.$suffix.'.photourl'} = $content;
3530: $newphoto =
3531: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3532: delete($env{'form.'.$suffix.'.photourl'});
3533: }
3534: }
3535: if ($newphoto =~ m{^/uploaded/}) {
3536: $contents{'uploaded.photourl'} = $newphoto;
3537: }
3538: }
3539: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3540: if ($prefix eq 'exttool') {
3541: unless ($toolcopyerror) {
3542: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3543: if (exists($contents{$key})) {
3544: delete($contents{$key});
3545: }
3546: }
3547: if ($dbref->{'delgradable'}) {
3548: if (exists($contents{'gradable'})) {
3549: delete($contents{'gradable'});
3550: }
3551: }
3552: if ($toolpassback) {
3553: if ($contents{'gradable'}) {
3554: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3555: $contents{'gradesecret'} = $gradesecret;
3556: $contents{'gradesecretdate'} = time;
3557: }
3558: }
3559: if ($toolroster) {
3560: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3561: $contents{'rostersecret'} = $rostersecret;
3562: $contents{'rostersecretdate'} = time;
3563: }
3564: }
1.649 raeburn 3565: }
1.704 raeburn 3566: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3567: $result = 'error';
3568: } else {
3569: $result=&Apache::lonnet::put($db_name,\%contents,
3570: $coursedom,$coursenum);
3571: if ($result eq 'ok') {
3572: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3573: }
1.533 raeburn 3574: }
3575: }
3576: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3577: $lockerrorsref->{$prefix} =
1.533 raeburn 3578: '<div class="LC_error">'.
3579: &mt('There was a problem removing a lockfile.');
3580: if ($prefix eq 'smppg') {
1.560 raeburn 3581: $lockerrorsref->{$prefix} .=
1.559 raeburn 3582: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3583: } elsif ($prefix eq 'exttool') {
3584: $lockerrorsref->{$prefix} .=
3585: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3586: } else {
1.565 bisitz 3587: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3588: }
1.560 raeburn 3589: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3590: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3591: '</div>';
1.533 raeburn 3592: }
3593: }
3594: } elsif ($url =~ m{/syllabus$}) {
3595: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3596: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3597: if (($dbref->{'cdom'} ne $coursedom) ||
3598: ($dbref->{'cnum'} ne $coursenum)) {
3599: my %contents=&Apache::lonnet::dump('syllabus',
3600: $dbref->{'cdom'},
3601: $dbref->{'cnum'});
3602: $result=&Apache::lonnet::put('syllabus',\%contents,
3603: $coursedom,$coursenum);
3604: }
3605: }
1.488 raeburn 3606: }
3607: }
1.533 raeburn 3608: return ($url,$result,$errtext);
1.488 raeburn 3609: }
3610:
1.597 raeburn 3611: sub copy_templated_files {
3612: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3613: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3614: my $srccontainer = 'sequence';
3615: if ($srcwaspage) {
3616: $srccontainer = 'page';
3617: }
3618: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3619: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3620: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3621: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3622: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3623: $template.'.problem';
3624: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3625: if ($template eq 'simpleproblem') {
3626: $srcprefix .= '.0.';
3627: my $weightprefix = $newprefix;
3628: $newprefix .= '.0.';
3629: my @simpleprobqtypes = qw(radio option string essay numerical);
3630: my $qtype=$srcparms{$srcprefix.'questiontype'};
3631: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3632: my %newdata = (
3633: $newprefix.'questiontype' => $qtype,
3634: );
1.597 raeburn 3635: foreach my $type (@simpleprobqtypes) {
3636: if ($type eq $qtype) {
3637: $newdata{"$weightprefix.$type.weight"}=1;
3638: } else {
3639: $newdata{"$weightprefix.$type.weight"}=0;
3640: }
3641: }
3642: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3643: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3644: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3645: if ($qtype eq 'numerical') {
3646: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3647: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3648: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3649: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3650: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3651: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3652: unless (defined($maxfoils)) { $maxfoils=10; }
3653: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3654: if ($maxfoils<=0) { $maxfoils=10; }
3655: my $randomize=$srcparms{$srcprefix.'randomize'};
3656: unless (defined($randomize)) { $randomize='yes'; }
3657: unless ($randomize eq 'no') { $randomize='yes'; }
3658: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3659: $newdata{$newprefix.'randomize'} = $randomize;
3660: if ($qtype eq 'option') {
3661: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3662: }
3663: for (my $i=1; $i<=10; $i++) {
3664: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3665: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3666: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3667: }
3668:
3669: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3670: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3671: unless (defined($maxfoils)) { $maxfoils=10; }
3672: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3673: if ($maxfoils<=0) { $maxfoils=10; }
3674: my $randomize=$srcparms{$srcprefix.'randomize'};
3675: unless (defined($randomize)) { $randomize='yes'; }
3676: unless ($randomize eq 'no') { $randomize='yes'; }
3677: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3678: $newdata{$newprefix.'randomize'} = $randomize;
3679: if ($qtype eq 'option') {
3680: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3681: }
3682: for (my $i=1; $i<=10; $i++) {
3683: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3684: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3685: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3686: }
3687: } elsif ($qtype eq 'string') {
3688: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3689: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3690: }
3691: if (keys(%newdata)) {
3692: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3693: $coursenum);
3694: if ($putres eq 'ok') {
3695: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3696: }
3697: }
3698: }
3699: }
3700: }
3701:
1.329 droeschl 3702: sub uniqueness_check {
3703: my ($newurl) = @_;
3704: my $unique = 1;
3705: foreach my $res (@LONCAPA::map::order) {
3706: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3707: $url=&LONCAPA::map::qtescape($url);
3708: if ($newurl eq $url) {
3709: $unique = 0;
1.344 bisitz 3710: last;
1.329 droeschl 3711: }
3712: }
3713: return $unique;
3714: }
3715:
1.488 raeburn 3716: sub contained_map_check {
1.627 raeburn 3717: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3718: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3719: my $content = &Apache::lonnet::getfile($url);
3720: unless ($content eq '-1') {
3721: my $parser = HTML::TokeParser->new(\$content);
3722: $parser->attr_encoded(1);
3723: while (my $token = $parser->get_token) {
3724: next if ($token->[0] ne 'S');
3725: if ($token->[1] eq 'resource') {
3726: next if ($token->[2]->{'type'} eq 'zombie');
3727: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3728: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3729: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3730: unless ($srcdom eq $coursedom) {
3731: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3732: next;
3733: }
1.704 raeburn 3734: unless ($srcnum eq $coursenum) {
3735: my %toolsettings =
3736: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3737: my %tooltypes = &Apache::loncommon::usable_exttools();
3738: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3739: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3740: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3741: next;
3742: }
3743: }
1.627 raeburn 3744: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3745: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3746: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3747: next;
3748: }
3749: }
1.703 raeburn 3750: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3751: my ($srcdom,$srcnum) = ($1,$2);
3752: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3753: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3754: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3755: next;
3756: }
3757: }
3758: }
1.492 raeburn 3759: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3760: if ($1 eq 'uploaded') {
3761: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3762: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3763: } else {
1.492 raeburn 3764: if ($allmaps->{$ressrc}) {
1.529 raeburn 3765: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3766: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3767: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3768: } else {
3769: $addedmaps->{$ressrc} = [$url];
3770: }
1.488 raeburn 3771: }
1.627 raeburn 3772: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3773: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3774: }
1.492 raeburn 3775: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3776: if ($folder =~ /^supplemental/) {
1.492 raeburn 3777: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3778: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3779: } else {
3780: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3781: }
1.488 raeburn 3782: }
3783: }
3784: }
3785: }
3786: return;
3787: }
3788:
3789: sub url_paste_fixups {
1.533 raeburn 3790: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3791: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3792: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3793: my $checktitle;
3794: if (($prefixchg) &&
1.492 raeburn 3795: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3796: $checktitle = 1;
3797: }
1.492 raeburn 3798: my $skip;
3799: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3800: my $mapid = $1.$2;
3801: if ($tomove->{$mapid}) {
3802: $skip = 1;
3803: }
3804: }
1.491 raeburn 3805: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3806: return if ($file eq '-1');
3807: my $parser = HTML::TokeParser->new(\$file);
3808: $parser->attr_encoded(1);
1.491 raeburn 3809: my $changed = 0;
1.488 raeburn 3810: while (my $token = $parser->get_token) {
3811: next if ($token->[0] ne 'S');
3812: if ($token->[1] eq 'resource') {
3813: my $ressrc = $token->[2]->{'src'};
3814: next if ($ressrc eq '');
1.491 raeburn 3815: my $id = $token->[2]->{'id'};
1.492 raeburn 3816: my $title = $token->[2]->{'title'};
1.491 raeburn 3817: if ($checktitle) {
3818: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3819: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3820: }
3821: }
1.488 raeburn 3822: next if ($token->[2]->{'type'} eq 'external');
3823: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3824: next if ($skip);
1.532 raeburn 3825: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3826: $changed = 1;
3827: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3828: my $srcdom = $1;
3829: my $srcnum = $2;
1.488 raeburn 3830: my $rem = $3;
1.492 raeburn 3831: my $newurl;
3832: my $mapname;
3833: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3834: my $prefix = $1;
3835: $mapname = $prefix.$2;
3836: if ($tomove->{$mapname}) {
1.533 raeburn 3837: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3838: $srcdom,$srcnum,$allmaps,$rewrites,
3839: $retitles,$copies,$dbcopies,$zombies,
3840: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3841: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3842: next;
3843: } else {
3844: ($newurl,my $error) =
3845: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3846: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3847: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3848: $newsubdir->{$ressrc} = $1;
3849: }
3850: if ($error) {
3851: next;
3852: }
3853: }
3854: }
3855: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3856: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3857:
1.488 raeburn 3858: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3859: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3860: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3861: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3862: $cnum,$srcdom,$srcnum,$allmaps,
3863: $rewrites,$retitles,$copies,$dbcopies,
3864: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3865: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3866: $mapmoves->{$ressrc} = 1;
3867: }
3868: $changed = 1;
1.488 raeburn 3869: } else {
1.532 raeburn 3870: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3871: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3872: $changed = 1;
1.488 raeburn 3873: }
3874: }
1.649 raeburn 3875: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3876: next if ($skip);
1.492 raeburn 3877: my $srcdom = $1;
3878: my $srcnum = $2;
1.649 raeburn 3879: my $rem = $3;
3880: my ($is_exttool,$exttoolchg);
3881: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3882: $is_exttool = 1;
1.649 raeburn 3883: }
1.492 raeburn 3884: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3885: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3886: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3887: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3888: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3889: $changed = 1;
1.649 raeburn 3890: if ($is_exttool) {
3891: $exttoolchg = 1;
3892: }
1.700 raeburn 3893: } elsif (($is_exttool) &&
1.649 raeburn 3894: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3895: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3896: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3897: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3898: $changed = 1;
3899: $exttoolchg = 1;
3900: }
3901: if (($is_exttool) && ($prefixchg)) {
3902: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3903: if ($exttoolchg) {
3904: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3905: }
3906: }
1.533 raeburn 3907: }
3908: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3909: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3910: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3911: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3912: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3913: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3914: $changed = 1;
1.488 raeburn 3915: }
1.597 raeburn 3916: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3917: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3918: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3919: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3920: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3921: }
1.488 raeburn 3922: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3923: next if ($skip);
3924: my $srcdom = $1;
3925: my $srcnum = $2;
3926: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3927: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3928: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3929: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3930: $changed = 1;
1.488 raeburn 3931: }
3932: }
3933: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3934: next if ($skip);
1.488 raeburn 3935: my $to = $token->[2]->{'to'};
3936: if ($to ne '') {
3937: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3938: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3939: } else {
3940: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3941: }
3942: }
3943: }
3944: }
1.491 raeburn 3945: return $changed;
1.488 raeburn 3946: }
3947:
3948: sub apply_fixups {
1.529 raeburn 3949: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3950: $oldurl,$url,$caller) = @_;
3951: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3952: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3953: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3954: %currltititles,$currltimax);
3955: $currltimax = 0;
1.529 raeburn 3956: if (ref($updated) eq 'HASH') {
3957: if (ref($updated->{'rewrites'}) eq 'HASH') {
3958: %rewrites = %{$updated->{'rewrites'}};
3959: }
3960: if (ref($updated->{'zombies'}) eq 'HASH') {
3961: %zombies = %{$updated->{'zombies'}};
3962: }
3963: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3964: %removefrommap = %{$updated->{'removefrommap'}};
3965: }
3966: if (ref($updated->{'removeparam'}) eq 'HASH') {
3967: %removeparam = %{$updated->{'removeparam'}};
3968: }
3969: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3970: %dbcopies = %{$updated->{'dbcopies'}};
3971: }
3972: if (ref($updated->{'retitles'}) eq 'HASH') {
3973: %retitles = %{$updated->{'retitles'}};
3974: }
1.597 raeburn 3975: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3976: %resdatacopy = %{$updated->{'resdatacopy'}};
3977: }
1.529 raeburn 3978: }
3979: if (ref($info) eq 'HASH') {
3980: if (ref($info->{'newsubdir'}) eq 'HASH') {
3981: %newsubdir = %{$info->{'newsubdir'}};
3982: }
3983: if (ref($info->{'params'}) eq 'HASH') {
3984: %params = %{$info->{'params'}};
3985: }
3986: if (ref($info->{'before'}) eq 'HASH') {
3987: %before = %{$info->{'before'}};
3988: }
3989: if (ref($info->{'after'}) eq 'HASH') {
3990: %after = %{$info->{'after'}};
3991: }
3992: }
3993: if (ref($moves) eq 'HASH') {
3994: if (ref($moves->{'copies'}) eq 'HASH') {
3995: %copies = %{$moves->{'copies'}};
3996: }
3997: if (ref($moves->{'docmoves'}) eq 'HASH') {
3998: %docmoves = %{$moves->{'docmoves'}};
3999: }
4000: if (ref($moves->{'mapmoves'}) eq 'HASH') {
4001: %mapmoves = %{$moves->{'mapmoves'}};
4002: }
4003: }
4004: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 4005: my @allcopies;
1.529 raeburn 4006: if (exists($copies{$key})) {
4007: if (ref($copies{$key}) eq 'HASH') {
4008: my %added;
4009: foreach my $innerkey (keys(%{$copies{$key}})) {
4010: if (($innerkey ne '') && (!$added{$innerkey})) {
4011: push(@allcopies,$innerkey);
4012: $added{$innerkey} = 1;
4013: }
1.491 raeburn 4014: }
1.529 raeburn 4015: undef(%added);
1.491 raeburn 4016: }
4017: }
4018: if ($key eq $oldurl) {
1.529 raeburn 4019: if ((exists($docmoves{$key}))) {
1.532 raeburn 4020: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 4021: push(@allcopies,$oldurl);
4022: }
4023: }
4024: }
4025: if (@allcopies > 0) {
4026: foreach my $item (@allcopies) {
1.492 raeburn 4027: my ($relpath,$oldsubdir,$fname) =
4028: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 4029: if ($fname ne '') {
4030: my $content = &Apache::lonnet::getfile($item);
4031: unless ($content eq '-1') {
4032: my $storefn;
1.529 raeburn 4033: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
4034: $storefn = $docmoves{$key};
1.491 raeburn 4035: } else {
4036: $storefn = $relpath;
4037: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4038: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
4039: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 4040: }
1.529 raeburn 4041: if ($newsubdir{$key}) {
1.532 raeburn 4042: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 4043: }
4044: }
4045: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
4046: my $copyurl =
4047: &Apache::lonclonecourse::writefile($env{'request.course.id'},
4048: $storefn.$fname,$content);
4049: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 4050: if (exists($docmoves{$oldurl})) {
1.491 raeburn 4051: return &mt('Paste failed: an error occurred copying the file.');
4052: } elsif (ref($errors) eq 'HASH') {
4053: $errors->{$item} = 1;
1.489 raeburn 4054: }
4055: }
1.488 raeburn 4056: }
4057: }
1.491 raeburn 4058: }
4059: }
4060: }
1.529 raeburn 4061: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 4062: my $storefn=$key;
4063: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4064: if ($prefixchg && $before{'map'} && $after{'map'}) {
4065: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4066: }
1.529 raeburn 4067: if ($newsubdir{$key}) {
4068: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4069: }
1.491 raeburn 4070: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 4071: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
4072: ($after{'map'} eq 'default') &&
4073: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
4074: $mapcontent = '<map>'."\n".
4075: '<resource id="1" src="" type="start" />'."\n".
4076: '<link from="1" to="2" index="1" />'."\n".
4077: '<resource id="2" src="" type="finish" />'."\n".
4078: '</map>';
4079: }
1.491 raeburn 4080: if ($mapcontent eq '-1') {
4081: if (ref($errors) eq 'HASH') {
4082: $errors->{$key} = 1;
4083: }
4084: } else {
4085: my $newmap =
4086: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
4087: $mapcontent);
4088: if ($newmap eq '/adm/notfound.html') {
4089: if (ref($errors) eq 'HASH') {
4090: $errors->{$key} = 1;
1.489 raeburn 4091: }
1.488 raeburn 4092: }
4093: }
4094: }
1.491 raeburn 4095: my %updates;
4096: if ($is_map) {
1.529 raeburn 4097: if (ref($updated) eq 'HASH') {
4098: foreach my $type (keys(%{$updated})) {
4099: if (ref($updated->{$type}) eq 'HASH') {
4100: foreach my $key (keys(%{$updated->{$type}})) {
4101: $updates{$key} = 1;
4102: }
4103: }
4104: }
1.491 raeburn 4105: }
1.704 raeburn 4106: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 4107: foreach my $key (keys(%updates)) {
1.492 raeburn 4108: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 4109: if (ref($rewrites{$key}) eq 'HASH') {
4110: %torewrite = %{$rewrites{$key}};
1.491 raeburn 4111: }
1.529 raeburn 4112: if (ref($retitles{$key}) eq 'HASH') {
4113: %toretitle = %{$retitles{$key}};
1.491 raeburn 4114: }
1.529 raeburn 4115: if (ref($removefrommap{$key}) eq 'HASH') {
4116: %toremove = %{$removefrommap{$key}};
1.491 raeburn 4117: }
1.529 raeburn 4118: if (ref($removeparam{$key}) eq 'HASH') {
4119: %remparam = %{$removeparam{$key}};
1.492 raeburn 4120: }
1.529 raeburn 4121: if (ref($zombies{$key}) eq 'HASH') {
4122: %zombie = %{$zombies{$key}};
1.491 raeburn 4123: }
1.529 raeburn 4124: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 4125: foreach my $idx (keys(%{$dbcopies{$key}})) {
4126: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 4127: my $oldurl = $dbcopies{$key}{$idx}{'src'};
4128: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
4129: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
4130: my $oldmarker;
4131: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
4132: $oldmarker = $1;
4133: unless (($gotcrsltitools) ||
4134: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
4135: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
4136: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
4137: unless ($gotcrsltitools) {
4138: %currcrsltitools =
4139: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
4140: foreach my $item (sort(keys(%currcrsltitools))) {
4141: if (ref($currcrsltitools{$item}) eq 'HASH') {
4142: $currltimax ++;
4143: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
4144: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
4145: } else {
4146: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
4147: }
4148: }
4149: }
4150: $gotcrsltitools = 1;
4151: }
4152: unless ($checkedsameinst) {
4153: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
4154: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4155: if ($intdom ne '') {
4156: my $internet_names =
4157: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4158: if (ref($internet_names) eq 'ARRAY') {
4159: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4160: $same_institution = 1;
4161: }
4162: }
4163: }
4164: $checkedsameinst = 1;
4165: }
4166: }
4167: }
4168: }
1.533 raeburn 4169: my ($newurl,$result,$errtext) =
1.704 raeburn 4170: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
4171: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 4172: if ($result eq 'ok') {
4173: $newdb{$idx} = $newurl;
1.704 raeburn 4174: if ($newurl =~ /ext\.tool$/) {
4175: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
4176: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
4177: my $newmarker = $1;
4178: unless ($oldmarker eq $newmarker) {
4179: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
4180: }
4181: }
4182: }
4183: }
1.533 raeburn 4184: } elsif (ref($errors) eq 'HASH') {
4185: $errors->{$key} = 1;
4186: }
4187: push(@msgs,$errtext);
4188: }
1.491 raeburn 4189: }
4190: }
1.597 raeburn 4191: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 4192: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 4193: foreach my $idx (keys(%{$resdatacopy{$key}})) {
4194: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
4195: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
4196: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
4197: my $template = $1;
4198: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
4199: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
4200: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
4201: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 4202: unless ($gotnewmapname) {
4203: ($newmapname) = ($key =~ m{/([^/]+)$});
4204: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
4205: if ($newsubdir{$key}) {
4206: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
4207: }
4208: $gotnewmapname = 1;
4209: }
1.597 raeburn 4210: my $srcmapinfo = $srcfolder.':'.$idx;
4211: if ($srccontainer eq 'page') {
4212: $srcmapinfo .= ':1';
4213: }
4214: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
4215: $cnum,$template,$idx,$newmapname);
4216: }
4217: }
4218: }
4219: }
4220: }
1.529 raeburn 4221: if (ref($params{$key}) eq 'HASH') {
4222: %currparam = %{$params{$key}};
1.492 raeburn 4223: }
4224: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
4225: if ($fatal) {
1.533 raeburn 4226: return ($errtext);
1.492 raeburn 4227: }
4228: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
4229: if (defined($LONCAPA::map::zombies[$i])) {
4230: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 4231: if ($zombie{$i} eq $src) {
1.492 raeburn 4232: undef($LONCAPA::map::zombies[$i]);
4233: }
4234: }
4235: }
1.646 raeburn 4236: my $total = scalar(@LONCAPA::map::order) - 1;
4237: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 4238: my $idx = $LONCAPA::map::order[$i];
4239: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 4240: my $changed;
1.529 raeburn 4241: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 4242: if ((exists($toremove{$idx})) &&
4243: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 4244: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 4245: if (ref($currparam{$idx}) eq 'ARRAY') {
4246: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 4247: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 4248: }
4249: }
4250: next;
4251: }
4252: my $origsrc = $src;
1.532 raeburn 4253: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 4254: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
4255: $changed = 1;
1.491 raeburn 4256: }
1.492 raeburn 4257: }
1.532 raeburn 4258: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 4259: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
4260: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 4261: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 4262: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 4263: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 4264: } else {
1.529 raeburn 4265: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 4266: }
1.491 raeburn 4267: }
1.532 raeburn 4268: if ($origsrc =~ /\.(page|sequence)$/) {
4269: if ($newsubdir{$origsrc}) {
1.529 raeburn 4270: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 4271: }
1.532 raeburn 4272: } elsif ($newsubdir{$key}) {
4273: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 4274: }
4275: }
1.492 raeburn 4276: $changed = 1;
1.533 raeburn 4277: } elsif ($newdb{$idx} ne '') {
4278: $src = $newdb{$idx};
1.492 raeburn 4279: $changed = 1;
4280: }
4281: if ($changed) {
1.538 raeburn 4282: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 4283: }
4284: }
4285: }
4286: foreach my $idx (keys(%remparam)) {
4287: if (ref($remparam{$idx}) eq 'ARRAY') {
4288: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 4289: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 4290: }
4291: }
4292: }
1.533 raeburn 4293: if (values(%lockerrors) > 0) {
4294: $lockmsg = join('<br />',values(%lockerrors));
4295: }
1.491 raeburn 4296: my $storefn;
4297: if ($key eq $oldurl) {
4298: $storefn = $url;
4299: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
4300: } else {
4301: $storefn = $key;
4302: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4303: if ($prefixchg && $before{'map'} && $after{'map'}) {
4304: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4305: }
1.529 raeburn 4306: if ($newsubdir{$key}) {
4307: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4308: }
1.491 raeburn 4309: }
1.492 raeburn 4310: my $report;
4311: if ($folder !~ /^supplemental/) {
4312: $report = 1;
4313: }
1.527 raeburn 4314: (my $outtext,$errtext) =
1.492 raeburn 4315: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
4316: if ($errtext) {
1.529 raeburn 4317: if ($caller eq 'paste') {
1.533 raeburn 4318: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 4319: }
1.491 raeburn 4320: }
4321: }
1.704 raeburn 4322: if (($updatetoolscache) || (@updatetoolsenc)) {
4323: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
4324: \@updatetoolsenc);
4325: }
1.491 raeburn 4326: }
1.533 raeburn 4327: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 4328: }
4329:
4330: sub copy_dependencies {
4331: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4332: my $content;
4333: if (ref($contentref)) {
4334: $content = $$contentref;
4335: } else {
4336: $content = &Apache::lonnet::getfile($item);
4337: }
4338: unless ($content eq '-1') {
4339: my $mm = new File::MMagic;
4340: my $mimetype = $mm->checktype_contents($content);
4341: if ($mimetype eq 'text/html') {
4342: my (%allfiles,%codebase,$state);
4343: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4344: if ($res eq 'ok') {
4345: my ($numexisting,$numpathchanges,$existing);
4346: (undef,$numexisting,$numpathchanges,$existing) =
4347: &Apache::loncommon::ask_for_embedded_content(
4348: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4349: {'error_on_invalid_names' => 1,
4350: 'ignore_remote_references' => 1,
4351: 'docs_url' => $item,
4352: 'context' => 'paste'});
4353: if ($numexisting > 0) {
4354: if (ref($existing) eq 'HASH') {
4355: foreach my $dep (keys(%{$existing})) {
4356: my $depfile = $dep;
4357: unless ($depfile =~ m{^\Q$relpath\E}) {
4358: $depfile = $relpath.$dep;
4359: }
4360: my $depcontent = &Apache::lonnet::getfile($depfile);
4361: unless ($depcontent eq '-1') {
4362: my $storedep = $dep;
4363: $storedep =~ s{^\Q$relpath\E}{};
4364: my $dep_url =
4365: &Apache::lonclonecourse::writefile(
4366: $env{'request.course.id'},
4367: $storefn.$storedep,$depcontent);
4368: if ($dep_url eq '/adm/notfound.html') {
4369: if (ref($errors) eq 'HASH') {
4370: $errors->{$depfile} = 1;
4371: }
4372: } else {
4373: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4374: }
4375: }
4376: }
1.488 raeburn 4377: }
4378: }
4379: }
4380: }
4381: }
4382: return;
4383: }
4384:
1.329 droeschl 4385: my %parameter_type = ( 'randompick' => 'int_pos',
4386: 'hiddenresource' => 'string_yesno',
4387: 'encrypturl' => 'string_yesno',
4388: 'randomorder' => 'string_yesno',);
4389: my $valid_parameters_re = join('|',keys(%parameter_type));
4390: # set parameters
4391: sub update_parameter {
1.537 raeburn 4392: if ($env{'form.changeparms'} eq 'all') {
4393: my (@allidx,@allmapidx,%allchecked,%currchecked);
4394: %allchecked = (
4395: 'hiddenresource' => {},
4396: 'encrypturl' => {},
4397: 'randompick' => {},
4398: 'randomorder' => {},
4399: );
4400: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4401: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4402: if ($which eq 'randompick') {
4403: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4404: my ($res,$value) = split(/:/,$item);
4405: if ($value =~ /^\d+$/) {
4406: $allchecked{$which}{$res} = $value;
4407: }
4408: }
4409: } else {
1.539 raeburn 4410: if ($env{'form.all'.$which}) {
4411: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4412: }
1.537 raeburn 4413: }
4414: }
4415: my $haschanges = 0;
4416: foreach my $res (@LONCAPA::map::order) {
4417: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4418: $name=&LONCAPA::map::qtescape($name);
4419: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4420: next unless $url;
1.537 raeburn 4421: my $is_map;
4422: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4423: $is_map = 1;
4424: }
4425: foreach my $which (keys(%allchecked)) {
4426: if (($which eq 'randompick' || $which eq 'randomorder')) {
4427: next if (!$is_map);
4428: }
4429: my $oldvalue = 0;
4430: my $newvalue = 0;
4431: if ($allchecked{$which}{$res}) {
4432: $newvalue = $allchecked{$which}{$res};
4433: }
4434: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4435: if ($which eq 'randompick') {
4436: if ($current =~ /^(\d+)$/) {
4437: $oldvalue = $1;
4438: }
4439: } else {
4440: if ($current =~ /^yes$/i) {
4441: $oldvalue = 1;
4442: }
4443: }
4444: if ($oldvalue ne $newvalue) {
4445: $haschanges = 1;
4446: if ($newvalue) {
4447: my $storeval = 'yes';
4448: if ($which eq 'randompick') {
4449: $storeval = $newvalue;
4450: }
4451: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4452: $storeval,
4453: $parameter_type{$which});
4454: &remember_parms($res,$which,'set',$storeval);
4455: } elsif ($oldvalue) {
4456: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4457: &remember_parms($res,$which,'del');
4458: }
4459: }
4460: }
4461: }
4462: return $haschanges;
4463: } else {
1.588 raeburn 4464: my $haschanges = 0;
4465: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4466:
1.537 raeburn 4467: my $which = $env{'form.changeparms'};
4468: my $idx = $env{'form.setparms'};
1.588 raeburn 4469: my $oldvalue = 0;
4470: my $newvalue = 0;
4471: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4472: if ($which eq 'randompick') {
4473: if ($current =~ /^(\d+)$/) {
4474: $oldvalue = $1;
4475: }
4476: } elsif ($current =~ /^yes$/i) {
4477: $oldvalue = 1;
4478: }
1.537 raeburn 4479: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4480: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4481: : 1;
4482: }
4483: if ($oldvalue ne $newvalue) {
4484: $haschanges = 1;
4485: if ($newvalue) {
4486: my $storeval = 'yes';
4487: if ($which eq 'randompick') {
4488: $storeval = $newvalue;
4489: }
4490: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4491: $parameter_type{$which});
4492: &remember_parms($idx,$which,'set',$storeval);
4493: } else {
4494: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4495: &remember_parms($idx,$which,'del');
4496: }
1.537 raeburn 4497: }
1.588 raeburn 4498: return $haschanges;
1.329 droeschl 4499: }
4500: }
4501:
4502: sub handle_edit_cmd {
4503: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4504: my $haschanges = 0;
1.543 raeburn 4505: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4506: return $haschanges;
1.543 raeburn 4507: }
1.329 droeschl 4508: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4509:
4510: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4511: my ($title, $url, @rrest) = split(':', $ratstr);
4512:
1.538 raeburn 4513: if ($cmd eq 'remove') {
1.329 droeschl 4514: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4515: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4516: &Apache::lonnet::removeuploadedurl($url);
4517: } else {
4518: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4519: }
4520: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4521: $haschanges = 1;
1.329 droeschl 4522: } elsif ($cmd eq 'cut') {
4523: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4524: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4525: $haschanges = 1;
1.344 bisitz 4526: } elsif ($cmd eq 'up'
1.329 droeschl 4527: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4528: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4529: $haschanges = 1;
1.329 droeschl 4530: } elsif ($cmd eq 'down'
4531: && defined($LONCAPA::map::order[$idx+1])) {
4532: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4533: $haschanges = 1;
1.329 droeschl 4534: } elsif ($cmd eq 'rename') {
4535: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4536: if ($comment=~/\S/) {
4537: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4538: $comment.':'.join(':', $url, @rrest);
4539: }
4540: # Devalidate title cache
4541: my $renamed_url=&LONCAPA::map::qtescape($url);
4542: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4543: $haschanges = 1;
4544: } elsif ($cmd eq 'setalias') {
4545: my $newvalue = $env{'form.alias'};
4546: if ($newvalue ne '') {
4547: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4548: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4549: 'string');
4550: &remember_parms($idx,'mapalias','set',$newvalue);
4551: $haschanges = 1;
4552: }
4553: }
4554: } elsif ($cmd eq 'delalias') {
4555: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4556: if ($current ne '') {
4557: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4558: &remember_parms($idx,'mapalias','del');
4559: $haschanges = 1;
4560: }
1.329 droeschl 4561: }
1.633 raeburn 4562: return $haschanges;
1.329 droeschl 4563: }
4564:
4565: sub editor {
1.458 raeburn 4566: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4567: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4568: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4569: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4570: if ($allowed) {
1.519 raeburn 4571: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4572: $is_random_order,$container) =
1.510 raeburn 4573: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4574: $r->print($breadcrumbtrail);
1.519 raeburn 4575: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4576: $container = 'page';
4577: } else {
4578: $container = 'sequence';
1.510 raeburn 4579: }
1.484 raeburn 4580:
1.525 raeburn 4581: my $jumpto;
4582:
4583: unless ($supplementalflag) {
1.546 raeburn 4584: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4585: }
1.484 raeburn 4586:
4587: unless ($allowed) {
4588: $randompick = -1;
4589: }
4590:
1.615 raeburn 4591: my ($errtext,$fatal);
4592: if (($folder eq '') && (!$supplementalflag)) {
4593: if (@LONCAPA::map::order) {
4594: undef(@LONCAPA::map::order);
4595: undef(@LONCAPA::map::resources);
4596: undef(@LONCAPA::map::resparms);
4597: undef(@LONCAPA::map::zombies);
4598: }
4599: $folder = 'default';
4600: $container = 'sequence';
4601: } else {
4602: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4603: $folder.'.'.$container);
4604: return $errtext if ($fatal);
4605: }
1.329 droeschl 4606:
4607: if ($#LONCAPA::map::order<1) {
4608: my $idx=&LONCAPA::map::getresidx();
4609: if ($idx<=0) { $idx=1; }
4610: $LONCAPA::map::order[0]=$idx;
4611: $LONCAPA::map::resources[$idx]='';
4612: }
1.364 bisitz 4613:
1.329 droeschl 4614: # ------------------------------------------------------------ Process commands
4615:
4616: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4617: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4618: # set parameters and change order
4619: &snapshotbefore();
4620:
4621: if (&update_parameter()) {
1.588 raeburn 4622: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4623: return $errtext if ($fatal);
4624: }
4625:
4626: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4627: # change order
4628: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4629: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4630:
4631: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4632: return $errtext if ($fatal);
4633: }
1.364 bisitz 4634:
1.329 droeschl 4635: if ($env{'form.pastemarked'}) {
1.491 raeburn 4636: my %paste_errors;
1.533 raeburn 4637: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4638: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4639: \%paste_errors);
1.541 raeburn 4640: if (ref($pastemsgarray) eq 'ARRAY') {
4641: if (@{$pastemsgarray} > 0) {
4642: $r->print('<p class="LC_info">'.
4643: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4644: '</p>');
4645: }
1.541 raeburn 4646: }
4647: if ($lockerror) {
4648: $r->print('<p class="LC_error">'.
4649: $lockerror.
4650: '</p>');
4651: }
4652: if ($save_error ne '') {
4653: return $save_error;
4654: }
4655: if ($paste_res) {
4656: my %errortext = &Apache::lonlocal::texthash (
4657: fail => 'Storage of folder contents failed',
4658: failread => 'Reading folder contents failed',
4659: failstore => 'Storage of folder contents failed',
4660: );
4661: if ($errortext{$paste_res}) {
4662: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4663: }
1.329 droeschl 4664: }
1.491 raeburn 4665: if (keys(%paste_errors) > 0) {
1.538 raeburn 4666: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4667: &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".
4668: '<ul>'."\n");
4669: foreach my $key (sort(keys(%paste_errors))) {
4670: $r->print('<li>'.$key.'</li>'."\n");
4671: }
4672: $r->print('</ul></p>'."\n");
4673: }
1.538 raeburn 4674: } elsif ($env{'form.clearmarked'}) {
4675: my $output = &do_buffer_empty();
4676: if ($output) {
4677: $r->print('<p class="LC_info">'.$output.'</p>');
4678: }
4679: }
1.329 droeschl 4680:
4681: $r->print($upload_output);
4682:
1.538 raeburn 4683: # Rename, cut, copy or remove a single resource
1.602 raeburn 4684: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4685: my $contentchg;
1.633 raeburn 4686: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4687: $contentchg = 1;
4688: }
4689: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4690: return $errtext if ($fatal);
4691: }
1.538 raeburn 4692:
4693: # Cut, copy and/or remove multiple resources
4694: if ($env{'form.multichange'}) {
4695: my %allchecked = (
4696: cut => {},
4697: remove => {},
4698: );
4699: my $needsupdate;
4700: foreach my $which (keys(%allchecked)) {
4701: $env{'form.multi'.$which} =~ s/,$//;
4702: if ($env{'form.multi'.$which}) {
4703: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4704: if (ref($allchecked{$which}) eq 'HASH') {
4705: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4706: }
4707: }
4708: }
4709: if ($needsupdate) {
4710: my $haschanges = 0;
4711: my %curr_groups = &Apache::longroup::coursegroups();
4712: my $total = scalar(@LONCAPA::map::order) - 1;
4713: for (my $i=$total; $i>=0; $i--) {
4714: my $res = $LONCAPA::map::order[$i];
4715: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4716: $name=&LONCAPA::map::qtescape($name);
4717: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4718: next unless $url;
1.538 raeburn 4719: my %denied =
4720: &action_restrictions($coursenum,$coursedom,$url,
4721: $env{'form.folderpath'},\%curr_groups);
4722: foreach my $which (keys(%allchecked)) {
4723: next if ($denied{$which});
4724: next unless ($allchecked{$which}{$res});
4725: if ($which eq 'remove') {
4726: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4727: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4728: &Apache::lonnet::removeuploadedurl($url);
4729: } else {
4730: &LONCAPA::map::makezombie($res);
4731: }
4732: splice(@LONCAPA::map::order,$i,1);
4733: $haschanges ++;
4734: } elsif ($which eq 'cut') {
4735: &LONCAPA::map::makezombie($res);
4736: splice(@LONCAPA::map::order,$i,1);
4737: $haschanges ++;
4738: }
4739: }
4740: }
4741: if ($haschanges) {
4742: ($errtext,$fatal) =
4743: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4744: return $errtext if ($fatal);
4745: }
4746: }
4747: }
4748:
1.329 droeschl 4749: # Group import/search
4750: if ($env{'form.importdetail'}) {
4751: my @imports;
4752: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4753: if (defined($item)) {
4754: my ($name,$url,$residx)=
1.533 raeburn 4755: map { &unescape($_); } split(/\=/,$item);
4756: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4757: my ($suffix,$errortxt,$locknotfreed) =
4758: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4759: if ($locknotfreed) {
4760: $r->print($locknotfreed);
4761: }
4762: if ($suffix) {
4763: $url =~ s/_new\./_$suffix./;
4764: } else {
4765: return $errortxt;
4766: }
1.533 raeburn 4767: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4768: my $type = $1;
4769: my ($suffix,$errortxt,$locknotfreed) =
4770: &new_timebased_suffix($coursedom,$coursenum,$type);
4771: if ($locknotfreed) {
4772: $r->print($locknotfreed);
4773: }
4774: if ($suffix) {
4775: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4776: } else {
4777: return $errortxt;
4778: }
1.626 raeburn 4779: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4780: my ($suffix,$errortxt,$locknotfreed) =
4781: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4782: if ($locknotfreed) {
4783: $r->print($locknotfreed);
4784: }
4785: if ($suffix) {
4786: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4787: } else {
4788: return $errortxt;
4789: }
1.534 raeburn 4790: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4791: if ($supplementalflag) {
4792: next unless ($1 eq 'supplemental');
4793: if ($folder eq 'supplemental') {
4794: next unless ($2 eq 'default');
4795: } else {
4796: next unless ($folder eq 'supplemental_'.$2);
4797: }
4798: } else {
4799: next unless ($1 eq 'docs');
4800: if ($folder eq 'default') {
4801: next unless ($2 eq 'default');
4802: } else {
4803: next unless ($folder eq 'default_'.$2);
4804: }
4805: }
1.504 raeburn 4806: }
1.329 droeschl 4807: push(@imports, [$name, $url, $residx]);
4808: }
4809: }
1.530 raeburn 4810: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4811: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4812: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4813: return $errtext if ($fatal);
1.529 raeburn 4814: if ($fixuperrors) {
4815: $r->print($fixuperrors);
4816: }
1.329 droeschl 4817: }
4818: # Loading a complete map
4819: if ($env{'form.loadmap'}) {
4820: if ($env{'form.importmap'}=~/\w/) {
4821: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4822: my ($title,$url,$ext,$type)=split(/\:/,$res);
4823: my $idx=&LONCAPA::map::getresidx($url);
4824: $LONCAPA::map::resources[$idx]=$res;
4825: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4826: }
4827: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4828: $folder.'.'.$container,1);
1.329 droeschl 4829: return $errtext if ($fatal);
4830: } else {
4831: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4832:
1.329 droeschl 4833: }
4834: }
4835: &log_differences($plain);
4836: }
4837: # ---------------------------------------------------------------- End commands
4838: # ---------------------------------------------------------------- Print screen
4839: my $idx=0;
4840: my $shown=0;
4841: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4842: $r->print('<div class="LC_Box">'.
1.432 raeburn 4843: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4844: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4845: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4846: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4847: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4848: '</ol>');
1.381 bisitz 4849: if ($randompick>=0) {
4850: $r->print('<p class="LC_warning">'
4851: .&mt('Caution: this folder is set to randomly pick a subset'
4852: .' of resources. Adding or removing resources from this'
4853: .' folder will change the set of resources that the'
4854: .' students see, resulting in spurious or missing credit'
4855: .' for completed problems, not limited to ones you'
4856: .' modify. Do not modify the contents of this folder if'
4857: .' it is in active student use.')
4858: .'</p>'
4859: );
4860: }
4861: if ($is_random_order) {
4862: $r->print('<p class="LC_warning">'
4863: .&mt('Caution: this folder is set to randomly order its'
4864: .' contents. Adding or removing resources from this folder'
4865: .' will change the order of resources shown.')
4866: .'</p>'
4867: );
4868: }
4869: $r->print('</div>');
1.364 bisitz 4870: }
1.381 bisitz 4871:
1.685 raeburn 4872: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4873: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4874: if (ref($supplemental) eq 'HASH') {
4875: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4876: (ref($supplemental->{'ids'}) eq 'HASH')) {
4877: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4878: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4879: if ($supplemental->{'hidden'}->{$mapnum}) {
4880: $ishidden = 1;
4881: }
4882: }
4883: }
4884: }
4885: }
4886:
1.538 raeburn 4887: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4888: %filters = (
1.543 raeburn 4889: canremove => [],
4890: cancut => [],
4891: cancopy => [],
4892: hiddenresource => [],
4893: encrypturl => [],
4894: randomorder => [],
4895: randompick => [],
1.538 raeburn 4896: );
4897: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4898: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4899: foreach my $res (@LONCAPA::map::order) {
4900: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4901: $name=&LONCAPA::map::qtescape($name);
4902: $url=&LONCAPA::map::qtescape($url);
4903: unless ($name) { $name=(split(/\//,$url))[-1]; }
4904: unless ($name) { $idx++; next; }
1.537 raeburn 4905: push(@allidx,$res);
4906: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4907: push(@allmapidx,$res);
4908: }
1.617 raeburn 4909:
1.682 raeburn 4910: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4911: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4912: $idx++;
4913: next;
4914: }
1.682 raeburn 4915: }
1.381 bisitz 4916: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4917: $coursenum,$coursedom,$crstype,
1.538 raeburn 4918: $pathitem,$supplementalflag,$container,
1.620 raeburn 4919: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4920: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4921: $idx++;
4922: $shown++;
1.329 droeschl 4923: }
1.424 onken 4924: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4925:
1.538 raeburn 4926: my $need_save;
1.611 raeburn 4927: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4928: my $toolslink;
1.682 raeburn 4929: if ($allowed || $canedit) {
4930: my $helpitem = 'Navigation_Screen';
4931: if (!$allowed) {
4932: $helpitem = 'Supplemental_Navigation';
4933: }
1.544 raeburn 4934: $toolslink = '<table><tr><td>'
1.520 raeburn 4935: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4936: $helpitem,undef,'RAT')
1.520 raeburn 4937: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4938: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4939: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4940: .'id="LC_content_toolbar_edittoplevel" '
4941: .'class="LC_toolbarItem" '
4942: .'title="'.&mt('Supplemental Content Editor').'">'
4943: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4944: }
1.510 raeburn 4945: if ($shown) {
4946: if ($allowed) {
4947: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4948: .&Apache::loncommon::start_data_table(undef,'contentlist')
4949: .&Apache::loncommon::start_data_table_header_row()
4950: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4951: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4952: .'<th>'.&mt('Document').'</th>'
4953: .'<th colspan="2">'.&mt('Settings').'</th>'
4954: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4955: if ($folder !~ /^supplemental/) {
1.538 raeburn 4956: $lists{'canhide'} = join(',',@allidx);
4957: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4958: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4959: 'randomorder','randompick');
4960: foreach my $item (@possfilters) {
1.538 raeburn 4961: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4962: if (@{$filters{$item}} > 0) {
4963: $lists{$item} = join(',',@{$filters{$item}});
4964: }
1.538 raeburn 4965: }
4966: }
1.537 raeburn 4967: if (@allidx > 0) {
4968: my $path;
4969: if ($env{'form.folderpath'}) {
1.630 raeburn 4970: $path =
1.537 raeburn 4971: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4972: }
1.538 raeburn 4973: if (@allidx > 1) {
1.630 raeburn 4974: $to_show .=
1.538 raeburn 4975: &Apache::loncommon::continue_data_table_row().
4976: '<td colspan="2"> </td>'.
4977: '<td>'.
1.611 raeburn 4978: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4979: '</td>'.
1.633 raeburn 4980: '<td colspan="3"> </td>'.
4981: '<td colspan="2">'.
1.611 raeburn 4982: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4983: '</td>'.
4984: &Apache::loncommon::end_data_table_row();
4985: $need_save = 1;
4986: }
1.537 raeburn 4987: }
4988: }
4989: $to_show .= $output.' '
1.510 raeburn 4990: .&Apache::loncommon::end_data_table()
4991: .'<br style="line-height:2px;" />'
4992: .&Apache::loncommon::end_scrollbox();
4993: } else {
1.520 raeburn 4994: $to_show .= $toolslink
1.510 raeburn 4995: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4996: .$output.' '
4997: .&Apache::loncommon::end_data_table();
1.393 raeburn 4998: }
1.510 raeburn 4999: } else {
1.520 raeburn 5000: if (!$allowed) {
5001: $to_show .= $toolslink;
5002: }
1.615 raeburn 5003: my $noresmsg;
5004: if ($allowed && $hiddentop && !$supplementalflag) {
5005: $noresmsg = &mt('Main Content Hidden');
5006: } else {
5007: $noresmsg = &mt('Currently empty');
5008: }
1.510 raeburn 5009: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
5010: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 5011: .$noresmsg
1.510 raeburn 5012: .'</div>'
5013: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 5014: }
5015: } else {
1.510 raeburn 5016: if ($shown) {
5017: $to_show = '<div>'
5018: .&Apache::loncommon::start_data_table('LC_tableOfContent')
5019: .$output
5020: .&Apache::loncommon::end_data_table()
5021: .'</div>';
5022: } else {
5023: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 5024: .&mt('Currently empty')
1.510 raeburn 5025: .'</div>'
5026: }
1.458 raeburn 5027: }
5028: my $tid = 1;
5029: if ($supplementalflag) {
5030: $tid = 2;
1.329 droeschl 5031: }
5032: if ($allowed) {
1.484 raeburn 5033: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 5034: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 5035: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
5036: if ($canedit) {
5037: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
5038: }
1.460 raeburn 5039: } else {
5040: $r->print($to_show);
1.329 droeschl 5041: }
5042: return;
5043: }
5044:
1.538 raeburn 5045: sub multiple_check_form {
1.611 raeburn 5046: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 5047: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 5048: my $disabled;
5049: unless ($canedit) {
1.700 raeburn 5050: $disabled = ' disabled="disabled"';
1.611 raeburn 5051: }
1.538 raeburn 5052: my $output =
5053: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
5054: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
5055: '<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>'.
5056: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
5057: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
5058: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
5059: if ($caller eq 'settings') {
5060: $output .=
5061: '<table><tr>'.
5062: '<td class="LC_docs_entry_parameter">'.
5063: '<span class="LC_nobreak"><label>'.
1.611 raeburn 5064: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 5065: '</label></span></td>'.
5066: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5067: '<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 5068: '</span></td>'.
5069: '</tr>'."\n".
5070: '<tr>'.
5071: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5072: '<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 5073: '</label></span>'.
5074: '</td></tr></table>'."\n";
5075: } else {
5076: $output .=
5077: '<table><tr>'.
5078: '<td class="LC_docs_entry_parameter">'.
5079: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 5080: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 5081: '</label></span></td>'.
5082: '<td class="LC_docs_entry_parameter">'.
5083: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 5084: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 5085: '</label></span></td>'."\n".
5086: '<td class="LC_docs_entry_parameter">'.
5087: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 5088: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 5089: '</label></span></td>'.
5090: '</tr></table>'."\n";
5091: }
5092: $output .=
5093: '</fieldset>'.
5094: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
5095: if ($caller eq 'settings') {
5096: $output .=
1.543 raeburn 5097: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
5098: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
5099: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
5100: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
5101: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 5102: } elsif ($caller eq 'actions') {
5103: $output .=
5104: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
5105: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
5106: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
5107: }
5108: $output .=
5109: '</form>'.
5110: '</div>';
5111: return $output;
5112: }
5113:
1.329 droeschl 5114: sub process_file_upload {
1.552 raeburn 5115: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 5116: # upload a file, if present
1.552 raeburn 5117: my $filesize = length($env{'form.uploaddoc'});
5118: if (!$filesize) {
5119: $$upload_output = '<div class="LC_error">'.
5120: &mt('Unable to upload [_1]. (size = [_2] bytes)',
5121: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
5122: $filesize).'<br />'.
5123: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
5124: '</div>';
5125: return;
5126: }
5127: my $quotatype = 'unofficial';
5128: if ($crstype eq 'Community') {
1.601 raeburn 5129: $quotatype = 'community';
5130: } elsif ($crstype eq 'Placement') {
5131: $quotatype = 'placement';
1.580 raeburn 5132: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 5133: $quotatype = 'official';
1.573 raeburn 5134: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5135: $quotatype = 'textbook';
1.552 raeburn 5136: }
5137: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
5138: $filesize = int($filesize/1000); #expressed in kb
5139: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 5140: $env{'form.uploaddoc.filename'},$filesize,
5141: 'upload',$quotatype);
1.552 raeburn 5142: return if ($$upload_output);
5143: }
1.440 raeburn 5144: my ($parseaction,$showupload,$nextphase,$mimetype);
5145: if ($env{'form.parserflag'}) {
1.329 droeschl 5146: $parseaction = 'parse';
5147: }
5148: my $folder=$env{'form.folder'};
5149: if ($folder eq '') {
5150: $folder='default';
5151: }
5152: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
5153: my $errtext='';
5154: my $fatal=0;
5155: my $container='sequence';
1.519 raeburn 5156: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 5157: $container='page';
5158: }
5159: ($errtext,$fatal)=
1.534 raeburn 5160: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 5161: if ($#LONCAPA::map::order<1) {
5162: $LONCAPA::map::order[0]=1;
5163: $LONCAPA::map::resources[1]='';
5164: }
5165: my $destination = 'docs/';
5166: if ($folder =~ /^supplemental/) {
5167: $destination = 'supplemental/';
5168: }
5169: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5170: $destination .= 'default/';
5171: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5172: $destination .= $2.'/';
5173: }
1.534 raeburn 5174: if ($fatal) {
5175: $$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>';
5176: return;
5177: }
1.440 raeburn 5178: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 5179: my $newidx=&LONCAPA::map::getresidx();
5180: $destination .= $newidx;
1.439 raeburn 5181: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 5182: $parseaction,$allfiles,
1.440 raeburn 5183: $codebase,undef,undef,undef,undef,
5184: undef,undef,\$mimetype);
5185: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
5186: my $stored = $1;
5187: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
5188: $stored.'</span>').'</p>';
5189: } else {
5190: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
5191:
1.457 raeburn 5192: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 5193: return;
5194: }
1.329 droeschl 5195: my $ext='false';
5196: if ($url=~m{^http://}) { $ext='true'; }
5197: $url = &LONCAPA::map::qtunescape($url);
5198: my $comment=$env{'form.comment'};
5199: $comment = &LONCAPA::map::qtunescape($comment);
5200: if ($folder=~/^supplemental/) {
5201: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
5202: $env{'user.domain'}.'___&&&___'.$comment;
5203: }
5204:
5205: $LONCAPA::map::resources[$newidx]=
5206: $comment.':'.$url.':'.$ext.':normal:res';
5207: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
5208: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 5209: $folder.'.'.$container,1);
1.329 droeschl 5210: if ($fatal) {
1.457 raeburn 5211: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 5212: return;
1.329 droeschl 5213: } else {
1.440 raeburn 5214: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
5215: $$upload_output = $showupload;
1.384 raeburn 5216: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 5217: if ($total_embedded > 0) {
1.440 raeburn 5218: my $uploadphase = 'upload_embedded';
5219: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
5220: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 5221: my ($embedded,$num) =
1.440 raeburn 5222: &Apache::loncommon::ask_for_embedded_content(
5223: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
5224: if ($embedded) {
5225: if ($num) {
5226: $$upload_output .=
5227: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
5228: $nextphase = $uploadphase;
5229: } else {
5230: $$upload_output .= $embedded;
5231: }
5232: } else {
5233: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
5234: }
1.329 droeschl 5235: } else {
1.440 raeburn 5236: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 5237: }
1.457 raeburn 5238: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 5239: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
5240: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 5241: $nextphase = 'decompress_uploaded';
5242: my $position = scalar(@LONCAPA::map::order)-1;
5243: my $noextract = &return_to_editor();
5244: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
5245: my %archiveitems = (
5246: folderpath => $env{'form.folderpath'},
5247: cmd => $nextphase,
5248: newidx => $newidx,
5249: position => $position,
5250: phase => $nextphase,
1.477 raeburn 5251: comment => $comment,
1.480 raeburn 5252: );
5253: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
5254: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 5255: $$upload_output = $showupload.
5256: &Apache::loncommon::decompress_form($mimetype,
5257: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 5258: \%archiveitems,\@current);
1.329 droeschl 5259: }
5260: }
5261: }
1.440 raeburn 5262: return $nextphase;
1.329 droeschl 5263: }
5264:
1.480 raeburn 5265: sub get_dir_list {
5266: my ($url,$coursenum,$coursedom,$newidx) = @_;
5267: my ($destination,$dir_root) = &embedded_destination();
5268: my ($dirlistref,$listerror) =
5269: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
5270: my @dir_lines;
5271: my $dirptr=16384;
5272: if (ref($dirlistref) eq 'ARRAY') {
5273: foreach my $dir_line (sort
5274: {
5275: my ($afile)=split('&',$a,2);
5276: my ($bfile)=split('&',$b,2);
5277: return (lc($afile) cmp lc($bfile));
5278: } (@{$dirlistref})) {
5279: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
5280: $filename =~ s/\s+$//;
5281: next if ($filename =~ /^\.\.?$/);
5282: my $isdir = 0;
5283: if ($dirptr&$testdir) {
5284: $isdir = 1;
5285: }
5286: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
5287: }
5288: }
5289: return @dir_lines;
5290: }
5291:
1.329 droeschl 5292: sub is_supplemental_title {
5293: my ($title) = @_;
5294: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
5295: }
5296:
5297: # --------------------------------------------------------------- An entry line
5298:
5299: sub entryline {
1.501 raeburn 5300: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 5301: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 5302: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 5303: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 5304: if (&is_supplemental_title($title)) {
1.488 raeburn 5305: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 5306: $encodedtitle=$title;
1.329 droeschl 5307: } else {
5308: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 5309: $encodedtitle=$title;
1.329 droeschl 5310: $renametitle=$title;
5311: $foldertitle=$title;
5312: }
5313:
1.611 raeburn 5314: my ($disabled,$readonly,$js_lt);
5315: unless ($canedit) {
5316: $disabled = 'disabled="disabled"';
5317: $readonly = 1;
5318: }
5319:
1.329 droeschl 5320: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 5321:
1.329 droeschl 5322: $renametitle=~s/\\/\\\\/g;
5323: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 5324: $renametitle=~s/"/%22/g;
1.581 raeburn 5325: $renametitle=~s/ /%20/g;
5326: $oldtitle = $renametitle;
1.576 raeburn 5327: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 5328: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 5329: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5330: # Edit commands
1.679 raeburn 5331: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5332: if ($env{'form.folderpath'}) {
5333: $esc_path=&escape($env{'form.folderpath'});
5334: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5335: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5336: }
1.505 raeburn 5337: my $isexternal;
1.510 raeburn 5338: if ($residx) {
1.501 raeburn 5339: my $currurl = $url;
5340: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5341: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5342: $isexternal = 1;
5343: }
1.510 raeburn 5344: if (!$supplementalflag) {
5345: my $path = 'uploaded/'.
5346: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5347: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5348: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5349: $residx,
5350: &Apache::lonnet::declutter($currurl));
5351: }
1.501 raeburn 5352: }
1.538 raeburn 5353: my ($renamelink,%lt,$ishash);
5354: if (ref($filtersref) eq 'HASH') {
5355: $ishash = 1;
5356: }
5357:
1.329 droeschl 5358: if ($allowed) {
1.538 raeburn 5359: $form_start = '
5360: <form action="/adm/coursedocs" method="post">
5361: ';
5362: $form_common=(<<END);
5363: <input type="hidden" name="folderpath" value="$path" />
5364: <input type="hidden" name="symb" value="$symb" />
5365: END
5366: $form_param=(<<END);
5367: <input type="hidden" name="setparms" value="$orderidx" />
5368: <input type="hidden" name="changeparms" value="0" />
5369: END
5370: $form_end = '</form>';
5371:
1.329 droeschl 5372: my $incindex=$index+1;
5373: my $selectbox='';
1.471 raeburn 5374: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5375: ((split(/\:/,
1.344 bisitz 5376: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5377: ne '') &&
1.329 droeschl 5378: ((split(/\:/,
1.344 bisitz 5379: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5380: ne '')) {
5381: $selectbox=
5382: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5383: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5384: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5385: if ($i==$incindex) {
1.358 bisitz 5386: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5387: } else {
5388: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5389: }
5390: }
5391: $selectbox.='</select>';
5392: }
1.501 raeburn 5393: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5394: 'up' => 'Move Up',
5395: 'dw' => 'Move Down',
5396: 'rm' => 'Remove',
5397: 'ct' => 'Cut',
5398: 'rn' => 'Rename',
1.501 raeburn 5399: 'cp' => 'Copy',
1.633 raeburn 5400: 'da' => 'Unset alias',
5401: 'sa' => 'Set alias',
1.501 raeburn 5402: 'ex' => 'External Resource',
1.598 raeburn 5403: 'et' => 'External Tool',
1.501 raeburn 5404: 'ed' => 'Edit',
5405: 'pr' => 'Preview',
5406: 'sv' => 'Save',
5407: 'ul' => 'URL',
1.611 raeburn 5408: 'ti' => 'Title',
1.618 raeburn 5409: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5410: );
1.538 raeburn 5411: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5412: $env{'form.folderpath'},
5413: $currgroups);
1.517 raeburn 5414: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5415: my $skip_confirm = 0;
1.603 raeburn 5416: my $confirm_removal = 0;
1.329 droeschl 5417: if ( $folder =~ /^supplemental/
5418: || ($url =~ m{( /smppg$
5419: |/syllabus$
5420: |/aboutme$
5421: |/navmaps$
5422: |/bulletinboard$
1.626 raeburn 5423: |/ext\.tool$
1.505 raeburn 5424: |\.html$)}x)
5425: || $isexternal) {
1.329 droeschl 5426: $skip_confirm = 1;
5427: }
1.603 raeburn 5428: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5429: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5430: $confirm_removal = 1;
5431: }
1.633 raeburn 5432: if ($url =~ /$LONCAPA::assess_re/) {
5433: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5434: }
1.329 droeschl 5435:
1.538 raeburn 5436: if ($denied{'copy'}) {
1.543 raeburn 5437: $copylink=(<<ENDCOPY)
1.507 raeburn 5438: <span style="visibility: hidden;">$lt{'cp'}</span>
5439: ENDCOPY
5440: } else {
1.538 raeburn 5441: my $formname = 'edit_copy_'.$orderidx;
5442: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5443: $copylink=(<<ENDCOPY);
1.538 raeburn 5444: <form name="$formname" method="post" action="/adm/coursedocs">
5445: $form_common
1.611 raeburn 5446: <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 5447: $form_end
1.329 droeschl 5448: ENDCOPY
1.538 raeburn 5449: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5450: push(@{$filtersref->{'cancopy'}},$orderidx);
5451: }
1.329 droeschl 5452: }
1.538 raeburn 5453: if ($denied{'cut'}) {
1.507 raeburn 5454: $cutlink=(<<ENDCUT);
5455: <span style="visibility: hidden;">$lt{'ct'}</span>
5456: ENDCUT
5457: } else {
1.538 raeburn 5458: my $formname = 'edit_cut_'.$orderidx;
5459: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5460: $cutlink=(<<ENDCUT);
1.538 raeburn 5461: <form name="$formname" method="post" action="/adm/coursedocs">
5462: $form_common
1.542 raeburn 5463: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 5464: <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 5465: $form_end
1.329 droeschl 5466: ENDCUT
1.538 raeburn 5467: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5468: push(@{$filtersref->{'cancut'}},$orderidx);
5469: }
1.329 droeschl 5470: }
1.538 raeburn 5471: if ($denied{'remove'}) {
1.507 raeburn 5472: $removelink=(<<ENDREM);
5473: <span style="visibility: hidden;">$lt{'rm'}</a>
5474: ENDREM
5475: } else {
1.538 raeburn 5476: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5477: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5478: $removelink=(<<ENDREM);
1.538 raeburn 5479: <form name="$formname" method="post" action="/adm/coursedocs">
5480: $form_common
1.542 raeburn 5481: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5482: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 5483: <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 5484: $form_end
1.497 raeburn 5485: ENDREM
1.538 raeburn 5486: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5487: push(@{$filtersref->{'canremove'}},$orderidx);
5488: }
1.497 raeburn 5489: }
1.551 raeburn 5490: $renamelink=(<<ENDREN);
1.581 raeburn 5491: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5492: ENDREN
1.611 raeburn 5493: my ($uplink,$downlink);
5494: if ($canedit) {
5495: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5496: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5497: } else {
5498: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5499: $downlink = $uplink;
5500: }
1.329 droeschl 5501: $line.=(<<END);
5502: <td>
1.379 bisitz 5503: <div class="LC_docs_entry_move">
1.611 raeburn 5504: <a href="$uplink">
1.501 raeburn 5505: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5506: </a>
5507: </div>
5508: <div class="LC_docs_entry_move">
1.611 raeburn 5509: <a href="$downlink">
1.501 raeburn 5510: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5511: </a>
5512: </div>
1.329 droeschl 5513: </td>
5514: <td>
5515: $form_start
1.538 raeburn 5516: $form_param
1.478 raeburn 5517: $form_common
1.329 droeschl 5518: $selectbox
5519: $form_end
5520: </td>
1.540 raeburn 5521: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5522: $removelink
1.329 droeschl 5523: $cutlink
5524: $copylink
5525: </td>
5526: END
5527: }
5528: # Figure out what kind of a resource this is
5529: my ($extension)=($url=~/\.(\w+)$/);
5530: my $uploaded=($url=~/^\/*uploaded\//);
5531: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5532: my $isfolder;
5533: my $ispage;
5534: my $containerarg;
1.615 raeburn 5535: my $folderurl;
1.685 raeburn 5536: my $plainurl;
1.329 droeschl 5537: if ($uploaded) {
1.472 raeburn 5538: if (($extension eq 'sequence') || ($extension eq 'page')) {
5539: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5540: $containerarg = $1;
1.472 raeburn 5541: if ($extension eq 'sequence') {
5542: $icon=$iconpath.'navmap.folder.closed.gif';
5543: $isfolder=1;
5544: } else {
5545: $icon=$iconpath.'page.gif';
5546: $ispage=1;
5547: }
1.615 raeburn 5548: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5549: if ($allowed) {
5550: $url='/adm/coursedocs?';
5551: } else {
5552: $url='/adm/supplemental?';
5553: }
1.329 droeschl 5554: } else {
1.685 raeburn 5555: $plainurl = $url;
1.329 droeschl 5556: }
5557: }
1.364 bisitz 5558:
1.621 raeburn 5559: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5560: my $orig_url = $url;
1.340 raeburn 5561: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5562: if ($container eq 'page') {
5563: $url=~s{^http(|s)(:|:)//}{/ext/};
5564: } else {
5565: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5566: }
1.501 raeburn 5567: if (!$supplementalflag && $residx && $symb) {
5568: if ((!$isfolder) && (!$ispage)) {
5569: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5570: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5571: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5572: } else {
5573: $url=&Apache::lonnet::clutter($url);
5574: }
1.501 raeburn 5575: if ($url=~/^\/*uploaded\//) {
5576: $url=~/\.(\w+)$/;
5577: my $embstyle=&Apache::loncommon::fileembstyle($1);
5578: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5579: $url='/adm/wrapper'.$url;
5580: } elsif ($embstyle eq 'ssi') {
5581: #do nothing with these
5582: } elsif ($url!~/\.(sequence|page)$/) {
5583: $url='/adm/coursedocs/showdoc'.$url;
5584: }
1.623 raeburn 5585: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5586: my $wrapped = $1;
5587: my $exturl = $2;
1.668 raeburn 5588: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5589: $url='/adm/wrapper'.$url;
5590: }
5591: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5592: $nomodal = 1;
5593: }
1.626 raeburn 5594: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5595: $url='/adm/wrapper'.$url;
1.621 raeburn 5596: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5597: if (($ENV{'SERVER_PORT'} == 443) &&
5598: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5599: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5600: $url .= '?usehttp=1';
5601: }
1.621 raeburn 5602: $nomodal = 1;
5603: }
1.598 raeburn 5604: }
1.696 raeburn 5605: my $checkencrypt;
1.680 raeburn 5606: if (!$env{'request.role.adv'}) {
1.615 raeburn 5607: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5608: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5609: $checkencrypt = 1;
1.620 raeburn 5610: } elsif (ref($navmapref)) {
1.615 raeburn 5611: unless (ref($$navmapref)) {
5612: $$navmapref = Apache::lonnavmaps::navmap->new();
5613: }
5614: if (ref($$navmapref)) {
5615: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5616: $checkencrypt = 1;
1.615 raeburn 5617: }
5618: }
5619: }
1.680 raeburn 5620: }
5621: if ($checkencrypt) {
5622: my $currenc = $env{'request.enc'};
5623: $env{'request.enc'} = 1;
5624: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5625: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5626: if (&Apache::lonnet::symbverify($symb,$url)) {
5627: $url = $shownurl;
5628: } else {
5629: $url = '';
5630: }
5631: $env{'request.enc'} = $currenc;
5632: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5633: $shownsymb = $symb;
5634: if ($isexternal) {
5635: $url =~ s/\#[^#]+$//;
5636: if ($container eq 'page') {
5637: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5638: }
1.612 raeburn 5639: }
1.696 raeburn 5640: } else {
5641: $url = '';
1.680 raeburn 5642: }
5643: unless ($env{'request.role.adv'}) {
5644: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5645: $url = '';
5646: }
5647: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5648: $url = '';
5649: $hiddenres = 1;
5650: }
5651: }
1.696 raeburn 5652: if (($url ne '') && ($shownsymb ne '')) {
5653: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5654: }
1.329 droeschl 5655: }
1.621 raeburn 5656: } elsif ($supplementalflag) {
1.610 raeburn 5657: if ($isexternal) {
5658: if ($url =~ /^([^#]+)#([^#]+)$/) {
5659: $url = $1;
5660: $anchor = $2;
1.623 raeburn 5661: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5662: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5663: if ($hostname ne '') {
5664: $url = 'http://'.$hostname.$url;
5665: }
5666: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5667: }
5668: $nomodal = 1;
5669: }
1.610 raeburn 5670: }
1.621 raeburn 5671: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5672: if (($ENV{'SERVER_PORT'} == 443) &&
5673: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5674: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5675: if ($hostname ne '') {
5676: $url = 'http://'.$hostname.$url;
5677: }
5678: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5679: }
1.621 raeburn 5680: $nomodal = 1;
5681: }
1.705 raeburn 5682: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5683: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5684: unless ($embstyle eq 'ssi') {
5685: if (($embstyle eq 'img')
5686: || ($embstyle eq 'emb')
5687: || ($embstyle eq 'wrp')) {
5688: $url='/adm/wrapper'.$url;
5689: } elsif ($url !~ /\.(sequence|page)$/) {
5690: $url='/adm/coursedocs/showdoc'.$url;
5691: }
5692: }
1.610 raeburn 5693: }
1.685 raeburn 5694: unless ($allowed && $env{'request.role.adv'}) {
5695: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5696: $hiddenres = 1;
5697: }
5698: }
1.329 droeschl 5699: }
1.615 raeburn 5700: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5701: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5702: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5703: my $foldername=&escape($foldertitle);
5704: my $folderpath=$env{'form.folderpath'};
5705: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5706: if (!$allowed && $supplementalflag) {
1.519 raeburn 5707: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5708: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5709: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5710: $hiddenfolder = 1;
1.682 raeburn 5711: }
1.510 raeburn 5712: } else {
1.617 raeburn 5713: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5714: 'parameter_randompick'))[0];
5715: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5716: 'parameter_randomorder'))[0]=~/^yes$/i);
5717: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5718: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5719: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5720: 'parameter_encrypturl'))[0]=~/^yes$/i);
5721: unless ($hiddenmap) {
1.620 raeburn 5722: if (ref($navmapref)) {
5723: unless (ref($$navmapref)) {
5724: $$navmapref = Apache::lonnavmaps::navmap->new();
5725: }
5726: if (ref($$navmapref)) {
5727: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5728: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5729: unless (@resources) {
5730: $hiddenmap = 1;
5731: unless ($env{'request.role.adv'}) {
5732: $url = '';
5733: $hiddenfolder = 1;
5734: }
1.617 raeburn 5735: }
1.615 raeburn 5736: }
5737: }
5738: }
5739: }
1.617 raeburn 5740: unless ($encryptmap) {
1.620 raeburn 5741: if ((ref($navmapref)) && (ref($$navmapref))) {
5742: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5743: $encryptmap = 1;
5744: }
1.617 raeburn 5745: }
5746: }
1.630 raeburn 5747:
1.617 raeburn 5748: # Append randompick number, hidden, and encrypted with ":" to foldername,
5749: # so it gets transferred between levels
5750: $folderpath.=$containerarg.'&'.$foldername.
5751: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5752: unless ($url eq '') {
1.612 raeburn 5753: $url.='folderpath='.&escape($folderpath);
5754: }
1.510 raeburn 5755: my $rpckchk;
5756: if ($rpicknum) {
5757: $rpckchk = ' checked="checked"';
1.543 raeburn 5758: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5759: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5760: }
1.510 raeburn 5761: }
1.537 raeburn 5762: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5763: $rand_pick_text =
1.478 raeburn 5764: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5765: $form_param."\n".
1.478 raeburn 5766: $form_common."\n".
1.611 raeburn 5767: '<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 5768: if ($rpicknum ne '') {
5769: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5770: }
1.537 raeburn 5771: $rand_pick_text .= '</span></span>'.
5772: $form_end;
1.543 raeburn 5773: my $ro_set;
1.617 raeburn 5774: if ($randorder) {
1.543 raeburn 5775: $ro_set = 'checked="checked"';
5776: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5777: push(@{$filtersref->{'randomorder'}},$orderidx);
5778: }
5779: }
1.564 raeburn 5780: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5781: $rand_order_text =
1.537 raeburn 5782: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5783: $form_param."\n".
1.537 raeburn 5784: $form_common."\n".
1.611 raeburn 5785: '<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 5786: $form_end;
1.510 raeburn 5787: }
1.705 raeburn 5788: } elsif ($supplementalflag) {
1.598 raeburn 5789: my $isexttool;
1.626 raeburn 5790: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5791: $url='/adm/wrapper'.$url;
5792: $isexttool = 1;
5793: }
1.510 raeburn 5794: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5795: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5796: if ($title) {
1.687 raeburn 5797: $url .= '&title='.$encodedtitle;
1.510 raeburn 5798: }
1.598 raeburn 5799: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5800: $url .= '&idx='.$orderidx;
5801: }
1.610 raeburn 5802: if ($anchor ne '') {
5803: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5804: }
1.329 droeschl 5805: }
1.519 raeburn 5806: my ($tdalign,$tdwidth);
1.501 raeburn 5807: if ($allowed) {
1.630 raeburn 5808: my $fileloc =
1.501 raeburn 5809: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5810: if ($isexternal) {
1.630 raeburn 5811: ($editlink,$extresform) =
1.611 raeburn 5812: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5813: undef,undef,undef,undef,undef,undef,
5814: undef,$disabled);
1.626 raeburn 5815: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5816: ($editlink,$extresform) =
5817: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5818: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5819: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5820: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5821: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5822: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5823: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5824: my $suppanchor;
5825: if ($supplementalflag) {
5826: $suppanchor = $anchor;
5827: }
1.630 raeburn 5828: my $jscall =
1.501 raeburn 5829: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5830: $switchserver,
1.503 raeburn 5831: $forceedit,
1.679 raeburn 5832: undef,$symb,$shownsymb,
1.511 raeburn 5833: &escape($env{'form.folderpath'}),
1.622 raeburn 5834: $renametitle,$hostname,
5835: '','',1,$suppanchor);
1.501 raeburn 5836: if ($jscall) {
1.518 raeburn 5837: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5838: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5839: }
5840: }
5841: }
1.519 raeburn 5842: $tdalign = ' align="right" valign="top"';
5843: $tdwidth = ' width="80%"';
1.329 droeschl 5844: }
1.408 raeburn 5845: my $reinit;
5846: if ($crstype eq 'Community') {
5847: $reinit = &mt('(re-initialize community to access)');
5848: } else {
5849: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5850: }
1.702 raeburn 5851: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5852: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5853: $line.= '<br />';
5854: if ($curralias ne '') {
5855: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5856: $lt{'da'}.'</a></span>';
5857: } else {
5858: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5859: $lt{'sa'}.'</a></span>';
5860: }
5861: }
1.701 raeburn 5862: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5863: my ($link,$nolink);
1.472 raeburn 5864: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5865: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5866: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5867: $nolink = 1;
5868: }
5869: }
5870: if ($nolink) {
5871: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5872: } else {
5873: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5874: }
1.469 www 5875: } elsif ($url) {
1.610 raeburn 5876: if ($anchor ne '') {
5877: if ($supplementalflag) {
5878: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5879: } else {
5880: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5881: }
5882: }
1.705 raeburn 5883: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5884: $link = 'http://'.$hostname.$url;
5885: } else {
5886: $link = $url;
5887: }
1.705 raeburn 5888: my $inhibitmenu;
5889: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5890: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5891: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5892: $inhibitmenu = 'only_body=1';
5893: } else {
5894: $inhibitmenu = 'inhibitmenu=yes';
5895: }
5896: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5897: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5898: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5899: $nolink = 1;
5900: }
5901: }
5902: if ($nolink) {
5903: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5904: } elsif ($nomodal) {
1.621 raeburn 5905: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5906: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5907: } else {
5908: $line.=&Apache::loncommon::modal_link($link,
5909: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5910: }
1.469 www 5911: } else {
5912: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5913: }
1.519 raeburn 5914: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5915: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5916: if ($nolink) {
5917: $line.=$title;
5918: } else {
5919: $line.='<a href="'.$url.'">'.$title.'</a>';
5920: }
1.682 raeburn 5921: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5922: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5923: my $editurl = $url;
5924: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5925: $line .= ' '.'<a href="'.$editurl.'">'.
5926: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5927: '</a>';
5928: }
5929: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5930: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5931: }
1.469 www 5932: } elsif ($url) {
1.685 raeburn 5933: if ($nolink) {
5934: $line.=$title;
5935: } elsif ($nomodal) {
1.621 raeburn 5936: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5937: $title.'</a>';
5938: } else {
5939: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5940: }
1.617 raeburn 5941: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5942: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5943: } else {
5944: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5945: }
1.633 raeburn 5946: if (($allowed) && ($curralias ne '')) {
5947: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5948: } else {
5949: $line .= $extresform;
5950: }
5951: $line .= '</td>';
1.478 raeburn 5952: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5953: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5954: if ($uploaded && $url && !$isfolder && !$ispage) {
5955: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5956: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5957: }
5958: }
1.682 raeburn 5959: if ($allowed) {
5960: my %lt=&Apache::lonlocal::texthash(
5961: 'hd' => 'Hidden',
5962: 'ec' => 'URL hidden');
5963: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5964: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5965: $hidtext = ' checked="checked"';
1.694 raeburn 5966: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5967: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5968: }
5969: }
1.682 raeburn 5970: $formhidden = 'edit_hiddenresource_'.$orderidx;
5971: $line.=(<<ENDPARMS);
1.329 droeschl 5972: <td class="LC_docs_entry_parameter">
1.537 raeburn 5973: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5974: $form_param
1.478 raeburn 5975: $form_common
1.611 raeburn 5976: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5977: $form_end
1.682 raeburn 5978: ENDPARMS
5979: if ($folder =~/^supplemental/) {
5980: $line.= "\n <td>";
5981: } else {
5982: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5983: $enctext = ' checked="checked"';
5984: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5985: push(@{$filtersref->{'encrypturl'}},$orderidx);
5986: }
5987: }
5988: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5989: $line.=(<<ENDPARMS);
1.458 raeburn 5990: <br />
1.537 raeburn 5991: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5992: $form_param
1.478 raeburn 5993: $form_common
1.611 raeburn 5994: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5995: $form_end
5996: </td>
1.478 raeburn 5997: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5998: $rand_order_text</td>
1.329 droeschl 5999: ENDPARMS
1.682 raeburn 6000: }
1.329 droeschl 6001: }
1.379 bisitz 6002: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 6003: return $line;
6004: }
6005:
1.538 raeburn 6006: sub action_restrictions {
6007: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
6008: my %denied = (
6009: cut => 0,
6010: copy => 0,
6011: remove => 0,
6012: );
6013: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
6014: # no copy for published maps
6015: $denied{'copy'} = 1;
1.597 raeburn 6016: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
6017: unless ($1 eq 'simpleproblem') {
6018: $denied{'copy'} = 1;
6019: }
6020: $denied{'cut'} = 1;
1.538 raeburn 6021: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
6022: if ($folderpath =~ /^default&[^\&]+$/) {
6023: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
6024: $denied{'remove'} = 1;
6025: }
6026: $denied{'cut'} = 1;
6027: $denied{'copy'} = 1;
6028: }
6029: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
6030: my $group = $1;
6031: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
6032: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6033: $denied{'remove'} = 1;
6034: }
6035: }
6036: $denied{'cut'} = 1;
6037: $denied{'copy'} = 1;
6038: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
6039: my $group = $1;
6040: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
6041: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6042: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6043: if (keys(%groupsettings) > 0) {
6044: $denied{'remove'} = 1;
6045: }
6046: $denied{'cut'} = 1;
6047: $denied{'copy'} = 1;
6048: }
6049: }
6050: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
6051: my $group = $1;
6052: if ($url =~ /group_boards_\Q$group\E/) {
6053: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6054: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6055: if (keys(%groupsettings) > 0) {
6056: if (ref($groupsettings{'functions'}) eq 'HASH') {
6057: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
6058: $denied{'remove'} = 1;
6059: }
6060: }
6061: }
6062: $denied{'cut'} = 1;
6063: $denied{'copy'} = 1;
6064: }
6065: }
6066: }
6067: return %denied;
6068: }
6069:
1.533 raeburn 6070: sub new_timebased_suffix {
1.538 raeburn 6071: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 6072: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 6073: if ($type eq 'paste') {
6074: $prefix = $type;
6075: $namespace = 'courseeditor';
1.587 raeburn 6076: $idtype = 'addcode';
1.538 raeburn 6077: } elsif ($type eq 'map') {
1.533 raeburn 6078: $prefix = 'docs';
6079: if ($area eq 'supplemental') {
6080: $prefix = 'supp';
6081: }
6082: $prefix .= $container;
6083: $namespace = 'uploadedmaps';
6084: } else {
6085: $prefix = $type;
6086: $namespace = 'templated';
1.504 raeburn 6087: }
6088: my ($suffix,$freedlock,$error) =
1.587 raeburn 6089: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 6090: if (!$suffix) {
1.538 raeburn 6091: if ($type eq 'paste') {
6092: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
6093: } elsif ($type eq 'map') {
1.533 raeburn 6094: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
6095: } elsif ($type eq 'smppg') {
6096: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 6097: } elsif ($type eq 'exttool') {
6098: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 6099: } else {
1.565 bisitz 6100: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 6101: }
1.504 raeburn 6102: if ($error) {
6103: $errtext .= '<br />'.$error;
6104: }
6105: }
6106: if ($freedlock ne 'ok') {
1.630 raeburn 6107: $locknotfreed =
1.533 raeburn 6108: '<div class="LC_error">'.
6109: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 6110: if ($type eq 'paste') {
1.591 raeburn 6111: if ($freedlock eq 'nolock') {
6112: $locknotfreed =
6113: '<div class="LC_error">'.
6114: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
6115:
1.593 droeschl 6116: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 6117: } else {
6118: $locknotfreed .=
6119: &mt('This will prevent addition of items to the clipboard until your next log-in.');
6120: }
1.538 raeburn 6121: } elsif ($type eq 'map') {
1.591 raeburn 6122: $locknotfreed .=
6123: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 6124: } elsif ($type eq 'smppg') {
6125: $locknotfreed .=
6126: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 6127: } elsif ($type eq 'exttool') {
6128: $locknotfreed .=
6129: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 6130: } else {
6131: $locknotfreed .=
1.565 bisitz 6132: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 6133: }
1.538 raeburn 6134: unless ($type eq 'paste') {
6135: $locknotfreed .=
1.560 raeburn 6136: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
6137: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 6138: }
6139: $locknotfreed .= '</div>';
1.504 raeburn 6140: }
6141: return ($suffix,$errtext,$locknotfreed);
6142: }
6143:
1.329 droeschl 6144: =pod
6145:
6146: =item tiehash()
6147:
6148: tie the hash
6149:
6150: =cut
6151:
6152: sub tiehash {
6153: my ($mode)=@_;
6154: $hashtied=0;
6155: if ($env{'request.course.fn'}) {
6156: if ($mode eq 'write') {
6157: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6158: &GDBM_WRCREAT(),0640)) {
6159: $hashtied=2;
6160: }
6161: } else {
6162: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6163: &GDBM_READER(),0640)) {
6164: $hashtied=1;
6165: }
6166: }
1.364 bisitz 6167: }
1.329 droeschl 6168: }
6169:
6170: sub untiehash {
6171: if ($hashtied) { untie %hash; }
6172: $hashtied=0;
6173: return OK;
6174: }
6175:
6176:
6177:
6178:
6179: sub checkonthis {
1.637 raeburn 6180: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 6181: $url=&unescape($url);
6182: $alreadyseen{$url}=1;
6183: $r->rflush();
6184: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
6185: $r->print("\n<br />");
6186: if ($level==0) {
6187: $r->print("<br />");
6188: }
6189: for (my $i=0;$i<=$level*5;$i++) {
6190: $r->print(' ');
6191: }
6192: $r->print('<a href="'.$url.'" target="cat">'.
6193: ($title?$title:$url).'</a> ');
6194: if ($url=~/^\/res\//) {
1.637 raeburn 6195: my $updated;
6196: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
6197: ($url !~ /\.\d+\.\w+$/)) {
6198: $updated = &Apache::lonnet::remove_stale_resfile($url);
6199: }
1.329 droeschl 6200: my $result=&Apache::lonnet::repcopy(
6201: &Apache::lonnet::filelocation('',$url));
6202: if ($result eq 'ok') {
6203: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 6204: if ($updated) {
6205: $r->print('<br />');
6206: for (my $i=0;$i<=$level*5;$i++) {
6207: $r->print(' ');
6208: }
6209: $r->print('- '.&mt('Outdated copy removed'));
6210: }
1.329 droeschl 6211: $r->rflush();
6212: &Apache::lonnet::countacc($url);
6213: $url=~/\.(\w+)$/;
6214: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
6215: $r->print('<br />');
6216: $r->rflush();
6217: for (my $i=0;$i<=$level*5;$i++) {
6218: $r->print(' ');
6219: }
6220: $r->print('- '.&mt('Rendering:').' ');
6221: my ($errorcount,$warningcount)=split(/:/,
6222: &Apache::lonnet::ssi_body($url,
6223: ('grade_target'=>'web',
6224: 'return_only_error_and_warning_counts' => 1)));
6225: if (($errorcount) ||
6226: ($warningcount)) {
6227: if ($errorcount) {
1.369 bisitz 6228: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 6229: &mt('[quant,_1,error]',$errorcount).'</span>');
6230: }
6231: if ($warningcount) {
6232: $r->print('<span class="LC_warning">'.
6233: &mt('[quant,_1,warning]',$warningcount).'</span>');
6234: }
6235: } else {
6236: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
6237: }
6238: $r->rflush();
6239: }
6240: my $dependencies=
6241: &Apache::lonnet::metadata($url,'dependencies');
6242: foreach my $dep (split(/\,/,$dependencies)) {
6243: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 6244: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 6245: }
6246: }
6247: } elsif ($result eq 'unavailable') {
6248: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
6249: } elsif ($result eq 'not_found') {
6250: unless ($url=~/\$/) {
1.521 bisitz 6251: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 6252: } else {
1.366 bisitz 6253: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 6254: }
6255: } else {
6256: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
6257: }
1.637 raeburn 6258: if (($updated) && ($result ne 'ok')) {
6259: $r->print('<br />'.&mt('Outdated copy removed'));
6260: }
1.329 droeschl 6261: }
6262: }
6263: }
6264:
6265:
6266:
6267: =pod
6268:
6269: =item list_symbs()
6270:
1.485 raeburn 6271: List Content Identifiers
1.329 droeschl 6272:
6273: =cut
6274:
6275: sub list_symbs {
6276: my ($r) = @_;
6277:
1.408 raeburn 6278: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6279: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
6280: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
6281: $r->print(&startContentScreen('tools'));
1.329 droeschl 6282: my $navmap = Apache::lonnavmaps::navmap->new();
6283: if (!defined($navmap)) {
6284: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
6285: '<div class="LC_error">'.
6286: &mt('Unable to retrieve information about course contents').
6287: '</div>');
1.408 raeburn 6288: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 6289: } else {
1.484 raeburn 6290: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
6291: &Apache::loncommon::start_data_table().
6292: &Apache::loncommon::start_data_table_header_row().
6293: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
6294: &Apache::loncommon::end_data_table_header_row()."\n");
6295: my $count;
1.329 droeschl 6296: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 6297: $r->print(&Apache::loncommon::start_data_table_row().
6298: '<td>'.$res->compTitle().'</td>'.
6299: '<td>'.$res->symb().'</td>'.
1.521 bisitz 6300: &Apache::loncommon::end_data_table_row());
1.484 raeburn 6301: $count ++;
6302: }
6303: if (!$count) {
6304: $r->print(&Apache::loncommon::start_data_table_row().
6305: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
6306: &Apache::loncommon::end_data_table_row());
1.329 droeschl 6307: }
1.484 raeburn 6308: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 6309: }
1.521 bisitz 6310: $r->print(&endContentScreen());
1.329 droeschl 6311: }
6312:
1.651 raeburn 6313: sub short_urls {
6314: my ($r,$canedit) = @_;
6315: my $crstype = &Apache::loncommon::course_type();
6316: my $formname = 'shortenurl';
6317: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
6318: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
6319: $r->print(&startContentScreen('tools'));
6320: my ($navmap,$errormsg) =
6321: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
6322: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6323: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6324: my (%maps,%resources,%titles);
6325: if (!ref($navmap)) {
6326: $r->print($errormsg.
6327: &endContentScreen());
6328: return '';
6329: } else {
1.652 raeburn 6330: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6331: $r->rflush();
6332: my $readonly;
6333: if ($canedit) {
1.671 raeburn 6334: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6335: if ($numnew) {
6336: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6337: }
6338: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6339: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6340: foreach my $error (@{$errors}) {
6341: $r->print('<li>'.$error.'</li>');
6342: }
6343: $r->print('</ul><br />');
6344: }
6345: } else {
6346: $readonly = 1;
6347: }
6348: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6349: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6350: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6351: }
6352: $r->print(&endContentScreen());
6353: }
6354:
1.637 raeburn 6355: sub contentverifyform {
6356: my ($r) = @_;
6357: my $crstype = &Apache::loncommon::course_type();
6358: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6359: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6360: $r->print(&startContentScreen('tools'));
6361: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6362: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6363: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6364: ' <span class="LC_nobreak">'.
6365: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6366: &mt('No').'</label>'.(' 'x2).
6367: '<label><input type="radio" name="checkstale" value="1" />'.
6368: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6369: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6370: '<input type="hidden" value="1" name="tools" />'.
6371: '<input type="hidden" value="1" name="verify" /></p></form>');
6372: $r->print(&endContentScreen());
6373: return;
6374: }
1.329 droeschl 6375:
6376: sub verifycontent {
1.637 raeburn 6377: my ($r,$checkstale) = @_;
1.408 raeburn 6378: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6379: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6380: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6381: $r->print(&startContentScreen('tools'));
6382: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6383: $hashtied=0;
6384: undef %alreadyseen;
6385: %alreadyseen=();
6386: &tiehash();
1.484 raeburn 6387:
1.329 droeschl 6388: foreach my $key (keys(%hash)) {
6389: if ($hash{$key}=~/\.(page|sequence)$/) {
6390: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6391: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6392: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6393: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6394: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6395: }
6396: }
6397: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6398: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6399: }
6400: }
6401: &untiehash();
1.442 www 6402: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6403: $r->print(&endContentScreen());
1.329 droeschl 6404: }
6405:
6406: sub devalidateversioncache {
6407: my $src=shift;
6408: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6409: &Apache::lonnet::clutter($src));
6410: }
6411:
6412: sub checkversions {
1.611 raeburn 6413: my ($r,$canedit) = @_;
1.408 raeburn 6414: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6415: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6416: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6417: $r->print(&startContentScreen('tools'));
1.442 www 6418:
1.329 droeschl 6419: my $header='';
6420: my $startsel='';
6421: my $monthsel='';
6422: my $weeksel='';
6423: my $daysel='';
6424: my $allsel='';
6425: my %changes=();
6426: my $starttime=0;
6427: my $haschanged=0;
6428: my %setversions=&Apache::lonnet::dump('resourceversions',
6429: $env{'course.'.$env{'request.course.id'}.'.domain'},
6430: $env{'course.'.$env{'request.course.id'}.'.num'});
6431:
6432: $hashtied=0;
6433: &tiehash();
1.611 raeburn 6434: if ($canedit) {
6435: my %newsetversions=();
6436: if ($env{'form.setmostrecent'}) {
6437: $haschanged=1;
6438: foreach my $key (keys(%hash)) {
6439: if ($key=~/^ids\_(\/res\/.+)$/) {
6440: $newsetversions{$1}='mostrecent';
6441: &devalidateversioncache($1);
6442: }
6443: }
6444: } elsif ($env{'form.setcurrent'}) {
6445: $haschanged=1;
6446: foreach my $key (keys(%hash)) {
6447: if ($key=~/^ids\_(\/res\/.+)$/) {
6448: my $getvers=&Apache::lonnet::getversion($1);
6449: if ($getvers>0) {
6450: $newsetversions{$1}=$getvers;
6451: &devalidateversioncache($1);
6452: }
6453: }
1.329 droeschl 6454: }
1.611 raeburn 6455: } elsif ($env{'form.setversions'}) {
6456: $haschanged=1;
6457: foreach my $key (keys(%env)) {
6458: if ($key=~/^form\.set_version_(.+)$/) {
6459: my $src=$1;
6460: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6461: $newsetversions{$src}=$env{$key};
6462: &devalidateversioncache($src);
6463: }
6464: }
1.329 droeschl 6465: }
1.611 raeburn 6466: }
6467: if ($haschanged) {
6468: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6469: $env{'course.'.$env{'request.course.id'}.'.domain'},
6470: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6471: $r->print(&Apache::loncommon::confirmwrapper(
6472: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6473: } else {
6474: $r->print(&Apache::loncommon::confirmwrapper(
6475: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6476: }
1.611 raeburn 6477: &mark_hash_old();
6478: }
6479: &changewarning($r,'');
1.329 droeschl 6480: }
6481: if ($env{'form.timerange'} eq 'all') {
6482: # show all documents
1.549 raeburn 6483: $header=&mt('All content in '.$crstype);
1.521 bisitz 6484: $allsel=' selected="selected"';
1.329 droeschl 6485: foreach my $key (keys(%hash)) {
6486: if ($key=~/^ids\_(\/res\/.+)$/) {
6487: my $src=$1;
6488: $changes{$src}=1;
6489: }
6490: }
6491: } else {
6492: # show documents which changed
6493: %changes=&Apache::lonnet::dump
6494: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6495: $env{'course.'.$env{'request.course.id'}.'.num'});
6496: my $firstkey=(keys(%changes))[0];
6497: unless ($firstkey=~/^error\:/) {
6498: unless ($env{'form.timerange'}) {
6499: $env{'form.timerange'}=604800;
6500: }
6501: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6502: .&mt('seconds');
6503: if ($env{'form.timerange'}==-1) {
6504: $seltext='since start of course';
1.521 bisitz 6505: $startsel=' selected="selected"';
1.329 droeschl 6506: $env{'form.timerange'}=time;
6507: }
6508: $starttime=time-$env{'form.timerange'};
6509: if ($env{'form.timerange'}==2592000) {
6510: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6511: $monthsel=' selected="selected"';
1.329 droeschl 6512: } elsif ($env{'form.timerange'}==604800) {
6513: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6514: $weeksel=' selected="selected"';
1.329 droeschl 6515: } elsif ($env{'form.timerange'}==86400) {
6516: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6517: $daysel=' selected="selected"';
1.329 droeschl 6518: }
6519: $header=&mt('Content changed').' '.$seltext;
6520: } else {
6521: $header=&mt('No content modifications yet.');
6522: }
6523: }
6524: %setversions=&Apache::lonnet::dump('resourceversions',
6525: $env{'course.'.$env{'request.course.id'}.'.domain'},
6526: $env{'course.'.$env{'request.course.id'}.'.num'});
6527: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6528: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6529: 'lm' => 'Version changes since last Month',
6530: 'lw' => 'Version changes since last Week',
6531: 'sy' => 'Version changes since Yesterday',
6532: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6533: 'cd' => 'Change display',
1.329 droeschl 6534: 'sd' => 'Display',
6535: 'fi' => 'File',
6536: 'md' => 'Modification Date',
6537: 'mr' => 'Most recently published Version',
1.408 raeburn 6538: 've' => 'Version used in '.$crstype,
6539: 'vu' => 'Set Version to be used in '.$crstype,
6540: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6541: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6542: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6543: 'di' => 'Differences',
1.484 raeburn 6544: 'save' => 'Save changes',
6545: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6546: 'act' => 'Actions');
1.611 raeburn 6547: my ($disabled,$readonly);
6548: unless ($canedit) {
6549: $disabled = 'disabled="disabled"';
6550: $readonly = 1;
6551: }
1.329 droeschl 6552: $r->print(<<ENDHEADERS);
1.484 raeburn 6553: <h4 class="LC_info">$header</h4>
1.329 droeschl 6554: <form action="/adm/coursedocs" method="post">
6555: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6556: <div class="LC_left_float">
1.479 golterma 6557: <fieldset>
1.484 raeburn 6558: <legend>$lt{'cd'}</legend>
1.329 droeschl 6559: <select name="timerange">
1.521 bisitz 6560: <option value='all'$allsel>$lt{'al'}</option>
6561: <option value="-1"$startsel>$lt{'st'}</option>
6562: <option value="2592000"$monthsel>$lt{'lm'}</option>
6563: <option value="604800"$weeksel>$lt{'lw'}</option>
6564: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6565: </select>
6566: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6567: </fieldset>
6568: </div>
6569: <div class="LC_left_float">
6570: <fieldset>
6571: <legend>$lt{'act'}</legend>
1.611 raeburn 6572: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6573: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6574: </fieldset>
6575: </div>
6576: <br clear="all" />
6577: <hr />
6578: <h4>$lt{'vers'}</h4>
1.329 droeschl 6579: ENDHEADERS
1.479 golterma 6580: #number of columns for version history
1.571 raeburn 6581: my %changedbytime;
6582: foreach my $key (keys(%changes)) {
6583: #excludes not versionable problems from resource version history:
6584: next if ($key =~ /^\/res\/lib\/templates/);
6585: my $chg;
6586: if ($env{'form.timerange'} eq 'all') {
6587: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6588: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6589: } else {
6590: $chg = $changes{$key};
6591: next if ($chg < $starttime);
6592: }
6593: push(@{$changedbytime{$chg}},$key);
6594: }
6595: if (keys(%changedbytime) == 0) {
6596: &untiehash();
6597: $r->print(&mt('No content changes in imported content in specified time frame').
6598: &endContentScreen());
6599: return;
6600: }
1.479 golterma 6601: $r->print(
1.611 raeburn 6602: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6603: &Apache::loncommon::start_data_table().
6604: &Apache::loncommon::start_data_table_header_row().
6605: '<th>'.&mt('Resources').'</th>'.
6606: "<th>$lt{'mr'}</th>".
6607: "<th>$lt{'ve'}</th>".
6608: "<th>$lt{'vu'}</th>".
6609: '<th>'.&mt('History').'</th>'.
6610: &Apache::loncommon::end_data_table_header_row()
6611: );
1.571 raeburn 6612: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6613: foreach my $key (sort(@{$changedbytime{$chg}})) {
6614: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6615: my $currentversion=&Apache::lonnet::getversion($key);
6616: if ($currentversion<0) {
6617: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6618: }
6619: my $linkurl=&Apache::lonnet::clutter($key);
6620: $r->print(
6621: &Apache::loncommon::start_data_table_row().
6622: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6623: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6624: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6625: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6626: '<td align="right">'
6627: );
6628: # Used in course
6629: my $usedversion=$hash{'version_'.$linkurl};
6630: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6631: if ($usedversion != $currentversion) {
1.479 golterma 6632: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6633: } else {
1.479 golterma 6634: $r->print($usedversion);
6635: }
1.329 droeschl 6636: } else {
1.521 bisitz 6637: $r->print($currentversion);
1.329 droeschl 6638: }
1.571 raeburn 6639: $r->print('</td><td title="'.$lt{'vu'}.'">');
6640: # Set version
6641: $r->print(&Apache::loncommon::select_form(
6642: $setversions{$linkurl},
6643: 'set_version_'.$linkurl,
6644: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6645: '' => '',
6646: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6647: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6648: my $lastold=1;
6649: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6650: my $url=$root.'.'.$prevvers.'.'.$extension;
6651: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6652: $lastold=$prevvers;
6653: }
6654: }
6655: $r->print('</td>');
6656: # List all available versions
6657: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6658: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6659: my $url=$root.'.'.$prevvers.'.'.$extension;
6660: $r->print(
6661: '<span class="LC_nobreak">'
6662: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6663: .&mt('Version [_1]',$prevvers).'</a>'
6664: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6665: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6666: .')');
6667: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6668: $r->print(
6669: ' <a href="/adm/diff?filename='.
6670: &Apache::lonnet::clutter($root.'.'.$extension).
6671: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6672: '" target="diffs">'.&mt('Diffs').'</a>');
6673: }
6674: $r->print('</span><br />');
1.329 droeschl 6675: }
1.571 raeburn 6676: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6677: }
1.329 droeschl 6678: }
1.521 bisitz 6679: $r->print(
6680: &Apache::loncommon::end_data_table().
1.611 raeburn 6681: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6682: '</form>'
6683: );
1.329 droeschl 6684:
6685: &untiehash();
1.521 bisitz 6686: $r->print(&endContentScreen());
1.571 raeburn 6687: return;
1.329 droeschl 6688: }
6689:
6690: sub mark_hash_old {
6691: my $retie_hash=0;
6692: if ($hashtied) {
6693: $retie_hash=1;
6694: &untiehash();
6695: }
6696: &tiehash('write');
6697: $hash{'old'}=1;
6698: &untiehash();
6699: if ($retie_hash) { &tiehash(); }
6700: }
6701:
6702: sub is_hash_old {
6703: my $untie_hash=0;
6704: if (!$hashtied) {
6705: $untie_hash=1;
6706: &tiehash();
6707: }
6708: my $return=$hash{'old'};
6709: if ($untie_hash) { &untiehash(); }
6710: return $return;
6711: }
6712:
6713: sub changewarning {
6714: my ($r,$postexec,$message,$url)=@_;
6715: if (!&is_hash_old()) { return; }
6716: my $pathvar='folderpath';
6717: my $path=&escape($env{'form.folderpath'});
6718: if (!defined($url)) {
6719: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6720: }
6721: my $course_type = &Apache::loncommon::course_type();
6722: if (!defined($message)) {
6723: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6724: }
1.653 raeburn 6725: my $windowname = 'loncapaclient';
6726: if ($env{'request.lti.login'}) {
6727: $windowname .= 'lti';
6728: }
1.329 droeschl 6729: $r->print("\n\n".
1.372 bisitz 6730: '<script type="text/javascript">'."\n".
6731: '// <![CDATA['."\n".
6732: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6733: '// ]]>'."\n".
1.369 bisitz 6734: '</script>'."\n".
1.653 raeburn 6735: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6736: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6737: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6738: &mt($message,' <input type="hidden" name="'.
6739: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6740: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6741: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6742: }
6743:
6744:
6745: sub init_breadcrumbs {
1.571 raeburn 6746: my ($form,$text,$help)=@_;
1.329 droeschl 6747: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6748: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6749: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6750: faq=>273,
6751: bug=>'Instructor Interface',
1.571 raeburn 6752: help => $help});
1.329 droeschl 6753: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6754: text=>$text,
6755: faq=>273,
6756: bug=>'Instructor Interface'});
6757: }
6758:
1.441 www 6759: # subroutine to list form elements
6760: sub create_list_elements {
6761: my @formarr = @_;
6762: my $list = '';
1.501 raeburn 6763: foreach my $button (@formarr){
6764: foreach my $picture (keys(%{$button})) {
6765: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6766: }
6767: }
6768: return $list;
6769: }
1.329 droeschl 6770:
1.441 www 6771: # subroutine to create ul from list elements
6772: sub create_form_ul {
6773: my $list = shift;
6774: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6775: return $ul;
6776: }
1.329 droeschl 6777:
1.442 www 6778: #
6779: # Start tabs
6780: #
6781:
6782: sub startContentScreen {
1.484 raeburn 6783: my ($mode) = @_;
6784: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6785: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6786: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6787: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6788: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6789: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6790: } else {
1.549 raeburn 6791: $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 6792: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6793: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6794: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6795: }
6796: $output .= "\n".'</ul>'."\n";
6797: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6798: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6799: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6800: return $output;
1.442 www 6801: }
6802:
6803: #
6804: # End tabs
6805: #
6806:
6807: sub endContentScreen {
1.484 raeburn 6808: return '</div></div></div>';
1.442 www 6809: }
1.329 droeschl 6810:
1.446 www 6811: sub supplemental_base {
1.548 raeburn 6812: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6813: }
6814:
1.329 droeschl 6815: sub handler {
6816: my $r = shift;
6817: &Apache::loncommon::content_type($r,'text/html');
6818: $r->send_http_header;
6819: return OK if $r->header_only;
1.484 raeburn 6820:
6821: # get course data
1.408 raeburn 6822: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6823: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6824: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6825: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6826:
1.606 raeburn 6827: # get docroot
6828: my $londocroot = $r->dir_config('lonDocRoot');
6829:
1.484 raeburn 6830: # graphics settings
6831: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6832:
1.443 www 6833: #
1.329 droeschl 6834: # --------------------------------------------- Initialize help topics for this
6835: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6836: 'Adding_External_Resource','Adding_External_Tool',
6837: 'Navigate_Content','Adding_Folders','Docs_Overview',
6838: 'Load_Map','Supplemental','Score_Upload_Form',
6839: 'Adding_Pages','Importing_LON-CAPA_Resource',
6840: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6841: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6842: 'Standard_Problem','Course_Resources',
6843: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6844: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6845: }
6846: # Composite help files
6847: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6848: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6849: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6850: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6851: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6852: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6853: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6854: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6855: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6856: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6857:
1.611 raeburn 6858: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6859: # does this user have privileges to modify content.
6860: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6861: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6862: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6863: $allowed = 1;
1.682 raeburn 6864: }
6865: $canedit = 1;
6866: $canview = 1;
6867: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6868: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6869: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6870: $allowed = 1;
6871: }
1.682 raeburn 6872: $canview = 1;
1.611 raeburn 6873: }
6874: unless ($canedit) {
6875: $disabled = ' disabled="disabled"';
1.472 raeburn 6876: }
1.582 raeburn 6877: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6878: if ($env{'form.inhibitmenu'}) {
6879: unless ($env{'form.inhibitmenu'} eq 'yes') {
6880: delete($env{'form.inhibitmenu'});
6881: }
6882: }
6883:
1.582 raeburn 6884: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6885: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6886: if (!$canedit) {
6887: &verifycontent($r);
6888: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6889: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6890: text=>'Results',
6891: faq=>273,
6892: bug=>'Instructor Interface'});
6893: &verifycontent($r,$env{'form.checkstale'});
6894: } else {
6895: &contentverifyform($r);
6896: }
1.329 droeschl 6897: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6898: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6899: &list_symbs($r);
1.651 raeburn 6900: } elsif ($allowed && $env{'form.shorturls'}) {
6901: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6902: &short_urls($r,$canedit);
1.329 droeschl 6903: } elsif ($allowed && $env{'form.docslog'}) {
6904: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6905: my $folder = $env{'form.folder'};
6906: if ($folder eq '') {
6907: $folder='default';
6908: }
1.611 raeburn 6909: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6910: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6911: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6912: &checkversions($r,$canedit);
6913: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6914: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6915: &dumpcourse($r);
1.712 raeburn 6916: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
6917: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
6918: my $readonly;
6919: if (!$canedit) {
6920: $readonly = 1;
6921: }
6922: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6923: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6924: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6925: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6926: } else {
1.611 raeburn 6927: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6928: $noendpage = 1;
6929: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6930: if ($redirect) {
6931: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6932: my $container = 'sequence';
6933: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6934: $is_random_order,$container) =
6935: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6936: my (@folders)=split('&',$env{'form.folderpath'});
6937: $env{'form.foldername'}=&unescape(pop(@folders));
6938: my $folder=pop(@folders);
6939: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6940: $folder.'.'.$container);
6941: my $warning;
6942: if ($fatal) {
6943: if ($container eq 'page') {
6944: $warning = &mt('An error occurred retrieving the contents of the current page.');
6945: } else {
6946: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6947: }
6948: } else {
6949: my $url = $redirect;
6950: my $srcfile = $londocroot.$url;
6951: $url =~ s{^/priv/}{/res/};
6952: my $targetfile = $londocroot.$url;
6953: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6954: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6955: $env{'form.folder'} = $folder;
6956: &snapshotbefore();
6957: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6958: my $ext = 'false';
6959: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6960: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6961: ':'.$ext.':normal:res';
6962: push(@LONCAPA::map::order,$newidx);
6963: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6964: 'string_yesno');
6965: &remember_parms($newidx,'hiddenresource','set','yes');
6966: ($errtext,$fatal) =
6967: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6968: &log_differences($plain);
6969: &mark_hash_old();
6970: $r->internal_redirect($redirect);
6971: return OK;
6972: }
1.654 raeburn 6973: } else {
6974: $r->internal_redirect($redirect);
1.606 raeburn 6975: }
6976: }
6977: }
1.445 www 6978: #
6979: # Done catching special calls
1.484 raeburn 6980: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6981: # Get the parameters that may be needed
6982: #
6983: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6984: ['folderpath','title',
1.519 raeburn 6985: 'forcesupplement','forcestandard',
1.510 raeburn 6986: 'tools','symb','command','supppath']);
1.445 www 6987:
1.635 raeburn 6988: foreach my $item ('forcesupplement','forcestandard','tools') {
6989: next if ($env{'form.'.$item} eq '');
6990: unless ($env{'form.'.$item} eq '1') {
6991: delete($env{'form.'.$item});
6992: }
6993: }
6994:
6995: if ($env{'form.command'}) {
6996: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6997: delete($env{'form.command'});
6998: }
6999: }
7000:
7001: if ($env{'form.symb'}) {
7002: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
7003: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
7004: delete($env{'form.symb'});
7005: }
7006: }
7007:
1.445 www 7008: # standard=1: this is a "new-style" course with an uploaded map as top level
7009: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 7010:
7011: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 7012:
1.484 raeburn 7013: # Decide whether this should display supplemental or main content or utilities
1.445 www 7014: # supplementalflag=1: show supplemental documents
7015: # supplementalflag=0: show standard documents
1.484 raeburn 7016: # toolsflag=1: show utilities
1.445 www 7017:
1.561 raeburn 7018: my $unesc_folderpath = &unescape($env{'form.folderpath'});
7019: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
7020: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 7021: $supplementalflag=0;
7022: }
7023: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
7024: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 7025: unless (($supplementalflag) ||
7026: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
7027: unless ($allowed) { $supplementalflag=1; }
7028: unless ($standard) { $supplementalflag=1; }
7029: }
1.484 raeburn 7030: my $toolsflag=0;
7031: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 7032:
1.635 raeburn 7033: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7034: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 7035: }
7036:
1.685 raeburn 7037: my $backto_supppath;
1.635 raeburn 7038: if ($env{'form.supppath'} ne '') {
1.685 raeburn 7039: if ($supplementalflag && $allowed) {
7040: $backto_supppath = &validate_supppath($coursenum,$coursedom);
7041: }
1.635 raeburn 7042: }
7043:
1.329 droeschl 7044: my $script='';
7045: my $showdoc=0;
1.457 raeburn 7046: my $addentries = {};
1.475 raeburn 7047: my $container;
1.329 droeschl 7048: my $containertag;
1.508 raeburn 7049: my $pathitem;
1.598 raeburn 7050: my %ltitools;
1.699 raeburn 7051: my $posslti;
1.617 raeburn 7052: my $hiddentop;
1.615 raeburn 7053: my $navmap;
1.617 raeburn 7054: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 7055:
1.464 www 7056: # Do we directly jump somewhere?
1.525 raeburn 7057: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 7058: if ($env{'form.symb'} ne '') {
1.522 raeburn 7059: $env{'form.folderpath'}=
1.617 raeburn 7060: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 7061: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 7062: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 7063: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 7064: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 7065: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 7066: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 7067: }
1.472 raeburn 7068: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 7069: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 7070: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 7071: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 7072: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 7073: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
7074: } elsif ($env{'form.command'} eq 'contents') {
7075: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
7076: } elsif ($env{'form.command'} eq 'home') {
7077: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 7078: }
7079:
1.525 raeburn 7080:
1.445 www 7081: # Where do we store these for when we come back?
7082: my $stored_folderpath='docs_folderpath';
7083: if ($supplementalflag) {
7084: $stored_folderpath='docs_sup_folderpath';
7085: }
1.464 www 7086:
1.519 raeburn 7087: # No folderpath, and in edit mode, see if we have something stored
7088: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 7089: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 7090: {'folderpath' => 'scalar'});
1.615 raeburn 7091:
7092: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
7093: if ($supplementalflag) {
7094: undef($env{'form.folderpath'}) if ($1 eq 'default');
7095: } else {
7096: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
7097: }
7098: } else {
1.523 raeburn 7099: undef($env{'form.folderpath'});
7100: }
1.677 raeburn 7101: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7102: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 7103: }
1.329 droeschl 7104: }
1.706 raeburn 7105:
7106: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 7107: if ((!$allowed) && ($supplementalflag)) {
1.446 www 7108: unless ($env{'form.folderpath'} =~ /^supplemental/) {
7109: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 7110: }
7111: }
1.446 www 7112: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 7113: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 7114: $env{'form.folderpath'} = &supplemental_base()
7115: .'&'.
1.329 droeschl 7116: $env{'form.folderpath'};
7117: }
1.685 raeburn 7118: # If allowed and user's role is not advanced check folderpath is not hidden
7119: my $hidden_and_empty;
1.687 raeburn 7120: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 7121: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 7122: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 7123: my $folder = $pathitems[-2];
7124: if ($folder eq '') {
7125: undef($env{'form.folderpath'});
7126: } else {
7127: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 7128: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 7129: $folderurl .= '.page';
7130: } else {
7131: $folderurl .= '.sequence';
7132: }
1.685 raeburn 7133: if ($supplementalflag) {
7134: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
7135: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 7136: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 7137: if (ref($supplemental) eq 'HASH') {
7138: my ($suppmap,$suppmapnum);
7139: if ($folder eq 'supplemental') {
7140: $suppmap = 'default';
7141: $suppmapnum = 0;
7142: } elsif ($folder =~ /^supplemental_(\d+)$/) {
7143: $suppmap = $1;
7144: $suppmapnum = $suppmap;
7145: }
7146: if ($hiddenfolder) {
7147: my $hascontent;
7148: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
7149: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
7150: $hascontent = 1;
7151: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
7152: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
7153: if ($id =~ /^$suppmapnum\:/) {
7154: $hascontent = 1;
7155: last;
7156: }
7157: }
7158: }
7159: last if ($hascontent);
7160: }
7161: unless ($hascontent) {
7162: if ($foldername ne '') {
7163: $hidden_and_empty = $foldername;
7164: } else {
7165: $hidden_and_empty = $folder;
7166: }
7167: }
7168: }
7169: }
7170: } else {
7171: unless (ref($navmap)) {
7172: $navmap = Apache::lonnavmaps::navmap->new();
7173: }
7174: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
7175: $foldername = &HTML::Entities::decode(&unescape($foldername));
7176: if (ref($navmap)) {
7177: if ($hiddenfolder ||
7178: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
7179: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
7180: unless (@resources) {
7181: if ($foldername ne '') {
7182: $hidden_and_empty = $foldername;
7183: } else {
7184: $hidden_and_empty = $folder;
7185: }
7186: }
7187: }
7188: }
1.617 raeburn 7189: }
1.685 raeburn 7190: if ($hidden_and_empty ne '') {
7191: splice(@pathitems,-2);
7192: if (@pathitems) {
7193: $env{'form.folderpath'} = join('&',@pathitems);
7194: } else {
7195: undef($env{'form.folderpath'});
1.615 raeburn 7196: }
7197: }
7198: }
7199: }
7200:
1.446 www 7201: # If after all of this, we still don't have any paths, make them
1.519 raeburn 7202: unless ($env{'form.folderpath'}) {
1.446 www 7203: if ($supplementalflag) {
7204: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 7205: } elsif ($allowed) {
7206: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 7207: }
1.472 raeburn 7208: }
1.446 www 7209:
1.445 www 7210: # Store this
1.484 raeburn 7211: unless ($toolsflag) {
1.615 raeburn 7212: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 7213: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 7214: {'folderpath' => 'scalar'});
1.510 raeburn 7215: }
1.519 raeburn 7216: my $folderpath;
1.484 raeburn 7217: if ($env{'form.folderpath'}) {
1.519 raeburn 7218: $folderpath = $env{'form.folderpath'};
7219: my (@folders)=split('&',$env{'form.folderpath'});
7220: $env{'form.foldername'}=&unescape(pop(@folders));
7221: if ($env{'form.foldername'} =~ /\:1$/) {
7222: $container = 'page';
7223: } else {
7224: $container = 'sequence';
7225: }
7226: $env{'form.folder'}=pop(@folders);
1.484 raeburn 7227: } else {
1.519 raeburn 7228: if ($env{'form.folder'} eq '' ||
7229: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 7230: if ($env{'form.folder'} eq 'supplemental') {
7231: $folderpath=&supplemental_base();
7232: } elsif (!$hiddentop) {
7233: $folderpath='default&'.
7234: &escape(&mt('Main Content').':::::');
7235: }
1.484 raeburn 7236: }
7237: }
1.519 raeburn 7238: $containertag = '<input type="hidden" name="folderpath" value="" />';
7239: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 7240: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
7241: $showdoc='/'.$1;
7242: }
7243: if ($showdoc) { # got called in sequence from course
7244: $allowed=0;
7245: } else {
1.611 raeburn 7246: if ($canedit) {
1.484 raeburn 7247: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
7248: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 7249: }
7250: }
1.329 droeschl 7251: }
7252:
1.344 bisitz 7253: # get personal data
1.329 droeschl 7254: my $uname=$env{'user.name'};
7255: my $udom=$env{'user.domain'};
7256: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
7257:
7258: if ($allowed) {
1.484 raeburn 7259: if ($toolsflag) {
7260: $script .= &inject_data_js();
7261: my ($home,$other,%outhash)=&authorhosts();
7262: if (!$home && $other) {
7263: my @hosts;
7264: foreach my $aurole (keys(%outhash)) {
7265: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7266: push(@hosts,$outhash{$aurole});
7267: }
7268: }
7269: $script .= &dump_switchserver_js(@hosts);
7270: }
1.458 raeburn 7271: } else {
1.570 raeburn 7272: my $tid = 1;
1.484 raeburn 7273: my @tabids;
7274: if ($supplementalflag) {
1.655 raeburn 7275: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 7276: $tid = 2;
1.484 raeburn 7277: } else {
7278: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 7279: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 7280: unshift(@tabids,'001');
7281: push(@tabids,('dd1','ee1'));
7282: }
1.458 raeburn 7283: }
1.484 raeburn 7284: my $tabidstr = join("','",@tabids);
1.699 raeburn 7285: my (%domtools,%crstools);
7286: my %tooltypes = &Apache::loncommon::usable_exttools();
7287: if ($tooltypes{'dom'}) {
7288: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
7289: }
7290: if ($tooltypes{'crs'}) {
7291: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
7292: }
7293: %ltitools = (
7294: dom => \%domtools,
7295: crs => \%crstools,
7296: );
7297: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 7298: my $hostname = $r->hostname();
1.606 raeburn 7299: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 7300: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 7301: &history_tab_js().
7302: &inject_data_js().
1.570 raeburn 7303: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 7304: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 7305: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
7306: if ($hidden_and_empty ne '') {
7307: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
7308: $hidden_and_empty);
7309: $onload .= "javascript:alert('".&js_escape($alert)."');";
7310: }
1.484 raeburn 7311: $addentries = {
1.685 raeburn 7312: onload => $onload,
1.484 raeburn 7313: };
1.458 raeburn 7314: }
1.538 raeburn 7315: $script .= &paste_popup_js();
1.501 raeburn 7316: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
7317: &mt('Switch server?');
7318:
7319:
1.329 droeschl 7320: }
7321: # -------------------------------------------------------------------- Body tag
1.369 bisitz 7322: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 7323: .'// <![CDATA['."\n"
7324: .$script."\n"
7325: .'// ]]>'."\n"
1.595 musolffc 7326: .'</script>'."\n"
7327: .'<script type="text/javascript"
7328: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 7329:
7330: # Breadcrumbs
7331: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7332:
7333: if ($showdoc) {
1.682 raeburn 7334: my $args;
7335: if ($supplementalflag) {
1.687 raeburn 7336: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7337: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7338: $args = {'bread_crumbs' => $brcrum,
7339: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7340: } else {
7341: $args = {'force_register' => $showdoc};
7342: }
7343: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7344: } elsif ($toolsflag) {
1.611 raeburn 7345: my ($breadtext,$breadtitle);
1.617 raeburn 7346: $breadtext = "$crstype Editor";
1.611 raeburn 7347: if ($canedit) {
7348: $breadtitle = 'Editing '.$crstype.' Contents';
7349: } else {
7350: $breadtext .= ' (View-only mode)';
7351: $breadtitle = 'Viewing '.$crstype.' Contents';
7352: }
1.571 raeburn 7353: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7354: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7355: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7356: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7357: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7358: $breadtitle)
1.571 raeburn 7359: );
1.510 raeburn 7360: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7361: unless ($env{'request.role.adv'}) {
7362: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7363: $r->internal_redirect('/adm/navmaps');
7364: return OK;
7365: }
7366: }
1.510 raeburn 7367: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7368: my $args = {'bread_crumbs' => $brcrum};
7369: unless (($env{'form.folderpath'} eq '') ||
7370: ($env{'form.folder'} eq 'supplemental')) {
7371: $args->{'bread_crumbs_nomenu'} = 1;
7372: }
1.510 raeburn 7373: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7374: $args));
1.510 raeburn 7375: } else {
1.611 raeburn 7376: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7377: $breadtext = "$crstype Editor";
1.611 raeburn 7378: if ($canedit) {
7379: $breadtitle = 'Editing '.$crstype.' Contents';
7380: $helpitem = 'Docs_Adding_Course_Doc';
7381: } else {
7382: $breadtext .= ' (View-only mode)';
7383: $breadtitle = 'Viewing '.$crstype.' Contents';
7384: $helpitem = 'Docs_Viewing_Course_Doc';
7385: }
1.392 raeburn 7386: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7387: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7388: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7389: {'add_entries' => $addentries}
7390: )
1.392 raeburn 7391: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7392: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7393: $breadtitle,
7394: $helpitem)
1.392 raeburn 7395: );
7396: }
1.364 bisitz 7397:
1.329 droeschl 7398: my %allfiles = ();
7399: my %codebase = ();
1.440 raeburn 7400: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7401: if ($canedit) {
1.684 raeburn 7402: undef($suppchanges);
1.329 droeschl 7403: if (($env{'form.uploaddoc.filename'}) &&
7404: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7405: my $context = $1;
7406: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7407: undef($hadchanges);
1.440 raeburn 7408: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7409: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7410: undef($navmap);
1.329 droeschl 7411: if ($hadchanges) {
7412: &mark_hash_old();
7413: }
1.684 raeburn 7414: if ($suppchanges) {
7415: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7416: undef($suppchanges);
7417: }
1.440 raeburn 7418: $r->print($upload_output);
7419: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7420: # Process file upload - phase two - upload embedded objects
7421: $uploadphase = 'check_embedded';
7422: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7423: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7424: $env{'form.newidx'});
7425: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7426: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7427: my ($destination,$dir_root) = &embedded_destination();
7428: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7429: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7430: my ($result,$flag) =
1.440 raeburn 7431: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7432: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7433: $actionurl);
7434: $r->print($result.&return_to_editor());
7435: } elsif ($env{'form.phase'} eq 'check_embedded') {
7436: # Process file upload - phase three - modify references in HTML file
7437: $uploadphase = 'modified_orightml';
7438: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7439: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7440: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7441: my $result =
1.482 raeburn 7442: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7443: $docuname,$docudom,undef,
7444: $dir_root);
1.630 raeburn 7445: $r->print($result.&return_to_editor());
1.476 raeburn 7446: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7447: $uploadphase = 'decompress_phase_one';
7448: $r->print(&decompression_phase_one().
7449: &return_to_editor());
7450: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7451: $uploadphase = 'decompress_phase_two';
7452: $r->print(&decompression_phase_two().
7453: &return_to_editor());
1.329 droeschl 7454: }
7455: }
7456:
1.484 raeburn 7457: if ($allowed && $toolsflag) {
7458: $r->print(&startContentScreen('tools'));
1.708 raeburn 7459: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7460: $r->print(&endContentScreen());
7461: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7462: # -----------------------------------------------------------------------------
7463: my %lt=&Apache::lonlocal::texthash(
7464: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7465: 'upfi' => 'Upload File',
1.553 raeburn 7466: 'upld' => 'Upload Content',
1.706 raeburn 7467: 'srch' => 'Search Repository',
7468: 'impo' => 'Import from Repository',
1.487 raeburn 7469: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7470: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7471: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7472: 'extr' => 'External Resource',
7473: 'extt' => 'External Tool',
1.329 droeschl 7474: 'selm' => 'Select Map',
7475: 'load' => 'Load Map',
7476: 'newf' => 'New Folder',
7477: 'newp' => 'New Composite Page',
7478: 'syll' => 'Syllabus',
1.425 raeburn 7479: 'navc' => 'Table of Contents',
1.343 biermanm 7480: 'sipa' => 'Simple Course Page',
1.329 droeschl 7481: 'sipr' => 'Simple Problem',
1.630 raeburn 7482: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7483: 'stpr' => 'Standard Problem',
7484: 'news' => 'New sub-directory',
7485: 'crpr' => 'Create Problem',
1.689 raeburn 7486: 'swit' => 'Switch Server',
1.329 droeschl 7487: 'drbx' => 'Drop Box',
1.451 www 7488: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7489: 'bull' => 'Discussion Board',
1.347 weissno 7490: 'mypi' => 'My Personal Information Page',
1.353 weissno 7491: 'grpo' => 'Group Portfolio',
1.329 droeschl 7492: 'rost' => 'Course Roster',
1.528 raeburn 7493: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7494: 'imsf' => 'IMS Upload',
7495: 'imsl' => 'Upload IMS package',
1.501 raeburn 7496: 'cms' => 'Origin of IMS package',
7497: 'se' => 'Select',
1.329 droeschl 7498: 'file' => 'File',
7499: 'title' => 'Title',
1.606 raeburn 7500: 'addp' => 'Add Placeholder to course?',
7501: 'uste' => 'Use Template?',
7502: 'fnam' => 'File Name:',
7503: 'loca' => 'Location:',
7504: 'dire' => 'Directory:',
7505: 'cate' => 'Category:',
7506: 'tmpl' => 'Template:',
1.698 raeburn 7507: 'empd' => 'No resources found',
1.329 droeschl 7508: 'comment' => 'Comment',
1.403 raeburn 7509: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7510: 'bb5' => 'Blackboard 5',
7511: 'bb6' => 'Blackboard 6',
7512: 'angel5' => 'ANGEL 5.5',
7513: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7514: 'yes' => 'Yes',
7515: 'no' => 'No',
1.618 raeburn 7516: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7517: );
1.329 droeschl 7518: # -----------------------------------------------------------------------------
1.595 musolffc 7519:
7520: # Calculate free quota space for a user or course. A javascript function checks
7521: # file size to determine if upload should be allowed.
7522: my $quotatype = 'unofficial';
7523: if ($crstype eq 'Community') {
1.601 raeburn 7524: $quotatype = 'community';
7525: } elsif ($crstype eq 'Placement') {
7526: $quotatype = 'placement';
1.595 musolffc 7527: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7528: $quotatype = 'official';
7529: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7530: $quotatype = 'textbook';
7531: }
7532: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7533: 'course',$quotatype); # expressed in MB
7534: my $current_disk_usage = 0;
7535: foreach my $subdir ('docs','supplemental') {
7536: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7537: "userfiles/$subdir",1); # expressed in kB
7538: }
7539: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7540: my $usage = $current_disk_usage/1024; # in MB
7541: my $quota = $disk_quota;
7542: my $percent;
7543: if ($disk_quota == 0) {
7544: $percent = 100.0;
7545: } else {
1.619 raeburn 7546: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7547: }
7548: $usage = sprintf("%.2f",$usage);
7549: $quota = sprintf("%.2f",$quota);
7550: $percent = sprintf("%.0f",$percent);
7551: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7552: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7553:
1.329 droeschl 7554: my $fileupload=(<<FIUP);
1.605 raeburn 7555: $quotainfo
1.329 droeschl 7556: $lt{'file'}:<br />
7557: FIUP
7558: my $checkbox=(<<CHBO);
7559: <!-- <label>$lt{'parse'}?
7560: <input type="checkbox" name="parserflag" />
7561: </label> -->
7562: <label>
1.611 raeburn 7563: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7564: </label>
7565: CHBO
1.501 raeburn 7566: my $imsfolder = $env{'form.folder'};
7567: if ($imsfolder eq '') {
7568: $imsfolder = 'default';
7569: }
7570: my $imspform=(<<IMSFORM);
7571: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7572: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7573: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7574: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7575: <legend>$lt{'imsf'}</legend>
7576: $fileupload
1.702 raeburn 7577: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7578: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7579: <br />
7580: <p>
7581: $lt{'cms'}:
1.611 raeburn 7582: <select name="source" $disabled>
1.501 raeburn 7583: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7584: <option value="bb5">$lt{'bb5'}</option>
7585: <option value="bb6">$lt{'bb6'}</option>
7586: <option value="angel5">$lt{'angel5'}</option>
7587: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7588: </select>
7589: <input type="hidden" name="folder" value="$imsfolder" />
7590: </p>
7591: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7592: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7593: </fieldset>
7594: </form>
7595: IMSFORM
1.329 droeschl 7596:
7597: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7598: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7599: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7600: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7601: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7602: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7603: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7604: $fileupload
1.702 raeburn 7605: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7606: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7607: <br />
7608: $lt{'title'}:<br />
1.611 raeburn 7609: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7610: $pathitem
1.329 droeschl 7611: <input type="hidden" name="cmd" value="upload_default" />
7612: <br />
1.458 raeburn 7613: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7614: $checkbox
7615: </span>
1.501 raeburn 7616: <br clear="all" />
1.611 raeburn 7617: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7618: </fieldset>
7619: </form>
1.383 tempelho 7620: FUFORM
1.329 droeschl 7621:
1.611 raeburn 7622: my $mapimportjs;
7623: if ($canedit) {
7624: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7625: } else {
7626: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7627: }
1.502 raeburn 7628: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7629: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7630: $lt{'impm'}</a>$help{'Load_Map'}
7631: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7632: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7633: <legend>$lt{'impm'}</legend>
1.371 tempelho 7634: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7635: $lt{'copm'}<br />
7636: <span class="LC_nobreak">
7637: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7638: onfocus="this.blur();$mapimportjs" $disabled />
7639: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7640: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7641: </fieldset>
7642: </form>
7643:
1.383 tempelho 7644: SEDFFORM
1.706 raeburn 7645: my ($importcrsresform,$checkcrsres);
7646: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7647: $checkcrsres = 1;
7648: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7649: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7650: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7651: unless (($type eq 'community') || ($type eq 'placement')) {
7652: $type = 'unofficial';
7653: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7654: $type = 'official';
7655: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7656: $type = 'textbook';
7657: } else {
7658: $type = 'unofficial';
7659: }
7660: }
7661: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7662: $checkcrsres = 1;
7663: }
7664: }
7665: if ($checkcrsres) {
7666: my ($numdirs,$pickfile) =
7667: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7668: "resize_scrollbox('contentscroll','1','0');",
7669: undef,'res');
7670: if ($pickfile) {
7671: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7672: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7673: $lt{'imcr'}</a>$help{'Course_Resources'}
7674: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7675: <fieldset id="importcrsresform" style="display: none;">
7676: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7677: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7678: <input type="hidden" name="active" value="bb" />
7679: $pickfile
7680: <p>
1.699 raeburn 7681: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7682: </p>
7683: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7684: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7685: </div>
7686: <div id="importcrsresempty" style="display: none;">
7687: <p>
7688: $lt{'empd'}
7689: </p>
7690: </div>
1.606 raeburn 7691: </fieldset>
7692: </form>
7693: CRSFORM
1.706 raeburn 7694: }
1.606 raeburn 7695: }
7696:
1.611 raeburn 7697: my $fromstoredjs;
7698: if ($canedit) {
7699: $fromstoredjs = 'open_StoredLinks_Import()';
7700: } else {
7701: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7702: }
7703:
1.502 raeburn 7704: my @importpubforma = (
1.706 raeburn 7705: { '<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 7706: { '<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 7707: { '<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 7708: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7709: );
1.706 raeburn 7710: if ($importcrsresform) {
7711: 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 7712: }
1.502 raeburn 7713: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7714: my $extresourcesform =
7715: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7716: $help{'Adding_External_Resource'},
7717: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7718: my $exttoolform =
7719: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7720: $help{'Adding_External_Tool'},undef,
7721: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7722: \%ltitools,$disabled);
1.329 droeschl 7723: if ($allowed) {
1.492 raeburn 7724: my $folder = $env{'form.folder'};
7725: if ($folder eq '') {
7726: $folder='default';
7727: }
1.615 raeburn 7728: if ($canedit) {
7729: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7730: if ($output) {
7731: $r->print($output);
7732: }
1.538 raeburn 7733: }
1.337 ehlerst 7734: $r->print(<<HIDDENFORM);
7735: <form name="renameform" method="post" action="/adm/coursedocs">
7736: <input type="hidden" name="title" />
7737: <input type="hidden" name="cmd" />
7738: <input type="hidden" name="markcopy" />
7739: <input type="hidden" name="copyfolder" />
7740: $containertag
7741: </form>
1.633 raeburn 7742: <form name="aliasform" method="post" action="/adm/coursedocs">
7743: <input type="hidden" name="alias" />
7744: <input type="hidden" name="cmd" />
7745: $containertag
7746: </form>
1.484 raeburn 7747:
1.337 ehlerst 7748: HIDDENFORM
1.508 raeburn 7749: $r->print(&makesimpleeditform($pathitem)."\n".
7750: &makedocslogform($pathitem."\n".
1.484 raeburn 7751: '<input type="hidden" name="folder" value="'.
7752: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7753: }
1.442 www 7754:
7755: # Generate the tabs
1.510 raeburn 7756: my ($mode,$needs_end);
1.472 raeburn 7757: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7758: my @folders = split('&',$env{'form.folderpath'});
7759: unless (@folders > 2) {
7760: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7761: $needs_end = 1;
7762: }
1.472 raeburn 7763: } else {
1.484 raeburn 7764: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7765: $needs_end = 1;
1.472 raeburn 7766: }
1.443 www 7767:
1.442 www 7768: #
1.622 raeburn 7769: my $hostname = $r->hostname();
1.442 www 7770: my $savefolderpath;
7771:
1.395 raeburn 7772: if ($allowed) {
1.329 droeschl 7773: my $folder=$env{'form.folder'};
1.615 raeburn 7774: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7775: $folder='default';
1.356 tempelho 7776: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7777: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7778: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7779: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7780: }
7781: my $postexec='';
7782: if ($folder eq 'default') {
1.653 raeburn 7783: my $windowname = 'loncapaclient';
7784: if ($env{'request.lti.login'}) {
7785: $windowname .= 'lti';
7786: }
1.372 bisitz 7787: $r->print('<script type="text/javascript">'."\n"
7788: .'// <![CDATA['."\n"
1.653 raeburn 7789: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7790: .'// ]]>'."\n"
7791: .'</script>'."\n"
1.369 bisitz 7792: );
1.329 droeschl 7793: } else {
7794: #$postexec='self.close();';
7795: }
1.504 raeburn 7796: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7797: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7798: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7799:
7800: my $newnavform=(<<NNFORM);
7801: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7802: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7803: $pathitem
1.329 droeschl 7804: <input type="hidden" name="importdetail"
7805: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7806: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7807: $help{'Navigate_Content'}
7808: </form>
7809: NNFORM
7810: my $newsmppageform=(<<NSPFORM);
7811: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7812: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7813: $pathitem
1.329 droeschl 7814: <input type="hidden" name="importdetail" value="" />
1.423 onken 7815: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7816: $help{'Simple Page'}
1.329 droeschl 7817: </form>
7818: NSPFORM
7819:
7820: my $newsmpproblemform=(<<NSPROBFORM);
7821: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7822: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7823: $pathitem
1.329 droeschl 7824: <input type="hidden" name="importdetail" value="" />
1.423 onken 7825: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7826: $help{'Simple_Problem'}
1.329 droeschl 7827: </form>
7828:
7829: NSPROBFORM
7830:
7831: my $newdropboxform=(<<NDBFORM);
7832: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7833: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7834: $pathitem
1.329 droeschl 7835: <input type="hidden" name="importdetail" value="" />
1.423 onken 7836: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7837: $help{'Dropbox'}
1.344 bisitz 7838: </form>
1.329 droeschl 7839: NDBFORM
7840:
7841: my $newexuploadform=(<<NEXUFORM);
7842: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7843: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7844: $pathitem
1.329 droeschl 7845: <input type="hidden" name="importdetail" value="" />
1.423 onken 7846: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7847: $help{'Score_Upload_Form'}
7848: </form>
7849: NEXUFORM
7850:
7851: my $newbulform=(<<NBFORM);
7852: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7853: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7854: $pathitem
1.329 droeschl 7855: <input type="hidden" name="importdetail" value="" />
1.423 onken 7856: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7857: $help{'Bulletin Board'}
7858: </form>
7859: NBFORM
7860:
7861: my $newaboutmeform=(<<NAMFORM);
7862: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7863: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7864: $pathitem
1.329 droeschl 7865: <input type="hidden" name="importdetail"
7866: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7867: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7868: $help{'My Personal Information Page'}
1.329 droeschl 7869: </form>
7870: NAMFORM
7871:
7872: my $newaboutsomeoneform=(<<NASOFORM);
7873: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7874: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7875: $pathitem
1.329 droeschl 7876: <input type="hidden" name="importdetail" value="" />
1.423 onken 7877: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7878: </form>
7879: NASOFORM
7880:
7881: my $newrosterform=(<<NROSTFORM);
7882: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7883: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7884: $pathitem
1.329 droeschl 7885: <input type="hidden" name="importdetail"
7886: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7887: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7888: $help{'Course_Roster'}
1.329 droeschl 7889: </form>
7890: NROSTFORM
7891:
1.534 raeburn 7892: my $newwebpage;
7893: if ($folder =~ /^default_?(\d*)$/) {
7894: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7895: if ($1) {
7896: $newwebpage .= $1;
7897: } else {
7898: $newwebpage .= 'default';
7899: }
7900: $newwebpage .= '/new.html';
7901: }
7902: my $newwebpageform =(<<NWEBFORM);
7903: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7904: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7905: $pathitem
7906: <input type="hidden" name="importdetail" value="$newwebpage" />
7907: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7908: $help{'Web_Page'}
1.534 raeburn 7909: </form>
7910: NWEBFORM
1.701 raeburn 7911: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7912: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7913: my $machines_str = "'".join("','",@ids)."'";
7914: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7915: if ($env{'user.author'}) {
7916: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7917: $is_home{'author'} = 1;
1.606 raeburn 7918: }
1.691 raeburn 7919: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7920: }
7921: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7922: ['active'],['ca','aa']);
1.691 raeburn 7923: my %by_roletype;
1.606 raeburn 7924: if (keys(%roleshash)) {
7925: foreach my $entry (keys(%roleshash)) {
7926: my ($auname,$audom,$roletype) = split(/:/,$entry);
7927: my $key = $entry;
7928: $key =~ s/:/___/g;
1.691 raeburn 7929: my $author = $auname.'___'.$audom;
7930: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7931: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7932: $toppath{$author} = "/priv/$audom/$auname";
7933: if (grep(/^\Q$rolehome\E$/,@ids)) {
7934: $is_home{$author} = 1;
1.606 raeburn 7935: }
1.691 raeburn 7936: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7937: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7938: }
1.691 raeburn 7939: }
7940: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7941: if (grep(/^\Q$crshome\E$/,@ids)) {
7942: $is_home{'course'} = 1;
7943: }
7944: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7945: my $pickdir = $lt{'loca'}.
7946: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7947: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7948: if ($env{'user.author'}) {
7949: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7950: }
7951: if (keys(%by_roletype)) {
7952: foreach my $possrole ('ca','aa') {
7953: if (ref($by_roletype{$possrole}) eq 'HASH') {
7954: my $roletitle = &Apache::lonnet::plaintext($possrole);
7955: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7956: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7957: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7958: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7959: }
7960: }
7961: }
7962: }
1.706 raeburn 7963: if ($checkcrsres) {
7964: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7965: }
7966: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7967: $lt{'dire'}.
7968: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7969: '<option value=""></option>'.
7970: '</select><br />'."\n";
1.606 raeburn 7971: my %seltemplate_menus;
7972: my @files = &Apache::lonhomework::get_template_list('problem');
7973: my @noexamplelink = ('blank.problem','blank.library','script.library');
7974: my $currentcategory = '';
7975: my @ordered = ('');
7976: my %templatehelp;
7977: my $defcategory = '';
7978: my @catorder = ($defcategory);
7979: $seltemplate_menus{$defcategory}->{'order'} = [''];
7980: $seltemplate_menus{$defcategory}->{'text'} = '';
7981: foreach my $file (@files) {
7982: if (ref($file) eq 'ARRAY') {
7983: my ($path,$title,$category,$help) = @{$file};
7984: next if ($title !~ /\S/);
7985: if (&js_escape($category) ne $currentcategory) {
7986: $currentcategory = &js_escape($category);
7987: push(@catorder,&js_escape($currentcategory));
7988: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7989: $seltemplate_menus{$currentcategory}->{'default'} = '';
7990: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7991: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7992: }
7993: if ($path) {
7994: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7995: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7996: if ($help) {
7997: $templatehelp{$path} = $help;
7998: }
7999: }
8000: }
8001: }
8002:
8003: my $templates = $lt{'cate'}.' '.
8004: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
8005: $defcategory,'tempcategory','template',
8006: \%seltemplate_menus,\@catorder,
8007: "resize_scrollbox('contentscroll','1','0');",
8008: "toggleExampleText();",'template').'<br />';
8009: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 8010: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 8011: my $crsresform;
8012: if (($env{'user.author'}) || ($checkcrsres)) {
8013: $crsresform=(<<RESFORM);
1.691 raeburn 8014: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 8015: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 8016: <form action="/adm/coursedocs" method="post" name="courseresform">
8017: <fieldset id="crsresform" style="display:none;">
8018: <legend>$lt{'stpr'}</legend>
1.655 raeburn 8019: <input type="hidden" name="active" value="bb" />
1.606 raeburn 8020: <p>
8021: $pickdir
1.701 raeburn 8022: </p>
1.691 raeburn 8023: <div id="newstdproblem" style="display:none;">
1.701 raeburn 8024: <p>
1.606 raeburn 8025: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 8026: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 8027:
1.611 raeburn 8028: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 8029: </span><span id="newsubdir"></span>
8030: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 8031: </p>
1.699 raeburn 8032: </div>
1.606 raeburn 8033: $lt{'fnam'}
1.611 raeburn 8034: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 8035: <div id="newresource" style="display:none">
1.606 raeburn 8036: <p>
8037: $lt{'addp'}
1.611 raeburn 8038: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8039: $lt{'no'}</label>
1.611 raeburn 8040: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8041: $lt{'yes'}</label>
8042: <span id="newrestitle"></span>
1.611 raeburn 8043: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 8044: </p>
1.606 raeburn 8045: </div>
8046: <p>
8047: $lt{'uste'}
1.611 raeburn 8048: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8049: $lt{'no'}</label>
1.611 raeburn 8050: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8051: $lt{'yes'}</label>
1.701 raeburn 8052: </p>
1.606 raeburn 8053: <div id="newrestemplate" style="display:none">
8054: $templates
8055: $templatepreview
8056: </div>
8057: <span class="LC_nobreak">
1.701 raeburn 8058: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 8059: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 8060: </span>
1.691 raeburn 8061: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 8062: $rolehomes
8063: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
8064: </div>
1.606 raeburn 8065: </fieldset>
8066: </form>
8067:
8068: RESFORM
1.706 raeburn 8069: }
1.534 raeburn 8070:
1.342 ehlerst 8071: my $specialdocumentsform;
1.383 tempelho 8072: my @specialdocumentsforma;
1.451 www 8073: my $gradingform;
8074: my @gradingforma;
8075: my $communityform;
8076: my @communityforma;
1.351 ehlerst 8077: my $newfolderform;
1.390 tempelho 8078: my $newfolderb;
1.342 ehlerst 8079:
1.451 www 8080: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 8081:
1.329 droeschl 8082: my $newpageform=(<<NPFORM);
8083: <form action="/adm/coursedocs" method="post" name="newpage">
8084: <input type="hidden" name="folderpath" value="$path" />
8085: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8086: <input type="hidden" name="active" value="ee" />
1.423 onken 8087: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 8088: $help{'Adding_Pages'}
1.329 droeschl 8089: </form>
8090: NPFORM
1.390 tempelho 8091:
8092:
1.351 ehlerst 8093: $newfolderform=(<<NFFORM);
1.329 droeschl 8094: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 8095: $pathitem
1.329 droeschl 8096: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8097: <input type="hidden" name="active" value="" />
1.422 onken 8098: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 8099: </form>
8100: NFFORM
8101:
8102: my $newsylform=(<<NSYLFORM);
8103: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 8104: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8105: $pathitem
1.329 droeschl 8106: <input type="hidden" name="importdetail"
8107: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8108: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 8109: $help{'Syllabus'}
1.383 tempelho 8110:
1.329 droeschl 8111: </form>
8112: NSYLFORM
1.364 bisitz 8113:
1.329 droeschl 8114: my $newgroupfileform=(<<NGFFORM);
8115: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 8116: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8117: $pathitem
1.329 droeschl 8118: <input type="hidden" name="importdetail"
8119: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 8120: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 8121: $help{'Group Portfolio'}
1.329 droeschl 8122: </form>
8123: NGFFORM
1.672 raeburn 8124: if ($container eq 'page') {
8125: @specialdocumentsforma=(
8126: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
8127: );
8128: } else {
8129: @specialdocumentsforma=(
1.421 onken 8130: {'<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 8131: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 8132: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 8133: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 8134: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 8135: );
8136: }
1.451 www 8137: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
8138:
1.655 raeburn 8139: my @external = (
8140: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 8141: );
1.699 raeburn 8142: if ($posslti) {
1.655 raeburn 8143: push(@external,
8144: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
8145: );
1.598 raeburn 8146: }
1.655 raeburn 8147: my $externalform = &create_form_ul(&create_list_elements(@external));
8148:
8149: my @importdoc = ();
1.519 raeburn 8150: unless ($container eq 'page') {
8151: push(@importdoc,
8152: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
8153: );
8154: }
8155: push(@importdoc,
1.558 raeburn 8156: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 8157: );
1.501 raeburn 8158: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 8159:
1.451 www 8160: @gradingforma=(
8161: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
8162: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 8163: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 8164: );
1.706 raeburn 8165: if ($crsresform) {
8166: push(@gradingforma,
8167: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
8168: );
8169: }
1.451 www 8170: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
8171:
8172: @communityforma=(
8173: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
8174: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
8175: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 8176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
8177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 8178: );
8179: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 8180:
1.330 tempelho 8181: my %orderhash = (
1.553 raeburn 8182: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 8183: 'bb' => ['External',$externalform],
8184: 'cc' => ['Import',$importpubform],
1.701 raeburn 8185: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 8186: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 8187: );
1.519 raeburn 8188: unless ($container eq 'page') {
1.434 raeburn 8189: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 8190: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 8191: }
8192:
1.341 ehlerst 8193: $hadchanges=0;
1.484 raeburn 8194: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 8195: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 8196: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 8197: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 8198: undef($navmap);
1.443 www 8199: if ($error) {
8200: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8201: }
1.639 raeburn 8202: if ($hadchanges) {
8203: unless (&is_hash_old()) {
1.638 raeburn 8204: &mark_hash_old();
8205: }
8206: }
1.341 ehlerst 8207:
1.443 www 8208: &changewarning($r,'');
8209: }
1.458 raeburn 8210: }
1.442 www 8211:
1.443 www 8212: # Supplemental documents start here
8213:
1.329 droeschl 8214: my $folder=$env{'form.folder'};
1.443 www 8215: unless ($supplementalflag) {
1.329 droeschl 8216: $folder='supplemental';
8217: }
1.685 raeburn 8218: if (($folder eq 'supplemental') &&
1.329 droeschl 8219: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 8220: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 8221: } elsif ($allowed) {
1.356 tempelho 8222: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 8223: }
1.508 raeburn 8224: $pathitem = '<input type="hidden" name="folderpath" value="'.
8225: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 8226: if ($allowed) {
8227: my $folderseq=
1.504 raeburn 8228: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 8229:
8230: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 8231: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
8232: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 8233: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 8234: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 8235: <legend>$lt{'upfi'}</legend>
1.630 raeburn 8236: <input type="hidden" name="active" value="ee" />
1.329 droeschl 8237: $fileupload
1.702 raeburn 8238: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
8239: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 8240: <br />
8241: <br />
8242: <span class="LC_nobreak">
8243: $checkbox
8244: </span>
8245: <br /><br />
8246: $lt{'comment'}:<br />
1.383 tempelho 8247: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 8248: <br />
1.508 raeburn 8249: $pathitem
1.329 droeschl 8250: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 8251: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 8252: </fieldset>
1.501 raeburn 8253: </form>
1.329 droeschl 8254: SUPDOCFORM
8255:
8256: my $supnewfolderform=(<<SNFFORM);
8257: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 8258: <input type="hidden" name="active" value="" />
1.508 raeburn 8259: $pathitem
1.329 droeschl 8260: <input type="hidden" name="importdetail" value="" />
1.423 onken 8261: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 8262: $help{'Adding_Folders'}
1.329 droeschl 8263: </form>
8264: SNFFORM
1.383 tempelho 8265:
1.510 raeburn 8266: my $supextform =
8267: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 8268: $help{'Adding_External_Resource'},
8269: undef,undef,undef,undef,undef,undef,
8270: $disabled);
1.329 droeschl 8271:
1.598 raeburn 8272: my $supexttoolform =
8273: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
8274: $help{'Adding_External_Tool'},
8275: undef,undef,'tool',$coursedom,
1.611 raeburn 8276: $coursenum,\%ltitools,$disabled);
1.598 raeburn 8277:
1.329 droeschl 8278: my $supnewsylform=(<<SNSFORM);
8279: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 8280: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8281: $pathitem
1.329 droeschl 8282: <input type="hidden" name="importdetail"
8283: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8284: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 8285: $help{'Syllabus'}
8286: </form>
8287: SNSFORM
8288:
8289: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 8290: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 8291: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8292: $pathitem
1.329 droeschl 8293: <input type="hidden" name="importdetail"
8294: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 8295: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 8296: $help{'My Personal Information Page'}
1.329 droeschl 8297: </form>
8298: SNAMFORM
8299:
1.534 raeburn 8300: my $supwebpage;
8301: if ($folder =~ /^supplemental_?(\d*)$/) {
8302: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
8303: if ($1) {
8304: $supwebpage .= $1;
8305: } else {
8306: $supwebpage .= 'default';
8307: }
8308: $supwebpage .= '/new.html';
8309: }
8310: my $supwebpageform =(<<SWEBFORM);
8311: <form action="/adm/coursedocs" method="post" name="supwebpage">
8312: <input type="hidden" name="active" value="cc" />
8313: $pathitem
8314: <input type="hidden" name="importdetail" value="$supwebpage" />
8315: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 8316: $help{'Web_Page'}
1.534 raeburn 8317: </form>
8318: SWEBFORM
8319:
1.333 muellerd 8320:
1.383 tempelho 8321: my @specialdocs = (
1.618 raeburn 8322: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 8323: =>$supnewsylform},
1.611 raeburn 8324: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 8325: =>$supnewaboutmeform},
1.534 raeburn 8326: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
8327:
1.383 tempelho 8328: );
1.655 raeburn 8329: my @supexternal = (
8330: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8331: =>$supextform});
1.699 raeburn 8332: if ($posslti) {
1.655 raeburn 8333: push(@supexternal,
8334: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8335: =>$supexttoolform});
8336: }
1.655 raeburn 8337: my @supimportdoc = (
1.598 raeburn 8338: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8339: =>$supupdocform},
1.598 raeburn 8340: );
1.501 raeburn 8341:
8342: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8343: my %suporderhash = (
1.390 tempelho 8344: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8345: 'dd' => ['Upload',$supupdocform],
8346: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8347: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8348: );
1.443 www 8349: if ($supplementalflag) {
1.682 raeburn 8350: $suppchanges = 0;
8351: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8352: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8353: \%ltitools,$canedit,$hostname);
8354: if ($error) {
8355: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8356: }
8357: if ($suppchanges) {
1.684 raeburn 8358: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8359: undef($suppchanges);
8360: }
1.393 raeburn 8361: }
1.443 www 8362: } elsif ($supplementalflag) {
1.458 raeburn 8363: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8364: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8365: $hostname);
1.393 raeburn 8366: if ($error) {
8367: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8368: }
1.393 raeburn 8369: }
1.389 tempelho 8370:
1.510 raeburn 8371: if ($needs_end) {
8372: $r->print(&endContentScreen());
8373: }
1.383 tempelho 8374:
1.329 droeschl 8375: if ($allowed) {
8376: $r->print('
8377: <form method="post" name="extimport" action="/adm/coursedocs">
8378: <input type="hidden" name="title" />
8379: <input type="hidden" name="url" />
8380: <input type="hidden" name="useform" />
8381: <input type="hidden" name="residx" />
8382: </form>');
8383: }
1.484 raeburn 8384: } elsif ($showdoc) {
1.329 droeschl 8385: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8386: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8387: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8388: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8389: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8390: }
8391: }
1.630 raeburn 8392: unless ($noendpage) {
1.606 raeburn 8393: $r->print(&Apache::loncommon::end_page());
8394: }
1.329 droeschl 8395: return OK;
1.364 bisitz 8396: }
1.329 droeschl 8397:
1.440 raeburn 8398: sub embedded_form_elems {
8399: my ($phase,$primaryurl,$newidx) = @_;
8400: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8401: $newidx =~s /\D+//g;
1.440 raeburn 8402: return <<STATE;
8403: <input type="hidden" name="folderpath" value="$folderpath" />
8404: <input type="hidden" name="cmd" value="upload_embedded" />
8405: <input type="hidden" name="newidx" value="$newidx" />
8406: <input type="hidden" name="phase" value="$phase" />
8407: <input type="hidden" name="primaryurl" value="$primaryurl" />
8408: STATE
8409: }
8410:
8411: sub embedded_destination {
8412: my $folder=$env{'form.folder'};
8413: my $destination = 'docs/';
8414: if ($folder =~ /^supplemental/) {
8415: $destination = 'supplemental/';
8416: }
8417: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8418: $destination .= 'default/';
8419: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8420: $destination .= $2.'/';
8421: }
1.634 raeburn 8422: my $newidx = $env{'form.newidx'};
8423: $newidx =~s /\D+//g;
8424: if ($newidx) {
8425: $destination .= $newidx;
8426: }
1.440 raeburn 8427: my $dir_root = '/userfiles';
8428: return ($destination,$dir_root);
8429: }
8430:
8431: sub return_to_editor {
8432: my $actionurl = '/adm/coursedocs';
8433: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8434: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8435: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8436: '</a></p>';
8437: }
8438:
1.476 raeburn 8439: sub decompression_info {
8440: my ($destination,$dir_root) = &embedded_destination();
8441: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8442: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8443: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8444: my $container='sequence';
1.480 raeburn 8445: my ($pathitem,$hiddenelem);
1.583 raeburn 8446: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8447: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8448: $container='page';
8449: }
1.480 raeburn 8450: unshift(@hiddens,$pathitem);
8451: foreach my $item (@hiddens) {
1.634 raeburn 8452: if ($item eq 'newidx') {
8453: next if ($env{'form.'.$item} =~ /\D/);
8454: }
1.480 raeburn 8455: if ($env{'form.'.$item}) {
8456: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8457: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8458: }
1.477 raeburn 8459: }
1.476 raeburn 8460: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8461: $hiddenelem);
8462: }
8463:
8464: sub decompression_phase_one {
8465: my ($dir,$file,$warning,$error,$output);
8466: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8467: &decompression_info();
1.490 raeburn 8468: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8469: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8470: } else {
8471: my $file = $1;
1.630 raeburn 8472: $output =
1.481 raeburn 8473: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8474: $destination,$dir_root,
8475: $hiddenelem);
8476: if ($env{'form.autoextract_camtasia'}) {
8477: $output .= &remove_archive($docudom,$docuname,$container);
8478: }
1.476 raeburn 8479: }
8480: if ($error) {
8481: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8482: $error.'</p>'."\n";
8483: }
8484: if ($warning) {
8485: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8486: }
8487: return $output;
8488: }
8489:
8490: sub decompression_phase_two {
8491: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8492: &decompression_info();
1.481 raeburn 8493: my $output;
1.480 raeburn 8494: if ($env{'form.archivedelete'}) {
1.481 raeburn 8495: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8496: }
8497: $output .=
1.481 raeburn 8498: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8499: $destination,$dir_root,$hiddenelem);
8500: return $output;
8501: }
8502:
1.480 raeburn 8503: sub remove_archive {
8504: my ($docudom,$docuname,$container) = @_;
8505: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8506: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8507: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8508: if ($fatal) {
8509: if ($container eq 'page') {
8510: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8511: } else {
8512: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8513: }
1.583 raeburn 8514: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8515: } else {
8516: my $currcmd = $env{'form.cmd'};
8517: my $position = $env{'form.position'};
1.583 raeburn 8518: my $archiveidx = $position;
1.563 raeburn 8519: if ($position > 0) {
1.583 raeburn 8520: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8521: $archiveidx = $position-1;
8522: }
8523: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8524: my ($title,$url,@rrest) =
1.583 raeburn 8525: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8526: if ($url eq $env{'form.archiveurl'}) {
8527: if (&handle_edit_cmd($docuname,$docudom)) {
8528: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8529: if ($suppchanges) {
8530: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8531: undef($suppchanges);
8532: }
1.583 raeburn 8533: if ($fatal) {
8534: if ($container eq 'page') {
8535: $delwarning = &mt('An error occurred updating the contents of the current page.');
8536: } else {
8537: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8538: }
1.480 raeburn 8539: } else {
1.583 raeburn 8540: $delresult = &mt('Archive file removed.');
1.480 raeburn 8541: }
8542: }
1.583 raeburn 8543: } else {
8544: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8545: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8546: }
8547: }
8548: $env{'form.cmd'} = $currcmd;
8549: }
8550: if ($delwarning) {
8551: $output = '<p class="LC_warning">'.
8552: $delwarning.
8553: '</p>';
8554: }
8555: if ($delresult) {
8556: $output .= '<p class="LC_info">'.
8557: $delresult.
8558: '</p>';
8559: }
1.481 raeburn 8560: return $output;
1.480 raeburn 8561: }
8562:
1.484 raeburn 8563: sub generate_admin_menu {
1.708 raeburn 8564: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8565: my $lc_crstype = lc($crstype);
8566: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8567: my %lt= ( # do not translate here
1.484 raeburn 8568: 'vc' => 'Verify Content',
8569: 'cv' => 'Check/Set Resource Versions',
8570: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8571: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8572: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8573: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8574: 'dcd' => 'Copy uploaded content to Authoring Space',
8575: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8576: );
1.712 raeburn 8577: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8578: if ($home + $other > 0) {
8579: $candump = 'F';
8580: if ($home) {
8581: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8582: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8583: } else {
8584: my @hosts;
8585: foreach my $aurole (keys(%outhash)) {
8586: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8587: push(@hosts,$outhash{$aurole});
1.538 raeburn 8588: }
1.484 raeburn 8589: }
8590: if (@hosts == 1) {
8591: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8592: '&role='.
8593: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8594: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8595: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8596: $exportcrsurl = $dumpurl;
1.484 raeburn 8597: } else {
8598: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8599: $exportcrsurl = $dumpurl;
1.484 raeburn 8600: }
8601: }
8602: }
8603: my @menu=
8604: ({ categorytitle=>'Administration',
8605: items =>[
8606: { linktext => $lt{'vc'},
8607: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8608: permission => 'F',
1.571 raeburn 8609: help => 'Docs_Verify_Content',
1.484 raeburn 8610: icon => 'verify.png',
8611: linktitle => 'Verify contents can be retrieved/rendered',
8612: },
8613: { linktext => $lt{'cv'},
8614: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8615: permission => 'F',
1.571 raeburn 8616: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8617: icon => 'resversion.png',
8618: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8619: },
8620: { linktext => $lt{'ls'},
8621: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8622: permission => 'F',
8623: #help => '',
8624: icon => 'symbs.png',
8625: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8626: },
1.651 raeburn 8627: { linktext => $lt{'ct'},
8628: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8629: permission => 'F',
8630: help => 'Docs_Short_URLs',
8631: icon => 'shorturls.png',
8632: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8633: },
1.484 raeburn 8634: ]
1.611 raeburn 8635: });
8636: if ($canedit) {
1.708 raeburn 8637: my ($crsauname,$crsaudom,$crshome);
8638: if (($coursenum ne '') && ($coursedom ne '')) {
8639: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8640: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8641: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8642: my @ids=&Apache::lonnet::current_machine_ids();
8643: my $linkurl;
8644: if (grep(/^\Q$crshome\E$/,@ids)) {
8645: $linkurl = $crsauthorurl;
8646: } else {
8647: $linkurl =
8648: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8649: }
8650: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
8651: push(@{$menu[0]->{items}},
8652: { linktext => $lt{'ca'},
8653: url => $linkurl,
8654: permission => 'F',
8655: help => 'Docs_Course_Authorspace',
8656: icon => 'impcrsau.png',
8657: linktitle => $lt{'ca'},
8658: });
8659: }
8660: }
8661: }
1.611 raeburn 8662: push(@menu,
1.484 raeburn 8663: { categorytitle=>'Export',
8664: items =>[
8665: { linktext => $lt{'imse'},
8666: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8667: permission => 'F',
8668: help => 'Docs_Export_Course_Docs',
8669: icon => 'imsexport.png',
8670: linktitle => $lt{'imse'},
8671: },
8672: { linktext => $lt{'dcd'},
8673: url => $dumpurl,
8674: permission => $candump,
1.571 raeburn 8675: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8676: icon => 'dump.png',
8677: linktitle => $lt{'dcd'},
8678: },
8679: ]
8680: });
1.712 raeburn 8681: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8682: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8683: push(@{$menu[1]->{items}},
8684: { linktext => $lt{'cpc'},
8685: url => $exportcrsurl,
8686: permission => 'F',
8687: help => 'Docs_Export_Course_Author',
8688: icon => 'res.png',
8689: linktitle => $lt{'cpc'},
8690: });
8691: }
8692: }
1.611 raeburn 8693: }
1.484 raeburn 8694: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8695: '<input type="hidden" id="dummy" />'."\n".
8696: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8697: '</form>';
1.329 droeschl 8698: }
8699:
8700: sub generate_edit_table {
1.538 raeburn 8701: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8702: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8703: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8704: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8705: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8706: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8707: $activetab = $env{'form.active'};
8708: }
1.611 raeburn 8709: unless ($canedit) {
8710: $disabled = ' disabled="disabled"';
8711: }
1.472 raeburn 8712: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8713: my $backtext = &mt('Exit Editor');
1.458 raeburn 8714: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8715: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8716: '<li class="goback">'.
1.546 raeburn 8717: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8718: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8719: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8720: '<li>'.
8721: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8722: &mt('Undo Delete').'</a></li>'."\n";
8723: if ($env{'form.docslog'}) {
8724: $form .= '<li class="active">';
8725: } else {
8726: $form .= '<li>';
8727: }
8728: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8729: &mt('History').'</a></li>'."\n";
8730: if ($env{'form.docslog'}) {
8731: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8732: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8733: }
1.458 raeburn 8734: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8735: if($name ne '00'){
1.371 tempelho 8736: if($activetab eq '' || $activetab ne $name){
8737: $active = '';
8738: }elsif($activetab eq $name){
8739: $active = 'class="active"';
8740: }
1.458 raeburn 8741: $form .= '<li style="float:right" '.$active
1.484 raeburn 8742: .' 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 8743: } else {
1.570 raeburn 8744: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8745:
8746: }
1.329 droeschl 8747: }
1.484 raeburn 8748: $form .= '</ul>'."\n";
8749: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8750:
8751: if ($to_show ne '') {
1.538 raeburn 8752: my $saveform;
8753: if ($need_save) {
8754: my $button = &mt('Make changes');
8755: my $path;
8756: if ($env{'form.folderpath'}) {
8757: $path =
8758: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8759: }
8760: $saveform = <<"END";
8761: <div id="multisave" style="display:none; clear:both;" >
8762: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8763: <input type="hidden" name="folderpath" value="$path" />
8764: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8765: <input type="hidden" name="allhiddenresource" value="" />
8766: <input type="hidden" name="allencrypturl" value="" />
8767: <input type="hidden" name="allrandompick" value="" />
8768: <input type="hidden" name="allrandomorder" value="" />
8769: <input type="hidden" name="changeparms" value="" />
8770: <input type="hidden" name="multiremove" value="" />
8771: <input type="hidden" name="multicut" value="" />
8772: <input type="hidden" name="multicopy" value="" />
8773: <input type="hidden" name="multichange" value="" />
8774: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8775: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8776: </form>
8777: </div>
8778: END
8779: }
8780: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8781: }
1.363 ehlerst 8782: foreach my $field (keys(%orderhash)){
1.390 tempelho 8783: if($field ne '00'){
1.422 onken 8784: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8785: $active = 'style="display: none;float:left"';
1.422 onken 8786: }elsif($activetab eq $field){
1.458 raeburn 8787: $active = 'style="display:block;float:left"';
1.422 onken 8788: }
8789: $form .= '<div id="'.$field.$tid.'"'
8790: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8791: .'</div>'."\n";
1.363 ehlerst 8792: }
8793: }
1.484 raeburn 8794: unless ($env{'form.docslog'}) {
8795: $form .= '</div></div>'."\n";
8796: }
1.329 droeschl 8797: return $form;
8798: }
8799:
8800: sub editing_js {
1.622 raeburn 8801: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8802: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8803: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8804: p_mnf => 'Name of New Folder',
8805: t_mnf => 'New Folder',
8806: p_mnp => 'Name of New Page',
8807: t_mnp => 'New Page',
1.451 www 8808: p_mxu => 'Title for the External Score',
1.349 biermanm 8809: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8810: p_msb => 'Title for the Problem',
8811: p_mdb => 'Title for the Drop Box',
1.336 schafran 8812: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8813: p_mwp => 'Title for Web Page',
1.606 raeburn 8814: p_mnr => 'Title for the Resource',
1.348 weissno 8815: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8816: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8817: p_mab_alrt1 => 'Not a valid user:domain',
8818: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8819: p_chn => 'New Title',
8820: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8821: p_rmr2a => 'Remove',
8822: p_rmr2b => '?',
8823: p_rmr3a => 'Remove those',
8824: p_rmr3b => 'items?',
8825: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8826: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8827: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8828: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8829: p_ctr2a => 'Cut',
8830: p_ctr2b => '?',
8831: p_ctr3a => 'Cut those',
8832: p_ctr3b => 'items?',
1.633 raeburn 8833: setal => 'Enter a (unique) alias',
8834: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8835: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8836: imsfile => 'You must choose an IMS package for import',
8837: imscms => 'You must select which Course Management System was the source of the IMS package',
8838: invurl => 'Invalid URL',
8839: titbl => 'Title is blank',
1.538 raeburn 8840: more => '(More ...)',
8841: less => '(Less ...)',
1.543 raeburn 8842: noor => 'No actions selected or changes to settings specified.',
8843: noch => 'No changes to settings specified.',
8844: noac => 'No actions selected.',
1.606 raeburn 8845: nofi => 'No file selected',
8846: tinc => 'Title in course',
8847: sunm => 'Sub-directory name',
1.618 raeburn 8848: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8849: sele => 'Select',
8850: swit => 'Switch server required',
1.329 droeschl 8851: );
1.594 damieng 8852: &js_escape(\%js_lt);
1.433 raeburn 8853: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8854: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8855: my $main_container_page;
1.519 raeburn 8856: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8857: $main_container_page = 1;
1.434 raeburn 8858: }
1.617 raeburn 8859: my $backtourl;
8860: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8861: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8862: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8863: my @ids=&Apache::lonnet::current_machine_ids();
8864: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8865: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8866: my $caller = $1;
1.525 raeburn 8867: if ($caller =~ /^supplemental/) {
8868: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8869: } else {
8870: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8871: $res = &Apache::lonnet::clutter($res);
8872: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8873: my ($url,$anchor);
8874: if ($res =~ /^([^#]+)#([^#]+)$/) {
8875: $url = $1;
8876: $anchor = $2;
8877: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8878: $caller = $1.&escape('#').$anchor;
8879: }
1.614 raeburn 8880: } else {
8881: $url = $res;
1.609 raeburn 8882: }
1.640 raeburn 8883: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8884: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8885: $backtourl .= '?navmap=1';
8886: } else {
8887: $backtourl .= '?symb='.
8888: &HTML::Entities::encode($caller,'<>&"');
8889: }
1.622 raeburn 8890: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8891: if (($ENV{'SERVER_PORT'} == 443) &&
8892: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8893: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8894: if ($hostname ne '') {
8895: $backtourl = 'http://'.$hostname.$backtourl;
8896: }
8897: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8898: }
8899: }
1.623 raeburn 8900: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8901: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8902: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8903: if ($hostname ne '') {
8904: $backtourl = 'http://'.$hostname.$backtourl;
8905: }
8906: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8907: }
1.623 raeburn 8908: }
1.622 raeburn 8909: }
1.609 raeburn 8910: if ($anchor ne '') {
8911: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8912: }
1.590 raeburn 8913: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8914: } else {
8915: $backtourl = '/adm/navmaps';
1.525 raeburn 8916: }
8917: }
8918: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8919: $backtourl = '/adm/menu';
8920: } elsif ($supplementalflag) {
1.682 raeburn 8921: if (($env{'request.role.adv'}) ||
8922: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8923: $backtourl = '/adm/supplemental';
8924: } else {
8925: $backtourl = '/adm/navmaps';
8926: }
1.525 raeburn 8927: } else {
8928: $backtourl = '/adm/navmaps';
1.472 raeburn 8929: }
8930:
1.655 raeburn 8931: my $fieldsets = "'doc'";
1.519 raeburn 8932: unless ($main_container_page) {
8933: $fieldsets .=",'ims'";
8934: }
1.655 raeburn 8935: my $extfieldsets = "'ext'";
8936: if ($posslti) {
8937: $extfieldsets .= ",'tool'";
8938: }
1.501 raeburn 8939: if ($supplementalflag) {
1.655 raeburn 8940: $fieldsets = "'suppdoc'";
8941: $extfieldsets = "'suppext'";
1.600 raeburn 8942: if ($posslti) {
1.655 raeburn 8943: $extfieldsets .= ",'supptool'";
1.600 raeburn 8944: }
1.501 raeburn 8945: }
1.655 raeburn 8946:
1.611 raeburn 8947: my $jsmakefunctions;
8948: if ($canedit) {
8949: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8950: function makenewfolder(targetform,folderseq) {
1.594 damieng 8951: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8952: if (foldername) {
1.676 raeburn 8953: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8954: targetform.submit();
8955: }
8956: }
8957:
8958: function makenewpage(targetform,folderseq) {
1.594 damieng 8959: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8960: if (pagename) {
1.676 raeburn 8961: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8962: targetform.submit();
8963: }
8964: }
8965:
8966: function makeexamupload() {
1.594 damieng 8967: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8968: if (title) {
1.329 droeschl 8969: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8970: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8971: this.document.forms.newexamupload.submit();
8972: }
8973: }
8974:
8975: function makesmppage() {
1.594 damieng 8976: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8977: if (title) {
1.329 droeschl 8978: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8979: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8980: this.document.forms.newsmppg.submit();
8981: }
8982: }
8983:
1.534 raeburn 8984: function makewebpage(type) {
1.594 damieng 8985: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8986: var formname;
8987: if (type == 'supp') {
8988: formname = this.document.forms.supwebpage;
8989: } else {
8990: formname = this.document.forms.newwebpage;
8991: }
8992: if (title) {
8993: var webpage = formname.importdetail.value;
1.675 raeburn 8994: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8995: formname.submit();
8996: }
8997: }
8998:
1.329 droeschl 8999: function makesmpproblem() {
1.594 damieng 9000: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 9001: if (title) {
1.329 droeschl 9002: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 9003: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 9004: this.document.forms.newsmpproblem.submit();
9005: }
9006: }
9007:
9008: function makedropbox() {
1.594 damieng 9009: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 9010: if (title) {
1.329 droeschl 9011: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 9012: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 9013: this.document.forms.newdropbox.submit();
9014: }
9015: }
9016:
9017: function makebulboard() {
1.594 damieng 9018: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 9019: if (title) {
9020: this.document.forms.newbul.importdetail.value=
1.676 raeburn 9021: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 9022: this.document.forms.newbul.submit();
9023: }
9024: }
9025:
9026: function makeabout() {
1.594 damieng 9027: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 9028: if (user) {
9029: var comp=new Array();
9030: comp=user.split(':');
9031: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
9032: if ((comp[0]) && (comp[1])) {
9033: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 9034: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 9035: this.document.forms.newaboutsomeone.submit();
9036: } else {
9037: alert("$js_lt{'p_mab_alrt1'}");
9038: }
9039: } else {
9040: alert("$js_lt{'p_mab_alrt2'}");
9041: }
9042: }
9043: }
9044:
9045: function makenew(targetform) {
9046: targetform.submit();
9047: }
9048:
9049: function changename(folderpath,index,oldtitle) {
9050: var title=prompt('$js_lt{"p_chn"}',oldtitle);
9051: if (title) {
9052: this.document.forms.renameform.markcopy.value='';
9053: this.document.forms.renameform.title.value=title;
9054: this.document.forms.renameform.cmd.value='rename_'+index;
9055: this.document.forms.renameform.folderpath.value=folderpath;
9056: this.document.forms.renameform.submit();
9057: }
9058: }
9059:
1.633 raeburn 9060: function setalias(folderpath,index) {
9061: var alias = prompt('$js_lt{"setal"}');
9062: if ((alias != null) && (alias != '')) {
9063: this.document.forms.aliasform.alias.value=alias;
9064: this.document.forms.aliasform.cmd.value='setalias_'+index;
9065: this.document.forms.aliasform.folderpath.value=folderpath;
9066: this.document.forms.aliasform.submit();
9067: }
9068: }
9069:
9070: function delalias(folderpath,index) {
9071: if (confirm('$js_lt{"delal"}')) {
9072: this.document.forms.aliasform.cmd.value='delalias_'+index;
9073: this.document.forms.aliasform.folderpath.value=folderpath;
9074: this.document.forms.aliasform.submit();
9075: }
9076: }
9077:
1.611 raeburn 9078: ENDNEWSCRIPT
9079: } else {
9080: $jsmakefunctions = <<ENDNEWSCRIPT;
9081:
9082: function makenewfolder() {
9083: alert("$js_lt{'edri'}");
9084: }
9085:
9086: function makenewpage() {
9087: alert("$js_lt{'edri'}");
9088: }
9089:
9090: function makeexamupload() {
9091: alert("$js_lt{'edri'}");
9092: }
9093:
9094: function makesmppage() {
9095: alert("$js_lt{'edri'}");
9096: }
9097:
9098: function makewebpage(type) {
9099: alert("$js_lt{'edri'}");
9100: }
9101:
9102: function makesmpproblem() {
9103: alert("$js_lt{'edri'}");
9104: }
9105:
9106: function makedropbox() {
9107: alert("$js_lt{'edri'}");
9108: }
9109:
9110: function makebulboard() {
9111: alert("$js_lt{'edri'}");
9112: }
9113:
9114: function makeabout() {
9115: alert("$js_lt{'edri'}");
9116: }
9117:
9118: function changename() {
9119: alert("$js_lt{'edri'}");
9120: }
9121:
1.633 raeburn 9122: function setalias() {
9123: alert("$js_lt{'edri'}");
9124: }
9125:
9126: function delalias() {
9127: alert("$js_lt{'edri'}");
9128: }
9129:
1.611 raeburn 9130: function makenew() {
9131: alert("$js_lt{'edri'}");
9132: }
9133:
9134: function groupimport() {
9135: alert("$js_lt{'edri'}");
1.335 ehlerst 9136: }
1.611 raeburn 9137:
9138: function groupsearch() {
9139: alert("$js_lt{'edri'}");
1.335 ehlerst 9140: }
1.611 raeburn 9141:
9142: function groupopen(url,recover) {
9143: var options="scrollbars=1,resizable=1,menubar=0";
9144: idxflag=1;
9145: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
9146: idx.focus();
1.329 droeschl 9147: }
9148:
1.611 raeburn 9149: ENDNEWSCRIPT
9150:
9151: }
9152: return <<ENDSCRIPT;
9153:
9154: $jsmakefunctions
9155:
1.501 raeburn 9156: function toggleUpload(caller) {
9157: var blocks = Array($fieldsets);
9158: for (var i=0; i<blocks.length; i++) {
9159: var disp = 'none';
9160: if (caller == blocks[i]) {
9161: var curr = document.getElementById('upload'+caller+'form').style.display;
9162: if (curr == 'none') {
9163: disp='block';
9164: }
9165: }
9166: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 9167: }
9168: resize_scrollbox('contentscroll','1','1');
9169: return;
9170: }
9171:
9172: function toggleExternal(caller) {
9173: var blocks = Array($extfieldsets);
9174: for (var i=0; i<blocks.length; i++) {
9175: var disp = 'none';
9176: if (caller == blocks[i]) {
9177: var curr = document.getElementById('external'+caller+'form').style.display;
9178: if (curr == 'none') {
9179: disp='block';
9180: }
9181: }
9182: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 9183: if ((caller == 'tool') || (caller == 'supptool')) {
9184: if (disp == 'block') {
1.655 raeburn 9185: if (document.getElementById('LC_exttoolid')) {
9186: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 9187: var suppflag = 0;
9188: if (caller == 'supptool') {
9189: suppflag = 1;
9190: }
9191: currForm = document.getElementById('new'+caller);
1.655 raeburn 9192: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 9193: }
9194: }
9195: }
1.501 raeburn 9196: }
1.502 raeburn 9197: resize_scrollbox('contentscroll','1','1');
9198: return;
9199: }
9200:
1.514 raeburn 9201: function toggleMap(caller) {
1.502 raeburn 9202: var disp = 'none';
1.510 raeburn 9203: if (document.getElementById('importmapform')) {
1.514 raeburn 9204: if (caller == 'map') {
9205: var curr = document.getElementById('importmapform').style.display;
9206: if (curr == 'none') {
9207: disp='block';
9208: }
1.510 raeburn 9209: }
9210: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 9211: if (disp == 'block') {
9212: if (document.getElementById('importcrsresform')) {
9213: if (document.getElementById('importcrsresform').style.display == 'block') {
9214: document.getElementById('importcrsresform').style.display = 'none';
9215: }
9216: }
9217: }
1.510 raeburn 9218: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 9219: }
1.501 raeburn 9220: return;
1.329 droeschl 9221: }
9222:
1.691 raeburn 9223: function toggleCrsRes(caller) {
1.606 raeburn 9224: var disp = 'none';
9225: if (document.getElementById('crsresform')) {
9226: if (caller == 'res') {
1.691 raeburn 9227: var form = document.getElementById('crsresform');
9228: var curr = form.style.display;
1.606 raeburn 9229: if (curr == 'none') {
9230: disp='block';
1.691 raeburn 9231: document.courseresform.authorrole.selectedIndex = 0;
9232: document.courseresform.authorpath.selectedIndex = 0;
9233: document.courseresform.newresourceadd.selectedIndex = 0;
9234: populateDirSelects(form,'authorrole','authorpath',1,0,0);
9235: toggleNewInCourse(document.courseresform);
9236: if (document.getElementById('newresource')) {
9237: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 9238: }
9239: if (document.courseresform.newresusetemp.length) {
9240: document.courseresform.newresusetemp[0].checked = true;
9241: toggleWithTemplate(document.courseresform);
9242: }
9243: document.courseresform.newresourcename.value = '';
9244: }
9245: }
9246: if (document.courseresform.newsubdir.length) {
9247: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
9248: if (document.courseresform.newsubdir[j].value == 0) {
9249: document.courseresform.newsubdir[j].checked = true;
9250: }
9251: break;
9252: }
9253: if (document.getElementById('newsubdirname')) {
9254: document.getElementById('newsubdirname').type = "hidden";
9255: document.getElementById('newsubdirname').value = "";
9256: }
9257: if (document.getElementById('newsubdir')) {
9258: document.getElementById('newsubdir').innerHTML = "";
9259: }
9260: }
9261: document.getElementById('crsresform').style.display=disp;
9262: resize_scrollbox('contentscroll','1','0');
9263: }
9264: return;
9265: }
9266:
9267: function toggleNewsubdir(form) {
9268: if (form.newsubdir.length) {
9269: for (var j=0; j<form.newsubdir.length; j++) {
9270: if (form.newsubdir[j].checked) {
9271: if (document.getElementById('newsubdirname')) {
9272: if (form.newsubdir[j].value == '1') {
9273: document.getElementById('newsubdirname').type = "text";
9274: if (document.getElementById('newsubdir')) {
9275: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
9276: }
9277: } else {
9278: document.getElementById('newsubdirname').type = "hidden";
9279: document.getElementById('newsubdirname').value = "";
9280: document.getElementById('newsubdir').innerHTML = "";
9281: }
9282: }
9283: break;
9284: }
9285: }
9286: }
9287: }
9288:
9289: function toggleCrsResTitle() {
9290: if (document.getElementById('newresource')) {
1.691 raeburn 9291: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9292: if (selloc == 'course') {
1.606 raeburn 9293: document.getElementById('newresource').style.display = 'inline';
9294: document.courseresform.newresourceadd[0].checked = true;
9295: toggleNewInCourse(document.courseresform);
9296: } else {
9297: document.getElementById('newresource').style.display = 'none';
9298: }
1.689 raeburn 9299: }
9300: if (document.getElementById('newstdproblem')) {
9301: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9302: document.getElementById('newstdproblem').style.display = 'none';
9303: if (document.getElementById('stdprobswitch')) {
9304: document.getElementById('stdprobswitch').style.display = 'block';
9305: }
9306: } else {
9307: document.getElementById('newstdproblem').style.display = 'block';
9308: if (document.getElementById('stdprobswitch')) {
9309: document.getElementById('stdprobswitch').style.display = 'none';
9310: }
9311: }
9312: }
1.606 raeburn 9313: }
9314:
9315: function toggleNewInCourse(form) {
9316: if (form.newresourceadd.length) {
9317: for (var i=0; i<form.newresourceadd.length; i++) {
9318: if (form.newresourceadd[i].checked) {
9319: if (document.getElementById('newresourcetitle')) {
9320: if (form.newresourceadd[i].value == '1') {
9321: document.getElementById('newresourcetitle').type = 'text';
9322: if (document.getElementById('newrestitle')) {
9323: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
9324: }
9325: } else {
9326: document.getElementById('newresourcetitle').type = 'hidden';
9327: document.getElementById('newresourcetitle').value = '';
9328: if (document.getElementById('newrestitle')) {
9329: document.getElementById('newrestitle').innerHTML = '';
9330: }
9331: }
9332: }
9333: break;
9334: }
9335: }
9336: }
9337: }
9338:
9339: function toggleWithTemplate(form) {
9340: if (form.newresusetemp.length) {
9341: for (var i=0; i<form.newresusetemp.length; i++) {
9342: if (form.newresusetemp[i].checked) {
9343: if (document.getElementById('newrestemplate')) {
9344: if (form.newresusetemp[i].value == '1') {
9345: document.getElementById('newrestemplate').style.display = 'inline';
9346: toggleExampleText();
9347: } else {
9348: form.tempcategory.selectedIndex = 0;
9349: select1template_changed();
9350: document.getElementById('newrestemplate').style.display = 'none';
9351: }
9352: }
9353: }
9354: }
9355: }
9356: }
9357:
9358: function toggleExampleText() {
9359: if (document.getElementById('newresexample')) {
9360: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9361: if (url == '') {
9362: document.getElementById('newresexample').style.fontWeight = 'normal';
9363: } else {
9364: document.getElementById('newresexample').style.fontWeight = 'bold';
9365: }
9366: }
9367: }
9368:
9369: function getExample(width,height,scrolling,transparency) {
9370: var url;
9371: if (document.courseresform.newresusetemp.length) {
9372: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9373: if (document.courseresform.newresusetemp[i].checked) {
9374: if (document.courseresform.newresusetemp[i].value == '1') {
9375: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9376: if (url == '') {
9377: alert('Pick a category and template');
9378: } else {
9379: url = url.replace("$londocroot","");
9380: url += '?inhibitmenu=yes';
9381: }
9382: }
9383: break;
9384: }
9385: }
9386: }
9387: if (url != '') {
9388: openMyModal(url,width,height,scrolling,transparency,'');
9389: }
9390: }
9391:
1.690 raeburn 9392: function toggleImportCrsres(caller) {
1.606 raeburn 9393: var disp = 'none';
9394: if (document.getElementById('importcrsresform')) {
9395: if (caller == 'res') {
9396: var curr = document.getElementById('importcrsresform').style.display;
9397: if (curr == 'none') {
9398: disp='block';
1.698 raeburn 9399: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9400: if ((document.getElementById('importcrsrescontent')) &&
9401: (document.getElementById('importcrsresempty'))) {
9402: var selelem = document.crsresimportform.elements['coursepath'];
9403: var numdirs = 0;
9404: if (selelem.options.length) {
9405: numdirs = selelem.options.length - 1;
9406: }
9407: if (numdirs) {
9408: document.getElementById('importcrsrescontent').style.display='block';
9409: document.getElementById('importcrsresempty').style.display='none';
9410: } else {
9411: document.getElementById('importcrsrescontent').style.display='none';
9412: document.getElementById('importcrsresempty').style.display='block';
9413: }
9414: }
1.606 raeburn 9415: }
9416: }
9417: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9418: if (disp == 'block') {
9419: if (document.getElementById('importmapform')) {
9420: if (document.getElementById('importmapform').style.display == 'block') {
9421: document.getElementById('importmapform').style.display = 'none';
9422: }
9423: }
9424: }
1.606 raeburn 9425: resize_scrollbox('contentscroll','1','0');
9426: }
9427: return;
9428: }
9429:
1.690 raeburn 9430: $showfile_js
9431:
1.691 raeburn 9432: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9433: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9434: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9435: var selelem = form.elements[dirsel];
9436: var i, numfiles = selelem.options.length -1;
9437: if (numfiles >=0) {
9438: for (i = numfiles; i >= 0; i--) {
9439: selelem.remove(i);
9440: }
9441: }
9442: if ((location == '') || (location == null) || (location == 'undefined')) {
9443: if (selelem.options.length == 0) {
9444: selelem.options[selelem.options.length] = new Option('','');
9445: selelem.selectedIndex = 0;
9446: }
9447: if (document.getElementById('newstdproblem')) {
9448: document.getElementById('newstdproblem').style.display = 'none';
9449: }
9450: return;
9451: }
9452: var machineIds = new Array($machines_str);
9453: var athome = 0;
9454: var role = location;
9455: if ((location == 'author') || (location == 'course')) {
9456: if (document.getElementById('rolehome_'+location)) {
9457: var currhome = document.getElementById('rolehome_'+location).value;
9458: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9459: if (machineIds.includes(currhome)) {
9460: athome = 1;
9461: }
9462: }
9463: }
9464: } else {
9465: const roleinfo = location.split('___');
9466: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9467: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9468: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9469: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9470: if (machineIds.includes(currhome)) {
9471: athome = 1;
9472: }
9473: }
9474: }
9475: }
1.706 raeburn 9476: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9477: if (athome) {
9478: if (document.getElementById('stdprobswitch')) {
9479: document.getElementById('stdprobswitch').style.display = 'none';
9480: }
9481: if (document.getElementById('newstdproblem')) {
9482: document.getElementById('newstdproblem').style.display = 'none';
9483: }
1.706 raeburn 9484: var canedit = '$canedit';
9485: if (canedit) {
9486: if (templateradio.length > 1) {
9487: for (var i=0; i<templateradio.length; i++) {
9488: templateradio[i].disabled = false;
9489: }
9490: }
9491: document.courseresform.newresourcename.disabled = false;
9492: document.courseresform.newcrs.disabled = false;
9493: }
1.691 raeburn 9494: var http = new XMLHttpRequest();
9495: var url = "/adm/courseauthor";
1.698 raeburn 9496: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9497: http.open("POST", url, true);
9498: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9499: http.onreadystatechange = function() {
9500: if (http.readyState == 4 && http.status == 200) {
9501: var data = JSON.parse(http.responseText);
9502: if (Array.isArray(data.dirs)) {
9503: var len = data.dirs.length;
9504: if (len) {
9505: if (len > 1) {
9506: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9507: }
9508: }
9509: if (len) {
9510: var j;
9511: for (j = 0; j < len; j++) {
9512: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9513: }
9514: selelem.selectedIndex = 0;
1.697 raeburn 9515: if (len == 1) {
9516: toggleCrsResTitle();
9517: }
1.691 raeburn 9518: }
9519: }
9520: }
9521: }
9522: http.send(params);
9523: } else {
9524: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9525: selelem.selectedIndex = 0;
9526: if (document.getElementById('stdprobswitch')) {
9527: document.getElementById('stdprobswitch').style.display = 'block';
9528: }
9529: if (document.getElementById('newstdproblem')) {
9530: document.getElementById('newstdproblem').style.display = 'none';
9531: }
1.706 raeburn 9532: if (templateradio.length > 1) {
9533: for (var i=0; i<templateradio.length; i++) {
9534: templateradio[i].disabled = true;
9535: }
9536: }
9537: document.courseresform.newresourcename.disabled = true;
9538: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9539: }
9540: }
9541: return;
9542: }
9543:
1.689 raeburn 9544: function switchForProb() {
9545: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9546: var url = '/adm/switchserver?otherserver=';
9547: var newhostid = '';
9548: var role = '';
9549: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9550: if (selloc == 'author') {
9551: newhostid = document.courseresform.rolehome_author.value;
9552: role = "au./&js_escape($env{'user.domain'})/";
9553: } else if (selloc == 'course') {
9554: newhostid = document.courseresform.rolehome_course.value;
9555: role = "&js_escape($env{'request.role'})";
9556: } else {
9557: var items = new Array();
9558: items = selloc.split('___');
9559: var len = document.courseresform.rolehome_coauthor.length;
9560: if (null == len) {
9561: var currval = document.courseresform.rolehome_coauthor.value;
9562: if (null != currval) {
9563: var info = new Array();
9564: info = currval.split('=');
9565: newhostid = info[2];
9566: role = info[0]+'./'+info[1];
9567: }
9568: } else {
9569: for (var i=0; i<len; i++) {
9570: var currval = document.courseresform.rolehome_coauthor[i].value;
9571: if (null != currval) {
9572: var info = new Array();
9573: info = currval.split('=');
9574: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9575: newhostid = info[2];
9576: role = info[0]+'./'+info[1];
9577: break;
9578: }
9579: }
9580: }
9581: }
9582: }
9583: if (newhostid != '') {
9584: url += newhostid;
9585: if (role != '') {
9586: url += '&role='+role;
9587: }
9588: document.location.href = url;
9589: }
9590: }
9591: return;
9592: }
9593:
1.501 raeburn 9594: function makeims(imsform) {
9595: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9596: alert("$js_lt{'imsfile'}");
1.501 raeburn 9597: return;
9598: }
9599: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9600: alert("$js_lt{'imscms'}");
1.501 raeburn 9601: return;
9602: }
9603: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9604: imsform.submit();
9605: }
9606:
1.478 raeburn 9607: function updatePick(targetform,index,caller) {
1.537 raeburn 9608: var pickitem;
9609: var picknumitem;
9610: var picknumtext;
9611: if (index == 'all') {
9612: pickitem = document.getElementById('randompickall');
9613: picknumitem = document.getElementById('rpicknumall');
9614: picknumtext = document.getElementById('rpicktextall');
9615: } else {
9616: pickitem = document.getElementById('randompick_'+index);
9617: picknumitem = document.getElementById('rpicknum_'+index);
9618: picknumtext = document.getElementById('randompicknum_'+index);
9619: }
1.478 raeburn 9620: if (pickitem.checked) {
1.594 damieng 9621: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9622: if (picknum == '' || picknum == null) {
9623: if (caller == 'check') {
9624: pickitem.checked=false;
1.537 raeburn 9625: if (index == 'all') {
9626: picknumtext.innerHTML = '';
9627: if (caller == 'link') {
9628: propagateState(targetform,'rpicknum');
9629: }
9630: } else {
1.538 raeburn 9631: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9632: }
1.478 raeburn 9633: }
9634: } else {
9635: picknum.toString();
9636: var regexdigit=/^\\d+\$/;
9637: if (regexdigit.test(picknum)) {
9638: picknumitem.value = picknum;
1.537 raeburn 9639: if (index == 'all') {
1.538 raeburn 9640: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9641: if (caller == 'link') {
9642: propagateState(targetform,'rpicknum');
9643: }
9644: } else {
9645: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9646: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9647: }
1.478 raeburn 9648: } else {
9649: if (caller == 'check') {
1.537 raeburn 9650: if (index == 'all') {
9651: picknumtext.innerHTML = '';
9652: if (caller == 'link') {
9653: propagateState(targetform,'rpicknum');
9654: }
9655: } else {
9656: pickitem.checked=false;
1.538 raeburn 9657: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9658: }
1.478 raeburn 9659: }
9660: return;
9661: }
9662: }
9663: } else {
1.537 raeburn 9664: picknumitem.value = '';
9665: picknumtext.innerHTML = '';
9666: if (index == 'all') {
9667: if (caller == 'link') {
9668: propagateState(targetform,'rpicknum');
9669: }
9670: } else {
1.538 raeburn 9671: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9672: }
9673: }
9674: }
9675:
9676: function propagateState(form,param) {
9677: if (document.getElementById(param+'all')) {
9678: var setcheck = 0;
9679: var rpick = 0;
9680: if (param == 'rpicknum') {
9681: if (document.getElementById('randompickall')) {
9682: if (document.getElementById('randompickall').checked) {
9683: if (document.getElementById('rpicknumall')) {
9684: rpick = document.getElementById('rpicknumall').value;
9685: }
9686: }
9687: }
9688: } else {
9689: if (document.getElementById(param+'all').checked) {
9690: setcheck = 1;
9691: }
9692: }
1.538 raeburn 9693: var allidxlist;
9694: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9695: if (document.getElementById('all'+param+'idx')) {
9696: allidxlist = document.getElementById('all'+param+'idx').value;
9697: }
9698: var actions = new Array ('remove','cut','copy');
9699: for (var i=0; i<actions.length; i++) {
9700: if (actions[i] != param) {
9701: if (document.getElementById(actions[i]+'all')) {
9702: document.getElementById(actions[i]+'all').checked = false;
9703: }
9704: }
9705: }
9706: }
1.537 raeburn 9707: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9708: allidxlist = form.allidx.value;
9709: }
9710: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9711: allidxlist = form.allmapidx.value;
9712: }
9713: if ((allidxlist != '') && (allidxlist != null)) {
9714: var allidxs = allidxlist.split(',');
9715: if (allidxs.length > 1) {
9716: for (var i=0; i<allidxs.length; i++) {
9717: if (document.getElementById(param+'_'+allidxs[i])) {
9718: if (param == 'rpicknum') {
9719: if (document.getElementById('randompick_'+allidxs[i])) {
9720: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9721: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9722: if (rpick > 0) {
9723: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9724: } else {
9725: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9726: }
9727: }
9728: }
9729: } else {
1.537 raeburn 9730: if (setcheck == 1) {
9731: document.getElementById(param+'_'+allidxs[i]).checked = true;
9732: } else {
9733: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9734: if (param == 'randompick') {
9735: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9736: }
1.537 raeburn 9737: }
9738: }
9739: }
9740: }
1.538 raeburn 9741: if (setcheck == 1) {
9742: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9743: var actions = new Array('copy','cut','remove');
9744: for (var i=0; i<actions.length; i++) {
9745: var otheractions;
9746: var otheridxs;
9747: if (actions[i] === param) {
9748: continue;
9749: } else {
9750: if (document.getElementById('all'+actions[i]+'idx')) {
9751: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9752: otheridxs = otheractions.split(',');
9753: if (otheridxs.length > 1) {
9754: for (var j=0; j<otheridxs.length; j++) {
9755: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9756: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9757: }
1.537 raeburn 9758: }
9759: }
9760: }
1.538 raeburn 9761: }
9762: }
9763: }
9764: }
9765: }
9766: }
9767: }
9768: return;
9769: }
9770:
1.603 raeburn 9771: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9772: var canedit = '$canedit';
9773: if (canedit == '') {
9774: alert("$js_lt{'edri'}");
9775: return;
9776: }
1.539 raeburn 9777: var dosettings;
9778: var doaction;
1.538 raeburn 9779: var control = document.togglemultsettings;
9780: if (context == 'actions') {
9781: control = document.togglemultactions;
1.539 raeburn 9782: doaction = 1;
9783: } else {
9784: dosettings = 1;
1.538 raeburn 9785: }
1.539 raeburn 9786: if (control) {
9787: if (control.showmultpick.length) {
9788: for (var i=0; i<control.showmultpick.length; i++) {
9789: if (control.showmultpick[i].checked) {
9790: if (control.showmultpick[i].value == 1) {
9791: if (context == 'settings') {
9792: dosettings = 0;
9793: } else {
9794: doaction = 0;
1.538 raeburn 9795: }
9796: }
9797: }
1.537 raeburn 9798: }
9799: }
1.539 raeburn 9800: }
9801: if (context == 'settings') {
9802: if (dosettings == 1) {
1.538 raeburn 9803: targetform.changeparms.value=param;
9804: targetform.submit();
9805: }
1.537 raeburn 9806: }
1.539 raeburn 9807: if (context == 'actions') {
9808: if (doaction == 1) {
9809: targetform.cmd.value=param+'_'+index;
9810: targetform.folderpath.value=folderpath;
9811: targetform.markcopy.value=idx+':'+param;
9812: targetform.copyfolder.value=folder+'.'+container;
9813: if (param == 'remove') {
1.603 raeburn 9814: var doremove = 0;
9815: if (skip_confirm) {
9816: if (confirm_removal) {
9817: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9818: doremove = 1;
9819: }
9820: } else {
9821: doremove = 1;
9822: }
9823: } else {
9824: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9825: doremove = 1;
9826: }
9827: }
9828: if (doremove) {
1.539 raeburn 9829: targetform.markcopy.value='';
9830: targetform.copyfolder.value='';
9831: targetform.submit();
9832: }
9833: }
9834: if (param == 'cut') {
1.594 damieng 9835: 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 9836: targetform.submit();
9837: return;
9838: }
9839: }
9840: if (param == 'copy') {
9841: targetform.submit();
9842: return;
9843: }
9844: targetform.markcopy.value='';
9845: targetform.copyfolder.value='';
9846: targetform.cmd.value='';
9847: targetform.folderpath.value='';
9848: return;
9849: } else {
9850: if (document.getElementById(param+'_'+idx)) {
9851: item = document.getElementById(param+'_'+idx);
9852: if (item.type == 'checkbox') {
9853: if (item.checked) {
9854: item.checked = false;
9855: } else {
9856: item.checked = true;
9857: singleCheck(item,idx,param);
9858: }
9859: }
9860: }
9861: }
9862: }
1.537 raeburn 9863: return;
9864: }
9865:
1.538 raeburn 9866: function singleCheck(caller,idx,action) {
9867: actions = new Array('cut','copy','remove');
9868: if (caller.checked) {
9869: for (var i=0; i<actions.length; i++) {
9870: if (actions[i] != action) {
9871: if (document.getElementById(actions[i]+'_'+idx)) {
9872: if (document.getElementById(actions[i]+'_'+idx).checked) {
9873: document.getElementById(actions[i]+'_'+idx).checked = false;
9874: }
1.537 raeburn 9875: }
9876: }
9877: }
1.478 raeburn 9878: }
1.537 raeburn 9879: return;
1.478 raeburn 9880: }
9881:
1.334 muellerd 9882: function unselectInactive(nav) {
1.335 ehlerst 9883: currentNav = document.getElementById(nav);
9884: currentLis = currentNav.getElementsByTagName('LI');
9885: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9886: if (currentLis[i].className == 'goback') {
9887: currentLis[i].className = 'goback';
9888: } else {
9889: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9890: currentLis[i].className = 'right';
1.472 raeburn 9891: } else {
1.374 tempelho 9892: currentLis[i].className = 'i';
1.472 raeburn 9893: }
9894: }
1.335 ehlerst 9895: }
1.332 tempelho 9896: }
9897:
1.334 muellerd 9898: function hideAll(current, nav, data) {
1.335 ehlerst 9899: unselectInactive(nav);
1.570 raeburn 9900: if (current) {
9901: if (current.className == 'right'){
9902: current.className = 'right active'
9903: } else {
9904: current.className = 'active';
9905: }
1.374 tempelho 9906: }
1.335 ehlerst 9907: currentData = document.getElementById(data);
9908: currentDivs = currentData.getElementsByTagName('DIV');
9909: for (i = 0; i < currentDivs.length; i++) {
9910: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9911: currentDivs[i].style.display = 'none';
1.330 tempelho 9912: }
9913: }
1.335 ehlerst 9914: }
1.330 tempelho 9915:
1.374 tempelho 9916: function openTabs(pageId) {
9917: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9918: if(tabnav.length > 2 ){
1.389 tempelho 9919: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9920: currentLis = currentNav.getElementsByTagName('LI');
9921: for(i = 0; i< currentLis.length; i++){
9922: if(currentLis[i].className == 'active') {
1.375 tempelho 9923: funcString = currentLis[i].onclick.toString();
9924: tab = funcString.split('"');
1.420 onken 9925: if(tab.length < 2) {
9926: tab = funcString.split("'");
9927: }
1.375 tempelho 9928: currentData = document.getElementById(tab[1]);
9929: currentData.style.display = 'block';
1.374 tempelho 9930: }
9931: }
9932: }
9933: }
9934:
1.334 muellerd 9935: function showPage(current, pageId, nav, data) {
1.570 raeburn 9936: currstate = current.className;
1.334 muellerd 9937: hideAll(current, nav, data);
1.375 tempelho 9938: openTabs(pageId);
1.334 muellerd 9939: unselectInactive(nav);
1.570 raeburn 9940: if ((currstate == 'active') || (currstate == 'right active')) {
9941: if (currstate == 'active') {
9942: current.className = '';
9943: } else {
9944: current.className = 'right';
9945: }
9946: activeTab = '';
1.656 raeburn 9947: toggleExternal();
1.570 raeburn 9948: toggleUpload();
9949: toggleMap();
1.606 raeburn 9950: toggleCrsRes();
9951: toggleImportCrsres();
1.570 raeburn 9952: resize_scrollbox('contentscroll','1','0');
9953: return;
9954: } else {
9955: current.className = 'active';
9956: }
1.330 tempelho 9957: currentData = document.getElementById(pageId);
9958: currentData.style.display = 'block';
1.458 raeburn 9959: activeTab = pageId;
1.656 raeburn 9960: toggleExternal();
1.501 raeburn 9961: toggleUpload();
1.503 raeburn 9962: toggleMap();
1.606 raeburn 9963: toggleCrsRes();
9964: toggleImportCrsres();
1.433 raeburn 9965: if (nav == 'mainnav') {
9966: var storedpath = "$docs_folderpath";
1.434 raeburn 9967: var storedpage = "$main_container_page";
1.433 raeburn 9968: var reg = new RegExp("^supplemental");
9969: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9970: if (storedpage == 1) {
9971: document.simpleedit.folderpath.value = '';
9972: document.uploaddocument.folderpath.value = '';
9973: } else {
9974: if (reg.test(storedpath)) {
9975: document.simpleedit.folderpath.value = '$toplevelmain';
9976: document.uploaddocument.folderpath.value = '$toplevelmain';
9977: document.newext.folderpath.value = '$toplevelmain';
9978: } else {
9979: document.simpleedit.folderpath.value = storedpath;
9980: document.uploaddocument.folderpath.value = storedpath;
9981: document.newext.folderpath.value = storedpath;
9982: }
1.433 raeburn 9983: }
9984: } else {
1.434 raeburn 9985: if (reg.test(storedpath)) {
9986: document.simpleedit.folderpath.value = storedpath;
9987: document.supuploaddocument.folderpath.value = storedpath;
9988: document.supnewext.folderpath.value = storedpath;
9989: } else {
1.433 raeburn 9990: document.simpleedit.folderpath.value = '$toplevelsupp';
9991: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9992: document.supnewext.folderpath.value = '$toplevelsupp';
9993: }
9994: }
9995: }
1.485 raeburn 9996: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9997: return false;
9998: }
1.329 droeschl 9999:
1.472 raeburn 10000: function toContents(jumpto) {
10001: var newurl = '$backtourl';
1.525 raeburn 10002: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 10003: newurl = newurl+'?postdata='+jumpto;
10004: }
10005: location.href=newurl;
10006: }
10007:
1.538 raeburn 10008: function togglePick(caller,value) {
10009: var disp = 'none';
10010: if (document.getElementById('multi'+caller)) {
10011: var curr = document.getElementById('multi'+caller).style.display;
10012: if (value == 1) {
10013: disp='block';
10014: }
10015: if (curr == disp) {
10016: return;
10017: }
10018: document.getElementById('multi'+caller).style.display=disp;
10019: if (value == 1) {
1.594 damieng 10020: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10021: } else {
10022: document.getElementById('more'+caller).innerHTML = '';
10023: }
10024: if (caller == 'actions') {
10025: setClass(value);
10026: setBoxes(value);
10027: }
10028: }
10029: var showButton = multiSettings();
10030: if (showButton != 1) {
10031: showButton = multiActions();
10032: }
10033: if (document.getElementById('multisave')) {
10034: if (showButton == 1) {
10035: document.getElementById('multisave').style.display='block';
10036: } else {
10037: document.getElementById('multisave').style.display='none';
10038: }
10039: }
10040: resize_scrollbox('contentscroll','1','1');
10041: return;
10042: }
10043:
10044: function toggleCheckUncheck(caller,more) {
10045: if (more == 1) {
1.594 damieng 10046: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 10047: document.getElementById('allfields'+caller).style.display='block';
10048: } else {
1.594 damieng 10049: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10050: document.getElementById('allfields'+caller).style.display='none';
10051: }
10052: resize_scrollbox('contentscroll','1','1');
10053: }
10054:
10055: function multiSettings() {
10056: var inuse = 0;
10057: var settingsform = document.togglemultsettings;
10058: if (settingsform.showmultpick.length > 1) {
10059: for (var i=0; i<settingsform.showmultpick.length; i++) {
10060: if (settingsform.showmultpick[i].checked) {
10061: if (settingsform.showmultpick[i].value == 1) {
10062: inuse = 1;
10063: }
10064: }
10065: }
10066: }
10067: return inuse;
10068: }
10069:
10070: function multiActions() {
10071: var inuse = 0;
10072: var actionsform = document.togglemultactions;
10073: if (actionsform.showmultpick.length > 1) {
10074: for (var i=0; i<actionsform.showmultpick.length; i++) {
10075: if (actionsform.showmultpick[i].checked) {
10076: if (actionsform.showmultpick[i].value == 1) {
10077: inuse = 1;
10078: }
10079: }
10080: }
10081: }
10082: return inuse;
10083: }
10084:
10085: function checkSubmits() {
10086: var numchanges = 0;
10087: var form = document.saveactions;
10088: var doactions = multiActions();
1.542 raeburn 10089: var cutwarnings = 0;
10090: var remwarnings = 0;
1.603 raeburn 10091: var removalinfo = 0;
1.538 raeburn 10092: if (doactions == 1) {
10093: var remidxlist = document.cumulativeactions.allremoveidx.value;
10094: if ((remidxlist != '') && (remidxlist != null)) {
10095: var remidxs = remidxlist.split(',');
10096: for (var i=0; i<remidxs.length; i++) {
10097: if (document.getElementById('remove_'+remidxs[i])) {
10098: if (document.getElementById('remove_'+remidxs[i]).checked) {
10099: form.multiremove.value += remidxs[i]+',';
10100: numchanges ++;
1.542 raeburn 10101: if (document.getElementById('skip_remove_'+remidxs[i])) {
10102: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
10103: remwarnings ++;
10104: }
10105: }
1.603 raeburn 10106: if (document.getElementById('confirm_removal_'+remidxs[i])) {
10107: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
10108: removalinfo ++;
10109: }
10110: }
1.537 raeburn 10111: }
10112: }
1.538 raeburn 10113: }
10114: }
10115: var cutidxlist = document.cumulativeactions.allcutidx.value;
10116: if ((cutidxlist != '') && (cutidxlist != null)) {
10117: var cutidxs = cutidxlist.split(',');
10118: for (var i=0; i<cutidxs.length; i++) {
10119: if (document.getElementById('cut_'+cutidxs[i])) {
10120: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
10121: form.multicut.value += cutidxs[i]+',';
10122: numchanges ++;
1.542 raeburn 10123: if (document.getElementById('skip_cut_'+cutidxs[i])) {
10124: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
10125: cutwarnings ++;
10126: }
10127: }
1.537 raeburn 10128: }
10129: }
10130: }
10131: }
1.538 raeburn 10132: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10133: if ((copyidxlist != '') && (copyidxlist != null)) {
10134: var copyidxs = copyidxlist.split(',');
10135: for (var i=0; i<copyidxs.length; i++) {
10136: if (document.getElementById('copy_'+copyidxs[i])) {
10137: if (document.getElementById('copy_'+copyidxs[i]).checked) {
10138: form.multicopy.value += copyidxs[i]+',';
10139: numchanges ++;
10140: }
10141: }
10142: }
10143: }
10144: if (numchanges > 0) {
10145: form.multichange.value = numchanges;
10146: }
1.537 raeburn 10147: }
1.538 raeburn 10148: var dosettings = multiSettings();
1.543 raeburn 10149: var haschanges = 0;
1.538 raeburn 10150: if (dosettings == 1) {
10151: form.allencrypturl.value = '';
10152: form.allhiddenresource.value = '';
1.543 raeburn 10153: form.changeparms.value = 'all';
10154: var patt=new RegExp(",\$");
1.538 raeburn 10155: var allidxlist = document.cumulativesettings.allidx.value;
10156: if ((allidxlist != '') && (allidxlist != null)) {
10157: var allidxs = allidxlist.split(',');
10158: if (allidxs.length > 1) {
10159: for (var i=0; i<allidxs.length; i++) {
10160: if (document.getElementById('hiddenresource_'+allidxs[i])) {
10161: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
10162: form.allhiddenresource.value += allidxs[i]+',';
10163: }
10164: }
10165: if (document.getElementById('encrypturl_'+allidxs[i])) {
10166: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
10167: form.allencrypturl.value += allidxs[i]+',';
10168: }
10169: }
10170: }
1.543 raeburn 10171: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
10172: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 10173: }
1.538 raeburn 10174: }
10175: form.allrandompick.value = '';
10176: form.allrandomorder.value = '';
10177: var allmapidxlist = document.cumulativesettings.allmapidx.value;
10178: if ((allmapidxlist != '') && (allmapidxlist != null)) {
10179: var allmapidxs = allmapidxlist.split(',');
10180: for (var i=0; i<allmapidxs.length; i++) {
10181: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
10182: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
10183: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
10184: if ((randompick.checked) && (rpicknum.value != '')) {
10185: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
10186: }
10187: if (randorder.checked) {
10188: form.allrandomorder.value += allmapidxs[i]+',';
10189: }
1.537 raeburn 10190: }
1.543 raeburn 10191: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
10192: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
10193: }
10194: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
10195: haschanges = 1;
10196: }
10197: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
10198: haschanges = 1;
10199: }
10200: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
10201: haschanges = 1;
10202: }
10203: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
10204: haschanges = 1;
1.537 raeburn 10205: }
10206: }
1.543 raeburn 10207: if (doactions == 1) {
1.542 raeburn 10208: if (numchanges > 0) {
1.603 raeburn 10209: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 10210: if (remwarnings > 0) {
1.594 damieng 10211: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 10212: return false;
10213: }
10214: }
1.603 raeburn 10215: if (removalinfo > 0) {
10216: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
10217: return false;
10218: }
10219: }
1.542 raeburn 10220: if (cutwarnings > 0) {
1.594 damieng 10221: 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 10222: return false;
10223: }
10224: }
10225: }
10226: form.submit();
10227: return true;
1.543 raeburn 10228: }
10229: }
10230: if (dosettings == 1) {
10231: if (haschanges == 1) {
1.542 raeburn 10232: form.submit();
10233: return true;
10234: }
1.543 raeburn 10235: }
10236: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 10237: alert("$js_lt{'noor'}");
1.543 raeburn 10238: } else {
10239: if (dosettings == 1) {
1.594 damieng 10240: alert("$js_lt{'noch'}");
1.543 raeburn 10241: } else {
1.594 damieng 10242: alert("$js_lt{'noac'}");
1.543 raeburn 10243: }
10244: }
1.538 raeburn 10245: return false;
10246: }
10247:
10248: function setClass(value) {
10249: var cutclass = 'LC_docs_cut';
10250: var copyclass = 'LC_docs_copy';
10251: var removeclass = 'LC_docs_remove';
10252: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
10253: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
10254: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
10255: var links = document.getElementsByTagName('a');
10256: for (var i=0; i<links.length; i++) {
10257: var classes = links[i].className;
10258: if (cutreg.test(classes)) {
10259: links[i].className = cutclass;
10260: if (value == 1) {
10261: links[i].className += " LC_menubuttons_link";
10262: }
10263: } else {
10264: if (copyreg.test(classes)) {
10265: links[i].className = copyclass;
10266: if (value == 1) {
10267: links[i].className += " LC_menubuttons_link";
10268: }
10269: } else {
10270: if (removereg.test(classes)) {
10271: links[i].className = removeclass;
10272: if (value == 1) {
10273: links[i].className += " LC_menubuttons_link";
10274: }
10275: }
10276: }
10277: }
10278: }
10279: return;
1.537 raeburn 10280: }
10281:
1.538 raeburn 10282: function setBoxes(value) {
10283: var remidxlist = document.cumulativeactions.allremoveidx.value;
10284: if ((remidxlist != '') && (remidxlist != null)) {
10285: var remidxs = remidxlist.split(',');
10286: for (var i=0; i<remidxs.length; i++) {
10287: if (document.getElementById('remove_'+remidxs[i])) {
10288: var item = document.getElementById('remove_'+remidxs[i]);
10289: if (value == 1) {
10290: item.className = 'LC_docs_remove';
10291: } else {
10292: item.className = 'LC_hidden';
10293: }
10294: }
10295: }
10296: }
10297: var cutidxlist = document.cumulativeactions.allcutidx.value;
10298: if ((cutidxlist != '') && (cutidxlist != null)) {
10299: var cutidxs = cutidxlist.split(',');
10300: for (var i=0; i<cutidxs.length; i++) {
10301: if (document.getElementById('cut_'+cutidxs[i])) {
10302: var item = document.getElementById('cut_'+cutidxs[i]);
10303: if (value == 1) {
10304: item.className = 'LC_docs_cut';
10305: } else {
10306: item.className = 'LC_hidden';
10307: }
10308: }
1.537 raeburn 10309: }
10310: }
1.538 raeburn 10311: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10312: if ((copyidxlist != '') && (copyidxlist != null)) {
10313: var copyidxs = copyidxlist.split(',');
10314: for (var i=0; i<copyidxs.length; i++) {
10315: if (document.getElementById('copy_'+copyidxs[i])) {
10316: var item = document.getElementById('copy_'+copyidxs[i]);
10317: if (value == 1) {
10318: item.className = 'LC_docs_copy';
10319: } else {
10320: item.className = 'LC_hidden';
10321: }
10322: }
1.537 raeburn 10323: }
10324: }
10325: return;
10326: }
10327:
1.606 raeburn 10328: function validImportCrsRes() {
10329: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10330: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10331: if ((fname == '') || (fname == null)) {
10332: alert("$js_lt{'nofi'}");
10333: return false;
10334: }
10335: var url = '/res/$coursedom/$coursenum/';
10336: if (path && path != '/') {
10337: url += path+'/';
10338: }
10339: if (fname != '') {
10340: url += fname;
10341: }
10342: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10343: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10344: return true;
10345: }
10346:
10347: function validateNewRes(caller) {
10348: if (caller == 'single') {
10349: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10350: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10351: var resname = document.courseresform.newresourcename.value;
10352: }
10353: }
10354:
1.611 raeburn 10355: ENDSCRIPT
1.329 droeschl 10356: }
1.457 raeburn 10357:
1.483 raeburn 10358: sub history_tab_js {
10359: return <<"ENDHIST";
10360: function toggleHistoryDisp(choice) {
10361: document.docslogform.docslog.value = choice;
10362: document.docslogform.submit();
10363: return;
10364: }
10365:
10366: ENDHIST
10367: }
10368:
1.484 raeburn 10369: sub inject_data_js {
10370: return <<ENDINJECT;
10371:
10372: function injectData(current, hiddenField, name, value) {
10373: currentElement = document.getElementById(hiddenField);
10374: currentElement.name = name;
10375: currentElement.value = value;
10376: current.submit();
10377: }
10378:
10379: ENDINJECT
10380: }
10381:
10382: sub dump_switchserver_js {
10383: my @hosts = @_;
1.594 damieng 10384: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10385: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10386: swit => 'Switch server?',
1.594 damieng 10387: );
10388: my %html_js_lt = &Apache::lonlocal::texthash(
10389: swit => 'Switch server?',
1.709 raeburn 10390: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10391: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10392: chos => 'Choose server',
10393: );
1.594 damieng 10394: &js_escape(\%js_lt);
10395: &html_escape(\%html_js_lt);
10396: &js_escape(\%html_js_lt);
1.484 raeburn 10397: my $role = $env{'request.role'};
10398: my $js = <<"ENDSWJS";
10399: <script type="text/javascript">
10400: function write_switchserver() {
10401: var server;
10402: if (document.setserver.posshosts.length > 0) {
10403: for (var i=0; i<document.setserver.posshosts.length; i++) {
10404: if (document.setserver.posshosts[i].checked) {
10405: server = document.setserver.posshosts[i].value;
10406: }
10407: }
10408: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10409: }
10410: window.close();
10411: }
10412: </script>
10413:
10414: ENDSWJS
10415:
10416: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10417: {'only_body' => 1,
10418: 'js_ready' => 1,});
10419: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10420:
10421: my $hostpicker;
10422: my $count = 0;
10423: foreach my $host (sort(@hosts)) {
10424: my $checked;
10425: if ($count == 0) {
10426: $checked = ' checked="checked"';
10427: }
10428: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10429: $host.'"'.$checked.' />'.$host.'</label> ';
10430: $count++;
10431: }
10432:
10433: return <<"ENDSWITCHJS";
10434:
10435: function dump_needs_switchserver(url) {
10436: if (url!='' && url!= null) {
1.594 damieng 10437: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10438: go(url);
10439: }
10440: }
10441: return;
10442: }
10443:
10444: function choose_switchserver_window() {
10445: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10446: newWindow.document.open();
10447: newWindow.document.writeln('$startpage');
1.594 damieng 10448: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10449: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10450: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10451: '<form name="setserver" method="post" action="" \\/>\\n'+
10452: '$hostpicker\\n'+
10453: '<br \\/><br \\/>\\n'+
1.594 damieng 10454: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10455: 'onclick="write_switchserver();" \\/>\\n'+
10456: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10457: newWindow.document.writeln('$endpage');
10458: newWindow.document.close();
10459: newWindow.focus();
10460: }
10461:
10462: ENDSWITCHJS
10463: }
10464:
10465: sub makedocslogform {
10466: my ($formelems,$docslog) = @_;
10467: return <<"LOGSFORM";
10468: <form action="/adm/coursedocs" method="post" name="docslogform">
10469: <input type="hidden" name="docslog" value="$docslog" />
10470: $formelems
10471: </form>
10472: LOGSFORM
10473: }
10474:
10475: sub makesimpleeditform {
10476: my ($formelems) = @_;
10477: return <<"SIMPFORM";
10478: <form name="simpleedit" method="post" action="/adm/coursedocs">
10479: <input type="hidden" name="importdetail" value="" />
10480: $formelems
10481: </form>
10482: SIMPFORM
10483: }
10484:
1.606 raeburn 10485: sub makenewproblem {
10486: my ($r,$coursedom,$coursenum) = @_;
10487: # Creating a new problem
10488: my ($redirect,$error);
10489: if ($env{'form.authorrole'}) {
10490: my ($newsubdir,$filename);
10491: if ($env{'form.newsubdir'}) {
10492: if ($env{'form.newsubdirname'} ne '') {
10493: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10494: }
1.606 raeburn 10495: }
10496: if ($env{'form.newresourcename'}) {
10497: $filename = $env{'form.newresourcename'};
10498: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10499: $filename =~ s/`//g;
10500: $filename =~ s{/\.\./}{_}g;
10501: $filename =~ s/\.+/./g;
10502: $filename =~ s{/+}{_}g;
10503: if ($filename ne '') {
10504: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10505: if (($ext) && ($ext ne '.problem')) {
10506: $filename = $name.'.problem';
10507: } elsif ($ext eq '') {
10508: $filename .= '.problem';
10509: }
10510: my $docroot = $r->dir_config('lonDocRoot');
10511: my @ids=&Apache::lonnet::current_machine_ids();
10512: if ($env{'form.authorrole'} eq 'author') {
10513: if ($env{'user.author'}) {
10514: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10515: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10516: my $path = $docroot.$url;
10517: my $subdir = $env{'form.authorpath'};
10518: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10519: }
10520: }
10521: } elsif ($env{'form.authorrole'} eq 'course') {
10522: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10523: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10524: my $url = "/priv/$coursedom/$coursenum";
10525: my $path=$docroot.$url;
10526: my $subdir = $env{'form.authorpath'};
10527: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10528: if ($redirect) {
10529: my $rightsfile = 'default.rights';
10530: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10531: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10532: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10533: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10534: if (!-e "$docroot/res/$coursedom") {
10535: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10536: }
1.654 raeburn 10537: if (!-e "$docroot/res/$coursedom/$coursenum") {
10538: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10539: }
10540: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10541: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10542: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10543: }
10544: }
1.654 raeburn 10545: my $source = $docroot.$redirect;
10546: if (!-e "$source.meta") {
10547: my $cid = $coursedom.'_'.$coursenum;
10548: my $now = time;
10549: if (open(my $fh,">$source.meta")) {
10550: my $author=$env{'environment.firstname'}.' '.
10551: $env{'environment.middlename'}.' '.
10552: $env{'environment.lastname'}.' '.
10553: $env{'environment.generation'};
10554: $author =~ s/\s+$//;
10555: my $title = $env{'form.newresourcetitle'};
10556: $title =~ s/^\s+|\s+$//g;
10557: print $fh <<END;
1.606 raeburn 10558:
10559: <abstract></abstract>
10560: <author>$author</author>
10561: <authorspace>$coursenum:$coursedom</authorspace>
10562: <copyright>custom</copyright>
10563: <creationdate>$now</creationdate>
10564: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10565: <dependencies></dependencies>
10566: <domain>$coursedom</domain>
10567: <highestgradelevel>0</highestgradelevel>
10568: <keywords></keywords>
10569: <language>notset </language>
10570: <lastrevisiondate>$now</lastrevisiondate>
10571: <lowestgradelevel>0</lowestgradelevel>
10572: <mime>problem</mime>
10573: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10574: <notes></notes>
10575: <obsolete></obsolete>
10576: <obsoletereplacement></obsoletereplacement>
10577: <owner>$coursenum:$coursedom</owner>
10578: <sourceavail></sourceavail>
10579: <standards></standards>
10580: <subject></subject>
10581: <title>$title</title>
10582: END
1.654 raeburn 10583: close($fh);
1.606 raeburn 10584: }
10585: }
10586: }
10587: }
10588: } else {
10589: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10590: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10591: if (grep(/^\Q$rolehome\E$/,@ids)) {
10592: my $now = time;
10593: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10594: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10595: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10596: my $url = "/priv/$audom/$auname";
10597: my $path = $r->dir_config('lonDocRoot').$url;
10598: my $subdir = $env{'form.authorpath'};
10599: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10600: }
10601: }
10602: }
10603: }
10604: }
10605: }
10606: }
10607: return ($redirect,$error);
10608: }
10609:
10610: sub finishnewprob {
1.654 raeburn 10611: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10612: unless (-d $path) {
10613: unless (mkdir($path,02770)) {
10614: return;
10615: }
10616: }
1.606 raeburn 10617: my $redirect;
10618: if ($subdir ne '/') {
10619: $subdir = &cleandir($subdir);
10620: if (($subdir ne '') && (-d "$path/$subdir")) {
10621: $path .= "/$subdir";
10622: $url .= "/$subdir";
10623: }
10624: }
10625: my $dest;
10626: if ($newsubdir ne '') {
10627: $newsubdir = &cleandir($newsubdir);
10628: }
10629: if ($newsubdir ne '') {
10630: if (-d "$path/$newsubdir") {
10631: $dest = "$path/$newsubdir/$filename";
10632: } else {
10633: my $dirok;
10634: unless (-e "$path/$newsubdir") {
10635: if (mkdir("$path/$newsubdir",02770)) {
10636: if (chmod(02770,"$path/$newsubdir")) {
10637: $dirok = 1;
10638: }
10639: }
10640: }
10641: if ($dirok) {
10642: $dest = "$path/$newsubdir/$filename";
10643: }
10644: }
10645: if (($dest ne '') && (!-e $dest)) {
10646: $redirect = "$url/$newsubdir/$filename";
10647: }
10648: } else {
10649: $dest = "$path/$filename";
10650: if (($dest ne '') && (!-e $dest)) {
10651: $redirect = "$url/$filename";
10652: }
10653: }
1.654 raeburn 10654: if ((!-e $dest) && ($context ne 'upload')) {
10655: my $template = $env{'form.template'};
10656: my $copyfrom;
10657: if ($template ne '') {
10658: my %templates;
10659: my @files = &Apache::lonhomework::get_template_list('problem');
10660: foreach my $poss (@files) {
10661: if (ref($poss) eq 'ARRAY') {
10662: if ($template eq $poss->[0]) {
10663: $templates{$template} = 1;
10664: last;
10665: }
10666: }
10667: }
10668: if ($templates{$template}) {
10669: $copyfrom = $template;
10670: }
10671: }
10672: if ($filename =~ /\.problem$/) {
10673: unless ($copyfrom) {
10674: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10675: }
10676: &File::Copy::copy($copyfrom,$dest);
10677: }
10678: }
1.606 raeburn 10679: return $redirect;
10680: }
10681:
10682: sub cleandir {
10683: my ($dir) = @_;
10684: $dir =~ s/^\s+//;
10685: $dir =~ s/\s+$//;
10686: $dir =~ s/\.+//g;
10687: $dir =~ s/[\#\?&%\":]//g;
10688: return $dir;
10689: }
10690:
1.329 droeschl 10691: 1;
10692: __END__
10693:
10694:
10695: =head1 NAME
10696:
10697: Apache::londocs.pm
10698:
10699: =head1 SYNOPSIS
10700:
10701: This is part of the LearningOnline Network with CAPA project
10702: described at http://www.lon-capa.org.
10703:
10704: =head1 SUBROUTINES
10705:
10706: =over
10707:
10708: =item %help=()
10709:
10710: Available help topics
10711:
10712: =item mapread()
10713:
1.344 bisitz 10714: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10715: @order and @resources, determines status
10716: sets @order - pointer to resources in right order
10717: sets @resources - array with the resources with correct idx
10718:
10719: =item authorhosts()
10720:
10721: Return hash with valid author names
10722:
10723: =item clean()
10724:
10725: =item dumpcourse()
10726:
10727: Actually dump course
10728:
10729: =item group_import()
10730:
10731: Imports the given (name, url) resources into the course
10732: coursenum, coursedom, and folder must precede the list
10733:
10734: =item breadcrumbs()
10735:
10736: =item log_docs()
10737:
10738: =item docs_change_log()
10739:
10740: =item update_paste_buffer()
10741:
10742: =item print_paste_buffer()
10743:
10744: =item do_paste_from_buffer()
10745:
1.538 raeburn 10746: =item do_buffer_empty()
10747:
10748: =item clear_from_buffer()
10749:
1.492 raeburn 10750: =item get_newmap_url()
10751:
10752: =item dbcopy()
10753:
10754: =item uniqueness_check()
10755:
10756: =item contained_map_check()
10757:
10758: =item url_paste_fixups()
10759:
10760: =item apply_fixups()
10761:
10762: =item copy_dependencies()
10763:
1.329 droeschl 10764: =item update_parameter()
10765:
10766: =item handle_edit_cmd()
10767:
10768: =item editor()
10769:
10770: =item process_file_upload()
10771:
10772: =item process_secondary_uploads()
10773:
10774: =item is_supplemental_title()
10775:
10776: =item entryline()
10777:
10778: =item tiehash()
10779:
10780: =item untiehash()
10781:
10782: =item checkonthis()
10783:
10784: check on this
10785:
10786: =item verifycontent()
10787:
10788: Verify Content
10789:
1.636 raeburn 10790: =item devalidateversioncache()
10791:
10792: =item checkversions()
1.329 droeschl 10793:
10794: Check Versions
10795:
10796: =item mark_hash_old()
10797:
10798: =item is_hash_old()
10799:
10800: =item changewarning()
10801:
10802: =item init_breadcrumbs()
10803:
10804: Breadcrumbs for special functions
10805:
1.484 raeburn 10806: =item create_list_elements()
10807:
10808: =item create_form_ul()
10809:
10810: =item startContentScreen()
10811:
10812: =item endContentScreen()
10813:
10814: =item supplemental_base()
10815:
10816: =item embedded_form_elems()
10817:
10818: =item embedded_destination()
10819:
10820: =item return_to_editor()
10821:
10822: =item decompression_info()
10823:
10824: =item decompression_phase_one()
10825:
10826: =item decompression_phase_two()
10827:
10828: =item remove_archive()
10829:
10830: =item generate_admin_menu()
10831:
10832: =item generate_edit_table()
10833:
10834: =item editing_js()
10835:
10836: =item history_tab_js()
10837:
10838: =item inject_data_js()
10839:
10840: =item dump_switchserver_js()
10841:
1.485 raeburn 10842: =item resize_scrollbox_js()
1.484 raeburn 10843:
10844: =item makedocslogform()
10845:
1.485 raeburn 10846: =item makesimpleeditform()
10847:
1.329 droeschl 10848: =back
10849:
10850: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>