Annotation of loncom/interface/londocs.pm, revision 1.712
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.712 ! raeburn 4: # $Id: londocs.pm,v 1.711 2024/12/15 02:22:53 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.651 raeburn 48: use Apache::loncourserespicker();
1.329 droeschl 49: use HTML::Entities;
1.488 raeburn 50: use HTML::TokeParser;
1.329 droeschl 51: use GDBM_File;
1.578 raeburn 52: use File::MMagic;
1.606 raeburn 53: use File::Copy;
1.329 droeschl 54: use Apache::lonlocal;
55: use Cwd;
1.643 raeburn 56: use UUID::Tiny ':std';
1.329 droeschl 57: use LONCAPA qw(:DEFAULT :match);
58:
59: my $iconpath;
60:
61: my %hash;
62:
63: my $hashtied;
64: my %alreadyseen=();
65:
66: my $hadchanges;
1.557 raeburn 67: my $suppchanges;
1.329 droeschl 68:
69:
70: my %help=();
71:
72:
73: sub mapread {
74: my ($coursenum,$coursedom,$map)=@_;
75: return
76: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map);
78: }
79:
80: sub storemap {
1.492 raeburn 81: my ($coursenum,$coursedom,$map,$contentchg)=@_;
82: my $report;
83: if (($contentchg) && ($map =~ /^default/)) {
84: $report = 1;
85: }
1.329 droeschl 86: my ($outtext,$errtext)=
87: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 88: $map,1,$report);
1.329 droeschl 89: if ($errtext) { return ($errtext,2); }
1.364 bisitz 90:
1.557 raeburn 91: if ($map =~ /^default/) {
92: $hadchanges=1;
1.682 raeburn 93: } elsif ($contentchg) {
1.557 raeburn 94: $suppchanges=1;
95: }
1.329 droeschl 96: return ($errtext,0);
97: }
98:
99:
100:
101: sub authorhosts {
102: my %outhash=();
103: my $home=0;
104: my $other=0;
1.709 raeburn 105: my @ids=&Apache::lonnet::current_machine_ids();
1.329 droeschl 106: foreach my $key (keys(%env)) {
107: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
108: my $role=$1;
109: my $realm=$2;
110: my ($start,$end)=split(/\./,$env{$key});
111: if (($start) && ($start>time)) { next; }
112: if (($end) && (time>$end)) { next; }
113: my ($ca,$cd);
114: if ($1 eq 'au') {
115: $ca=$env{'user.name'};
116: $cd=$env{'user.domain'};
117: } else {
118: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
119: }
120: my $allowed=0;
121: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
1.484 raeburn 122: foreach my $id (@ids) {
123: if ($id eq $myhome) {
124: $allowed=1;
125: last;
126: }
127: }
1.329 droeschl 128: if ($allowed) {
129: $home++;
1.484 raeburn 130: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 131: } else {
1.484 raeburn 132: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 133: $other++;
134: }
135: }
136: }
137: return ($home,$other,%outhash);
138: }
139:
140:
141: sub clean {
142: my ($title)=@_;
143: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 144: return $title;
1.329 droeschl 145: }
146:
1.617 raeburn 147: sub default_folderpath {
148: my ($coursenum,$coursedom,$navmapref) = @_;
149: return unless ($coursenum && $coursedom && ref($navmapref));
150: # Check if entire course is hidden and/or encrypted
151: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
152: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
153: unless (ref($$navmapref)) {
154: $$navmapref = Apache::lonnavmaps::navmap->new();
155: }
156: if (ref($$navmapref)) {
157: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
158: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
159: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
160: unless (@resources) {
161: $hiddenmap = 1;
162: unless ($env{'request.role.adv'}) {
163: $hiddentop = 1;
164: if ($env{'form.folder'}) {
165: undef($env{'form.folder'});
166: }
167: }
168: }
169: }
170: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
171: $encryptmap = 1;
172: }
173: }
174: unless ($hiddentop) {
175: $folderpath='default&'.&escape(&mt('Main Content')).
176: '::'.$hiddenmap.':'.$encryptmap.'::';
177: }
178: if (wantarray) {
179: return ($folderpath,$hiddentop);
180: } else {
181: return $folderpath;
182: }
183: }
1.329 droeschl 184:
1.685 raeburn 185: sub validate_supppath {
186: my ($coursenum,$coursedom) = @_;
187: my $backto;
1.677 raeburn 188: if ($env{'form.supppath'} ne '') {
189: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 190: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
194: $badpath = 1;
1.685 raeburn 195: last;
196: } elsif ($odd) {
197: my $suffix;
198: my $idx = $i-1;
199: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
200: $backto .= '&'.$1;
201: } elsif ($items[$idx] eq 'supplemental') {
202: $backto .= '&'.$items[$i];
203: } else {
204: $backto .= '&'.$items[$i];
205: my $is_hidden;
206: unless ($got_supp) {
1.688 raeburn 207: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 208: if (ref($supplemental) eq 'HASH') {
209: if (ref($supplemental->{'hidden'}) eq 'HASH') {
210: %supphidden = %{$supplemental->{'hidden'}};
211: }
212: if (ref($supplemental->{'ids'}) eq 'HASH') {
213: %suppids = %{$supplemental->{'ids'}};
214: }
215: }
216: $got_supp = 1;
217: }
218: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
219: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
220: if ($supphidden{$mapid}) {
221: $is_hidden = 1;
222: }
223: }
224: $suffix = '::'.$is_hidden.':::';
225: }
226: $supppath .= '&'.$items[$i].$suffix;
227: } else {
228: $supppath .= '&'.$items[$i];
229: $backto .= '&'.$items[$i];
1.677 raeburn 230: }
231: }
232: if ($badpath) {
233: delete($env{'form.supppath'});
1.685 raeburn 234: } else {
235: $supppath =~ s/^\&//;
236: $backto =~ s/^\&//;
237: $env{'form.supppath'} = $supppath;
1.677 raeburn 238: }
239: }
1.685 raeburn 240: return $backto;
1.677 raeburn 241: }
242:
1.329 droeschl 243: sub dumpcourse {
244: my ($r) = @_;
1.408 raeburn 245: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 246: my ($starthash,$js);
247: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
248: $js = <<"ENDJS";
249: <script type="text/javascript">
250: // <![CDATA[
251:
252: function hide_searching() {
253: if (document.getElementById('searching')) {
254: document.getElementById('searching').style.display = 'none';
255: }
256: return;
257: }
258:
259: // ]]>
260: </script>
261: ENDJS
262: $starthash = {
263: add_entries => {'onload' => "hide_searching();"},
264: };
265: }
1.709 raeburn 266: $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
267: &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n");
1.484 raeburn 268: $r->print(&startContentScreen('tools'));
1.329 droeschl 269: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 270: unless ($home) {
1.712 ! raeburn 271: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
1.484 raeburn 272: $r->print(&endContentScreen());
273: return '';
274: }
1.329 droeschl 275: my $origcrsid=$env{'request.course.id'};
276: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
277: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
278: # Do the dumping
1.484 raeburn 279: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
1.712 ! raeburn 280: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
! 281: &endContentScreen());
1.484 raeburn 282: return '';
283: }
1.531 raeburn 284: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 285: $r->print('<h3>'.&mt('Copying Files').'</h3>');
286: my $title=$env{'form.authorfolder'};
287: $title=&clean($title);
1.567 raeburn 288: my ($navmap,$errormsg) =
289: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
290: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
291: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
292: my (%maps,%resources,%titles);
293: if (!ref($navmap)) {
294: $r->print($errormsg.
295: &endContentScreen());
296: return '';
297: } else {
298: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
299: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 300: }
1.567 raeburn 301: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
302: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
303: %newcontent,%has_simpleprobs);
304: foreach my $item (sort {$a <=> $b} (@todump)) {
305: my $name = $env{'form.namefor_'.$item};
306: if ($resources{$item}) {
307: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
308: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
309: $tocopy{$1} = $name;
310: $display{$item} = $1;
311: $lookup{$1} = $item;
312: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
313: $simpleproblems{$item} = {
314: symb => $resources{$item},
315: name => $name,
316: };
317: $display{$item} = 'simpleproblem_'.$name;
318: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
319: $has_simpleprobs{$1}{$id} = $item;
320: }
321: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
322: my $marker = $1;
323: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
324: $simplepages{$item} = {
325: res => $res,
326: title => $titles{$item},
327: db => $db_name,
328: marker => $marker,
329: symb => $resources{$item},
330: name => $name,
331: };
332: $display{$item} = '/'.$res;
333: }
334: } elsif ($maps{$item}) {
335: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
336: $tocopy{$1} = $name;
337: $display{$item} = $1;
338: $lookup{$1} = $item;
339: }
340: } else {
341: next;
342: }
343: }
1.329 droeschl 344: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
345: $crs=~s/\_/\//g;
1.567 raeburn 346: my $mm = new File::MMagic;
347: my $prefix = "/uploaded/$cdom/$cnum/";
348: %replacehash = %tocopy;
349: foreach my $item (sort(keys(%simpleproblems))) {
350: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
351: $newcontent{$display{$item}} = $content;
352: }
353: my $gateway = Apache::lonhtmlgateway->new('web');
354: foreach my $item (sort(keys(%simplepages))) {
355: if (ref($simplepages{$item}) eq 'HASH') {
356: my $pagetitle = $simplepages{$item}{'title'};
357: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
358: my %contents;
359: foreach my $field (keys(%fields)) {
360: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
361: my $name = $1;
362: my $msg = $fields{$field};
363: if ($name eq 'webreferences') {
364: if ($msg =~ m{^https?://}) {
365: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
366: }
367: } else {
368: $msg = &Encode::decode('utf8',$msg);
369: $msg = $gateway->process_outgoing_html($msg,1);
370: $contents{$name} = $msg;
371: }
372: } elsif ($field eq 'uploaded.photourl') {
373: my $marker = $simplepages{$item}{marker};
374: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
375: my $filepath = $1;
376: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
377: if ($fname ne '') {
378: $fname=~s/\.(\w+)$//;
379: my $ext=$1;
380: $fname = &clean($fname);
381: $fname.='.'.$ext;
382: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
383: $replacehash{$filepath} = $relpath.$fname;
384: $deps{$item}{$filepath} = 1;
385: }
386: }
387: }
388: }
389: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
390: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
391: my $content = '
392: <html>
393: <head>
394: <title>'.$pagetitle.'</title>
395: </head>
396: <body bgcolor="#ffffff">';
397: if ($contents{title}) {
398: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
399: }
400: if ($contents{image}) {
401: $content .= "\n".$contents{image};
402: }
403: if ($contents{content}) {
404: $content .= '
405: <div class="LC_Box">
1.577 bisitz 406: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 407: $contents{content}.'
408: </div>';
409: }
410: if ($contents{webreferences}) {
411: $content .= '
412: <div class="LC_Box">
1.577 bisitz 413: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 414: $contents{webreferences}.'
415: </div>';
416: }
417: $content .= '
418: </body>
419: </html>
420: ';
421: $newcontent{'/'.$simplepages{$item}{res}} = $content;
422: }
423: }
424: foreach my $item (keys(%tocopy)) {
425: unless ($item=~/\.(sequence|page)$/) {
426: my $currurlpath = $prefix.$item;
427: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
428: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
429: }
430: }
431: foreach my $num (sort {$a <=> $b} (@todump)) {
432: my $src = $display{$num};
433: next if ($src eq '');
434: my @needcopy = ();
435: if ($replacehash{$src}) {
436: push(@needcopy,$src);
437: if (ref($deps{$num}) eq 'HASH') {
438: foreach my $dep (sort(keys(%{$deps{$num}}))) {
439: if ($replacehash{$dep}) {
440: push(@needcopy,$dep);
441: }
442: }
443: }
444: } elsif ($src =~ /^simpleproblem_/) {
445: push(@needcopy,$src);
446: }
447: next if (@needcopy == 0);
448: my ($result,$depresult);
449: for (my $i=0; $i<@needcopy; $i++) {
450: my $item = $needcopy[$i];
451: my $newfilename;
452: if ($simpleproblems{$num}) {
453: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
454: } else {
455: $newfilename=$title.'/'.$replacehash{$item};
456: }
457: $newfilename=~s/\.(\w+)$//;
458: my $ext=$1;
459: $newfilename=&clean($newfilename);
460: $newfilename.='.'.$ext;
461: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
462: if ($newrelpath ne $replacehash{$item}) {
463: $replacehash{$item} = $newrelpath;
464: }
465: my @dirs=split(/\//,$newfilename);
466: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
467: my $makepath=$path;
468: my $fail;
469: my $origin;
470: for (my $i=0;$i<$#dirs;$i++) {
471: $makepath.='/'.$dirs[$i];
472: unless (-e $makepath) {
473: unless(mkdir($makepath,0755)) {
474: $fail = &mt('Directory creation failed.');
475: }
476: }
477: }
478: if ($i == 0) {
479: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
480: } else {
481: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
482: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
483: &mt('(dependency)').'</span>: ';
484: }
485: if (-e $path.'/'.$newfilename) {
486: $fail = &mt('Destination already exists -- not overwriting.');
487: } else {
488: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
489: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
490: ($item =~ /^simpleproblem_/)) {
491: print $fh $newcontent{$item};
492: } else {
493: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
494: if (-e $fileloc) {
495: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
496: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
497: (ref($has_simpleprobs{$item}) eq 'HASH')) {
498: my %changes = %{$has_simpleprobs{$item}};
499: my $content = &Apache::lonclonecourse::rewritefile(
500: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
501: (%replacehash,$crs => '')
502: );
503: my $updatedcontent = '';
504: my $parser = HTML::TokeParser->new(\$content);
505: $parser->attr_encoded(1);
506: while (my $token = $parser->get_token) {
507: if ($token->[0] eq 'S') {
508: if (($token->[1] eq 'resource') &&
509: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
510: ($changes{$token->[2]->{'id'}})) {
511: my $id = $token->[2]->{'id'};
512: $updatedcontent .= '<'.$token->[1];
513: foreach my $attrib (@{$token->[3]}) {
514: next unless ($attrib =~ /^(src|type|title|id)$/);
515: if ($attrib eq 'src') {
516: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
517: if ($file) {
518: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
519: } else {
520: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
521: }
522: } else {
523: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
524: }
525: }
526: $updatedcontent .= ' />'."\n";
527: } else {
528: $updatedcontent .= $token->[4]."\n";
529: }
530: } else {
531: $updatedcontent .= $token->[2];
532: }
533: }
534: print $fh $updatedcontent;
535: } else {
536: print $fh &Apache::lonclonecourse::rewritefile(
537: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
538: (%replacehash,$crs => '')
539: );
540: }
541: } else {
542: print $fh
543: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
544: }
545: } else {
546: $fail = &mt('Source does not exist.');
547: }
548: }
549: $fh->close();
550: } else {
551: $fail = &mt('Could not write to destination.');
552: }
553: }
554: my $text;
555: if ($fail) {
556: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
557: } else {
558: $text = '<span class="LC_success">'.&mt('ok').'</span>';
559: }
560: if ($i == 0) {
561: $result .= $text;
562: } else {
563: $depresult .= $text.'</li>';
564: }
565: }
566: $r->print($result);
567: if ($depresult) {
568: $r->print('<ul>'.$depresult.'</ul>');
569: }
570: }
571: } else {
572: my ($navmap,$errormsg) =
573: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
574: if (!ref($navmap)) {
575: $r->print($errormsg);
576: } else {
577: my $title=$origcrsdata{'description'};
578: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 579: $title=&clean($title);
1.712 ! raeburn 580: my $formname = 'dumpdoc';
! 581: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash);
! 582: my %uploadedfiles;
1.567 raeburn 583: &tiehash();
584: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
585: my ($ext)=($file=~/\.(\w+)$/);
586: # FIXME Check supplemental here
587: my $title=$hash{'title_'.$hash{
588: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
589: if (!$title) {
590: $title=$file;
591: } else {
592: $title=~s|/|_|g;
593: }
594: $title=~s/\.(\w+)$//;
595: $title=&clean($title);
596: $title.='.'.$ext;
597: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
598: $uploadedfiles{$file} = $title;
599: }
600: &untiehash();
601: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
602: undef,undef,$preamble,$home,\%uploadedfiles));
603: }
1.329 droeschl 604: }
1.484 raeburn 605: $r->print(&endContentScreen());
1.329 droeschl 606: }
607:
1.712 ! raeburn 608: sub authorspace_selector {
! 609: my ($r,$formname,$home,$title,%outhash) = @_;
! 610: $r->print('<div id="searching">'.&mt('Searching ...').'</div>'."\n");
! 611: $r->rflush();
! 612: my $preamble;
! 613: unless ($home==1) {
! 614: $preamble = '<div class="LC_left_float">'.
! 615: '<fieldset><legend>'.
! 616: &mt('Select the Authoring Space').
! 617: '</legend><select name="authorspace">';
! 618: }
! 619: my @orderspaces = ();
! 620: foreach my $key (sort(keys(%outhash))) {
! 621: if ($key=~/^home_(.+)$/) {
! 622: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
! 623: unshift(@orderspaces,$1);
! 624: } else {
! 625: push(@orderspaces,$1);
! 626: }
! 627: }
! 628: }
! 629: if ($home>1) {
! 630: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
! 631: }
! 632: foreach my $user (@orderspaces) {
! 633: if ($home==1) {
! 634: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
! 635: } else {
! 636: $preamble .= '<option value="'.$user.'">'.$user.' - '.
! 637: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
! 638: }
! 639: }
! 640: unless ($home==1) {
! 641: $preamble .= '</select></fieldset></div>'."\n";
! 642: }
! 643: $preamble .= '<div class="LC_left_float">'.
! 644: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
! 645: '<input type="text" size="50" name="authorfolder" value="'.$title.'" />'."\n".
! 646: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
! 647: return $preamble;
! 648: }
! 649:
1.567 raeburn 650: sub recurse_html {
651: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
652: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
653: my (%allfiles,%codebase);
654: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
655: if (keys(%allfiles)) {
656: foreach my $dependency (keys(%allfiles)) {
657: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
658: my ($depurl,$relfile,$newcontainer);
659: if ($dependency =~ m{^/}) {
660: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
661: $relfile = $1;
662: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
663: $newcontainer = $1;
664: next if ($replacehash->{$newcontainer});
665: }
666: $depurl = $dependency;
667: } else {
668: next;
669: }
670: } else {
671: $relfile = $dependency;
672: $depurl = $currurlpath;
1.630 raeburn 673: $depurl =~ s{[^/]+$}{};
1.567 raeburn 674: $depurl .= $dependency;
1.630 raeburn 675: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 676: }
677: next if ($relfile eq '');
678: my $newname = $replacehash->{$container};
679: $newname =~ s{[^/]+$}{};
680: $replacehash->{$newcontainer} = $newname.$relfile;
681: $deps->{$item}{$newcontainer} = 1;
682: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
683: my $depfile = &Apache::lonnet::filelocation('',$depurl);
684: my $type = $mm->checktype_filename($depfile);
685: if ($type eq 'text/html') {
686: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
687: }
688: }
689: }
690: }
691: return;
692: }
693:
1.712 ! raeburn 694: sub copycrsauthored {
! 695: my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_;
! 696: my ($starthash,$js);
! 697: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
! 698: $js = <<"ENDJS";
! 699: <script type="text/javascript">
! 700: // <![CDATA[
! 701:
! 702: function hide_searching() {
! 703: if (document.getElementById('searching')) {
! 704: document.getElementById('searching').style.display = 'none';
! 705: }
! 706: return;
! 707: }
! 708:
! 709: // ]]>
! 710: </script>
! 711: ENDJS
! 712: $starthash = {
! 713: add_entries => {'onload' => "hide_searching();"},
! 714: };
! 715: }
! 716: $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
! 717: &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
! 718: $r->print(&startContentScreen('tools'));
! 719: my ($home,$other,%outhash)=&authorhosts();
! 720: unless ($home) {
! 721: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
! 722: $r->print(&endContentScreen());
! 723: return '';
! 724: }
! 725: my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
! 726: my $exclude = &Apache::lonnet::priv_exclude();
! 727: my $srcurl = "/priv/$coursedom/$coursenum";
! 728: my $srctop = $r->dir_config('lonDocRoot').$srcurl;
! 729: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
! 730: $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
! 731: if ($readonly) {
! 732: $r->print('<p class="LC_info">'.
! 733: &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
! 734: '</p>'.
! 735: &endContentScreen());
! 736: return '';
! 737: }
! 738: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
! 739: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
! 740: &endContentScreen());
! 741: return '';
! 742: }
! 743: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
! 744: my $desturl = "/priv/$cd/$ca";
! 745: my $desttop = $r->dir_config('lonDocRoot').$desturl;
! 746: my $subdir = &clean($env{'form.authorfolder'});
! 747: $subdir = &cleandir($subdir);
! 748: if ($subdir eq '') {
! 749: $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
! 750: &endContentScreen());
! 751: return '';
! 752: } elsif ($subdir =~/^_+$/) {
! 753: $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>'.
! 754: &endContentScreen());
! 755: return '';
! 756: }
! 757: my $is_course_home;
! 758: my @ids=&Apache::lonnet::current_machine_ids();
! 759: if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
! 760: $is_course_home = 1;
! 761: }
! 762: my (%tocopy,%dirs_to_make,%files_to_copy);
! 763: map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
! 764: if (keys(%tocopy)) {
! 765: my (%subdirs,%files);
! 766: &Apache::lonnet::recursedirs($home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
! 767: foreach my $possible (sort(keys(%tocopy))) {
! 768: if ($possible =~ m{/$}) {
! 769: my $possdir = $possible;
! 770: $possdir =~ s{^/+|/+$}{}g;
! 771: if (exists($subdirs{$possdir})) {
! 772: $dirs_to_make{$possdir} = 1;
! 773: } else {
! 774: delete($tocopy{$possible});
! 775: }
! 776: } else {
! 777: my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
! 778: my $found = 0;
! 779: if ($path eq '/') {
! 780: if (ref($files{$path}) eq 'HASH') {
! 781: if (exists($files{$path}{$fname})) {
! 782: $found = 1;
! 783: $files_to_copy{$fname} = 1;
! 784: }
! 785: }
! 786: } else {
! 787: $path =~ s{^/+|/+$}{}g;
! 788: if (ref($files{$path}) eq 'HASH') {
! 789: if (exists($files{$path}{$fname})) {
! 790: $dirs_to_make{$path} = 1;
! 791: $files_to_copy{"$path/$fname"} = 1;
! 792: $found = 1;
! 793: }
! 794: }
! 795: }
! 796: unless ($found) {
! 797: delete($tocopy{$possible});
! 798: }
! 799: }
! 800: }
! 801: } else {
! 802: $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
! 803: $r->print(&endContentScreen());
! 804: return '';
! 805: }
! 806: if (keys(%tocopy)) {
! 807: my $mm = new File::MMagic;
! 808: my ($notopdir,%newdir,%newfile);
! 809: $r->print('<p>'.&mt('Copy to: [_1]',
! 810: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
! 811: '</p>'."\n");
! 812: unless ($is_course_home) {
! 813: $r->print('<p class="LC_info>'.&mt("Session needs to be hosted on course's home server.").
! 814: '</p>'.
! 815: &endContentScreen());
! 816: return '';
! 817: }
! 818: if (keys(%dirs_to_make)) {
! 819: if ($is_course_home) {
! 820: unless (-e $desttop.'/'.$subdir) {
! 821: mkdir($desttop.'/'.$subdir,0755);
! 822: }
! 823: if (-e $desttop.'/'.$subdir) {
! 824: foreach my $dir (sort(keys(%dirs_to_make))) {
! 825: my @dirs=split(/\//,$dir);
! 826: my $path="$desttop/$subdir";
! 827: my $makepath=$path;
! 828: my $fail;
! 829: for (my $i=0;$i<@dirs;$i++) {
! 830: $makepath.='/'.$dirs[$i];
! 831: unless (-e $makepath) {
! 832: unless (mkdir($makepath,0755)) {
! 833: $fail = 1;
! 834: last;
! 835: }
! 836: if (($i == scalar(@dirs)-1) && (!$fail)) {
! 837: $newdir{$dir} = 1;
! 838: }
! 839: }
! 840: }
! 841: if ($fail) {
! 842: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
! 843: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
! 844: '</p>'."\n");
! 845: }
! 846: }
! 847: } else {
! 848: $notopdir = 1;
! 849: }
! 850: }
! 851: }
! 852: if (keys(%files_to_copy)) {
! 853: if ($is_course_home) {
! 854: unless (-e $desttop.'/'.$subdir) {
! 855: mkdir($desttop.'/'.$subdir,0755);
! 856: }
! 857: if (-e $desttop.'/'.$subdir) {
! 858: my $num = 0;
! 859: foreach my $file (keys(%files_to_copy)) {
! 860: my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
! 861: if ($file =~ m{/}) {
! 862: ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
! 863: if (-d "$desttop/$subdir/$path") {
! 864: if (-e "$desttop/$subdir/$path/$fname") {
! 865: $dup = 1;
! 866: } else {
! 867: $src = "$srctop/$path/$fname";
! 868: $dest = "$desttop/$subdir/$path/$fname";
! 869: }
! 870: } elsif (-f "$desttop/$subdir/$path") {
! 871: $dir_is_file = 1;
! 872: } else {
! 873: $fail = 1;
! 874: }
! 875: } elsif (-e "$desttop/$subdir/$file") {
! 876: $dup = 1;
! 877: } else {
! 878: $src = "$srctop/$file";
! 879: $dest = "$desttop/$subdir/$file";
! 880: $fname = $file;
! 881: }
! 882: if ($fail) {
! 883: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
! 884: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
! 885: '</p>'."\n");
! 886: } elsif ($dup) {
! 887: $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
! 888: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
! 889: '</p>'."\n");
! 890: } elsif ($dir_is_file) {
! 891: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
! 892: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
! 893: '</p>'."\n");
! 894: } elsif (($src ne '') && ($dest ne '')) {
! 895: if (&File::Copy::copy($src,$dest)) {
! 896: $newfile{$file} = 1;
! 897: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
! 898: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
! 899: #FIXME set distribution/copyright to author's default instead of custom. set author to $ca:$cd instead of $cdom:$cnum
! 900: }
! 901: }
! 902: my ($ext) = ($file =~ /\.(\w+)$/);
! 903: my $embstyle=&Apache::loncommon::fileembstyle($ext);
! 904: if ($embstyle eq 'ssi') {
! 905: #FIXME in any src or href attributes replace /res/$coursedom/$coursenum/ with /res/$cd/$ca/$subdir
! 906: }
! 907: }
! 908: }
! 909: }
! 910: } else {
! 911: $notopdir = 1;
! 912: }
! 913: }
! 914: }
! 915: if ($notopdir) {
! 916: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
! 917: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
! 918: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
! 919: '</span></p>'."\n");
! 920: }
! 921: if (keys(%newdir)) {
! 922: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
! 923: '</p>'."\n".
! 924: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
! 925: }
! 926: if (keys(%newfile)) {
! 927: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
! 928: '</p>'."\n".
! 929: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
! 930: }
! 931: } else {
! 932: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
! 933: $r->print(&endContentScreen());
! 934: return '';
! 935: }
! 936: } else {
! 937: my $formname = 'copycrsauthored';
! 938: my $chkname = 'copytouser';
! 939: my $context = 'crsauthored';
! 940: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
! 941: &Apache::lonnet::recursedirs($home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
! 942: foreach my $key (keys(%subdirs)) {
! 943: next if (($key eq '/') || ($key eq ''));
! 944: my @items = split(/\//,$key);
! 945: my $dir = pop(@items);
! 946: my $depth = scalar(@items);
! 947: my $path;
! 948: if (!$depth) {
! 949: $path = '/';
! 950: } else {
! 951: $path = join('/',@items);
! 952: }
! 953: $dirs_by_depth[$depth]{$path}{$dir} = 1;
! 954: }
! 955: foreach my $path (keys(%files)) {
! 956: next if ($path eq '');
! 957: my $depth;
! 958: if ($path eq '/') {
! 959: $depth = 0;
! 960: } else {
! 961: $depth = scalar(split(/\//,$path));
! 962: }
! 963: if (ref($files{$path}) eq 'HASH') {
! 964: foreach my $file (keys(%{$files{$path}})) {
! 965: $files_by_depth[$depth]{$path}{$file} = 1;
! 966: }
! 967: }
! 968: }
! 969: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
! 970: if ($readonly) {
! 971: $disabled = ' disabled="disabled"';
! 972: }
! 973: if ($disabled) {
! 974: $togglebuttons = '<br />';
! 975: } else {
! 976: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
! 977: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
! 978: ' <input type="button" value="'.&mt('uncheck all').'"'.
! 979: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
! 980: }
! 981: my $title=$origcrsdata{'description'};
! 982: $title=~s/[\/\s]+/\_/gs;
! 983: $title=&clean($title);
! 984: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash);
! 985: my $display = '<form name="'.$formname.'" action="" method="post">'."\n".
! 986: $preamble."\n".
! 987: '<div class="LC_float_left">'."\n".
! 988: '<fieldset>'."\n".
! 989: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
! 990: '<span class="LC_fontsize_medium">'.
! 991: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
! 992: '</span><br /><br />'."\n";
! 993: my $count = 0;
! 994: my $startcount = 4 + $home;
! 995: my $lastcontainer = $startcount;
! 996: $display .= &Apache::loncommon::start_data_table()."\n".
! 997: &Apache::loncommon::start_data_table_header_row().
! 998: '<th>'.&mt('Copy?').'</th>'.
! 999: '<th>'.&mt('Title').'</th>'.
! 1000: &Apache::loncommon::end_data_table_header_row()."\n";
! 1001: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
! 1002: $count,\$display,\%parent,\%children,$readonly,
! 1003: $formname,$chkname,\$lastcontainer);
! 1004: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
! 1005: unless ($readonly) {
! 1006: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 1007: '<div>'.
! 1008: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
! 1009: '</div>';
! 1010: }
! 1011: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
! 1012: \%hierarchy,\@checked_maps,$home,$chkname);
! 1013: $r->print($display);
! 1014: }
! 1015: $r->print(&endContentScreen());
! 1016: }
! 1017:
! 1018: sub recurse_crsauthored {
! 1019: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
! 1020: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref) = @_;
! 1021: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY'));
! 1022: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
! 1023: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
! 1024: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
! 1025: $hasdirs = 1;
! 1026: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
! 1027: map { $unique{$_} = 1; } keys(%dirs);
! 1028: }
! 1029: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
! 1030: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
! 1031: $hasfiles = 1;
! 1032: %files = %{$files_by_depth->[$currdepth]{$currpath}};
! 1033: map { $unique{$_} = 1; } keys(%files);
! 1034: }
! 1035: if ($readonly) {
! 1036: $disabled = ' disabled="disabled"';
! 1037: }
! 1038: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
! 1039: my $whitespace =
! 1040: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
! 1041: $parent->{$currdepth} = $$lastcontainerref;
! 1042: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
! 1043: next if ($item eq '');
! 1044: my $currelem;
! 1045: if ($hasdirs && exists($dirs{$item})) {
! 1046: $count ++;
! 1047: my $deeper = $currdepth+1;
! 1048: my ($newpath,$showpath);
! 1049: if ($currpath eq '/') {
! 1050: $newpath = $item;
! 1051: $showpath = $currpath.$item.'/';
! 1052: } else {
! 1053: $newpath = $currpath.'/'.$item;
! 1054: $showpath = '/'.$currpath.'/'.$item.'/';
! 1055: }
! 1056: $currelem = $count+$startcount;
! 1057: $$lastcontainerref = $currelem;
! 1058: $children->{$parent->{$currdepth}} .= $currelem.':';
! 1059: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
! 1060: $$displayref .= &Apache::loncommon::start_data_table_row().
! 1061: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
! 1062: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
! 1063: $disabled.' /></td><td>';
! 1064: for (my $i=0; $i<$currdepth; $i++) {
! 1065: $$displayref .= "$whitespace\n";
! 1066: }
! 1067: $$displayref .= '<img '.$icon.' /> '.$item.'</td>'.
! 1068: &Apache::loncommon::end_data_table_row()."\n";
! 1069: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
! 1070: $startcount,$count,$displayref,$parent,$children,
! 1071: $readonly,$formname,$chkname,$lastcontainerref);
! 1072: }
! 1073: if ($hasfiles && exists($files{$item})) {
! 1074: $count ++;
! 1075: $currelem = $count+$startcount;
! 1076: $children->{$parent->{$currdepth}} .= $currelem.':';
! 1077: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
! 1078: my ($ext) = ($item =~ /\.([^.]+)$/);
! 1079: my $alttext;
! 1080: if (lc($ext) eq 'problem') {
! 1081: $alttext = ' alt="'.&mt('Problem Icon').'"';
! 1082: } elsif ($ext =~ /^x?html?$/i) {
! 1083: $alttext = ' alt="'.&mt('Web Page Icon').'"';
! 1084: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
! 1085: $alttext = ' alt="'.&mt('Image Icon').'"';
! 1086: } else {
! 1087: $alttext = ' alt="'.&mt('Resource Icon').'"';
! 1088: }
! 1089: my $showpath;
! 1090: if ($currpath eq '/') {
! 1091: $showpath = $currpath;
! 1092: } else {
! 1093: $showpath = "/$currpath/";
! 1094: }
! 1095: $$displayref .= &Apache::loncommon::start_data_table_row().
! 1096: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
! 1097: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
! 1098: $disabled.' /></td><td>';
! 1099: for (my $i=0; $i<$currdepth; $i++) {
! 1100: $$displayref .= "$whitespace\n";
! 1101: }
! 1102: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
! 1103: &Apache::loncommon::end_data_table_row()."\n";
! 1104: }
! 1105: }
! 1106: $$lastcontainerref = $parent->{$currdepth};
! 1107: return $count;
! 1108: }
! 1109:
1.329 droeschl 1110: sub group_import {
1.598 raeburn 1111: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1112: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1113: %removeparam,$importuploaded,$fixuperrors);
1114: $allmaps = {};
1.329 droeschl 1115: while (@files) {
1116: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1117: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1118: && ($caller eq 'londocs')
1119: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1120:
1.329 droeschl 1121: my $errtext = '';
1122: my $fatal = 0;
1123: my $newmapstr = '<map>'."\n".
1124: '<resource id="1" src="" type="start"></resource>'."\n".
1125: '<link from="1" to="2" index="1"></link>'."\n".
1126: '<resource id="2" src="" type="finish"></resource>'."\n".
1127: '</map>';
1128: $env{'form.output'}=$newmapstr;
1129: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1130: 'output',$1.$2);
1.534 raeburn 1131: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1132: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1133: $fatal = 2;
1134: }
1135: if ($fatal) {
1136: return ($errtext,$fatal);
1137: }
1138: }
1139: if ($url) {
1.626 raeburn 1140: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1141: $url = $1;
1142: my $marker = $2;
1143: my $info = $3;
1.699 raeburn 1144: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1145: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1146: my @toolinfo = split(/:/,$info);
1147: if ($residx) {
1.604 raeburn 1148: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1149: $toolid = $toolsettings{'id'};
1150: } else {
1.604 raeburn 1151: $toolid = shift(@toolinfo);
1.598 raeburn 1152: }
1.699 raeburn 1153: if ($toolid =~ /^c/) {
1154: $tooltype = 'crs';
1155: $toolprefix = 'c';
1156: } else {
1157: $tooltype = 'dom';
1158: }
1.598 raeburn 1159: $toolid =~ s/\D//g;
1.604 raeburn 1160: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1161: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1162: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1163: foreach my $item (@extras) {
1164: $toolhash{$item} = &unescape($toolhash{$item});
1165: }
1.645 raeburn 1166: if ($folder =~ /^supplemental/) {
1.648 raeburn 1167: delete($toolhash{'gradable'});
1168: } else {
1169: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1170: }
1.598 raeburn 1171: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1172: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1173: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1174: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1175: my @deleted;
1176: $toolhash{'id'} = $toolprefix.$toolid;
1177: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1178: ($toolhash{'target'} eq 'window')) {
1179: if ($toolhash{'target'} eq 'window') {
1180: foreach my $item ('width','height') {
1181: $toolhash{$item} =~ s/^\s+//;
1182: $toolhash{$item} =~ s/\s+$//;
1183: if ($toolhash{$item} =~ /\D/) {
1184: delete($toolhash{$item});
1185: if ($residx) {
1186: if ($toolsettings{$item}) {
1187: push(@deleted,$item);
1188: }
1.624 raeburn 1189: }
1190: }
1191: }
1.604 raeburn 1192: }
1.699 raeburn 1193: } elsif ($residx) {
1194: $toolhash{'target'} = $toolsettings{'target'};
1195: if ($toolhash{'target'} eq 'window') {
1196: foreach my $item ('width','height') {
1197: $toolhash{$item} = $toolsettings{$item};
1198: }
1199: }
1200: } elsif (ref($tools{'display'}) eq 'HASH') {
1201: $toolhash{'target'} = $tools{'display'}{'target'};
1202: if ($toolhash{'target'} eq 'window') {
1203: $toolhash{'width'} = $tools{'display'}{'width'};
1204: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1205: }
1.604 raeburn 1206: }
1.699 raeburn 1207: if ($toolhash{'target'} eq 'iframe') {
1208: foreach my $item ('width','height','linktext','explanation') {
1209: delete($toolhash{$item});
1210: if ($residx) {
1211: if ($toolsettings{$item}) {
1212: push(@deleted,$item);
1213: }
1.624 raeburn 1214: }
1.604 raeburn 1215: }
1.699 raeburn 1216: } elsif ($toolhash{'target'} eq 'tab') {
1217: foreach my $item ('width','height') {
1218: delete($toolhash{$item});
1219: if ($residx) {
1220: if ($toolsettings{$item}) {
1221: push(@deleted,$item);
1222: }
1.628 raeburn 1223: }
1224: }
1225: }
1.699 raeburn 1226: if (ref($tools{'crsconf'}) eq 'HASH') {
1227: foreach my $item ('label','title','linktext','explanation') {
1228: my $crsitem;
1229: if (($item eq 'label') || ($item eq 'title')) {
1230: $crsitem = 'crs'.$item;
1231: } else {
1232: $crsitem = $item;
1233: }
1234: if ($tools{'crsconf'}{$item}) {
1235: $toolhash{$crsitem} =~ s/^\s+//;
1236: $toolhash{$crsitem} =~ s/\s+$//;
1237: if ($toolhash{$crsitem} eq '') {
1238: delete($toolhash{$crsitem});
1239: }
1240: } else {
1.624 raeburn 1241: delete($toolhash{$crsitem});
1.604 raeburn 1242: }
1.699 raeburn 1243: if (($residx) && (exists($toolsettings{$crsitem}))) {
1244: unless (exists($toolhash{$crsitem})) {
1245: push(@deleted,$crsitem);
1246: }
1247: }
1.604 raeburn 1248: }
1.699 raeburn 1249: }
1250: if ($toolhash{'passback'}) {
1251: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1252: $toolhash{'gradesecret'} = $gradesecret;
1253: $toolhash{'gradesecretdate'} = time;
1254: }
1255: if ($toolhash{'roster'}) {
1256: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1257: $toolhash{'rostersecret'} = $rostersecret;
1258: $toolhash{'rostersecretdate'} = time;
1259: }
1260: my $changegradable;
1261: if (($residx) && ($folder =~ /^default/)) {
1262: if ($toolsettings{'gradable'}) {
1263: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1264: push(@deleted,'gradable');
1265: $changegradable = 1;
1.604 raeburn 1266: }
1.699 raeburn 1267: } elsif ($toolhash{'gradable'}) {
1268: $changegradable = 1;
1.604 raeburn 1269: }
1.699 raeburn 1270: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1271: $changegradable = 1;
1.699 raeburn 1272: if ($toolsettings{'gradable'}) {
1273: $toolhash{'gradable'} = 1;
1274: }
1.645 raeburn 1275: }
1.648 raeburn 1276: }
1.699 raeburn 1277: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1278: if ($putres eq 'ok') {
1279: if (@deleted) {
1280: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1281: }
1.699 raeburn 1282: if (($changegradable) && ($folder =~ /^default/)) {
1283: my $val;
1284: if ($toolhash{'gradable'}) {
1285: $val = 'yes';
1286: } else {
1287: $val = 'no';
1288: }
1289: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1290: 'string_yesno');
1291: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1292: }
1.699 raeburn 1293: } else {
1294: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1295: }
1.604 raeburn 1296: }
1.598 raeburn 1297: }
1298: }
1299: }
1.529 raeburn 1300: if (($caller eq 'londocs') &&
1301: ($folder =~ /^default/)) {
1.534 raeburn 1302: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1303: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1304: my $cid = $coursedom.'_'.$coursenum;
1305: $allmaps =
1306: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1307: $chome,$cid);
1308: $donechk = 1;
1309: }
1310: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1311: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1312: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1313: $importuploaded = 1;
1314: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1315: next if ($allmaps->{$url});
1316: }
1317: }
1.344 bisitz 1318: if (!$residx
1.329 droeschl 1319: || defined($LONCAPA::map::zombies[$residx])) {
1320: $residx = &LONCAPA::map::getresidx($url,$residx);
1321: push(@LONCAPA::map::order, $residx);
1322: }
1323: my $ext = 'false';
1324: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1325: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1326: my $filepath = $1;
1.675 raeburn 1327: my $fname;
1328: if ($name eq '') {
1329: $name = &mt('Web Page');
1.534 raeburn 1330: $fname = 'web';
1331: } else {
1.675 raeburn 1332: $fname = $name;
1333: $fname=&Apache::lonnet::clean_filename($fname);
1334: if ($fname eq '') {
1335: $fname = 'web';
1336: } elsif (length($fname) > 15) {
1337: $fname = substr($fname,0,14);
1338: }
1.534 raeburn 1339: }
1.675 raeburn 1340: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1341: my $initialtext = &mt('Replace with your own content.');
1342: my $newhtml = <<END;
1.545 raeburn 1343: <html>
1.534 raeburn 1344: <head>
1.675 raeburn 1345: <title>$title</title>
1.534 raeburn 1346: </head>
1347: <body bgcolor="#ffffff">
1348: $initialtext
1349: </body>
1350: </html>
1351: END
1352: $env{'form.output'}=$newhtml;
1.630 raeburn 1353: my $result =
1.534 raeburn 1354: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1355: 'output',
1356: "$filepath/$residx/$fname.html");
1357: if ($result =~ m{^/uploaded/}) {
1358: $url = $result;
1359: if ($filepath =~ /^supplemental/) {
1360: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1361: $env{'user.domain'}.'___&&&___'.$name;
1362: }
1363: } else {
1364: return (&mt('Failed to save new web page.'),1);
1365: }
1366: }
1.675 raeburn 1367: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1368: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1369: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1370: join(':', ($name, $url, $ext, 'normal', 'res'));
1371: }
1372: }
1.529 raeburn 1373: if ($importuploaded) {
1374: my %import_errors;
1375: my %updated = (
1376: removefrommap => \%removefrommap,
1377: removeparam => \%removeparam,
1378: );
1.533 raeburn 1379: my ($result,$msgsarray,$lockerror) =
1380: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1381: if (keys(%import_errors) > 0) {
1.530 raeburn 1382: $fixuperrors =
1.529 raeburn 1383: '<p span class="LC_warning">'."\n".
1384: &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".
1385: '<ul>'."\n";
1386: foreach my $key (sort(keys(%import_errors))) {
1387: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1388: }
1389: $fixuperrors .= '</ul></p>'."\n";
1390: }
1.533 raeburn 1391: if (ref($msgsarray) eq 'ARRAY') {
1392: if (@{$msgsarray} > 0) {
1393: $fixuperrors .= '<p class="LC_info">'.
1394: join('<br />',@{$msgsarray}).
1395: '</p>';
1396: }
1397: }
1398: if ($lockerror) {
1399: $fixuperrors .= '<p class="LC_error">'.
1400: $lockerror.
1401: '</p>';
1402: }
1.529 raeburn 1403: }
1404: my ($errtext,$fatal) =
1405: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1406: unless ($fatal) {
1407: if ($folder =~ /^supplemental/) {
1.561 raeburn 1408: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1409: $folder.'.'.$container);
1.557 raeburn 1410: }
1411: }
1.529 raeburn 1412: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1413: }
1414:
1415: sub log_docs {
1.494 raeburn 1416: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1417: }
1418:
1419: {
1420: my @oldresources=();
1421: my @oldorder=();
1422: my $parmidx;
1423: my %parmaction=();
1424: my %parmvalue=();
1425: my $changedflag;
1426:
1427: sub snapshotbefore {
1428: @oldresources=@LONCAPA::map::resources;
1429: @oldorder=@LONCAPA::map::order;
1430: $parmidx=undef;
1431: %parmaction=();
1432: %parmvalue=();
1433: $changedflag=0;
1434: }
1435:
1436: sub remember_parms {
1437: my ($idx,$parameter,$action,$value)=@_;
1438: $parmidx=$idx;
1439: $parmaction{$parameter}=$action;
1440: $parmvalue{$parameter}=$value;
1441: $changedflag=1;
1442: }
1443:
1444: sub log_differences {
1445: my ($plain)=@_;
1446: my %storehash=('folder' => $plain,
1447: 'currentfolder' => $env{'form.folder'});
1448: if ($parmidx) {
1449: $storehash{'parameter_res'}=$oldresources[$parmidx];
1450: foreach my $parm (keys(%parmaction)) {
1451: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1452: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1453: }
1454: }
1455: my $maxidx=$#oldresources;
1456: if ($#LONCAPA::map::resources>$#oldresources) {
1457: $maxidx=$#LONCAPA::map::resources;
1458: }
1459: for (my $idx=0; $idx<=$maxidx; $idx++) {
1460: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1461: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1462: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1463: $changedflag=1;
1464: }
1465: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1466: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1467: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1468: $changedflag=1;
1469: }
1470: }
1471: $storehash{'maxidx'}=$maxidx;
1472: if ($changedflag) { &log_docs(\%storehash); }
1473: }
1474: }
1475:
1476: sub docs_change_log {
1.611 raeburn 1477: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1478: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1479: my $navmap;
1.483 raeburn 1480: my $js = '<script type="text/javascript">'."\n".
1481: '// <![CDATA['."\n".
1482: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1483: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1484: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1485: &history_tab_js()."\n".
1.484 raeburn 1486: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1487: '// ]]>'."\n".
1488: '</script>'."\n";
1.484 raeburn 1489: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1490: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1491: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1492: my %orderhash;
1493: my $container='sequence';
1494: my $pathitem;
1.519 raeburn 1495: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1496: $container='page';
1497: }
1.519 raeburn 1498: my $folderpath=$env{'form.folderpath'};
1499: if ($folderpath eq '') {
1.617 raeburn 1500: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1501: }
1.617 raeburn 1502: undef($navmap);
1.519 raeburn 1503: $pathitem = '<input type="hidden" name="folderpath" value="'.
1504: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1505: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1506: my $jumpto = $readfile;
1507: $jumpto =~ s{^/}{};
1508: my $tid = 1;
1.489 raeburn 1509: if ($supplementalflag) {
1510: $tid = 2;
1511: }
1.630 raeburn 1512: my ($breadcrumbtrail) =
1.509 raeburn 1513: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1514: $r->print($breadcrumbtrail.
1515: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1516: $readfile));
1.329 droeschl 1517: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1518: $env{'course.'.$env{'request.course.id'}.'.domain'},
1519: $env{'course.'.$env{'request.course.id'}.'.num'});
1520:
1521: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1522:
1523: my %saveable_parameters = ('show' => 'scalar',);
1524: &Apache::loncommon::store_course_settings('docs_log',
1525: \%saveable_parameters);
1526: &Apache::loncommon::restore_course_settings('docs_log',
1527: \%saveable_parameters);
1528: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1529: # FIXME: internationalization seems wrong here
1.329 droeschl 1530: my %lt=('hiddenresource' => 'Resources hidden',
1531: 'encrypturl' => 'URL hidden',
1532: 'randompick' => 'Randomly pick',
1533: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1534: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1535: 'set' => 'set to',
1536: 'del' => 'deleted');
1.484 raeburn 1537: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1538: $pathitem."\n".
1539: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1540: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1541: $r->print('<div class="LC_left_float">'.
1542: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1543: &makedocslogform($filter,1).
1544: '</fieldset></div><br clear="all" />');
1.329 droeschl 1545: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1546: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1547: &mt('After').'</th>'.
1548: &Apache::loncommon::end_data_table_header_row());
1549: my $shown=0;
1550: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1551: if ($env{'form.displayfilter'} eq 'currentfolder') {
1552: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1553: }
1554: my @changes=keys(%{$docslog{$id}{'logentry'}});
1555: if ($env{'form.displayfilter'} eq 'containing') {
1556: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1557: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1558: foreach my $key (@changes) {
1559: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1560: }
1.344 bisitz 1561: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1562: }
1563: my $count = 0;
1564: my $time =
1565: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1566: my $plainname =
1567: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1568: $docslog{$id}{'exe_udom'});
1569: my $about_me_link =
1570: &Apache::loncommon::aboutmewrapper($plainname,
1571: $docslog{$id}{'exe_uname'},
1572: $docslog{$id}{'exe_udom'});
1573: my $send_msg_link='';
1574: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1575: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1576: $send_msg_link ='<br />'.
1577: &Apache::loncommon::messagewrapper(&mt('Send message'),
1578: $docslog{$id}{'exe_uname'},
1579: $docslog{$id}{'exe_udom'});
1580: }
1581: $r->print(&Apache::loncommon::start_data_table_row());
1582: $r->print('<td>'.$time.'</td>
1583: <td>'.$about_me_link.
1584: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1585: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1586: $send_msg_link.'</td><td>'.
1587: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1588: my $is_supp = 0;
1589: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1590: $is_supp = 1;
1591: }
1.329 droeschl 1592: # Before
1593: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1594: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1595: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1596: if ($oldname ne $newname) {
1.488 raeburn 1597: my $shown = &LONCAPA::map::qtescape($oldname);
1598: if ($is_supp) {
1599: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1600: }
1601: $r->print($shown);
1.329 droeschl 1602: }
1603: }
1604: $r->print('<ul>');
1605: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1606: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1607: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1608: if ($is_supp) {
1609: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1610: }
1611: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1612: }
1613: }
1614: $r->print('</ul>');
1615: # After
1616: $r->print('</td><td>');
1617:
1618: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1619: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1620: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1621: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1622: my $shown = &LONCAPA::map::qtescape($newname);
1623: if ($is_supp) {
1624: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1625: }
1626: $r->print($shown);
1.329 droeschl 1627: }
1.364 bisitz 1628: }
1.329 droeschl 1629: $r->print('<ul>');
1630: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1631: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1632: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1633: if ($is_supp) {
1634: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1635: }
1636: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1637: }
1638: }
1639: $r->print('</ul>');
1640: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1641: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1642: if ($title eq '') {
1643: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1644: } elsif ($is_supp) {
1645: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1646: }
1647: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1648: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1649: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1650: # FIXME: internationalization seems wrong here
1.329 droeschl 1651: $r->print('<li>'.
1652: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1653: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1654: .'</li>');
1655: }
1656: }
1657: $r->print('</ul>');
1658: }
1659: # End
1660: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1661: $shown++;
1662: if (!($env{'form.show'} eq &mt('all')
1663: || $shown<=$env{'form.show'})) { last; }
1664: }
1.484 raeburn 1665: $r->print(&Apache::loncommon::end_data_table()."\n".
1666: &makesimpleeditform($pathitem)."\n".
1667: '</div></div>');
1668: $r->print(&endContentScreen());
1.329 droeschl 1669: }
1670:
1671: sub update_paste_buffer {
1.492 raeburn 1672: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1673: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1674: if ($env{'form.multiremove'}) {
1675: $env{'form.multiremove'} =~ s/,$//;
1676: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1677: }
1678: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1679: if ($env{'form.multicut'}) {
1680: $env{'form.multicut'} =~ s/,$//;
1681: foreach my $item (split(/,/,$env{'form.multicut'})) {
1682: unless ($removals{$item}) {
1683: $cuts{$item} = 1;
1684: push(@possibles,$item.':cut');
1685: }
1686: }
1687: }
1688: if ($env{'form.multicopy'}) {
1689: $env{'form.multicopy'} =~ s/,$//;
1690: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1691: unless ($removals{$item} || $cuts{$item}) {
1692: push(@possibles,$item.':copy');
1693: }
1694: }
1695: }
1696: } elsif ($env{'form.markcopy'}) {
1697: @possibles = split(/,/,$env{'form.markcopy'});
1698: }
1.329 droeschl 1699:
1.538 raeburn 1700: return if (@possibles == 0);
1.329 droeschl 1701: return if (!defined($env{'form.copyfolder'}));
1702:
1703: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1704: $env{'form.copyfolder'});
1.538 raeburn 1705: return if ($fatal);
1706:
1707: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1708:
1.538 raeburn 1709: # Retrieve current paste buffer suffixes.
1710: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1711: my (%pasteurls,@newpaste);
1712:
1713: # Construct identifiers for current contents of user's paste buffer
1714: if (@currpaste) {
1715: foreach my $suffix (@currpaste) {
1.667 raeburn 1716: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1717: my $url = $env{'docs.markedcopy_url_'.$suffix};
1718: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1719: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1720: ($url ne '')) {
1721: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1722: $pasteurls{$cid.'_'.$mapidx} = 1;
1723: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1724: $pasteurls{$url} = 1;
1725: } else {
1.669 raeburn 1726: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1727: }
1728: }
1.538 raeburn 1729: }
1730: }
1731:
1732: # Mark items for copying (skip any items already in user's paste buffer)
1733: my %addtoenv;
1.597 raeburn 1734:
1735: my @pathitems = split(/\&/,$env{'form.folderpath'});
1736: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1737: my $ispage = $folderconf[5];
1.597 raeburn 1738:
1.538 raeburn 1739: foreach my $item (@possibles) {
1740: my ($orderidx,$cmd) = split(/:/,$item);
1741: next if ($orderidx =~ /\D/);
1742: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1743: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1744: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1745: my %denied = &action_restrictions($coursenum,$coursedom,
1746: &LONCAPA::map::qtescape($url),
1747: $env{'form.folderpath'},\%curr_groups);
1748: next if ($denied{'copy'});
1749: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1750: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1751: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1752: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1753: next if (exists($pasteurls{$url}));
1754: } else {
1755: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1756: }
1.538 raeburn 1757: my ($suffix,$errortxt,$locknotfreed) =
1758: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1759: if ($suffix ne '') {
1760: push(@newpaste,$suffix);
1761: } else {
1762: if ($locknotfreed) {
1763: return $locknotfreed;
1764: }
1.538 raeburn 1765: }
1766: if (&is_supplemental_title($title)) {
1767: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1768: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1769: }
1.329 droeschl 1770:
1.538 raeburn 1771: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1772: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1773: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1774: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1775: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1776: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1777: my $prefix = $1;
1778: my $subdir =$2;
1779: if ($subdir eq '') {
1780: $subdir = $prefix;
1.492 raeburn 1781: }
1.538 raeburn 1782: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1783: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1784: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1785: if (ref($hierarchy{$url}) eq 'HASH') {
1786: my ($nested,$nestednames);
1787: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1788: $nested =~ s/\&$//;
1789: $nestednames =~ s/\Q___&&&___\E$//;
1790: if ($nested ne '') {
1791: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1792: }
1793: if ($nestednames ne '') {
1794: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1795: }
1.492 raeburn 1796: }
1797: }
1.591 raeburn 1798: if ($locknotfreed) {
1799: $output = $locknotfreed;
1800: last;
1801: }
1.492 raeburn 1802: }
1.538 raeburn 1803: if (@newpaste) {
1804: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1805: }
1.492 raeburn 1806: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1807: delete($env{'form.markcopy'});
1.591 raeburn 1808: return $output;
1.329 droeschl 1809: }
1810:
1.492 raeburn 1811: sub recurse_uploaded_maps {
1812: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1813: if (ref($hierarchy->{$url}) eq 'HASH') {
1814: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1815: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1816: my (@uploaded,@names,%shorter);
1817: for (my $i=0; $i<@maps; $i++) {
1818: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1819: if ($inner ne '') {
1820: push(@uploaded,$inner);
1821: push(@names,&escape($titles[$i]));
1822: $shorter{$maps[$i]} = $inner;
1823: }
1824: }
1825: $$nestref .= "$dir:".join(',',@uploaded).'&';
1826: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1827: foreach my $map (@maps) {
1828: if ($shorter{$map} ne '') {
1829: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1830: }
1831: }
1832: }
1833: return;
1834: }
1835:
1.329 droeschl 1836: sub print_paste_buffer {
1.492 raeburn 1837: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1838: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1839:
1.538 raeburn 1840: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1841: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1842: }
1843:
1.538 raeburn 1844: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 1845: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 1846: my $clipboardcount = 0;
1.488 raeburn 1847:
1.538 raeburn 1848: # Construct identifiers for current contents of user's paste buffer
1849: foreach my $suffix (@currpaste) {
1850: next if ($suffix =~ /\D/);
1851: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1852: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1853: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1854: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1855: ($url ne '')) {
1.575 raeburn 1856: $clipboardcount ++;
1.538 raeburn 1857: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 1858: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
1859: $toolcnum,$marker);
1.538 raeburn 1860: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1861: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1862: $is_external = 1;
1.704 raeburn 1863: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1864: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 1865: $is_exttool = 1;
1.538 raeburn 1866: }
1867: if ($folder =~ /^supplemental/) {
1868: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1869: unless ($canpaste) {
1870: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1871: }
1872: } else {
1873: $canpaste = 1;
1874: }
1875: if ($canpaste) {
1876: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1877: my $srcdom = $1;
1878: my $srcnum = $2;
1879: my $rem = $3;
1880: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1881: $othercourse = 1;
1882: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1883: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1884: } else {
1885: $canpaste = 0;
1886: $nopaste = &mt('Paste from another course unavailable.');
1887: }
1888: }
1889: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1890: my $prefix = $1;
1891: $parent = $2;
1892: if ($folder !~ /^\Q$prefix\E/) {
1893: $areachange = 1;
1894: }
1895: $is_uploaded_map = 1;
1.492 raeburn 1896: }
1.597 raeburn 1897: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1898: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1899: if ($cid ne $env{'request.course.id'}) {
1900: my ($srcdom,$srcnum) = split(/_/,$cid);
1901: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 1902: if ($is_exttool) {
1903: if ($toolcdom ne $coursedom) {
1904: $canpaste = 0;
1905: $nopaste = &mt('Paste from another domain unavailable.');
1906: } elsif ($toolcnum ne $coursenum) {
1907: my %toolsettings =
1908: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1909: my %tooltypes = &Apache::loncommon::usable_exttools();
1910: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1911: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1912: $canpaste = 0;
1913: $nopaste = &mt('Paste from another course unavailable.');
1914: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
1915: unless ($checkedsameinst) {
1916: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
1917: my $intdom = &Apache::lonnet::internet_dom($primary_id);
1918: if ($intdom ne '') {
1919: my $internet_names =
1920: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
1921: if (ref($internet_names) eq 'ARRAY') {
1922: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
1923: $same_institution = 1;
1924: }
1925: }
1926: }
1927: $checkedsameinst = 1;
1928: }
1929: if ($same_institution) {
1930: $othercrs = '<br />'.&mt('(from another course)');
1931: } else {
1932: $nopaste = &mt('Paste from another course unavailable.');
1933: }
1934: } else {
1935: $othercrs = '<br />'.&mt('(from another course)');
1936: }
1937: }
1.627 raeburn 1938: }
1.596 raeburn 1939: } else {
1940: $canpaste = 0;
1941: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1942: }
1.596 raeburn 1943: }
1.703 raeburn 1944: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
1945: my ($audom,$auname) = ($1,$2);
1946: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1947: if (&Apache::lonnet::is_course($audom,$auname)) {
1948: $canpaste = 0;
1949: $nopaste = &mt('Paste from another course unavailable.');
1950: }
1951: }
1.492 raeburn 1952: }
1.596 raeburn 1953: if ($canpaste) {
1954: push(@pasteable,$suffix);
1.629 raeburn 1955: }
1.538 raeburn 1956: }
1957: my $buffer;
1.627 raeburn 1958: if ($is_external) {
1.538 raeburn 1959: $buffer = &mt('External Resource').': '.
1960: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1961: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1962: } elsif ($is_exttool) {
1963: $buffer = &mt('External Tool').': '.
1964: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1965: } else {
1966: my $icon = &Apache::loncommon::icon($extension);
1967: if ($extension eq 'sequence' &&
1968: $url =~ m{/default_\d+\.sequence$}x) {
1969: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1970: $icon .= '/navmap.folder.closed.gif';
1971: }
1.589 raeburn 1972: my $title = $env{'docs.markedcopy_title_'.$suffix};
1973: if ($title eq '') {
1974: ($title) = ($url =~ m{/([^/]+)$});
1975: }
1.538 raeburn 1976: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1977: ': '.
1978: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1979: &LONCAPA::map::qtescape($title));
1.538 raeburn 1980: }
1981: $pasteitems .= '<div class="LC_left_float">';
1982: my ($options,$onclick);
1983: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1984: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1985: if (($is_uploaded_map) ||
1986: ($url =~ /(bulletinboard|smppg)$/) ||
1987: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1988: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1989: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1990: }
1991: }
1992: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1993: if ($nopaste) {
1.681 raeburn 1994: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1995: } else {
1996: if ($othercrs) {
1997: $pasteitems .= $othercrs;
1998: }
1999: if ($options) {
2000: $pasteitems .= $options;
1.492 raeburn 2001: }
2002: }
1.538 raeburn 2003: $pasteitems .= '</div>';
2004: }
2005: }
2006: if ($pasteitems eq '') {
2007: &Apache::lonnet::delenv('docs.markedcopies');
2008: }
2009: my ($pasteform,$form_start,$buttons,$form_end);
2010: if ($pasteitems) {
2011: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2012: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2013: if (@pasteable) {
1.575 raeburn 2014: my $value = &mt('Paste to current folder');
2015: if ($container eq 'page') {
2016: $value = &mt('Paste to current page');
2017: }
2018: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2019: }
2020: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2021: if ($clipboardcount > 1) {
2022: $buttons .=
2023: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2024: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2025: (' 'x2).
2026: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2027: (' 'x2);
1.492 raeburn 2028: }
1.575 raeburn 2029: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2030: '</form>';
1.538 raeburn 2031: } else {
2032: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2033: }
1.538 raeburn 2034: $r->print($form_start
2035: .'<fieldset>'
2036: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2037: .$pasteitems
2038: .'</fieldset>'
2039: .$form_end);
2040: }
2041:
2042: sub paste_options {
2043: my ($suffix,$is_uploaded_map,$parent) = @_;
2044: my ($copytext,$movetext);
2045: if ($is_uploaded_map) {
2046: $copytext = &mt('Copy to new folder');
2047: $movetext = &mt('Move old');
2048: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2049: $copytext = &mt('Copy to new board');
2050: $movetext = &mt('Move (not posts)');
2051: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2052: $copytext = &mt('Copy to new page');
2053: $movetext = &mt('Move');
1.533 raeburn 2054: } else {
1.538 raeburn 2055: $copytext = &mt('Copy to new file');
2056: $movetext = &mt('Move');
2057: }
2058: my $output = '<br />'.
2059: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2060: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2061: '<label>'.
2062: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2063: $copytext.'</label></span>'.(' 'x2).' '.
2064: '<span class="LC_nobreak"><label>'.
2065: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2066: $movetext.'</label></span>';
2067: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2068: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2069: '</legend><table border="0">';
2070: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2071: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2072: my $lastdir = $parent;
2073: my %depths = (
2074: $lastdir => 0,
2075: );
2076: my (%display,%deps);
2077: for (my $i=0; $i<@pastemaps; $i++) {
2078: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2079: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2080: my @subfolders = split(/,/,$subfolderstr);
2081: $deps{$lastdir} = \@subfolders;
2082: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2083: my $depth = $depths{$lastdir} + 1;
2084: my $offset = int($depth * 4);
2085: my $indent = (' ' x $offset);
2086: for (my $j=0; $j<@subfolders; $j++) {
2087: $depths{$subfolders[$j]} = $depth;
2088: $display{$subfolders[$j]} =
2089: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2090: '<td><label>'.
2091: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2092: '<label>'.
2093: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2094: &mt('Move old').'</label>'.
2095: '</td></tr>';
2096: }
1.492 raeburn 2097: }
1.538 raeburn 2098: &recurse_print(\$output,$parent,\%deps,\%display);
2099: $output .= '</table></fieldset>';
1.329 droeschl 2100: }
1.538 raeburn 2101: $output .= '</div>';
2102: return $output;
1.488 raeburn 2103: }
2104:
1.492 raeburn 2105: sub recurse_print {
1.538 raeburn 2106: my ($outputref,$dir,$deps,$display) = @_;
2107: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2108: if (ref($deps->{$dir}) eq 'ARRAY') {
2109: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2110: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2111: }
2112: }
2113: }
2114:
1.488 raeburn 2115: sub supp_pasteable {
2116: my ($url) = @_;
2117: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2118: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2119: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2120: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2121: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2122: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2123: return 1;
2124: }
2125: return;
1.329 droeschl 2126: }
2127:
1.492 raeburn 2128: sub paste_popup_js {
1.594 damieng 2129: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2130: show => 'Show Options',
2131: hide => 'Hide Options',
1.594 damieng 2132: );
2133: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2134: none => 'No items selected from clipboard.',
1.492 raeburn 2135: );
1.594 damieng 2136: &html_escape(\%html_js_lt);
2137: &js_escape(\%html_js_lt);
2138: &js_escape(\%js_lt);
1.492 raeburn 2139: return <<"END";
2140:
1.538 raeburn 2141: function showPasteOptions(suffix) {
2142: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2143: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2144: return;
2145: }
2146:
1.538 raeburn 2147: function hidePasteOptions(suffix) {
2148: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2149: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2150: return;
2151: }
2152:
2153: function showOptions(caller,suffix) {
2154: if (document.getElementById('pasteoptionstext_'+suffix)) {
2155: if (caller.checked) {
1.594 damieng 2156: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2157: } else {
2158: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2159: }
2160: if (document.getElementById('pasteoptions_'+suffix)) {
2161: document.getElementById('pasteoptions_'+suffix).style.display='none';
2162: }
2163: }
1.492 raeburn 2164: return;
2165: }
2166:
1.541 raeburn 2167: function validateClipboard() {
2168: var numchk = 0;
2169: if (document.pasteform.pasting.length > 1) {
2170: for (var i=0; i<document.pasteform.pasting.length; i++) {
2171: if (document.pasteform.pasting[i].checked) {
2172: numchk ++;
2173: }
2174: }
2175: } else {
2176: if (document.pasteform.pasting.type == 'checkbox') {
2177: if (document.pasteform.pasting.checked) {
2178: numchk ++;
2179: }
2180: }
2181: }
2182: if (numchk > 0) {
2183: return true;
2184: } else {
1.594 damieng 2185: alert("$js_lt{'none'}");
1.541 raeburn 2186: return false;
2187: }
2188: }
2189:
1.575 raeburn 2190: function checkClipboard() {
2191: if (document.pasteform.pasting.length > 1) {
2192: for (var i=0; i<document.pasteform.pasting.length; i++) {
2193: document.pasteform.pasting[i].checked = true;
2194: }
2195: }
2196: return;
2197: }
2198:
2199: function uncheckClipboard() {
2200: if (document.pasteform.pasting.length >1) {
2201: for (var i=0; i<document.pasteform.pasting.length; i++) {
2202: document.pasteform.pasting[i].checked = false;
2203: }
2204: }
2205: return;
2206: }
2207:
1.492 raeburn 2208: END
2209:
2210: }
2211:
1.329 droeschl 2212: sub do_paste_from_buffer {
1.492 raeburn 2213: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2214:
1.538 raeburn 2215: # Array of items in paste buffer
2216: my (@currpaste,%pastebuffer,%allerrors);
2217: @currpaste = split(/,/,$env{'docs.markedcopies'});
2218:
1.492 raeburn 2219: # Early out if paste buffer is empty
1.538 raeburn 2220: if (@currpaste == 0) {
1.492 raeburn 2221: return ();
1.538 raeburn 2222: }
2223: map { $pastebuffer{$_} = 1; } @currpaste;
2224:
2225: # Array of items selected items to paste
2226: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2227:
2228: # Early out if nothing selected to paste
2229: if (@reqpaste == 0) {
2230: return();
2231: }
2232: my @topaste;
2233: foreach my $suffix (@reqpaste) {
2234: next if ($suffix =~ /\D/);
2235: next unless (exists($pastebuffer{$suffix}));
2236: push(@topaste,$suffix);
2237: }
2238:
2239: # Early out if nothing available to paste
2240: if (@topaste == 0) {
2241: return();
1.329 droeschl 2242: }
2243:
1.704 raeburn 2244: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2245: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2246: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2247: %currltititles,$currltimax,$gotcrsltitools);
2248: $currltimax = 0;
2249: $gotcrsltitools = 0;
1.538 raeburn 2250: foreach my $suffix (@topaste) {
2251: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2252: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2253: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2254: # Supplemental content may only include certain types of content
2255: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2256: if ($folder =~ /^supplemental/) {
2257: unless (&supp_pasteable($url)) {
2258: $notinsupp{$suffix} = 1;
2259: next;
2260: }
1.492 raeburn 2261: }
1.538 raeburn 2262: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2263: my $srcd = $1;
2264: my $srcn = $2;
1.492 raeburn 2265: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2266: # check for mdc privilege in the course from which the resource was pasted
2267: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2268: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2269: $notincrs{$suffix} = 1;
2270: next;
2271: }
1.491 raeburn 2272: }
1.538 raeburn 2273: $srcdom{$suffix} = $srcd;
2274: $srcnum{$suffix} = $srcn;
1.597 raeburn 2275: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2276: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2277: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2278: my ($srcd,$srcn) = split(/_/,$cid);
2279: # When paste buffer was populated using an active role in a different course
2280: # check for mdc privilege in the course from which the resource was pasted
2281: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2282: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2283: $notincrs{$suffix} = 1;
2284: next;
2285: }
2286: }
1.632 raeburn 2287: # When buffer was populated using an active role in a different course
1.704 raeburn 2288: # disallow pasting of External Tool if course is in a different domain,
2289: # or if External Tool use is not permitted in this course.
2290: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2291: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2292: if ($toolcdom ne $coursedom) {
2293: $notindom{$suffix} = 1;
2294: next;
2295: } elsif ($toolcnum ne $coursenum) {
2296: my %toolsettings =
2297: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2298: my %tooltypes = &Apache::loncommon::usable_exttools();
2299: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2300: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2301: $othcrstool{$suffix} = 1;
2302: next;
2303: }
2304: if ($toolsettings{'id'} =~ /^c\d+$/) {
2305: unless ($gotcrsltitools) {
2306: %currcrsltitools =
2307: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2308: foreach my $item (sort(keys(%currcrsltitools))) {
2309: if (ref($currcrsltitools{$item}) eq 'HASH') {
2310: $currltimax ++;
2311: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2312: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2313: } else {
2314: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2315: }
2316: }
2317: }
2318: $gotcrsltitools = 1;
2319: }
2320: }
2321: }
1.627 raeburn 2322: }
1.596 raeburn 2323: $srcdom{$suffix} = $srcd;
2324: $srcnum{$suffix} = $srcn;
1.703 raeburn 2325: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2326: my ($audom,$auname) = ($1,$2);
2327: # When buffer was populated using an active role in a different course
2328: # disallow pasting of published resources from Course Authoring Space
2329: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2330: if (&Apache::lonnet::is_course($audom,$auname)) {
2331: $othcrsres{$suffix} = 1;
2332: next;
2333: }
2334: }
1.491 raeburn 2335: }
1.597 raeburn 2336: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2337: push(@dopaste,$suffix);
2338: if ($url=~/\.(page|sequence)$/) {
2339: $is_map{$suffix} = 1;
2340: }
2341: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2342: my $oldprefix = $1;
1.492 raeburn 2343: # When pasting content from Main Content to Supplemental Content and vice versa
2344: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2345: # a folder/page or a document).
1.538 raeburn 2346: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2347: $prefixchg{$suffix} = 'docstosupp';
2348: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2349: $prefixchg{$suffix} = 'supptodocs';
2350: }
1.491 raeburn 2351:
1.492 raeburn 2352: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2353: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2354: my @nested;
2355: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2356: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2357: my @deps = map { /\d+:([\d,]+$)/ } @items;
2358: foreach my $dep (@deps) {
2359: if ($dep =~ /,/) {
2360: push(@nested,split(/,/,$dep));
2361: } else {
2362: push(@nested,$dep);
2363: }
1.492 raeburn 2364: }
1.538 raeburn 2365: foreach my $item (@nested) {
2366: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2367: push(@{$marktomove{$suffix}},$type.'_'.$item);
2368: }
1.492 raeburn 2369: }
2370: }
1.488 raeburn 2371: }
2372: }
2373:
1.538 raeburn 2374: # Early out if nothing available to paste
2375: if (@dopaste == 0) {
2376: return ();
2377: }
2378:
2379: # Populate message hash and hashes used for main content <=> supplemental content
2380: # changes
2381:
2382: %msgs = &Apache::lonlocal::texthash (
2383: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2384: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2385: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2386: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2387: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2388: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2389: );
2390:
2391: %before = (
2392: docstosupp => {
2393: map => 'default',
2394: doc => 'docs',
2395: },
2396: supptodocs => {
2397: map => 'supplemental',
2398: doc => 'supplemental',
2399: },
2400: );
2401:
2402: %after = (
2403: docstosupp => {
2404: map => 'supplemental',
2405: doc => 'supplemental'
2406: },
2407: supptodocs => {
2408: map => 'default',
2409: doc => 'docs',
2410: },
2411: );
2412:
2413: # Retrieve information about all course maps in main content area
2414:
2415: my $allmaps = {};
1.704 raeburn 2416: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2417: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2418: $same_institution);
1.538 raeburn 2419:
2420: # Loop over the items to paste
2421: foreach my $suffix (@dopaste) {
1.329 droeschl 2422: # Maps need to be copied first
1.538 raeburn 2423: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2424: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2425: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2426: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2427: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2428: }
2429: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2430: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2431: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2432: my $oldurl = $url;
2433: if ($is_map{$suffix}) {
1.491 raeburn 2434: # If pasting a map, check if map contains other maps
1.538 raeburn 2435: my (%hierarchy,%titles);
1.660 raeburn 2436: if (($folder =~ /^default/) && (!$donechk)) {
2437: $allmaps =
2438: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2439: $env{"course.$env{'request.course.id'}.home"},
2440: $env{'request.course.id'});
2441: $donechk = 1;
2442: }
1.627 raeburn 2443: &contained_map_check($url,$folder,$coursenum,$coursedom,
2444: \%removefrommap,\%removeparam,\%addedmaps,
2445: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2446: if ($url=~ m{^/uploaded/}) {
2447: my $newurl;
2448: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2449: ($newurl,my $error) =
2450: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2451: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2452: \$title,$allmaps,\%newurls);
2453: if ($error) {
2454: $allerrors{$suffix} = $error;
2455: next;
2456: }
2457: if ($newurl ne '') {
2458: if ($newurl ne $url) {
2459: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2460: $newsubdir{$url} = $1;
2461: }
2462: $mapchanges{$url} = 1;
1.492 raeburn 2463: }
1.538 raeburn 2464: }
2465: }
2466: if (($srcdom{$suffix} ne $coursedom) ||
2467: ($srcnum{$suffix} ne $coursenum) ||
2468: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2469: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2470: $coursedom,$coursenum,$srcdom{$suffix},
2471: $srcnum{$suffix},$allmaps,\%rewrites,
2472: \%retitles,\%copies,\%dbcopies,
2473: \%zombies,\%params,\%mapmoves,
2474: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2475: \%newurls,\%resdatacopy)) {
1.538 raeburn 2476: $mapmoves{$url} = 1;
2477: }
2478: $url = $newurl;
2479: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2480: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2481: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2482: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2483: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 2484: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 2485: }
2486: } elsif ($url=~m {^/res/}) {
1.597 raeburn 2487: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 2488: push(@toclear,$suffix);
2489: # if pasting published map (main content area only) check map not already in course
2490: if ($folder =~ /^default/) {
2491: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2492: $duplicate{$suffix} = 1;
2493: next;
1.492 raeburn 2494: }
1.491 raeburn 2495: }
2496: }
1.538 raeburn 2497: }
1.627 raeburn 2498: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2499: my $prefix = $1;
1.648 raeburn 2500: my $fromothercrs;
1.538 raeburn 2501: #need to copy the db contents to a new one, unless this is a move.
2502: my %info = (
2503: src => $url,
2504: cdom => $coursedom,
2505: cnum => $coursenum,
1.596 raeburn 2506: );
1.649 raeburn 2507: if ($prefix eq 'ext.tool') {
1.655 raeburn 2508: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2509: $info{'delgradable'} = 1;
2510: }
2511: }
1.596 raeburn 2512: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2513: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2514: $fromothercrs = 1;
2515: $info{'cdom'} = $srcdom{$suffix};
2516: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 2517: unless ($checkedsameinst) {
2518: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2519: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2520: if ($intdom ne '') {
2521: my $internet_names =
2522: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2523: if (ref($internet_names) eq 'ARRAY') {
2524: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2525: $same_institution = 1;
2526: }
2527: }
2528: }
2529: $checkedsameinst = 1;
2530: }
1.596 raeburn 2531: }
2532: }
2533: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2534: my (%lockerr,$msg);
1.538 raeburn 2535: my ($newurl,$result,$errtext) =
1.704 raeburn 2536: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2537: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 2538: if ($result eq 'ok') {
2539: $url = $newurl;
2540: $title=&mt('Copy of').' '.$title;
2541: } else {
2542: if ($prefix eq 'smppg') {
2543: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2544: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2545: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2546: } elsif ($prefix eq 'ext.tool') {
2547: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2548: }
2549: $results{$suffix} = $result;
2550: $msgerrs{$suffix} = $msg;
2551: $lockerrs{$suffix} = $lockerr{$prefix};
2552: next;
2553: }
2554: if ($lockerr{$prefix}) {
2555: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2556: }
1.489 raeburn 2557: }
2558: }
1.538 raeburn 2559: $title = &LONCAPA::map::qtunescape($title);
2560: my $ext='false';
2561: if ($url=~m{^http(|s)://}) { $ext='true'; }
2562: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2563: if ($folder !~ /^supplemental/) {
2564: (undef,undef,$title) =
2565: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2566: }
2567: } else {
2568: if ($folder=~/^supplemental/) {
2569: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2570: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2571: }
1.533 raeburn 2572: }
1.491 raeburn 2573:
2574: # For uploaded files (excluding pages/sequences) path in copied file is changed
2575: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2576: # courses.
2577:
1.538 raeburn 2578: unless ($is_map{$suffix}) {
2579: my $newidx;
1.492 raeburn 2580: # Now insert the URL at the bottom
1.538 raeburn 2581: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2582: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2583: my $relpath = $1;
2584: if ($relpath ne '') {
2585: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2586: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2587: my $newprefix = $newloc;
2588: if ($newloc eq 'default') {
2589: $newprefix = 'docs';
2590: }
2591: if ($newdocsdir eq '') {
2592: $newdocsdir = 'default';
2593: }
1.630 raeburn 2594: if (($prefixchg{$suffix}) ||
2595: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2596: ($srcnum{$suffix} ne $coursenum) ||
2597: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2598: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2599: $url =
2600: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2601: &Apache::lonnet::getfile($oldurl));
2602: if ($url eq '/adm/notfound.html') {
2603: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2604: next;
2605: } else {
2606: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2607: $newsubpath =~ s{/+$}{/};
2608: $docmoves{$oldurl} = $newsubpath;
2609: }
1.491 raeburn 2610: }
2611: }
1.597 raeburn 2612: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2613: my $template = $1;
2614: if ($newidx) {
2615: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2616: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2617: }
1.649 raeburn 2618: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2619: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2620: my $marker = (split(m{/},$url))[4];
2621: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2622: my $val = 'no';
2623: if ($toolsettings{'gradable'}) {
2624: $val = 'yes';
2625: }
2626: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2627: 'string_yesno');
2628: &remember_parms($newidx,'gradable','set',$val);
2629: }
1.491 raeburn 2630: }
1.538 raeburn 2631: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2632: ':'.$ext.':normal:res';
2633: push(@LONCAPA::map::order,$newidx);
2634: # Store the result
2635: my ($errtext,$fatal) =
2636: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2637: if ($fatal) {
2638: $save_err .= $errtext;
2639: $allresult = 'fail';
2640: }
1.488 raeburn 2641: }
1.538 raeburn 2642:
1.597 raeburn 2643: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2644: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2645: unless ($allresult eq 'fail') {
2646: my %updated = (
2647: rewrites => \%rewrites,
2648: zombies => \%zombies,
2649: removefrommap => \%removefrommap,
2650: removeparam => \%removeparam,
2651: dbcopies => \%dbcopies,
1.597 raeburn 2652: resdatacopy => \%resdatacopy,
1.538 raeburn 2653: retitles => \%retitles,
2654: );
2655: my %info = (
2656: newsubdir => \%newsubdir,
2657: params => \%params,
2658: );
2659: if ($prefixchg{$suffix}) {
2660: $info{'before'} = $before{$prefixchg{$suffix}};
2661: $info{'after'} = $after{$prefixchg{$suffix}};
2662: }
2663: my %moves = (
2664: copies => \%copies,
2665: docmoves => \%docmoves,
2666: mapmoves => \%mapmoves,
2667: );
2668: (my $result,$msgs{$suffix},my $lockerror) =
2669: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2670: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2671: $url,'paste');
2672: $lockerrors .= $lockerror;
2673: if ($result eq 'ok') {
2674: if ($is_map{$suffix}) {
2675: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2676: $folder.'.'.$container);
2677: if ($fatal) {
2678: $allresult = 'failread';
2679: } else {
2680: if ($#LONCAPA::map::order<1) {
2681: my $idx=&LONCAPA::map::getresidx();
2682: if ($idx<=0) { $idx=1; }
2683: $LONCAPA::map::order[0]=$idx;
2684: $LONCAPA::map::resources[$idx]='';
2685: }
2686: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2687: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2688: ':'.$ext.':normal:res';
2689: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2690:
2691: # Store the result
1.538 raeburn 2692: my ($errtext,$fatal) =
2693: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2694: if ($fatal) {
2695: $save_err .= $errtext;
2696: $allresult = 'failstore';
2697: }
2698: }
2699: }
2700: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2701: push(@toclear,$suffix);
2702: }
2703: }
1.492 raeburn 2704: }
2705: }
1.704 raeburn 2706: if (($updatetoolscache) || (@updatetoolsenc)) {
2707: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2708: \@updatetoolsenc);
2709: }
1.538 raeburn 2710: &clear_from_buffer(\@toclear,\@currpaste);
2711: my $msgsarray;
2712: foreach my $suffix (keys(%msgs)) {
2713: if (ref($msgs{$suffix}) eq 'ARRAY') {
2714: $msgsarray .= join(',',@{$msgs{$suffix}});
2715: }
2716: }
2717: return ($allresult,$save_err,$msgsarray,$lockerrors);
2718: }
1.533 raeburn 2719:
1.538 raeburn 2720: sub do_buffer_empty {
2721: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2722: if (@currpaste == 0) {
2723: return &mt('Clipboard is already empty');
2724: }
2725: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2726: if (@toclear == 0) {
2727: return &mt('Nothing selected to clear from clipboard');
2728: }
2729: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2730: if ($numdel) {
2731: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2732: } else {
2733: return &mt('Clipboard unchanged');
1.492 raeburn 2734: }
1.538 raeburn 2735: return;
2736: }
2737:
2738: sub clear_from_buffer {
2739: my ($toclear,$currpaste) = @_;
2740: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2741: my %pastebuffer;
2742: map { $pastebuffer{$_} = 1; } @{$currpaste};
2743: my $numdel = 0;
2744: foreach my $suffix (@{$toclear}) {
2745: next if ($suffix =~ /\D/);
2746: next unless (exists($pastebuffer{$suffix}));
2747: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2748: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2749: delete($pastebuffer{$suffix});
2750: $numdel ++;
2751: }
2752: }
2753: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2754: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2755: return $numdel;
1.492 raeburn 2756: }
2757:
1.704 raeburn 2758: sub update_ltitools_caches {
2759: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2760: my $hashid=$coursedom.'_'.$coursenum;
2761: if ($updatetoolscache) {
2762: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2763: }
2764: if ((ref($updatetoolsenc) eq 'ARRAY') &&
2765: (@{$updatetoolsenc})) {
2766: my @ids=&Apache::lonnet::current_machine_ids();
2767: my $updatedone;
2768: foreach my $lonhost (@{$updatetoolsenc}) {
2769: if (grep(/^\Q$lonhost\E$/,@ids)) {
2770: unless ($updatedone) {
2771: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2772: }
2773: $updatedone = 1;
2774: } else {
2775: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2776: }
2777: }
2778: }
2779: return;
2780: }
2781:
1.492 raeburn 2782: sub get_newmap_url {
2783: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2784: $titleref,$allmaps,$newurls) = @_;
2785: my $newurl;
2786: if ($url=~ m{^/uploaded/}) {
2787: $$titleref=&mt('Copy of').' '.$$titleref;
2788: }
2789: my $now = time;
2790: my $suffix=$$.int(rand(100)).$now;
2791: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2792: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2793: my $path = $1;
2794: my $prefix = $2;
2795: my $ancestor = $3;
2796: if (length($ancestor) > 10) {
2797: $ancestor = substr($ancestor,-10,10);
2798: }
2799: my $newid;
2800: if ($prefixchg) {
2801: if ($folder =~ /^supplemental/) {
2802: $prefix =~ s/^default/supplemental/;
2803: } else {
2804: $prefix =~ s/^supplemental/default/;
2805: }
2806: }
2807: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2808: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2809: } else {
2810: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2811: }
2812: my $counter = 0;
2813: my $is_unique = &uniqueness_check($newurl);
2814: if ($folder =~ /^default/) {
2815: if ($allmaps->{$newurl}) {
2816: $is_unique = 0;
2817: }
2818: }
2819: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2820: $counter ++;
2821: $suffix ++;
2822: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2823: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2824: } else {
2825: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2826: }
2827: $is_unique = &uniqueness_check($newurl);
2828: }
2829: if ($is_unique) {
2830: $newurls->{$newurl} = 1;
2831: } else {
2832: if ($url=~/\.page$/) {
2833: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2834: } else {
2835: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2836: }
2837: }
1.329 droeschl 2838: }
1.492 raeburn 2839: return ($newurl);
1.329 droeschl 2840: }
2841:
1.488 raeburn 2842: sub dbcopy {
1.704 raeburn 2843: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
2844: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 2845: my ($url,$result,$errtext);
2846: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2847: $url = $dbref->{'src'};
1.627 raeburn 2848: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2849: my $prefix = $1;
1.627 raeburn 2850: if ($prefix eq 'ext.tool') {
2851: $prefix = 'exttool';
2852: }
1.533 raeburn 2853: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2854: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2855: my $db_name;
2856: my $marker = (split(m{/},$url))[4];
2857: $marker=~s/\D//g;
2858: if ($dbref->{'src'} =~ m{/smppg$}) {
2859: $db_name =
2860: &Apache::lonsimplepage::get_db_name($url,$marker,
2861: $dbref->{'cdom'},
2862: $dbref->{'cnum'});
1.627 raeburn 2863: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2864: $db_name = 'exttool_'.$marker;
1.533 raeburn 2865: } else {
2866: $db_name = 'bulletinpage_'.$marker;
2867: }
2868: my ($suffix,$freedlock,$error) =
2869: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2870: $coursedom,$coursenum,
2871: 'concat');
2872: if (!$suffix) {
2873: if ($prefix eq 'smppg') {
2874: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2875: } elsif ($prefix eq 'exttool') {
2876: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2877: } else {
1.565 bisitz 2878: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2879: }
2880: if ($error) {
2881: $errtext .= '<br />'.$error;
2882: }
2883: } else {
2884: #need to copy the db contents to a new one.
2885: my %contents=&Apache::lonnet::dump($db_name,
2886: $dbref->{'cdom'},
2887: $dbref->{'cnum'});
1.704 raeburn 2888: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
2889: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
2890: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
2891: $oldtoolid = $2;
2892: if ($1 eq 'c') {
2893: $defincrs = 1;
2894: %toolinfo =
2895: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
2896: } else {
2897: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
2898: }
2899: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
2900: if ($toolinfo{$oldtoolid}{'passback'}) {
2901: $toolpassback = 1;
2902: }
2903: if ($toolinfo{$oldtoolid}{'roster'}) {
2904: $toolroster = 1;
2905: }
2906: } else {
2907: $toolcopyerror = 1;
2908: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
2909: }
2910: }
2911: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
2912: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
2913: if ($contents{'crstitle'} ne '') {
2914: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
2915: }
2916: if (($defincrs) && (!$toolcopyerror)) {
2917: my %newtool;
2918: my $oldcdom = $dbref->{'cdom'};
2919: my $oldcnum = $dbref->{'cnum'};
2920: my $title = $toolinfo{$oldtoolid}{'title'};
2921: if (ref($currltititles) eq 'HASH') {
2922: if (exists($currltititles->{$title})) {
2923: $title .= ' (copied from another course)';
2924: }
2925: }
2926: my ($newid,$iderror) =
2927: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
2928: if ($newid =~ /^\d+$/) {
2929: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
2930: $newtool{$newid}{'title'} = $title;
2931: if (ref($currltimax)) {
2932: $newtool{$newid}{'order'} = $$currltimax;
2933: }
2934: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
2935: my $fname = $1;
2936: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
2937: if ($content eq '-1') {
2938: delete($newtool{$newid}{'image'});
2939: } else {
2940: $env{'form.'.$suffix.'.image'} = $content;
2941: my $newlogo =
2942: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
2943: delete($env{'form.'.$suffix.'.image'});
2944: if ($newlogo =~ m{^/uploaded/}) {
2945: $newtool{$newid}{'image'} = $newlogo;
2946: } else {
2947: delete($newtool{$newid}{'image'});
2948: }
2949: }
2950: }
2951: my $newusable;
2952: if ($same_institution) {
2953: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
2954: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
2955: my %newtoolsenc;
2956: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
2957: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
2958: if ($putres eq 'ok') {
2959: if (ref($updatetoolsenc) eq 'ARRAY') {
2960: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
2961: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
2962: push(@{$updatetoolsenc},$newhome);
2963: }
2964: }
2965: $newusable = 1;
2966: }
2967: }
2968: }
2969: if ($newtool{$newid}{'usable'}) {
2970: unless ($newusable) {
2971: delete($newtool{$newid}{'usable'});
2972: }
2973: }
2974: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
2975: if ($putres eq 'ok') {
2976: $contents{'id'} = "c$newid";
2977: if (ref($updatetoolscache)) {
2978: $$updatetoolscache ++;
2979: }
2980: if (ref($currltititles->{$title}) eq 'ARRAY') {
2981: push(@{$currltititles->{$title}},$newid);
2982: } else {
2983: $currltititles->{$title} = [$newid];
2984: }
2985: if (ref($currltimax)) {
2986: $$currltimax ++;
2987: }
2988: } else {
2989: $toolcopyerror = 1;
2990: $errtext = &mt('Unable to save external tool definition in Course Settings.');
2991: }
2992: } else {
2993: $toolcopyerror = 1;
2994: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
2995: }
2996: }
2997: }
2998: }
1.533 raeburn 2999: if (exists($contents{'uploaded.photourl'})) {
3000: my $photo = $contents{'uploaded.photourl'};
3001: my ($subdir,$fname) =
3002: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3003: my $newphoto;
1.533 raeburn 3004: if ($fname ne '') {
3005: my $content = &Apache::lonnet::getfile($photo);
3006: unless ($content eq '-1') {
3007: $env{'form.'.$suffix.'.photourl'} = $content;
3008: $newphoto =
3009: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3010: delete($env{'form.'.$suffix.'.photourl'});
3011: }
3012: }
3013: if ($newphoto =~ m{^/uploaded/}) {
3014: $contents{'uploaded.photourl'} = $newphoto;
3015: }
3016: }
3017: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3018: if ($prefix eq 'exttool') {
3019: unless ($toolcopyerror) {
3020: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3021: if (exists($contents{$key})) {
3022: delete($contents{$key});
3023: }
3024: }
3025: if ($dbref->{'delgradable'}) {
3026: if (exists($contents{'gradable'})) {
3027: delete($contents{'gradable'});
3028: }
3029: }
3030: if ($toolpassback) {
3031: if ($contents{'gradable'}) {
3032: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3033: $contents{'gradesecret'} = $gradesecret;
3034: $contents{'gradesecretdate'} = time;
3035: }
3036: }
3037: if ($toolroster) {
3038: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3039: $contents{'rostersecret'} = $rostersecret;
3040: $contents{'rostersecretdate'} = time;
3041: }
3042: }
1.649 raeburn 3043: }
1.704 raeburn 3044: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3045: $result = 'error';
3046: } else {
3047: $result=&Apache::lonnet::put($db_name,\%contents,
3048: $coursedom,$coursenum);
3049: if ($result eq 'ok') {
3050: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3051: }
1.533 raeburn 3052: }
3053: }
3054: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3055: $lockerrorsref->{$prefix} =
1.533 raeburn 3056: '<div class="LC_error">'.
3057: &mt('There was a problem removing a lockfile.');
3058: if ($prefix eq 'smppg') {
1.560 raeburn 3059: $lockerrorsref->{$prefix} .=
1.559 raeburn 3060: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3061: } elsif ($prefix eq 'exttool') {
3062: $lockerrorsref->{$prefix} .=
3063: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3064: } else {
1.565 bisitz 3065: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3066: }
1.560 raeburn 3067: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3068: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3069: '</div>';
1.533 raeburn 3070: }
3071: }
3072: } elsif ($url =~ m{/syllabus$}) {
3073: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3074: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3075: if (($dbref->{'cdom'} ne $coursedom) ||
3076: ($dbref->{'cnum'} ne $coursenum)) {
3077: my %contents=&Apache::lonnet::dump('syllabus',
3078: $dbref->{'cdom'},
3079: $dbref->{'cnum'});
3080: $result=&Apache::lonnet::put('syllabus',\%contents,
3081: $coursedom,$coursenum);
3082: }
3083: }
1.488 raeburn 3084: }
3085: }
1.533 raeburn 3086: return ($url,$result,$errtext);
1.488 raeburn 3087: }
3088:
1.597 raeburn 3089: sub copy_templated_files {
3090: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3091: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3092: my $srccontainer = 'sequence';
3093: if ($srcwaspage) {
3094: $srccontainer = 'page';
3095: }
3096: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3097: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3098: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3099: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3100: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3101: $template.'.problem';
3102: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3103: if ($template eq 'simpleproblem') {
3104: $srcprefix .= '.0.';
3105: my $weightprefix = $newprefix;
3106: $newprefix .= '.0.';
3107: my @simpleprobqtypes = qw(radio option string essay numerical);
3108: my $qtype=$srcparms{$srcprefix.'questiontype'};
3109: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3110: my %newdata = (
3111: $newprefix.'questiontype' => $qtype,
3112: );
1.597 raeburn 3113: foreach my $type (@simpleprobqtypes) {
3114: if ($type eq $qtype) {
3115: $newdata{"$weightprefix.$type.weight"}=1;
3116: } else {
3117: $newdata{"$weightprefix.$type.weight"}=0;
3118: }
3119: }
3120: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3121: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3122: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3123: if ($qtype eq 'numerical') {
3124: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3125: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3126: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3127: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3128: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3129: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3130: unless (defined($maxfoils)) { $maxfoils=10; }
3131: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3132: if ($maxfoils<=0) { $maxfoils=10; }
3133: my $randomize=$srcparms{$srcprefix.'randomize'};
3134: unless (defined($randomize)) { $randomize='yes'; }
3135: unless ($randomize eq 'no') { $randomize='yes'; }
3136: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3137: $newdata{$newprefix.'randomize'} = $randomize;
3138: if ($qtype eq 'option') {
3139: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3140: }
3141: for (my $i=1; $i<=10; $i++) {
3142: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3143: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3144: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3145: }
3146:
3147: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3148: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3149: unless (defined($maxfoils)) { $maxfoils=10; }
3150: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3151: if ($maxfoils<=0) { $maxfoils=10; }
3152: my $randomize=$srcparms{$srcprefix.'randomize'};
3153: unless (defined($randomize)) { $randomize='yes'; }
3154: unless ($randomize eq 'no') { $randomize='yes'; }
3155: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3156: $newdata{$newprefix.'randomize'} = $randomize;
3157: if ($qtype eq 'option') {
3158: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3159: }
3160: for (my $i=1; $i<=10; $i++) {
3161: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3162: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3163: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3164: }
3165: } elsif ($qtype eq 'string') {
3166: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3167: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3168: }
3169: if (keys(%newdata)) {
3170: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3171: $coursenum);
3172: if ($putres eq 'ok') {
3173: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3174: }
3175: }
3176: }
3177: }
3178: }
3179:
1.329 droeschl 3180: sub uniqueness_check {
3181: my ($newurl) = @_;
3182: my $unique = 1;
3183: foreach my $res (@LONCAPA::map::order) {
3184: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3185: $url=&LONCAPA::map::qtescape($url);
3186: if ($newurl eq $url) {
3187: $unique = 0;
1.344 bisitz 3188: last;
1.329 droeschl 3189: }
3190: }
3191: return $unique;
3192: }
3193:
1.488 raeburn 3194: sub contained_map_check {
1.627 raeburn 3195: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3196: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3197: my $content = &Apache::lonnet::getfile($url);
3198: unless ($content eq '-1') {
3199: my $parser = HTML::TokeParser->new(\$content);
3200: $parser->attr_encoded(1);
3201: while (my $token = $parser->get_token) {
3202: next if ($token->[0] ne 'S');
3203: if ($token->[1] eq 'resource') {
3204: next if ($token->[2]->{'type'} eq 'zombie');
3205: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3206: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3207: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3208: unless ($srcdom eq $coursedom) {
3209: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3210: next;
3211: }
1.704 raeburn 3212: unless ($srcnum eq $coursenum) {
3213: my %toolsettings =
3214: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3215: my %tooltypes = &Apache::loncommon::usable_exttools();
3216: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3217: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3218: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3219: next;
3220: }
3221: }
1.627 raeburn 3222: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3223: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3224: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3225: next;
3226: }
3227: }
1.703 raeburn 3228: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3229: my ($srcdom,$srcnum) = ($1,$2);
3230: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3231: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3232: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3233: next;
3234: }
3235: }
3236: }
1.492 raeburn 3237: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3238: if ($1 eq 'uploaded') {
3239: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3240: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3241: } else {
1.492 raeburn 3242: if ($allmaps->{$ressrc}) {
1.529 raeburn 3243: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3244: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3245: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3246: } else {
3247: $addedmaps->{$ressrc} = [$url];
3248: }
1.488 raeburn 3249: }
1.627 raeburn 3250: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3251: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3252: }
1.492 raeburn 3253: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3254: if ($folder =~ /^supplemental/) {
1.492 raeburn 3255: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3256: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3257: } else {
3258: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3259: }
1.488 raeburn 3260: }
3261: }
3262: }
3263: }
3264: return;
3265: }
3266:
3267: sub url_paste_fixups {
1.533 raeburn 3268: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3269: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3270: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3271: my $checktitle;
3272: if (($prefixchg) &&
1.492 raeburn 3273: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3274: $checktitle = 1;
3275: }
1.492 raeburn 3276: my $skip;
3277: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3278: my $mapid = $1.$2;
3279: if ($tomove->{$mapid}) {
3280: $skip = 1;
3281: }
3282: }
1.491 raeburn 3283: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3284: return if ($file eq '-1');
3285: my $parser = HTML::TokeParser->new(\$file);
3286: $parser->attr_encoded(1);
1.491 raeburn 3287: my $changed = 0;
1.488 raeburn 3288: while (my $token = $parser->get_token) {
3289: next if ($token->[0] ne 'S');
3290: if ($token->[1] eq 'resource') {
3291: my $ressrc = $token->[2]->{'src'};
3292: next if ($ressrc eq '');
1.491 raeburn 3293: my $id = $token->[2]->{'id'};
1.492 raeburn 3294: my $title = $token->[2]->{'title'};
1.491 raeburn 3295: if ($checktitle) {
3296: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3297: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3298: }
3299: }
1.488 raeburn 3300: next if ($token->[2]->{'type'} eq 'external');
3301: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3302: next if ($skip);
1.532 raeburn 3303: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3304: $changed = 1;
3305: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3306: my $srcdom = $1;
3307: my $srcnum = $2;
1.488 raeburn 3308: my $rem = $3;
1.492 raeburn 3309: my $newurl;
3310: my $mapname;
3311: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3312: my $prefix = $1;
3313: $mapname = $prefix.$2;
3314: if ($tomove->{$mapname}) {
1.533 raeburn 3315: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3316: $srcdom,$srcnum,$allmaps,$rewrites,
3317: $retitles,$copies,$dbcopies,$zombies,
3318: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3319: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3320: next;
3321: } else {
3322: ($newurl,my $error) =
3323: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3324: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3325: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3326: $newsubdir->{$ressrc} = $1;
3327: }
3328: if ($error) {
3329: next;
3330: }
3331: }
3332: }
3333: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3334: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3335:
1.488 raeburn 3336: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3337: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3338: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3339: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3340: $cnum,$srcdom,$srcnum,$allmaps,
3341: $rewrites,$retitles,$copies,$dbcopies,
3342: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3343: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3344: $mapmoves->{$ressrc} = 1;
3345: }
3346: $changed = 1;
1.488 raeburn 3347: } else {
1.532 raeburn 3348: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3349: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3350: $changed = 1;
1.488 raeburn 3351: }
3352: }
1.649 raeburn 3353: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3354: next if ($skip);
1.492 raeburn 3355: my $srcdom = $1;
3356: my $srcnum = $2;
1.649 raeburn 3357: my $rem = $3;
3358: my ($is_exttool,$exttoolchg);
3359: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3360: $is_exttool = 1;
1.649 raeburn 3361: }
1.492 raeburn 3362: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3363: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3364: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3365: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3366: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3367: $changed = 1;
1.649 raeburn 3368: if ($is_exttool) {
3369: $exttoolchg = 1;
3370: }
1.700 raeburn 3371: } elsif (($is_exttool) &&
1.649 raeburn 3372: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3373: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3374: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3375: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3376: $changed = 1;
3377: $exttoolchg = 1;
3378: }
3379: if (($is_exttool) && ($prefixchg)) {
3380: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3381: if ($exttoolchg) {
3382: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3383: }
3384: }
1.533 raeburn 3385: }
3386: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3387: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3388: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3389: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3390: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3391: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3392: $changed = 1;
1.488 raeburn 3393: }
1.597 raeburn 3394: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3395: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3396: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3397: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3398: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3399: }
1.488 raeburn 3400: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3401: next if ($skip);
3402: my $srcdom = $1;
3403: my $srcnum = $2;
3404: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3405: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3406: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3407: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3408: $changed = 1;
1.488 raeburn 3409: }
3410: }
3411: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3412: next if ($skip);
1.488 raeburn 3413: my $to = $token->[2]->{'to'};
3414: if ($to ne '') {
3415: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3416: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3417: } else {
3418: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3419: }
3420: }
3421: }
3422: }
1.491 raeburn 3423: return $changed;
1.488 raeburn 3424: }
3425:
3426: sub apply_fixups {
1.529 raeburn 3427: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3428: $oldurl,$url,$caller) = @_;
3429: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3430: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3431: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3432: %currltititles,$currltimax);
3433: $currltimax = 0;
1.529 raeburn 3434: if (ref($updated) eq 'HASH') {
3435: if (ref($updated->{'rewrites'}) eq 'HASH') {
3436: %rewrites = %{$updated->{'rewrites'}};
3437: }
3438: if (ref($updated->{'zombies'}) eq 'HASH') {
3439: %zombies = %{$updated->{'zombies'}};
3440: }
3441: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3442: %removefrommap = %{$updated->{'removefrommap'}};
3443: }
3444: if (ref($updated->{'removeparam'}) eq 'HASH') {
3445: %removeparam = %{$updated->{'removeparam'}};
3446: }
3447: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3448: %dbcopies = %{$updated->{'dbcopies'}};
3449: }
3450: if (ref($updated->{'retitles'}) eq 'HASH') {
3451: %retitles = %{$updated->{'retitles'}};
3452: }
1.597 raeburn 3453: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3454: %resdatacopy = %{$updated->{'resdatacopy'}};
3455: }
1.529 raeburn 3456: }
3457: if (ref($info) eq 'HASH') {
3458: if (ref($info->{'newsubdir'}) eq 'HASH') {
3459: %newsubdir = %{$info->{'newsubdir'}};
3460: }
3461: if (ref($info->{'params'}) eq 'HASH') {
3462: %params = %{$info->{'params'}};
3463: }
3464: if (ref($info->{'before'}) eq 'HASH') {
3465: %before = %{$info->{'before'}};
3466: }
3467: if (ref($info->{'after'}) eq 'HASH') {
3468: %after = %{$info->{'after'}};
3469: }
3470: }
3471: if (ref($moves) eq 'HASH') {
3472: if (ref($moves->{'copies'}) eq 'HASH') {
3473: %copies = %{$moves->{'copies'}};
3474: }
3475: if (ref($moves->{'docmoves'}) eq 'HASH') {
3476: %docmoves = %{$moves->{'docmoves'}};
3477: }
3478: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3479: %mapmoves = %{$moves->{'mapmoves'}};
3480: }
3481: }
3482: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 3483: my @allcopies;
1.529 raeburn 3484: if (exists($copies{$key})) {
3485: if (ref($copies{$key}) eq 'HASH') {
3486: my %added;
3487: foreach my $innerkey (keys(%{$copies{$key}})) {
3488: if (($innerkey ne '') && (!$added{$innerkey})) {
3489: push(@allcopies,$innerkey);
3490: $added{$innerkey} = 1;
3491: }
1.491 raeburn 3492: }
1.529 raeburn 3493: undef(%added);
1.491 raeburn 3494: }
3495: }
3496: if ($key eq $oldurl) {
1.529 raeburn 3497: if ((exists($docmoves{$key}))) {
1.532 raeburn 3498: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 3499: push(@allcopies,$oldurl);
3500: }
3501: }
3502: }
3503: if (@allcopies > 0) {
3504: foreach my $item (@allcopies) {
1.492 raeburn 3505: my ($relpath,$oldsubdir,$fname) =
3506: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 3507: if ($fname ne '') {
3508: my $content = &Apache::lonnet::getfile($item);
3509: unless ($content eq '-1') {
3510: my $storefn;
1.529 raeburn 3511: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3512: $storefn = $docmoves{$key};
1.491 raeburn 3513: } else {
3514: $storefn = $relpath;
3515: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3516: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3517: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 3518: }
1.529 raeburn 3519: if ($newsubdir{$key}) {
1.532 raeburn 3520: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 3521: }
3522: }
3523: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3524: my $copyurl =
3525: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3526: $storefn.$fname,$content);
3527: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 3528: if (exists($docmoves{$oldurl})) {
1.491 raeburn 3529: return &mt('Paste failed: an error occurred copying the file.');
3530: } elsif (ref($errors) eq 'HASH') {
3531: $errors->{$item} = 1;
1.489 raeburn 3532: }
3533: }
1.488 raeburn 3534: }
3535: }
1.491 raeburn 3536: }
3537: }
3538: }
1.529 raeburn 3539: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 3540: my $storefn=$key;
3541: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3542: if ($prefixchg && $before{'map'} && $after{'map'}) {
3543: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3544: }
1.529 raeburn 3545: if ($newsubdir{$key}) {
3546: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3547: }
1.491 raeburn 3548: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 3549: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3550: ($after{'map'} eq 'default') &&
3551: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3552: $mapcontent = '<map>'."\n".
3553: '<resource id="1" src="" type="start" />'."\n".
3554: '<link from="1" to="2" index="1" />'."\n".
3555: '<resource id="2" src="" type="finish" />'."\n".
3556: '</map>';
3557: }
1.491 raeburn 3558: if ($mapcontent eq '-1') {
3559: if (ref($errors) eq 'HASH') {
3560: $errors->{$key} = 1;
3561: }
3562: } else {
3563: my $newmap =
3564: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3565: $mapcontent);
3566: if ($newmap eq '/adm/notfound.html') {
3567: if (ref($errors) eq 'HASH') {
3568: $errors->{$key} = 1;
1.489 raeburn 3569: }
1.488 raeburn 3570: }
3571: }
3572: }
1.491 raeburn 3573: my %updates;
3574: if ($is_map) {
1.529 raeburn 3575: if (ref($updated) eq 'HASH') {
3576: foreach my $type (keys(%{$updated})) {
3577: if (ref($updated->{$type}) eq 'HASH') {
3578: foreach my $key (keys(%{$updated->{$type}})) {
3579: $updates{$key} = 1;
3580: }
3581: }
3582: }
1.491 raeburn 3583: }
1.704 raeburn 3584: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 3585: foreach my $key (keys(%updates)) {
1.492 raeburn 3586: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 3587: if (ref($rewrites{$key}) eq 'HASH') {
3588: %torewrite = %{$rewrites{$key}};
1.491 raeburn 3589: }
1.529 raeburn 3590: if (ref($retitles{$key}) eq 'HASH') {
3591: %toretitle = %{$retitles{$key}};
1.491 raeburn 3592: }
1.529 raeburn 3593: if (ref($removefrommap{$key}) eq 'HASH') {
3594: %toremove = %{$removefrommap{$key}};
1.491 raeburn 3595: }
1.529 raeburn 3596: if (ref($removeparam{$key}) eq 'HASH') {
3597: %remparam = %{$removeparam{$key}};
1.492 raeburn 3598: }
1.529 raeburn 3599: if (ref($zombies{$key}) eq 'HASH') {
3600: %zombie = %{$zombies{$key}};
1.491 raeburn 3601: }
1.529 raeburn 3602: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 3603: foreach my $idx (keys(%{$dbcopies{$key}})) {
3604: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 3605: my $oldurl = $dbcopies{$key}{$idx}{'src'};
3606: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3607: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3608: my $oldmarker;
3609: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3610: $oldmarker = $1;
3611: unless (($gotcrsltitools) ||
3612: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3613: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3614: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3615: unless ($gotcrsltitools) {
3616: %currcrsltitools =
3617: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3618: foreach my $item (sort(keys(%currcrsltitools))) {
3619: if (ref($currcrsltitools{$item}) eq 'HASH') {
3620: $currltimax ++;
3621: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3622: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3623: } else {
3624: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3625: }
3626: }
3627: }
3628: $gotcrsltitools = 1;
3629: }
3630: unless ($checkedsameinst) {
3631: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3632: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3633: if ($intdom ne '') {
3634: my $internet_names =
3635: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3636: if (ref($internet_names) eq 'ARRAY') {
3637: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3638: $same_institution = 1;
3639: }
3640: }
3641: }
3642: $checkedsameinst = 1;
3643: }
3644: }
3645: }
3646: }
1.533 raeburn 3647: my ($newurl,$result,$errtext) =
1.704 raeburn 3648: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3649: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 3650: if ($result eq 'ok') {
3651: $newdb{$idx} = $newurl;
1.704 raeburn 3652: if ($newurl =~ /ext\.tool$/) {
3653: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3654: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3655: my $newmarker = $1;
3656: unless ($oldmarker eq $newmarker) {
3657: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3658: }
3659: }
3660: }
3661: }
1.533 raeburn 3662: } elsif (ref($errors) eq 'HASH') {
3663: $errors->{$key} = 1;
3664: }
3665: push(@msgs,$errtext);
3666: }
1.491 raeburn 3667: }
3668: }
1.597 raeburn 3669: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 3670: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 3671: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3672: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3673: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3674: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3675: my $template = $1;
3676: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3677: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3678: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3679: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 3680: unless ($gotnewmapname) {
3681: ($newmapname) = ($key =~ m{/([^/]+)$});
3682: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3683: if ($newsubdir{$key}) {
3684: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3685: }
3686: $gotnewmapname = 1;
3687: }
1.597 raeburn 3688: my $srcmapinfo = $srcfolder.':'.$idx;
3689: if ($srccontainer eq 'page') {
3690: $srcmapinfo .= ':1';
3691: }
3692: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3693: $cnum,$template,$idx,$newmapname);
3694: }
3695: }
3696: }
3697: }
3698: }
1.529 raeburn 3699: if (ref($params{$key}) eq 'HASH') {
3700: %currparam = %{$params{$key}};
1.492 raeburn 3701: }
3702: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3703: if ($fatal) {
1.533 raeburn 3704: return ($errtext);
1.492 raeburn 3705: }
3706: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3707: if (defined($LONCAPA::map::zombies[$i])) {
3708: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 3709: if ($zombie{$i} eq $src) {
1.492 raeburn 3710: undef($LONCAPA::map::zombies[$i]);
3711: }
3712: }
3713: }
1.646 raeburn 3714: my $total = scalar(@LONCAPA::map::order) - 1;
3715: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 3716: my $idx = $LONCAPA::map::order[$i];
3717: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 3718: my $changed;
1.529 raeburn 3719: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 3720: if ((exists($toremove{$idx})) &&
3721: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 3722: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 3723: if (ref($currparam{$idx}) eq 'ARRAY') {
3724: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 3725: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 3726: }
3727: }
3728: next;
3729: }
3730: my $origsrc = $src;
1.532 raeburn 3731: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 3732: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3733: $changed = 1;
1.491 raeburn 3734: }
1.492 raeburn 3735: }
1.532 raeburn 3736: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 3737: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3738: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 3739: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 3740: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 3741: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 3742: } else {
1.529 raeburn 3743: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 3744: }
1.491 raeburn 3745: }
1.532 raeburn 3746: if ($origsrc =~ /\.(page|sequence)$/) {
3747: if ($newsubdir{$origsrc}) {
1.529 raeburn 3748: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 3749: }
1.532 raeburn 3750: } elsif ($newsubdir{$key}) {
3751: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 3752: }
3753: }
1.492 raeburn 3754: $changed = 1;
1.533 raeburn 3755: } elsif ($newdb{$idx} ne '') {
3756: $src = $newdb{$idx};
1.492 raeburn 3757: $changed = 1;
3758: }
3759: if ($changed) {
1.538 raeburn 3760: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 3761: }
3762: }
3763: }
3764: foreach my $idx (keys(%remparam)) {
3765: if (ref($remparam{$idx}) eq 'ARRAY') {
3766: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3767: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3768: }
3769: }
3770: }
1.533 raeburn 3771: if (values(%lockerrors) > 0) {
3772: $lockmsg = join('<br />',values(%lockerrors));
3773: }
1.491 raeburn 3774: my $storefn;
3775: if ($key eq $oldurl) {
3776: $storefn = $url;
3777: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3778: } else {
3779: $storefn = $key;
3780: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3781: if ($prefixchg && $before{'map'} && $after{'map'}) {
3782: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3783: }
1.529 raeburn 3784: if ($newsubdir{$key}) {
3785: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3786: }
1.491 raeburn 3787: }
1.492 raeburn 3788: my $report;
3789: if ($folder !~ /^supplemental/) {
3790: $report = 1;
3791: }
1.527 raeburn 3792: (my $outtext,$errtext) =
1.492 raeburn 3793: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3794: if ($errtext) {
1.529 raeburn 3795: if ($caller eq 'paste') {
1.533 raeburn 3796: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3797: }
1.491 raeburn 3798: }
3799: }
1.704 raeburn 3800: if (($updatetoolscache) || (@updatetoolsenc)) {
3801: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
3802: \@updatetoolsenc);
3803: }
1.491 raeburn 3804: }
1.533 raeburn 3805: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3806: }
3807:
3808: sub copy_dependencies {
3809: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3810: my $content;
3811: if (ref($contentref)) {
3812: $content = $$contentref;
3813: } else {
3814: $content = &Apache::lonnet::getfile($item);
3815: }
3816: unless ($content eq '-1') {
3817: my $mm = new File::MMagic;
3818: my $mimetype = $mm->checktype_contents($content);
3819: if ($mimetype eq 'text/html') {
3820: my (%allfiles,%codebase,$state);
3821: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3822: if ($res eq 'ok') {
3823: my ($numexisting,$numpathchanges,$existing);
3824: (undef,$numexisting,$numpathchanges,$existing) =
3825: &Apache::loncommon::ask_for_embedded_content(
3826: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3827: {'error_on_invalid_names' => 1,
3828: 'ignore_remote_references' => 1,
3829: 'docs_url' => $item,
3830: 'context' => 'paste'});
3831: if ($numexisting > 0) {
3832: if (ref($existing) eq 'HASH') {
3833: foreach my $dep (keys(%{$existing})) {
3834: my $depfile = $dep;
3835: unless ($depfile =~ m{^\Q$relpath\E}) {
3836: $depfile = $relpath.$dep;
3837: }
3838: my $depcontent = &Apache::lonnet::getfile($depfile);
3839: unless ($depcontent eq '-1') {
3840: my $storedep = $dep;
3841: $storedep =~ s{^\Q$relpath\E}{};
3842: my $dep_url =
3843: &Apache::lonclonecourse::writefile(
3844: $env{'request.course.id'},
3845: $storefn.$storedep,$depcontent);
3846: if ($dep_url eq '/adm/notfound.html') {
3847: if (ref($errors) eq 'HASH') {
3848: $errors->{$depfile} = 1;
3849: }
3850: } else {
3851: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3852: }
3853: }
3854: }
1.488 raeburn 3855: }
3856: }
3857: }
3858: }
3859: }
3860: return;
3861: }
3862:
1.329 droeschl 3863: my %parameter_type = ( 'randompick' => 'int_pos',
3864: 'hiddenresource' => 'string_yesno',
3865: 'encrypturl' => 'string_yesno',
3866: 'randomorder' => 'string_yesno',);
3867: my $valid_parameters_re = join('|',keys(%parameter_type));
3868: # set parameters
3869: sub update_parameter {
1.537 raeburn 3870: if ($env{'form.changeparms'} eq 'all') {
3871: my (@allidx,@allmapidx,%allchecked,%currchecked);
3872: %allchecked = (
3873: 'hiddenresource' => {},
3874: 'encrypturl' => {},
3875: 'randompick' => {},
3876: 'randomorder' => {},
3877: );
3878: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3879: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3880: if ($which eq 'randompick') {
3881: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3882: my ($res,$value) = split(/:/,$item);
3883: if ($value =~ /^\d+$/) {
3884: $allchecked{$which}{$res} = $value;
3885: }
3886: }
3887: } else {
1.539 raeburn 3888: if ($env{'form.all'.$which}) {
3889: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3890: }
1.537 raeburn 3891: }
3892: }
3893: my $haschanges = 0;
3894: foreach my $res (@LONCAPA::map::order) {
3895: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3896: $name=&LONCAPA::map::qtescape($name);
3897: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3898: next unless $url;
1.537 raeburn 3899: my $is_map;
3900: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3901: $is_map = 1;
3902: }
3903: foreach my $which (keys(%allchecked)) {
3904: if (($which eq 'randompick' || $which eq 'randomorder')) {
3905: next if (!$is_map);
3906: }
3907: my $oldvalue = 0;
3908: my $newvalue = 0;
3909: if ($allchecked{$which}{$res}) {
3910: $newvalue = $allchecked{$which}{$res};
3911: }
3912: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3913: if ($which eq 'randompick') {
3914: if ($current =~ /^(\d+)$/) {
3915: $oldvalue = $1;
3916: }
3917: } else {
3918: if ($current =~ /^yes$/i) {
3919: $oldvalue = 1;
3920: }
3921: }
3922: if ($oldvalue ne $newvalue) {
3923: $haschanges = 1;
3924: if ($newvalue) {
3925: my $storeval = 'yes';
3926: if ($which eq 'randompick') {
3927: $storeval = $newvalue;
3928: }
3929: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3930: $storeval,
3931: $parameter_type{$which});
3932: &remember_parms($res,$which,'set',$storeval);
3933: } elsif ($oldvalue) {
3934: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3935: &remember_parms($res,$which,'del');
3936: }
3937: }
3938: }
3939: }
3940: return $haschanges;
3941: } else {
1.588 raeburn 3942: my $haschanges = 0;
3943: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3944:
1.537 raeburn 3945: my $which = $env{'form.changeparms'};
3946: my $idx = $env{'form.setparms'};
1.588 raeburn 3947: my $oldvalue = 0;
3948: my $newvalue = 0;
3949: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3950: if ($which eq 'randompick') {
3951: if ($current =~ /^(\d+)$/) {
3952: $oldvalue = $1;
3953: }
3954: } elsif ($current =~ /^yes$/i) {
3955: $oldvalue = 1;
3956: }
1.537 raeburn 3957: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3958: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3959: : 1;
3960: }
3961: if ($oldvalue ne $newvalue) {
3962: $haschanges = 1;
3963: if ($newvalue) {
3964: my $storeval = 'yes';
3965: if ($which eq 'randompick') {
3966: $storeval = $newvalue;
3967: }
3968: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3969: $parameter_type{$which});
3970: &remember_parms($idx,$which,'set',$storeval);
3971: } else {
3972: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3973: &remember_parms($idx,$which,'del');
3974: }
1.537 raeburn 3975: }
1.588 raeburn 3976: return $haschanges;
1.329 droeschl 3977: }
3978: }
3979:
3980: sub handle_edit_cmd {
3981: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3982: my $haschanges = 0;
1.543 raeburn 3983: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3984: return $haschanges;
1.543 raeburn 3985: }
1.329 droeschl 3986: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3987:
3988: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3989: my ($title, $url, @rrest) = split(':', $ratstr);
3990:
1.538 raeburn 3991: if ($cmd eq 'remove') {
1.329 droeschl 3992: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3993: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3994: &Apache::lonnet::removeuploadedurl($url);
3995: } else {
3996: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3997: }
3998: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3999: $haschanges = 1;
1.329 droeschl 4000: } elsif ($cmd eq 'cut') {
4001: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4002: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4003: $haschanges = 1;
1.344 bisitz 4004: } elsif ($cmd eq 'up'
1.329 droeschl 4005: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4006: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4007: $haschanges = 1;
1.329 droeschl 4008: } elsif ($cmd eq 'down'
4009: && defined($LONCAPA::map::order[$idx+1])) {
4010: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4011: $haschanges = 1;
1.329 droeschl 4012: } elsif ($cmd eq 'rename') {
4013: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4014: if ($comment=~/\S/) {
4015: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4016: $comment.':'.join(':', $url, @rrest);
4017: }
4018: # Devalidate title cache
4019: my $renamed_url=&LONCAPA::map::qtescape($url);
4020: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4021: $haschanges = 1;
4022: } elsif ($cmd eq 'setalias') {
4023: my $newvalue = $env{'form.alias'};
4024: if ($newvalue ne '') {
4025: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4026: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4027: 'string');
4028: &remember_parms($idx,'mapalias','set',$newvalue);
4029: $haschanges = 1;
4030: }
4031: }
4032: } elsif ($cmd eq 'delalias') {
4033: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4034: if ($current ne '') {
4035: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4036: &remember_parms($idx,'mapalias','del');
4037: $haschanges = 1;
4038: }
1.329 droeschl 4039: }
1.633 raeburn 4040: return $haschanges;
1.329 droeschl 4041: }
4042:
4043: sub editor {
1.458 raeburn 4044: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4045: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4046: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4047: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4048: if ($allowed) {
1.519 raeburn 4049: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4050: $is_random_order,$container) =
1.510 raeburn 4051: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4052: $r->print($breadcrumbtrail);
1.519 raeburn 4053: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4054: $container = 'page';
4055: } else {
4056: $container = 'sequence';
1.510 raeburn 4057: }
1.484 raeburn 4058:
1.525 raeburn 4059: my $jumpto;
4060:
4061: unless ($supplementalflag) {
1.546 raeburn 4062: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4063: }
1.484 raeburn 4064:
4065: unless ($allowed) {
4066: $randompick = -1;
4067: }
4068:
1.615 raeburn 4069: my ($errtext,$fatal);
4070: if (($folder eq '') && (!$supplementalflag)) {
4071: if (@LONCAPA::map::order) {
4072: undef(@LONCAPA::map::order);
4073: undef(@LONCAPA::map::resources);
4074: undef(@LONCAPA::map::resparms);
4075: undef(@LONCAPA::map::zombies);
4076: }
4077: $folder = 'default';
4078: $container = 'sequence';
4079: } else {
4080: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4081: $folder.'.'.$container);
4082: return $errtext if ($fatal);
4083: }
1.329 droeschl 4084:
4085: if ($#LONCAPA::map::order<1) {
4086: my $idx=&LONCAPA::map::getresidx();
4087: if ($idx<=0) { $idx=1; }
4088: $LONCAPA::map::order[0]=$idx;
4089: $LONCAPA::map::resources[$idx]='';
4090: }
1.364 bisitz 4091:
1.329 droeschl 4092: # ------------------------------------------------------------ Process commands
4093:
4094: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4095: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4096: # set parameters and change order
4097: &snapshotbefore();
4098:
4099: if (&update_parameter()) {
1.588 raeburn 4100: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4101: return $errtext if ($fatal);
4102: }
4103:
4104: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4105: # change order
4106: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4107: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4108:
4109: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4110: return $errtext if ($fatal);
4111: }
1.364 bisitz 4112:
1.329 droeschl 4113: if ($env{'form.pastemarked'}) {
1.491 raeburn 4114: my %paste_errors;
1.533 raeburn 4115: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4116: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4117: \%paste_errors);
1.541 raeburn 4118: if (ref($pastemsgarray) eq 'ARRAY') {
4119: if (@{$pastemsgarray} > 0) {
4120: $r->print('<p class="LC_info">'.
4121: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4122: '</p>');
4123: }
1.541 raeburn 4124: }
4125: if ($lockerror) {
4126: $r->print('<p class="LC_error">'.
4127: $lockerror.
4128: '</p>');
4129: }
4130: if ($save_error ne '') {
4131: return $save_error;
4132: }
4133: if ($paste_res) {
4134: my %errortext = &Apache::lonlocal::texthash (
4135: fail => 'Storage of folder contents failed',
4136: failread => 'Reading folder contents failed',
4137: failstore => 'Storage of folder contents failed',
4138: );
4139: if ($errortext{$paste_res}) {
4140: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4141: }
1.329 droeschl 4142: }
1.491 raeburn 4143: if (keys(%paste_errors) > 0) {
1.538 raeburn 4144: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4145: &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".
4146: '<ul>'."\n");
4147: foreach my $key (sort(keys(%paste_errors))) {
4148: $r->print('<li>'.$key.'</li>'."\n");
4149: }
4150: $r->print('</ul></p>'."\n");
4151: }
1.538 raeburn 4152: } elsif ($env{'form.clearmarked'}) {
4153: my $output = &do_buffer_empty();
4154: if ($output) {
4155: $r->print('<p class="LC_info">'.$output.'</p>');
4156: }
4157: }
1.329 droeschl 4158:
4159: $r->print($upload_output);
4160:
1.538 raeburn 4161: # Rename, cut, copy or remove a single resource
1.602 raeburn 4162: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4163: my $contentchg;
1.633 raeburn 4164: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4165: $contentchg = 1;
4166: }
4167: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4168: return $errtext if ($fatal);
4169: }
1.538 raeburn 4170:
4171: # Cut, copy and/or remove multiple resources
4172: if ($env{'form.multichange'}) {
4173: my %allchecked = (
4174: cut => {},
4175: remove => {},
4176: );
4177: my $needsupdate;
4178: foreach my $which (keys(%allchecked)) {
4179: $env{'form.multi'.$which} =~ s/,$//;
4180: if ($env{'form.multi'.$which}) {
4181: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4182: if (ref($allchecked{$which}) eq 'HASH') {
4183: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4184: }
4185: }
4186: }
4187: if ($needsupdate) {
4188: my $haschanges = 0;
4189: my %curr_groups = &Apache::longroup::coursegroups();
4190: my $total = scalar(@LONCAPA::map::order) - 1;
4191: for (my $i=$total; $i>=0; $i--) {
4192: my $res = $LONCAPA::map::order[$i];
4193: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4194: $name=&LONCAPA::map::qtescape($name);
4195: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4196: next unless $url;
1.538 raeburn 4197: my %denied =
4198: &action_restrictions($coursenum,$coursedom,$url,
4199: $env{'form.folderpath'},\%curr_groups);
4200: foreach my $which (keys(%allchecked)) {
4201: next if ($denied{$which});
4202: next unless ($allchecked{$which}{$res});
4203: if ($which eq 'remove') {
4204: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4205: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4206: &Apache::lonnet::removeuploadedurl($url);
4207: } else {
4208: &LONCAPA::map::makezombie($res);
4209: }
4210: splice(@LONCAPA::map::order,$i,1);
4211: $haschanges ++;
4212: } elsif ($which eq 'cut') {
4213: &LONCAPA::map::makezombie($res);
4214: splice(@LONCAPA::map::order,$i,1);
4215: $haschanges ++;
4216: }
4217: }
4218: }
4219: if ($haschanges) {
4220: ($errtext,$fatal) =
4221: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4222: return $errtext if ($fatal);
4223: }
4224: }
4225: }
4226:
1.329 droeschl 4227: # Group import/search
4228: if ($env{'form.importdetail'}) {
4229: my @imports;
4230: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4231: if (defined($item)) {
4232: my ($name,$url,$residx)=
1.533 raeburn 4233: map { &unescape($_); } split(/\=/,$item);
4234: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4235: my ($suffix,$errortxt,$locknotfreed) =
4236: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4237: if ($locknotfreed) {
4238: $r->print($locknotfreed);
4239: }
4240: if ($suffix) {
4241: $url =~ s/_new\./_$suffix./;
4242: } else {
4243: return $errortxt;
4244: }
1.533 raeburn 4245: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4246: my $type = $1;
4247: my ($suffix,$errortxt,$locknotfreed) =
4248: &new_timebased_suffix($coursedom,$coursenum,$type);
4249: if ($locknotfreed) {
4250: $r->print($locknotfreed);
4251: }
4252: if ($suffix) {
4253: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4254: } else {
4255: return $errortxt;
4256: }
1.626 raeburn 4257: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4258: my ($suffix,$errortxt,$locknotfreed) =
4259: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4260: if ($locknotfreed) {
4261: $r->print($locknotfreed);
4262: }
4263: if ($suffix) {
4264: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4265: } else {
4266: return $errortxt;
4267: }
1.534 raeburn 4268: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4269: if ($supplementalflag) {
4270: next unless ($1 eq 'supplemental');
4271: if ($folder eq 'supplemental') {
4272: next unless ($2 eq 'default');
4273: } else {
4274: next unless ($folder eq 'supplemental_'.$2);
4275: }
4276: } else {
4277: next unless ($1 eq 'docs');
4278: if ($folder eq 'default') {
4279: next unless ($2 eq 'default');
4280: } else {
4281: next unless ($folder eq 'default_'.$2);
4282: }
4283: }
1.504 raeburn 4284: }
1.329 droeschl 4285: push(@imports, [$name, $url, $residx]);
4286: }
4287: }
1.530 raeburn 4288: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4289: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4290: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4291: return $errtext if ($fatal);
1.529 raeburn 4292: if ($fixuperrors) {
4293: $r->print($fixuperrors);
4294: }
1.329 droeschl 4295: }
4296: # Loading a complete map
4297: if ($env{'form.loadmap'}) {
4298: if ($env{'form.importmap'}=~/\w/) {
4299: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4300: my ($title,$url,$ext,$type)=split(/\:/,$res);
4301: my $idx=&LONCAPA::map::getresidx($url);
4302: $LONCAPA::map::resources[$idx]=$res;
4303: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4304: }
4305: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4306: $folder.'.'.$container,1);
1.329 droeschl 4307: return $errtext if ($fatal);
4308: } else {
4309: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4310:
1.329 droeschl 4311: }
4312: }
4313: &log_differences($plain);
4314: }
4315: # ---------------------------------------------------------------- End commands
4316: # ---------------------------------------------------------------- Print screen
4317: my $idx=0;
4318: my $shown=0;
4319: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4320: $r->print('<div class="LC_Box">'.
1.432 raeburn 4321: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4322: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4323: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4324: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4325: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4326: '</ol>');
1.381 bisitz 4327: if ($randompick>=0) {
4328: $r->print('<p class="LC_warning">'
4329: .&mt('Caution: this folder is set to randomly pick a subset'
4330: .' of resources. Adding or removing resources from this'
4331: .' folder will change the set of resources that the'
4332: .' students see, resulting in spurious or missing credit'
4333: .' for completed problems, not limited to ones you'
4334: .' modify. Do not modify the contents of this folder if'
4335: .' it is in active student use.')
4336: .'</p>'
4337: );
4338: }
4339: if ($is_random_order) {
4340: $r->print('<p class="LC_warning">'
4341: .&mt('Caution: this folder is set to randomly order its'
4342: .' contents. Adding or removing resources from this folder'
4343: .' will change the order of resources shown.')
4344: .'</p>'
4345: );
4346: }
4347: $r->print('</div>');
1.364 bisitz 4348: }
1.381 bisitz 4349:
1.685 raeburn 4350: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4351: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4352: if (ref($supplemental) eq 'HASH') {
4353: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4354: (ref($supplemental->{'ids'}) eq 'HASH')) {
4355: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4356: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4357: if ($supplemental->{'hidden'}->{$mapnum}) {
4358: $ishidden = 1;
4359: }
4360: }
4361: }
4362: }
4363: }
4364:
1.538 raeburn 4365: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4366: %filters = (
1.543 raeburn 4367: canremove => [],
4368: cancut => [],
4369: cancopy => [],
4370: hiddenresource => [],
4371: encrypturl => [],
4372: randomorder => [],
4373: randompick => [],
1.538 raeburn 4374: );
4375: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4376: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4377: foreach my $res (@LONCAPA::map::order) {
4378: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4379: $name=&LONCAPA::map::qtescape($name);
4380: $url=&LONCAPA::map::qtescape($url);
4381: unless ($name) { $name=(split(/\//,$url))[-1]; }
4382: unless ($name) { $idx++; next; }
1.537 raeburn 4383: push(@allidx,$res);
4384: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4385: push(@allmapidx,$res);
4386: }
1.617 raeburn 4387:
1.682 raeburn 4388: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4389: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4390: $idx++;
4391: next;
4392: }
1.682 raeburn 4393: }
1.381 bisitz 4394: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4395: $coursenum,$coursedom,$crstype,
1.538 raeburn 4396: $pathitem,$supplementalflag,$container,
1.620 raeburn 4397: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4398: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4399: $idx++;
4400: $shown++;
1.329 droeschl 4401: }
1.424 onken 4402: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4403:
1.538 raeburn 4404: my $need_save;
1.611 raeburn 4405: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4406: my $toolslink;
1.682 raeburn 4407: if ($allowed || $canedit) {
4408: my $helpitem = 'Navigation_Screen';
4409: if (!$allowed) {
4410: $helpitem = 'Supplemental_Navigation';
4411: }
1.544 raeburn 4412: $toolslink = '<table><tr><td>'
1.520 raeburn 4413: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4414: $helpitem,undef,'RAT')
1.520 raeburn 4415: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4416: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4417: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4418: .'id="LC_content_toolbar_edittoplevel" '
4419: .'class="LC_toolbarItem" '
4420: .'title="'.&mt('Supplemental Content Editor').'">'
4421: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4422: }
1.510 raeburn 4423: if ($shown) {
4424: if ($allowed) {
4425: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4426: .&Apache::loncommon::start_data_table(undef,'contentlist')
4427: .&Apache::loncommon::start_data_table_header_row()
4428: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4429: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4430: .'<th>'.&mt('Document').'</th>'
4431: .'<th colspan="2">'.&mt('Settings').'</th>'
4432: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4433: if ($folder !~ /^supplemental/) {
1.538 raeburn 4434: $lists{'canhide'} = join(',',@allidx);
4435: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4436: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4437: 'randomorder','randompick');
4438: foreach my $item (@possfilters) {
1.538 raeburn 4439: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4440: if (@{$filters{$item}} > 0) {
4441: $lists{$item} = join(',',@{$filters{$item}});
4442: }
1.538 raeburn 4443: }
4444: }
1.537 raeburn 4445: if (@allidx > 0) {
4446: my $path;
4447: if ($env{'form.folderpath'}) {
1.630 raeburn 4448: $path =
1.537 raeburn 4449: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4450: }
1.538 raeburn 4451: if (@allidx > 1) {
1.630 raeburn 4452: $to_show .=
1.538 raeburn 4453: &Apache::loncommon::continue_data_table_row().
4454: '<td colspan="2"> </td>'.
4455: '<td>'.
1.611 raeburn 4456: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4457: '</td>'.
1.633 raeburn 4458: '<td colspan="3"> </td>'.
4459: '<td colspan="2">'.
1.611 raeburn 4460: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4461: '</td>'.
4462: &Apache::loncommon::end_data_table_row();
4463: $need_save = 1;
4464: }
1.537 raeburn 4465: }
4466: }
4467: $to_show .= $output.' '
1.510 raeburn 4468: .&Apache::loncommon::end_data_table()
4469: .'<br style="line-height:2px;" />'
4470: .&Apache::loncommon::end_scrollbox();
4471: } else {
1.520 raeburn 4472: $to_show .= $toolslink
1.510 raeburn 4473: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4474: .$output.' '
4475: .&Apache::loncommon::end_data_table();
1.393 raeburn 4476: }
1.510 raeburn 4477: } else {
1.520 raeburn 4478: if (!$allowed) {
4479: $to_show .= $toolslink;
4480: }
1.615 raeburn 4481: my $noresmsg;
4482: if ($allowed && $hiddentop && !$supplementalflag) {
4483: $noresmsg = &mt('Main Content Hidden');
4484: } else {
4485: $noresmsg = &mt('Currently empty');
4486: }
1.510 raeburn 4487: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4488: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 4489: .$noresmsg
1.510 raeburn 4490: .'</div>'
4491: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4492: }
4493: } else {
1.510 raeburn 4494: if ($shown) {
4495: $to_show = '<div>'
4496: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4497: .$output
4498: .&Apache::loncommon::end_data_table()
4499: .'</div>';
4500: } else {
4501: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 4502: .&mt('Currently empty')
1.510 raeburn 4503: .'</div>'
4504: }
1.458 raeburn 4505: }
4506: my $tid = 1;
4507: if ($supplementalflag) {
4508: $tid = 2;
1.329 droeschl 4509: }
4510: if ($allowed) {
1.484 raeburn 4511: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 4512: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 4513: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4514: if ($canedit) {
4515: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4516: }
1.460 raeburn 4517: } else {
4518: $r->print($to_show);
1.329 droeschl 4519: }
4520: return;
4521: }
4522:
1.538 raeburn 4523: sub multiple_check_form {
1.611 raeburn 4524: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 4525: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 4526: my $disabled;
4527: unless ($canedit) {
1.700 raeburn 4528: $disabled = ' disabled="disabled"';
1.611 raeburn 4529: }
1.538 raeburn 4530: my $output =
4531: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4532: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4533: '<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>'.
4534: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4535: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4536: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4537: if ($caller eq 'settings') {
4538: $output .=
4539: '<table><tr>'.
4540: '<td class="LC_docs_entry_parameter">'.
4541: '<span class="LC_nobreak"><label>'.
1.611 raeburn 4542: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 4543: '</label></span></td>'.
4544: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4545: '<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 4546: '</span></td>'.
4547: '</tr>'."\n".
4548: '<tr>'.
4549: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4550: '<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 4551: '</label></span>'.
4552: '</td></tr></table>'."\n";
4553: } else {
4554: $output .=
4555: '<table><tr>'.
4556: '<td class="LC_docs_entry_parameter">'.
4557: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 4558: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 4559: '</label></span></td>'.
4560: '<td class="LC_docs_entry_parameter">'.
4561: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 4562: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 4563: '</label></span></td>'."\n".
4564: '<td class="LC_docs_entry_parameter">'.
4565: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 4566: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 4567: '</label></span></td>'.
4568: '</tr></table>'."\n";
4569: }
4570: $output .=
4571: '</fieldset>'.
4572: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4573: if ($caller eq 'settings') {
4574: $output .=
1.543 raeburn 4575: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4576: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4577: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4578: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4579: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 4580: } elsif ($caller eq 'actions') {
4581: $output .=
4582: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4583: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4584: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4585: }
4586: $output .=
4587: '</form>'.
4588: '</div>';
4589: return $output;
4590: }
4591:
1.329 droeschl 4592: sub process_file_upload {
1.552 raeburn 4593: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4594: # upload a file, if present
1.552 raeburn 4595: my $filesize = length($env{'form.uploaddoc'});
4596: if (!$filesize) {
4597: $$upload_output = '<div class="LC_error">'.
4598: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4599: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4600: $filesize).'<br />'.
4601: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4602: '</div>';
4603: return;
4604: }
4605: my $quotatype = 'unofficial';
4606: if ($crstype eq 'Community') {
1.601 raeburn 4607: $quotatype = 'community';
4608: } elsif ($crstype eq 'Placement') {
4609: $quotatype = 'placement';
1.580 raeburn 4610: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 4611: $quotatype = 'official';
1.573 raeburn 4612: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4613: $quotatype = 'textbook';
1.552 raeburn 4614: }
4615: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4616: $filesize = int($filesize/1000); #expressed in kb
4617: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 4618: $env{'form.uploaddoc.filename'},$filesize,
4619: 'upload',$quotatype);
1.552 raeburn 4620: return if ($$upload_output);
4621: }
1.440 raeburn 4622: my ($parseaction,$showupload,$nextphase,$mimetype);
4623: if ($env{'form.parserflag'}) {
1.329 droeschl 4624: $parseaction = 'parse';
4625: }
4626: my $folder=$env{'form.folder'};
4627: if ($folder eq '') {
4628: $folder='default';
4629: }
4630: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4631: my $errtext='';
4632: my $fatal=0;
4633: my $container='sequence';
1.519 raeburn 4634: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 4635: $container='page';
4636: }
4637: ($errtext,$fatal)=
1.534 raeburn 4638: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 4639: if ($#LONCAPA::map::order<1) {
4640: $LONCAPA::map::order[0]=1;
4641: $LONCAPA::map::resources[1]='';
4642: }
4643: my $destination = 'docs/';
4644: if ($folder =~ /^supplemental/) {
4645: $destination = 'supplemental/';
4646: }
4647: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4648: $destination .= 'default/';
4649: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4650: $destination .= $2.'/';
4651: }
1.534 raeburn 4652: if ($fatal) {
4653: $$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>';
4654: return;
4655: }
1.440 raeburn 4656: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 4657: my $newidx=&LONCAPA::map::getresidx();
4658: $destination .= $newidx;
1.439 raeburn 4659: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 4660: $parseaction,$allfiles,
1.440 raeburn 4661: $codebase,undef,undef,undef,undef,
4662: undef,undef,\$mimetype);
4663: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4664: my $stored = $1;
4665: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4666: $stored.'</span>').'</p>';
4667: } else {
4668: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4669:
1.457 raeburn 4670: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 4671: return;
4672: }
1.329 droeschl 4673: my $ext='false';
4674: if ($url=~m{^http://}) { $ext='true'; }
4675: $url = &LONCAPA::map::qtunescape($url);
4676: my $comment=$env{'form.comment'};
4677: $comment = &LONCAPA::map::qtunescape($comment);
4678: if ($folder=~/^supplemental/) {
4679: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4680: $env{'user.domain'}.'___&&&___'.$comment;
4681: }
4682:
4683: $LONCAPA::map::resources[$newidx]=
4684: $comment.':'.$url.':'.$ext.':normal:res';
4685: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4686: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4687: $folder.'.'.$container,1);
1.329 droeschl 4688: if ($fatal) {
1.457 raeburn 4689: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 4690: return;
1.329 droeschl 4691: } else {
1.440 raeburn 4692: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4693: $$upload_output = $showupload;
1.384 raeburn 4694: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 4695: if ($total_embedded > 0) {
1.440 raeburn 4696: my $uploadphase = 'upload_embedded';
4697: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4698: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 4699: my ($embedded,$num) =
1.440 raeburn 4700: &Apache::loncommon::ask_for_embedded_content(
4701: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4702: if ($embedded) {
4703: if ($num) {
4704: $$upload_output .=
4705: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4706: $nextphase = $uploadphase;
4707: } else {
4708: $$upload_output .= $embedded;
4709: }
4710: } else {
4711: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4712: }
1.329 droeschl 4713: } else {
1.440 raeburn 4714: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 4715: }
1.457 raeburn 4716: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 4717: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4718: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 4719: $nextphase = 'decompress_uploaded';
4720: my $position = scalar(@LONCAPA::map::order)-1;
4721: my $noextract = &return_to_editor();
4722: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4723: my %archiveitems = (
4724: folderpath => $env{'form.folderpath'},
4725: cmd => $nextphase,
4726: newidx => $newidx,
4727: position => $position,
4728: phase => $nextphase,
1.477 raeburn 4729: comment => $comment,
1.480 raeburn 4730: );
4731: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4732: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 4733: $$upload_output = $showupload.
4734: &Apache::loncommon::decompress_form($mimetype,
4735: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 4736: \%archiveitems,\@current);
1.329 droeschl 4737: }
4738: }
4739: }
1.440 raeburn 4740: return $nextphase;
1.329 droeschl 4741: }
4742:
1.480 raeburn 4743: sub get_dir_list {
4744: my ($url,$coursenum,$coursedom,$newidx) = @_;
4745: my ($destination,$dir_root) = &embedded_destination();
4746: my ($dirlistref,$listerror) =
4747: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4748: my @dir_lines;
4749: my $dirptr=16384;
4750: if (ref($dirlistref) eq 'ARRAY') {
4751: foreach my $dir_line (sort
4752: {
4753: my ($afile)=split('&',$a,2);
4754: my ($bfile)=split('&',$b,2);
4755: return (lc($afile) cmp lc($bfile));
4756: } (@{$dirlistref})) {
4757: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4758: $filename =~ s/\s+$//;
4759: next if ($filename =~ /^\.\.?$/);
4760: my $isdir = 0;
4761: if ($dirptr&$testdir) {
4762: $isdir = 1;
4763: }
4764: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4765: }
4766: }
4767: return @dir_lines;
4768: }
4769:
1.329 droeschl 4770: sub is_supplemental_title {
4771: my ($title) = @_;
4772: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4773: }
4774:
4775: # --------------------------------------------------------------- An entry line
4776:
4777: sub entryline {
1.501 raeburn 4778: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4779: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4780: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4781: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4782: if (&is_supplemental_title($title)) {
1.488 raeburn 4783: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4784: $encodedtitle=$title;
1.329 droeschl 4785: } else {
4786: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4787: $encodedtitle=$title;
1.329 droeschl 4788: $renametitle=$title;
4789: $foldertitle=$title;
4790: }
4791:
1.611 raeburn 4792: my ($disabled,$readonly,$js_lt);
4793: unless ($canedit) {
4794: $disabled = 'disabled="disabled"';
4795: $readonly = 1;
4796: }
4797:
1.329 droeschl 4798: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4799:
1.329 droeschl 4800: $renametitle=~s/\\/\\\\/g;
4801: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4802: $renametitle=~s/"/%22/g;
1.581 raeburn 4803: $renametitle=~s/ /%20/g;
4804: $oldtitle = $renametitle;
1.576 raeburn 4805: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4806: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4807: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4808: # Edit commands
1.679 raeburn 4809: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4810: if ($env{'form.folderpath'}) {
4811: $esc_path=&escape($env{'form.folderpath'});
4812: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4813: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4814: }
1.505 raeburn 4815: my $isexternal;
1.510 raeburn 4816: if ($residx) {
1.501 raeburn 4817: my $currurl = $url;
4818: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4819: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4820: $isexternal = 1;
4821: }
1.510 raeburn 4822: if (!$supplementalflag) {
4823: my $path = 'uploaded/'.
4824: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4825: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4826: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4827: $residx,
4828: &Apache::lonnet::declutter($currurl));
4829: }
1.501 raeburn 4830: }
1.538 raeburn 4831: my ($renamelink,%lt,$ishash);
4832: if (ref($filtersref) eq 'HASH') {
4833: $ishash = 1;
4834: }
4835:
1.329 droeschl 4836: if ($allowed) {
1.538 raeburn 4837: $form_start = '
4838: <form action="/adm/coursedocs" method="post">
4839: ';
4840: $form_common=(<<END);
4841: <input type="hidden" name="folderpath" value="$path" />
4842: <input type="hidden" name="symb" value="$symb" />
4843: END
4844: $form_param=(<<END);
4845: <input type="hidden" name="setparms" value="$orderidx" />
4846: <input type="hidden" name="changeparms" value="0" />
4847: END
4848: $form_end = '</form>';
4849:
1.329 droeschl 4850: my $incindex=$index+1;
4851: my $selectbox='';
1.471 raeburn 4852: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4853: ((split(/\:/,
1.344 bisitz 4854: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4855: ne '') &&
1.329 droeschl 4856: ((split(/\:/,
1.344 bisitz 4857: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4858: ne '')) {
4859: $selectbox=
4860: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4861: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4862: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4863: if ($i==$incindex) {
1.358 bisitz 4864: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4865: } else {
4866: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4867: }
4868: }
4869: $selectbox.='</select>';
4870: }
1.501 raeburn 4871: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4872: 'up' => 'Move Up',
4873: 'dw' => 'Move Down',
4874: 'rm' => 'Remove',
4875: 'ct' => 'Cut',
4876: 'rn' => 'Rename',
1.501 raeburn 4877: 'cp' => 'Copy',
1.633 raeburn 4878: 'da' => 'Unset alias',
4879: 'sa' => 'Set alias',
1.501 raeburn 4880: 'ex' => 'External Resource',
1.598 raeburn 4881: 'et' => 'External Tool',
1.501 raeburn 4882: 'ed' => 'Edit',
4883: 'pr' => 'Preview',
4884: 'sv' => 'Save',
4885: 'ul' => 'URL',
1.611 raeburn 4886: 'ti' => 'Title',
1.618 raeburn 4887: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4888: );
1.538 raeburn 4889: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4890: $env{'form.folderpath'},
4891: $currgroups);
1.517 raeburn 4892: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4893: my $skip_confirm = 0;
1.603 raeburn 4894: my $confirm_removal = 0;
1.329 droeschl 4895: if ( $folder =~ /^supplemental/
4896: || ($url =~ m{( /smppg$
4897: |/syllabus$
4898: |/aboutme$
4899: |/navmaps$
4900: |/bulletinboard$
1.626 raeburn 4901: |/ext\.tool$
1.505 raeburn 4902: |\.html$)}x)
4903: || $isexternal) {
1.329 droeschl 4904: $skip_confirm = 1;
4905: }
1.603 raeburn 4906: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4907: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4908: $confirm_removal = 1;
4909: }
1.633 raeburn 4910: if ($url =~ /$LONCAPA::assess_re/) {
4911: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4912: }
1.329 droeschl 4913:
1.538 raeburn 4914: if ($denied{'copy'}) {
1.543 raeburn 4915: $copylink=(<<ENDCOPY)
1.507 raeburn 4916: <span style="visibility: hidden;">$lt{'cp'}</span>
4917: ENDCOPY
4918: } else {
1.538 raeburn 4919: my $formname = 'edit_copy_'.$orderidx;
4920: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4921: $copylink=(<<ENDCOPY);
1.538 raeburn 4922: <form name="$formname" method="post" action="/adm/coursedocs">
4923: $form_common
1.611 raeburn 4924: <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 4925: $form_end
1.329 droeschl 4926: ENDCOPY
1.538 raeburn 4927: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4928: push(@{$filtersref->{'cancopy'}},$orderidx);
4929: }
1.329 droeschl 4930: }
1.538 raeburn 4931: if ($denied{'cut'}) {
1.507 raeburn 4932: $cutlink=(<<ENDCUT);
4933: <span style="visibility: hidden;">$lt{'ct'}</span>
4934: ENDCUT
4935: } else {
1.538 raeburn 4936: my $formname = 'edit_cut_'.$orderidx;
4937: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4938: $cutlink=(<<ENDCUT);
1.538 raeburn 4939: <form name="$formname" method="post" action="/adm/coursedocs">
4940: $form_common
1.542 raeburn 4941: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4942: <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 4943: $form_end
1.329 droeschl 4944: ENDCUT
1.538 raeburn 4945: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4946: push(@{$filtersref->{'cancut'}},$orderidx);
4947: }
1.329 droeschl 4948: }
1.538 raeburn 4949: if ($denied{'remove'}) {
1.507 raeburn 4950: $removelink=(<<ENDREM);
4951: <span style="visibility: hidden;">$lt{'rm'}</a>
4952: ENDREM
4953: } else {
1.538 raeburn 4954: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4955: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4956: $removelink=(<<ENDREM);
1.538 raeburn 4957: <form name="$formname" method="post" action="/adm/coursedocs">
4958: $form_common
1.542 raeburn 4959: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4960: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4961: <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 4962: $form_end
1.497 raeburn 4963: ENDREM
1.538 raeburn 4964: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4965: push(@{$filtersref->{'canremove'}},$orderidx);
4966: }
1.497 raeburn 4967: }
1.551 raeburn 4968: $renamelink=(<<ENDREN);
1.581 raeburn 4969: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4970: ENDREN
1.611 raeburn 4971: my ($uplink,$downlink);
4972: if ($canedit) {
4973: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4974: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4975: } else {
4976: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4977: $downlink = $uplink;
4978: }
1.329 droeschl 4979: $line.=(<<END);
4980: <td>
1.379 bisitz 4981: <div class="LC_docs_entry_move">
1.611 raeburn 4982: <a href="$uplink">
1.501 raeburn 4983: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4984: </a>
4985: </div>
4986: <div class="LC_docs_entry_move">
1.611 raeburn 4987: <a href="$downlink">
1.501 raeburn 4988: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4989: </a>
4990: </div>
1.329 droeschl 4991: </td>
4992: <td>
4993: $form_start
1.538 raeburn 4994: $form_param
1.478 raeburn 4995: $form_common
1.329 droeschl 4996: $selectbox
4997: $form_end
4998: </td>
1.540 raeburn 4999: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5000: $removelink
1.329 droeschl 5001: $cutlink
5002: $copylink
5003: </td>
5004: END
5005: }
5006: # Figure out what kind of a resource this is
5007: my ($extension)=($url=~/\.(\w+)$/);
5008: my $uploaded=($url=~/^\/*uploaded\//);
5009: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5010: my $isfolder;
5011: my $ispage;
5012: my $containerarg;
1.615 raeburn 5013: my $folderurl;
1.685 raeburn 5014: my $plainurl;
1.329 droeschl 5015: if ($uploaded) {
1.472 raeburn 5016: if (($extension eq 'sequence') || ($extension eq 'page')) {
5017: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5018: $containerarg = $1;
1.472 raeburn 5019: if ($extension eq 'sequence') {
5020: $icon=$iconpath.'navmap.folder.closed.gif';
5021: $isfolder=1;
5022: } else {
5023: $icon=$iconpath.'page.gif';
5024: $ispage=1;
5025: }
1.615 raeburn 5026: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5027: if ($allowed) {
5028: $url='/adm/coursedocs?';
5029: } else {
5030: $url='/adm/supplemental?';
5031: }
1.329 droeschl 5032: } else {
1.685 raeburn 5033: $plainurl = $url;
1.329 droeschl 5034: }
5035: }
1.364 bisitz 5036:
1.621 raeburn 5037: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5038: my $orig_url = $url;
1.340 raeburn 5039: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5040: if ($container eq 'page') {
5041: $url=~s{^http(|s)(:|:)//}{/ext/};
5042: } else {
5043: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5044: }
1.501 raeburn 5045: if (!$supplementalflag && $residx && $symb) {
5046: if ((!$isfolder) && (!$ispage)) {
5047: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5048: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5049: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5050: } else {
5051: $url=&Apache::lonnet::clutter($url);
5052: }
1.501 raeburn 5053: if ($url=~/^\/*uploaded\//) {
5054: $url=~/\.(\w+)$/;
5055: my $embstyle=&Apache::loncommon::fileembstyle($1);
5056: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5057: $url='/adm/wrapper'.$url;
5058: } elsif ($embstyle eq 'ssi') {
5059: #do nothing with these
5060: } elsif ($url!~/\.(sequence|page)$/) {
5061: $url='/adm/coursedocs/showdoc'.$url;
5062: }
1.623 raeburn 5063: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5064: my $wrapped = $1;
5065: my $exturl = $2;
1.668 raeburn 5066: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5067: $url='/adm/wrapper'.$url;
5068: }
5069: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5070: $nomodal = 1;
5071: }
1.626 raeburn 5072: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5073: $url='/adm/wrapper'.$url;
1.621 raeburn 5074: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5075: if (($ENV{'SERVER_PORT'} == 443) &&
5076: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5077: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5078: $url .= '?usehttp=1';
5079: }
1.621 raeburn 5080: $nomodal = 1;
5081: }
1.598 raeburn 5082: }
1.696 raeburn 5083: my $checkencrypt;
1.680 raeburn 5084: if (!$env{'request.role.adv'}) {
1.615 raeburn 5085: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5086: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5087: $checkencrypt = 1;
1.620 raeburn 5088: } elsif (ref($navmapref)) {
1.615 raeburn 5089: unless (ref($$navmapref)) {
5090: $$navmapref = Apache::lonnavmaps::navmap->new();
5091: }
5092: if (ref($$navmapref)) {
5093: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5094: $checkencrypt = 1;
1.615 raeburn 5095: }
5096: }
5097: }
1.680 raeburn 5098: }
5099: if ($checkencrypt) {
5100: my $currenc = $env{'request.enc'};
5101: $env{'request.enc'} = 1;
5102: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5103: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5104: if (&Apache::lonnet::symbverify($symb,$url)) {
5105: $url = $shownurl;
5106: } else {
5107: $url = '';
5108: }
5109: $env{'request.enc'} = $currenc;
5110: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5111: $shownsymb = $symb;
5112: if ($isexternal) {
5113: $url =~ s/\#[^#]+$//;
5114: if ($container eq 'page') {
5115: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5116: }
1.612 raeburn 5117: }
1.696 raeburn 5118: } else {
5119: $url = '';
1.680 raeburn 5120: }
5121: unless ($env{'request.role.adv'}) {
5122: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5123: $url = '';
5124: }
5125: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5126: $url = '';
5127: $hiddenres = 1;
5128: }
5129: }
1.696 raeburn 5130: if (($url ne '') && ($shownsymb ne '')) {
5131: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5132: }
1.329 droeschl 5133: }
1.621 raeburn 5134: } elsif ($supplementalflag) {
1.610 raeburn 5135: if ($isexternal) {
5136: if ($url =~ /^([^#]+)#([^#]+)$/) {
5137: $url = $1;
5138: $anchor = $2;
1.623 raeburn 5139: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5140: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5141: if ($hostname ne '') {
5142: $url = 'http://'.$hostname.$url;
5143: }
5144: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5145: }
5146: $nomodal = 1;
5147: }
1.610 raeburn 5148: }
1.621 raeburn 5149: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5150: if (($ENV{'SERVER_PORT'} == 443) &&
5151: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5152: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5153: if ($hostname ne '') {
5154: $url = 'http://'.$hostname.$url;
5155: }
5156: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5157: }
1.621 raeburn 5158: $nomodal = 1;
5159: }
1.705 raeburn 5160: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5161: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5162: unless ($embstyle eq 'ssi') {
5163: if (($embstyle eq 'img')
5164: || ($embstyle eq 'emb')
5165: || ($embstyle eq 'wrp')) {
5166: $url='/adm/wrapper'.$url;
5167: } elsif ($url !~ /\.(sequence|page)$/) {
5168: $url='/adm/coursedocs/showdoc'.$url;
5169: }
5170: }
1.610 raeburn 5171: }
1.685 raeburn 5172: unless ($allowed && $env{'request.role.adv'}) {
5173: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5174: $hiddenres = 1;
5175: }
5176: }
1.329 droeschl 5177: }
1.615 raeburn 5178: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5179: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5180: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5181: my $foldername=&escape($foldertitle);
5182: my $folderpath=$env{'form.folderpath'};
5183: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5184: if (!$allowed && $supplementalflag) {
1.519 raeburn 5185: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5186: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5187: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5188: $hiddenfolder = 1;
1.682 raeburn 5189: }
1.510 raeburn 5190: } else {
1.617 raeburn 5191: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5192: 'parameter_randompick'))[0];
5193: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5194: 'parameter_randomorder'))[0]=~/^yes$/i);
5195: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5196: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5197: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5198: 'parameter_encrypturl'))[0]=~/^yes$/i);
5199: unless ($hiddenmap) {
1.620 raeburn 5200: if (ref($navmapref)) {
5201: unless (ref($$navmapref)) {
5202: $$navmapref = Apache::lonnavmaps::navmap->new();
5203: }
5204: if (ref($$navmapref)) {
5205: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5206: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5207: unless (@resources) {
5208: $hiddenmap = 1;
5209: unless ($env{'request.role.adv'}) {
5210: $url = '';
5211: $hiddenfolder = 1;
5212: }
1.617 raeburn 5213: }
1.615 raeburn 5214: }
5215: }
5216: }
5217: }
1.617 raeburn 5218: unless ($encryptmap) {
1.620 raeburn 5219: if ((ref($navmapref)) && (ref($$navmapref))) {
5220: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5221: $encryptmap = 1;
5222: }
1.617 raeburn 5223: }
5224: }
1.630 raeburn 5225:
1.617 raeburn 5226: # Append randompick number, hidden, and encrypted with ":" to foldername,
5227: # so it gets transferred between levels
5228: $folderpath.=$containerarg.'&'.$foldername.
5229: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5230: unless ($url eq '') {
1.612 raeburn 5231: $url.='folderpath='.&escape($folderpath);
5232: }
1.510 raeburn 5233: my $rpckchk;
5234: if ($rpicknum) {
5235: $rpckchk = ' checked="checked"';
1.543 raeburn 5236: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5237: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5238: }
1.510 raeburn 5239: }
1.537 raeburn 5240: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5241: $rand_pick_text =
1.478 raeburn 5242: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5243: $form_param."\n".
1.478 raeburn 5244: $form_common."\n".
1.611 raeburn 5245: '<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 5246: if ($rpicknum ne '') {
5247: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5248: }
1.537 raeburn 5249: $rand_pick_text .= '</span></span>'.
5250: $form_end;
1.543 raeburn 5251: my $ro_set;
1.617 raeburn 5252: if ($randorder) {
1.543 raeburn 5253: $ro_set = 'checked="checked"';
5254: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5255: push(@{$filtersref->{'randomorder'}},$orderidx);
5256: }
5257: }
1.564 raeburn 5258: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5259: $rand_order_text =
1.537 raeburn 5260: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5261: $form_param."\n".
1.537 raeburn 5262: $form_common."\n".
1.611 raeburn 5263: '<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 5264: $form_end;
1.510 raeburn 5265: }
1.705 raeburn 5266: } elsif ($supplementalflag) {
1.598 raeburn 5267: my $isexttool;
1.626 raeburn 5268: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5269: $url='/adm/wrapper'.$url;
5270: $isexttool = 1;
5271: }
1.510 raeburn 5272: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5273: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5274: if ($title) {
1.687 raeburn 5275: $url .= '&title='.$encodedtitle;
1.510 raeburn 5276: }
1.598 raeburn 5277: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5278: $url .= '&idx='.$orderidx;
5279: }
1.610 raeburn 5280: if ($anchor ne '') {
5281: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5282: }
1.329 droeschl 5283: }
1.519 raeburn 5284: my ($tdalign,$tdwidth);
1.501 raeburn 5285: if ($allowed) {
1.630 raeburn 5286: my $fileloc =
1.501 raeburn 5287: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5288: if ($isexternal) {
1.630 raeburn 5289: ($editlink,$extresform) =
1.611 raeburn 5290: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5291: undef,undef,undef,undef,undef,undef,
5292: undef,$disabled);
1.626 raeburn 5293: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5294: ($editlink,$extresform) =
5295: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5296: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5297: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5298: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5299: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5300: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5301: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5302: my $suppanchor;
5303: if ($supplementalflag) {
5304: $suppanchor = $anchor;
5305: }
1.630 raeburn 5306: my $jscall =
1.501 raeburn 5307: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5308: $switchserver,
1.503 raeburn 5309: $forceedit,
1.679 raeburn 5310: undef,$symb,$shownsymb,
1.511 raeburn 5311: &escape($env{'form.folderpath'}),
1.622 raeburn 5312: $renametitle,$hostname,
5313: '','',1,$suppanchor);
1.501 raeburn 5314: if ($jscall) {
1.518 raeburn 5315: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5316: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5317: }
5318: }
5319: }
1.519 raeburn 5320: $tdalign = ' align="right" valign="top"';
5321: $tdwidth = ' width="80%"';
1.329 droeschl 5322: }
1.408 raeburn 5323: my $reinit;
5324: if ($crstype eq 'Community') {
5325: $reinit = &mt('(re-initialize community to access)');
5326: } else {
5327: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5328: }
1.702 raeburn 5329: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5330: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5331: $line.= '<br />';
5332: if ($curralias ne '') {
5333: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5334: $lt{'da'}.'</a></span>';
5335: } else {
5336: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5337: $lt{'sa'}.'</a></span>';
5338: }
5339: }
1.701 raeburn 5340: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5341: my ($link,$nolink);
1.472 raeburn 5342: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5343: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5344: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5345: $nolink = 1;
5346: }
5347: }
5348: if ($nolink) {
5349: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5350: } else {
5351: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5352: }
1.469 www 5353: } elsif ($url) {
1.610 raeburn 5354: if ($anchor ne '') {
5355: if ($supplementalflag) {
5356: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5357: } else {
5358: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5359: }
5360: }
1.705 raeburn 5361: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5362: $link = 'http://'.$hostname.$url;
5363: } else {
5364: $link = $url;
5365: }
1.705 raeburn 5366: my $inhibitmenu;
5367: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5368: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5369: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5370: $inhibitmenu = 'only_body=1';
5371: } else {
5372: $inhibitmenu = 'inhibitmenu=yes';
5373: }
5374: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5375: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5376: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5377: $nolink = 1;
5378: }
5379: }
5380: if ($nolink) {
5381: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5382: } elsif ($nomodal) {
1.621 raeburn 5383: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5384: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5385: } else {
5386: $line.=&Apache::loncommon::modal_link($link,
5387: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5388: }
1.469 www 5389: } else {
5390: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5391: }
1.519 raeburn 5392: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5393: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5394: if ($nolink) {
5395: $line.=$title;
5396: } else {
5397: $line.='<a href="'.$url.'">'.$title.'</a>';
5398: }
1.682 raeburn 5399: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5400: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5401: my $editurl = $url;
5402: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5403: $line .= ' '.'<a href="'.$editurl.'">'.
5404: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5405: '</a>';
5406: }
5407: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5408: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5409: }
1.469 www 5410: } elsif ($url) {
1.685 raeburn 5411: if ($nolink) {
5412: $line.=$title;
5413: } elsif ($nomodal) {
1.621 raeburn 5414: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5415: $title.'</a>';
5416: } else {
5417: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5418: }
1.617 raeburn 5419: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5420: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5421: } else {
5422: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5423: }
1.633 raeburn 5424: if (($allowed) && ($curralias ne '')) {
5425: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5426: } else {
5427: $line .= $extresform;
5428: }
5429: $line .= '</td>';
1.478 raeburn 5430: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5431: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5432: if ($uploaded && $url && !$isfolder && !$ispage) {
5433: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5434: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5435: }
5436: }
1.682 raeburn 5437: if ($allowed) {
5438: my %lt=&Apache::lonlocal::texthash(
5439: 'hd' => 'Hidden',
5440: 'ec' => 'URL hidden');
5441: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5442: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5443: $hidtext = ' checked="checked"';
1.694 raeburn 5444: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5445: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5446: }
5447: }
1.682 raeburn 5448: $formhidden = 'edit_hiddenresource_'.$orderidx;
5449: $line.=(<<ENDPARMS);
1.329 droeschl 5450: <td class="LC_docs_entry_parameter">
1.537 raeburn 5451: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5452: $form_param
1.478 raeburn 5453: $form_common
1.611 raeburn 5454: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5455: $form_end
1.682 raeburn 5456: ENDPARMS
5457: if ($folder =~/^supplemental/) {
5458: $line.= "\n <td>";
5459: } else {
5460: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5461: $enctext = ' checked="checked"';
5462: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5463: push(@{$filtersref->{'encrypturl'}},$orderidx);
5464: }
5465: }
5466: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5467: $line.=(<<ENDPARMS);
1.458 raeburn 5468: <br />
1.537 raeburn 5469: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5470: $form_param
1.478 raeburn 5471: $form_common
1.611 raeburn 5472: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5473: $form_end
5474: </td>
1.478 raeburn 5475: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5476: $rand_order_text</td>
1.329 droeschl 5477: ENDPARMS
1.682 raeburn 5478: }
1.329 droeschl 5479: }
1.379 bisitz 5480: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 5481: return $line;
5482: }
5483:
1.538 raeburn 5484: sub action_restrictions {
5485: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5486: my %denied = (
5487: cut => 0,
5488: copy => 0,
5489: remove => 0,
5490: );
5491: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5492: # no copy for published maps
5493: $denied{'copy'} = 1;
1.597 raeburn 5494: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5495: unless ($1 eq 'simpleproblem') {
5496: $denied{'copy'} = 1;
5497: }
5498: $denied{'cut'} = 1;
1.538 raeburn 5499: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5500: if ($folderpath =~ /^default&[^\&]+$/) {
5501: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5502: $denied{'remove'} = 1;
5503: }
5504: $denied{'cut'} = 1;
5505: $denied{'copy'} = 1;
5506: }
5507: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5508: my $group = $1;
5509: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5510: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5511: $denied{'remove'} = 1;
5512: }
5513: }
5514: $denied{'cut'} = 1;
5515: $denied{'copy'} = 1;
5516: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5517: my $group = $1;
5518: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5519: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5520: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5521: if (keys(%groupsettings) > 0) {
5522: $denied{'remove'} = 1;
5523: }
5524: $denied{'cut'} = 1;
5525: $denied{'copy'} = 1;
5526: }
5527: }
5528: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5529: my $group = $1;
5530: if ($url =~ /group_boards_\Q$group\E/) {
5531: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5532: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5533: if (keys(%groupsettings) > 0) {
5534: if (ref($groupsettings{'functions'}) eq 'HASH') {
5535: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5536: $denied{'remove'} = 1;
5537: }
5538: }
5539: }
5540: $denied{'cut'} = 1;
5541: $denied{'copy'} = 1;
5542: }
5543: }
5544: }
5545: return %denied;
5546: }
5547:
1.533 raeburn 5548: sub new_timebased_suffix {
1.538 raeburn 5549: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 5550: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 5551: if ($type eq 'paste') {
5552: $prefix = $type;
5553: $namespace = 'courseeditor';
1.587 raeburn 5554: $idtype = 'addcode';
1.538 raeburn 5555: } elsif ($type eq 'map') {
1.533 raeburn 5556: $prefix = 'docs';
5557: if ($area eq 'supplemental') {
5558: $prefix = 'supp';
5559: }
5560: $prefix .= $container;
5561: $namespace = 'uploadedmaps';
5562: } else {
5563: $prefix = $type;
5564: $namespace = 'templated';
1.504 raeburn 5565: }
5566: my ($suffix,$freedlock,$error) =
1.587 raeburn 5567: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 5568: if (!$suffix) {
1.538 raeburn 5569: if ($type eq 'paste') {
5570: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5571: } elsif ($type eq 'map') {
1.533 raeburn 5572: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5573: } elsif ($type eq 'smppg') {
5574: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 5575: } elsif ($type eq 'exttool') {
5576: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 5577: } else {
1.565 bisitz 5578: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 5579: }
1.504 raeburn 5580: if ($error) {
5581: $errtext .= '<br />'.$error;
5582: }
5583: }
5584: if ($freedlock ne 'ok') {
1.630 raeburn 5585: $locknotfreed =
1.533 raeburn 5586: '<div class="LC_error">'.
5587: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 5588: if ($type eq 'paste') {
1.591 raeburn 5589: if ($freedlock eq 'nolock') {
5590: $locknotfreed =
5591: '<div class="LC_error">'.
5592: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5593:
1.593 droeschl 5594: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 5595: } else {
5596: $locknotfreed .=
5597: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5598: }
1.538 raeburn 5599: } elsif ($type eq 'map') {
1.591 raeburn 5600: $locknotfreed .=
5601: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 5602: } elsif ($type eq 'smppg') {
5603: $locknotfreed .=
5604: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 5605: } elsif ($type eq 'exttool') {
5606: $locknotfreed .=
5607: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 5608: } else {
5609: $locknotfreed .=
1.565 bisitz 5610: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 5611: }
1.538 raeburn 5612: unless ($type eq 'paste') {
5613: $locknotfreed .=
1.560 raeburn 5614: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5615: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 5616: }
5617: $locknotfreed .= '</div>';
1.504 raeburn 5618: }
5619: return ($suffix,$errtext,$locknotfreed);
5620: }
5621:
1.329 droeschl 5622: =pod
5623:
5624: =item tiehash()
5625:
5626: tie the hash
5627:
5628: =cut
5629:
5630: sub tiehash {
5631: my ($mode)=@_;
5632: $hashtied=0;
5633: if ($env{'request.course.fn'}) {
5634: if ($mode eq 'write') {
5635: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5636: &GDBM_WRCREAT(),0640)) {
5637: $hashtied=2;
5638: }
5639: } else {
5640: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5641: &GDBM_READER(),0640)) {
5642: $hashtied=1;
5643: }
5644: }
1.364 bisitz 5645: }
1.329 droeschl 5646: }
5647:
5648: sub untiehash {
5649: if ($hashtied) { untie %hash; }
5650: $hashtied=0;
5651: return OK;
5652: }
5653:
5654:
5655:
5656:
5657: sub checkonthis {
1.637 raeburn 5658: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 5659: $url=&unescape($url);
5660: $alreadyseen{$url}=1;
5661: $r->rflush();
5662: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5663: $r->print("\n<br />");
5664: if ($level==0) {
5665: $r->print("<br />");
5666: }
5667: for (my $i=0;$i<=$level*5;$i++) {
5668: $r->print(' ');
5669: }
5670: $r->print('<a href="'.$url.'" target="cat">'.
5671: ($title?$title:$url).'</a> ');
5672: if ($url=~/^\/res\//) {
1.637 raeburn 5673: my $updated;
5674: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5675: ($url !~ /\.\d+\.\w+$/)) {
5676: $updated = &Apache::lonnet::remove_stale_resfile($url);
5677: }
1.329 droeschl 5678: my $result=&Apache::lonnet::repcopy(
5679: &Apache::lonnet::filelocation('',$url));
5680: if ($result eq 'ok') {
5681: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 5682: if ($updated) {
5683: $r->print('<br />');
5684: for (my $i=0;$i<=$level*5;$i++) {
5685: $r->print(' ');
5686: }
5687: $r->print('- '.&mt('Outdated copy removed'));
5688: }
1.329 droeschl 5689: $r->rflush();
5690: &Apache::lonnet::countacc($url);
5691: $url=~/\.(\w+)$/;
5692: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5693: $r->print('<br />');
5694: $r->rflush();
5695: for (my $i=0;$i<=$level*5;$i++) {
5696: $r->print(' ');
5697: }
5698: $r->print('- '.&mt('Rendering:').' ');
5699: my ($errorcount,$warningcount)=split(/:/,
5700: &Apache::lonnet::ssi_body($url,
5701: ('grade_target'=>'web',
5702: 'return_only_error_and_warning_counts' => 1)));
5703: if (($errorcount) ||
5704: ($warningcount)) {
5705: if ($errorcount) {
1.369 bisitz 5706: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 5707: &mt('[quant,_1,error]',$errorcount).'</span>');
5708: }
5709: if ($warningcount) {
5710: $r->print('<span class="LC_warning">'.
5711: &mt('[quant,_1,warning]',$warningcount).'</span>');
5712: }
5713: } else {
5714: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5715: }
5716: $r->rflush();
5717: }
5718: my $dependencies=
5719: &Apache::lonnet::metadata($url,'dependencies');
5720: foreach my $dep (split(/\,/,$dependencies)) {
5721: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 5722: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 5723: }
5724: }
5725: } elsif ($result eq 'unavailable') {
5726: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5727: } elsif ($result eq 'not_found') {
5728: unless ($url=~/\$/) {
1.521 bisitz 5729: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 5730: } else {
1.366 bisitz 5731: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 5732: }
5733: } else {
5734: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5735: }
1.637 raeburn 5736: if (($updated) && ($result ne 'ok')) {
5737: $r->print('<br />'.&mt('Outdated copy removed'));
5738: }
1.329 droeschl 5739: }
5740: }
5741: }
5742:
5743:
5744:
5745: =pod
5746:
5747: =item list_symbs()
5748:
1.485 raeburn 5749: List Content Identifiers
1.329 droeschl 5750:
5751: =cut
5752:
5753: sub list_symbs {
5754: my ($r) = @_;
5755:
1.408 raeburn 5756: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5757: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5758: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5759: $r->print(&startContentScreen('tools'));
1.329 droeschl 5760: my $navmap = Apache::lonnavmaps::navmap->new();
5761: if (!defined($navmap)) {
5762: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5763: '<div class="LC_error">'.
5764: &mt('Unable to retrieve information about course contents').
5765: '</div>');
1.408 raeburn 5766: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5767: } else {
1.484 raeburn 5768: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5769: &Apache::loncommon::start_data_table().
5770: &Apache::loncommon::start_data_table_header_row().
5771: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5772: &Apache::loncommon::end_data_table_header_row()."\n");
5773: my $count;
1.329 droeschl 5774: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5775: $r->print(&Apache::loncommon::start_data_table_row().
5776: '<td>'.$res->compTitle().'</td>'.
5777: '<td>'.$res->symb().'</td>'.
1.521 bisitz 5778: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5779: $count ++;
5780: }
5781: if (!$count) {
5782: $r->print(&Apache::loncommon::start_data_table_row().
5783: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5784: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5785: }
1.484 raeburn 5786: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5787: }
1.521 bisitz 5788: $r->print(&endContentScreen());
1.329 droeschl 5789: }
5790:
1.651 raeburn 5791: sub short_urls {
5792: my ($r,$canedit) = @_;
5793: my $crstype = &Apache::loncommon::course_type();
5794: my $formname = 'shortenurl';
5795: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5796: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5797: $r->print(&startContentScreen('tools'));
5798: my ($navmap,$errormsg) =
5799: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5800: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5801: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5802: my (%maps,%resources,%titles);
5803: if (!ref($navmap)) {
5804: $r->print($errormsg.
5805: &endContentScreen());
5806: return '';
5807: } else {
1.652 raeburn 5808: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5809: $r->rflush();
5810: my $readonly;
5811: if ($canedit) {
1.671 raeburn 5812: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5813: if ($numnew) {
5814: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5815: }
5816: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5817: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5818: foreach my $error (@{$errors}) {
5819: $r->print('<li>'.$error.'</li>');
5820: }
5821: $r->print('</ul><br />');
5822: }
5823: } else {
5824: $readonly = 1;
5825: }
5826: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5827: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 5828: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 5829: }
5830: $r->print(&endContentScreen());
5831: }
5832:
1.637 raeburn 5833: sub contentverifyform {
5834: my ($r) = @_;
5835: my $crstype = &Apache::loncommon::course_type();
5836: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5837: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5838: $r->print(&startContentScreen('tools'));
5839: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5840: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5841: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5842: ' <span class="LC_nobreak">'.
5843: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5844: &mt('No').'</label>'.(' 'x2).
5845: '<label><input type="radio" name="checkstale" value="1" />'.
5846: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5847: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5848: '<input type="hidden" value="1" name="tools" />'.
5849: '<input type="hidden" value="1" name="verify" /></p></form>');
5850: $r->print(&endContentScreen());
5851: return;
5852: }
1.329 droeschl 5853:
5854: sub verifycontent {
1.637 raeburn 5855: my ($r,$checkstale) = @_;
1.408 raeburn 5856: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5857: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5858: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5859: $r->print(&startContentScreen('tools'));
5860: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5861: $hashtied=0;
5862: undef %alreadyseen;
5863: %alreadyseen=();
5864: &tiehash();
1.484 raeburn 5865:
1.329 droeschl 5866: foreach my $key (keys(%hash)) {
5867: if ($hash{$key}=~/\.(page|sequence)$/) {
5868: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5869: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5870: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5871: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5872: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5873: }
5874: }
5875: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5876: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5877: }
5878: }
5879: &untiehash();
1.442 www 5880: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5881: $r->print(&endContentScreen());
1.329 droeschl 5882: }
5883:
5884: sub devalidateversioncache {
5885: my $src=shift;
5886: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5887: &Apache::lonnet::clutter($src));
5888: }
5889:
5890: sub checkversions {
1.611 raeburn 5891: my ($r,$canedit) = @_;
1.408 raeburn 5892: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5893: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5894: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5895: $r->print(&startContentScreen('tools'));
1.442 www 5896:
1.329 droeschl 5897: my $header='';
5898: my $startsel='';
5899: my $monthsel='';
5900: my $weeksel='';
5901: my $daysel='';
5902: my $allsel='';
5903: my %changes=();
5904: my $starttime=0;
5905: my $haschanged=0;
5906: my %setversions=&Apache::lonnet::dump('resourceversions',
5907: $env{'course.'.$env{'request.course.id'}.'.domain'},
5908: $env{'course.'.$env{'request.course.id'}.'.num'});
5909:
5910: $hashtied=0;
5911: &tiehash();
1.611 raeburn 5912: if ($canedit) {
5913: my %newsetversions=();
5914: if ($env{'form.setmostrecent'}) {
5915: $haschanged=1;
5916: foreach my $key (keys(%hash)) {
5917: if ($key=~/^ids\_(\/res\/.+)$/) {
5918: $newsetversions{$1}='mostrecent';
5919: &devalidateversioncache($1);
5920: }
5921: }
5922: } elsif ($env{'form.setcurrent'}) {
5923: $haschanged=1;
5924: foreach my $key (keys(%hash)) {
5925: if ($key=~/^ids\_(\/res\/.+)$/) {
5926: my $getvers=&Apache::lonnet::getversion($1);
5927: if ($getvers>0) {
5928: $newsetversions{$1}=$getvers;
5929: &devalidateversioncache($1);
5930: }
5931: }
1.329 droeschl 5932: }
1.611 raeburn 5933: } elsif ($env{'form.setversions'}) {
5934: $haschanged=1;
5935: foreach my $key (keys(%env)) {
5936: if ($key=~/^form\.set_version_(.+)$/) {
5937: my $src=$1;
5938: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5939: $newsetversions{$src}=$env{$key};
5940: &devalidateversioncache($src);
5941: }
5942: }
1.329 droeschl 5943: }
1.611 raeburn 5944: }
5945: if ($haschanged) {
5946: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5947: $env{'course.'.$env{'request.course.id'}.'.domain'},
5948: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5949: $r->print(&Apache::loncommon::confirmwrapper(
5950: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5951: } else {
5952: $r->print(&Apache::loncommon::confirmwrapper(
5953: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5954: }
1.611 raeburn 5955: &mark_hash_old();
5956: }
5957: &changewarning($r,'');
1.329 droeschl 5958: }
5959: if ($env{'form.timerange'} eq 'all') {
5960: # show all documents
1.549 raeburn 5961: $header=&mt('All content in '.$crstype);
1.521 bisitz 5962: $allsel=' selected="selected"';
1.329 droeschl 5963: foreach my $key (keys(%hash)) {
5964: if ($key=~/^ids\_(\/res\/.+)$/) {
5965: my $src=$1;
5966: $changes{$src}=1;
5967: }
5968: }
5969: } else {
5970: # show documents which changed
5971: %changes=&Apache::lonnet::dump
5972: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5973: $env{'course.'.$env{'request.course.id'}.'.num'});
5974: my $firstkey=(keys(%changes))[0];
5975: unless ($firstkey=~/^error\:/) {
5976: unless ($env{'form.timerange'}) {
5977: $env{'form.timerange'}=604800;
5978: }
5979: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5980: .&mt('seconds');
5981: if ($env{'form.timerange'}==-1) {
5982: $seltext='since start of course';
1.521 bisitz 5983: $startsel=' selected="selected"';
1.329 droeschl 5984: $env{'form.timerange'}=time;
5985: }
5986: $starttime=time-$env{'form.timerange'};
5987: if ($env{'form.timerange'}==2592000) {
5988: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5989: $monthsel=' selected="selected"';
1.329 droeschl 5990: } elsif ($env{'form.timerange'}==604800) {
5991: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5992: $weeksel=' selected="selected"';
1.329 droeschl 5993: } elsif ($env{'form.timerange'}==86400) {
5994: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5995: $daysel=' selected="selected"';
1.329 droeschl 5996: }
5997: $header=&mt('Content changed').' '.$seltext;
5998: } else {
5999: $header=&mt('No content modifications yet.');
6000: }
6001: }
6002: %setversions=&Apache::lonnet::dump('resourceversions',
6003: $env{'course.'.$env{'request.course.id'}.'.domain'},
6004: $env{'course.'.$env{'request.course.id'}.'.num'});
6005: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6006: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6007: 'lm' => 'Version changes since last Month',
6008: 'lw' => 'Version changes since last Week',
6009: 'sy' => 'Version changes since Yesterday',
6010: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6011: 'cd' => 'Change display',
1.329 droeschl 6012: 'sd' => 'Display',
6013: 'fi' => 'File',
6014: 'md' => 'Modification Date',
6015: 'mr' => 'Most recently published Version',
1.408 raeburn 6016: 've' => 'Version used in '.$crstype,
6017: 'vu' => 'Set Version to be used in '.$crstype,
6018: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6019: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6020: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6021: 'di' => 'Differences',
1.484 raeburn 6022: 'save' => 'Save changes',
6023: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6024: 'act' => 'Actions');
1.611 raeburn 6025: my ($disabled,$readonly);
6026: unless ($canedit) {
6027: $disabled = 'disabled="disabled"';
6028: $readonly = 1;
6029: }
1.329 droeschl 6030: $r->print(<<ENDHEADERS);
1.484 raeburn 6031: <h4 class="LC_info">$header</h4>
1.329 droeschl 6032: <form action="/adm/coursedocs" method="post">
6033: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6034: <div class="LC_left_float">
1.479 golterma 6035: <fieldset>
1.484 raeburn 6036: <legend>$lt{'cd'}</legend>
1.329 droeschl 6037: <select name="timerange">
1.521 bisitz 6038: <option value='all'$allsel>$lt{'al'}</option>
6039: <option value="-1"$startsel>$lt{'st'}</option>
6040: <option value="2592000"$monthsel>$lt{'lm'}</option>
6041: <option value="604800"$weeksel>$lt{'lw'}</option>
6042: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6043: </select>
6044: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6045: </fieldset>
6046: </div>
6047: <div class="LC_left_float">
6048: <fieldset>
6049: <legend>$lt{'act'}</legend>
1.611 raeburn 6050: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6051: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6052: </fieldset>
6053: </div>
6054: <br clear="all" />
6055: <hr />
6056: <h4>$lt{'vers'}</h4>
1.329 droeschl 6057: ENDHEADERS
1.479 golterma 6058: #number of columns for version history
1.571 raeburn 6059: my %changedbytime;
6060: foreach my $key (keys(%changes)) {
6061: #excludes not versionable problems from resource version history:
6062: next if ($key =~ /^\/res\/lib\/templates/);
6063: my $chg;
6064: if ($env{'form.timerange'} eq 'all') {
6065: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6066: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6067: } else {
6068: $chg = $changes{$key};
6069: next if ($chg < $starttime);
6070: }
6071: push(@{$changedbytime{$chg}},$key);
6072: }
6073: if (keys(%changedbytime) == 0) {
6074: &untiehash();
6075: $r->print(&mt('No content changes in imported content in specified time frame').
6076: &endContentScreen());
6077: return;
6078: }
1.479 golterma 6079: $r->print(
1.611 raeburn 6080: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6081: &Apache::loncommon::start_data_table().
6082: &Apache::loncommon::start_data_table_header_row().
6083: '<th>'.&mt('Resources').'</th>'.
6084: "<th>$lt{'mr'}</th>".
6085: "<th>$lt{'ve'}</th>".
6086: "<th>$lt{'vu'}</th>".
6087: '<th>'.&mt('History').'</th>'.
6088: &Apache::loncommon::end_data_table_header_row()
6089: );
1.571 raeburn 6090: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6091: foreach my $key (sort(@{$changedbytime{$chg}})) {
6092: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6093: my $currentversion=&Apache::lonnet::getversion($key);
6094: if ($currentversion<0) {
6095: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6096: }
6097: my $linkurl=&Apache::lonnet::clutter($key);
6098: $r->print(
6099: &Apache::loncommon::start_data_table_row().
6100: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6101: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6102: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6103: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6104: '<td align="right">'
6105: );
6106: # Used in course
6107: my $usedversion=$hash{'version_'.$linkurl};
6108: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6109: if ($usedversion != $currentversion) {
1.479 golterma 6110: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6111: } else {
1.479 golterma 6112: $r->print($usedversion);
6113: }
1.329 droeschl 6114: } else {
1.521 bisitz 6115: $r->print($currentversion);
1.329 droeschl 6116: }
1.571 raeburn 6117: $r->print('</td><td title="'.$lt{'vu'}.'">');
6118: # Set version
6119: $r->print(&Apache::loncommon::select_form(
6120: $setversions{$linkurl},
6121: 'set_version_'.$linkurl,
6122: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6123: '' => '',
6124: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6125: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6126: my $lastold=1;
6127: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6128: my $url=$root.'.'.$prevvers.'.'.$extension;
6129: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6130: $lastold=$prevvers;
6131: }
6132: }
6133: $r->print('</td>');
6134: # List all available versions
6135: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6136: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6137: my $url=$root.'.'.$prevvers.'.'.$extension;
6138: $r->print(
6139: '<span class="LC_nobreak">'
6140: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6141: .&mt('Version [_1]',$prevvers).'</a>'
6142: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6143: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6144: .')');
6145: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6146: $r->print(
6147: ' <a href="/adm/diff?filename='.
6148: &Apache::lonnet::clutter($root.'.'.$extension).
6149: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6150: '" target="diffs">'.&mt('Diffs').'</a>');
6151: }
6152: $r->print('</span><br />');
1.329 droeschl 6153: }
1.571 raeburn 6154: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6155: }
1.329 droeschl 6156: }
1.521 bisitz 6157: $r->print(
6158: &Apache::loncommon::end_data_table().
1.611 raeburn 6159: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6160: '</form>'
6161: );
1.329 droeschl 6162:
6163: &untiehash();
1.521 bisitz 6164: $r->print(&endContentScreen());
1.571 raeburn 6165: return;
1.329 droeschl 6166: }
6167:
6168: sub mark_hash_old {
6169: my $retie_hash=0;
6170: if ($hashtied) {
6171: $retie_hash=1;
6172: &untiehash();
6173: }
6174: &tiehash('write');
6175: $hash{'old'}=1;
6176: &untiehash();
6177: if ($retie_hash) { &tiehash(); }
6178: }
6179:
6180: sub is_hash_old {
6181: my $untie_hash=0;
6182: if (!$hashtied) {
6183: $untie_hash=1;
6184: &tiehash();
6185: }
6186: my $return=$hash{'old'};
6187: if ($untie_hash) { &untiehash(); }
6188: return $return;
6189: }
6190:
6191: sub changewarning {
6192: my ($r,$postexec,$message,$url)=@_;
6193: if (!&is_hash_old()) { return; }
6194: my $pathvar='folderpath';
6195: my $path=&escape($env{'form.folderpath'});
6196: if (!defined($url)) {
6197: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6198: }
6199: my $course_type = &Apache::loncommon::course_type();
6200: if (!defined($message)) {
6201: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6202: }
1.653 raeburn 6203: my $windowname = 'loncapaclient';
6204: if ($env{'request.lti.login'}) {
6205: $windowname .= 'lti';
6206: }
1.329 droeschl 6207: $r->print("\n\n".
1.372 bisitz 6208: '<script type="text/javascript">'."\n".
6209: '// <![CDATA['."\n".
6210: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6211: '// ]]>'."\n".
1.369 bisitz 6212: '</script>'."\n".
1.653 raeburn 6213: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6214: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6215: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6216: &mt($message,' <input type="hidden" name="'.
6217: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6218: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6219: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6220: }
6221:
6222:
6223: sub init_breadcrumbs {
1.571 raeburn 6224: my ($form,$text,$help)=@_;
1.329 droeschl 6225: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6226: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6227: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6228: faq=>273,
6229: bug=>'Instructor Interface',
1.571 raeburn 6230: help => $help});
1.329 droeschl 6231: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6232: text=>$text,
6233: faq=>273,
6234: bug=>'Instructor Interface'});
6235: }
6236:
1.441 www 6237: # subroutine to list form elements
6238: sub create_list_elements {
6239: my @formarr = @_;
6240: my $list = '';
1.501 raeburn 6241: foreach my $button (@formarr){
6242: foreach my $picture (keys(%{$button})) {
6243: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6244: }
6245: }
6246: return $list;
6247: }
1.329 droeschl 6248:
1.441 www 6249: # subroutine to create ul from list elements
6250: sub create_form_ul {
6251: my $list = shift;
6252: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6253: return $ul;
6254: }
1.329 droeschl 6255:
1.442 www 6256: #
6257: # Start tabs
6258: #
6259:
6260: sub startContentScreen {
1.484 raeburn 6261: my ($mode) = @_;
6262: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6263: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6264: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6265: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6266: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6267: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6268: } else {
1.549 raeburn 6269: $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 6270: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6271: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6272: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6273: }
6274: $output .= "\n".'</ul>'."\n";
6275: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6276: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6277: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6278: return $output;
1.442 www 6279: }
6280:
6281: #
6282: # End tabs
6283: #
6284:
6285: sub endContentScreen {
1.484 raeburn 6286: return '</div></div></div>';
1.442 www 6287: }
1.329 droeschl 6288:
1.446 www 6289: sub supplemental_base {
1.548 raeburn 6290: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6291: }
6292:
1.329 droeschl 6293: sub handler {
6294: my $r = shift;
6295: &Apache::loncommon::content_type($r,'text/html');
6296: $r->send_http_header;
6297: return OK if $r->header_only;
1.484 raeburn 6298:
6299: # get course data
1.408 raeburn 6300: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6301: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6302: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 ! raeburn 6303: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6304:
1.606 raeburn 6305: # get docroot
6306: my $londocroot = $r->dir_config('lonDocRoot');
6307:
1.484 raeburn 6308: # graphics settings
6309: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6310:
1.443 www 6311: #
1.329 droeschl 6312: # --------------------------------------------- Initialize help topics for this
6313: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6314: 'Adding_External_Resource','Adding_External_Tool',
6315: 'Navigate_Content','Adding_Folders','Docs_Overview',
6316: 'Load_Map','Supplemental','Score_Upload_Form',
6317: 'Adding_Pages','Importing_LON-CAPA_Resource',
6318: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6319: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6320: 'Standard_Problem','Course_Resources',
6321: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6322: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6323: }
6324: # Composite help files
6325: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6326: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6327: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6328: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6329: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6330: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6331: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6332: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6333: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6334: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6335:
1.611 raeburn 6336: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6337: # does this user have privileges to modify content.
6338: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6339: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6340: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6341: $allowed = 1;
1.682 raeburn 6342: }
6343: $canedit = 1;
6344: $canview = 1;
6345: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6346: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6347: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6348: $allowed = 1;
6349: }
1.682 raeburn 6350: $canview = 1;
1.611 raeburn 6351: }
6352: unless ($canedit) {
6353: $disabled = ' disabled="disabled"';
1.472 raeburn 6354: }
1.582 raeburn 6355: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6356: if ($env{'form.inhibitmenu'}) {
6357: unless ($env{'form.inhibitmenu'} eq 'yes') {
6358: delete($env{'form.inhibitmenu'});
6359: }
6360: }
6361:
1.582 raeburn 6362: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6363: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6364: if (!$canedit) {
6365: &verifycontent($r);
6366: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6367: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6368: text=>'Results',
6369: faq=>273,
6370: bug=>'Instructor Interface'});
6371: &verifycontent($r,$env{'form.checkstale'});
6372: } else {
6373: &contentverifyform($r);
6374: }
1.329 droeschl 6375: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6376: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6377: &list_symbs($r);
1.651 raeburn 6378: } elsif ($allowed && $env{'form.shorturls'}) {
6379: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6380: &short_urls($r,$canedit);
1.329 droeschl 6381: } elsif ($allowed && $env{'form.docslog'}) {
6382: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6383: my $folder = $env{'form.folder'};
6384: if ($folder eq '') {
6385: $folder='default';
6386: }
1.611 raeburn 6387: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6388: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6389: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6390: &checkversions($r,$canedit);
6391: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6392: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6393: &dumpcourse($r);
1.712 ! raeburn 6394: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
! 6395: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
! 6396: my $readonly;
! 6397: if (!$canedit) {
! 6398: $readonly = 1;
! 6399: }
! 6400: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6401: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6402: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6403: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6404: } else {
1.611 raeburn 6405: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6406: $noendpage = 1;
6407: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6408: if ($redirect) {
6409: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6410: my $container = 'sequence';
6411: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6412: $is_random_order,$container) =
6413: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6414: my (@folders)=split('&',$env{'form.folderpath'});
6415: $env{'form.foldername'}=&unescape(pop(@folders));
6416: my $folder=pop(@folders);
6417: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6418: $folder.'.'.$container);
6419: my $warning;
6420: if ($fatal) {
6421: if ($container eq 'page') {
6422: $warning = &mt('An error occurred retrieving the contents of the current page.');
6423: } else {
6424: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6425: }
6426: } else {
6427: my $url = $redirect;
6428: my $srcfile = $londocroot.$url;
6429: $url =~ s{^/priv/}{/res/};
6430: my $targetfile = $londocroot.$url;
6431: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6432: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6433: $env{'form.folder'} = $folder;
6434: &snapshotbefore();
6435: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6436: my $ext = 'false';
6437: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6438: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6439: ':'.$ext.':normal:res';
6440: push(@LONCAPA::map::order,$newidx);
6441: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6442: 'string_yesno');
6443: &remember_parms($newidx,'hiddenresource','set','yes');
6444: ($errtext,$fatal) =
6445: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6446: &log_differences($plain);
6447: &mark_hash_old();
6448: $r->internal_redirect($redirect);
6449: return OK;
6450: }
1.654 raeburn 6451: } else {
6452: $r->internal_redirect($redirect);
1.606 raeburn 6453: }
6454: }
6455: }
1.445 www 6456: #
6457: # Done catching special calls
1.484 raeburn 6458: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6459: # Get the parameters that may be needed
6460: #
6461: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6462: ['folderpath','title',
1.519 raeburn 6463: 'forcesupplement','forcestandard',
1.510 raeburn 6464: 'tools','symb','command','supppath']);
1.445 www 6465:
1.635 raeburn 6466: foreach my $item ('forcesupplement','forcestandard','tools') {
6467: next if ($env{'form.'.$item} eq '');
6468: unless ($env{'form.'.$item} eq '1') {
6469: delete($env{'form.'.$item});
6470: }
6471: }
6472:
6473: if ($env{'form.command'}) {
6474: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6475: delete($env{'form.command'});
6476: }
6477: }
6478:
6479: if ($env{'form.symb'}) {
6480: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6481: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6482: delete($env{'form.symb'});
6483: }
6484: }
6485:
1.445 www 6486: # standard=1: this is a "new-style" course with an uploaded map as top level
6487: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 6488:
6489: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 6490:
1.484 raeburn 6491: # Decide whether this should display supplemental or main content or utilities
1.445 www 6492: # supplementalflag=1: show supplemental documents
6493: # supplementalflag=0: show standard documents
1.484 raeburn 6494: # toolsflag=1: show utilities
1.445 www 6495:
1.561 raeburn 6496: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6497: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6498: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 6499: $supplementalflag=0;
6500: }
6501: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6502: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 6503: unless (($supplementalflag) ||
6504: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
6505: unless ($allowed) { $supplementalflag=1; }
6506: unless ($standard) { $supplementalflag=1; }
6507: }
1.484 raeburn 6508: my $toolsflag=0;
6509: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 6510:
1.635 raeburn 6511: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6512: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 6513: }
6514:
1.685 raeburn 6515: my $backto_supppath;
1.635 raeburn 6516: if ($env{'form.supppath'} ne '') {
1.685 raeburn 6517: if ($supplementalflag && $allowed) {
6518: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6519: }
1.635 raeburn 6520: }
6521:
1.329 droeschl 6522: my $script='';
6523: my $showdoc=0;
1.457 raeburn 6524: my $addentries = {};
1.475 raeburn 6525: my $container;
1.329 droeschl 6526: my $containertag;
1.508 raeburn 6527: my $pathitem;
1.598 raeburn 6528: my %ltitools;
1.699 raeburn 6529: my $posslti;
1.617 raeburn 6530: my $hiddentop;
1.615 raeburn 6531: my $navmap;
1.617 raeburn 6532: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 6533:
1.464 www 6534: # Do we directly jump somewhere?
1.525 raeburn 6535: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 6536: if ($env{'form.symb'} ne '') {
1.522 raeburn 6537: $env{'form.folderpath'}=
1.617 raeburn 6538: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 6539: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 6540: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 6541: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 6542: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 6543: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 6544: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 6545: }
1.472 raeburn 6546: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 6547: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 6548: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 6549: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 6550: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 6551: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6552: } elsif ($env{'form.command'} eq 'contents') {
6553: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6554: } elsif ($env{'form.command'} eq 'home') {
6555: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 6556: }
6557:
1.525 raeburn 6558:
1.445 www 6559: # Where do we store these for when we come back?
6560: my $stored_folderpath='docs_folderpath';
6561: if ($supplementalflag) {
6562: $stored_folderpath='docs_sup_folderpath';
6563: }
1.464 www 6564:
1.519 raeburn 6565: # No folderpath, and in edit mode, see if we have something stored
6566: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6567: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 6568: {'folderpath' => 'scalar'});
1.615 raeburn 6569:
6570: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6571: if ($supplementalflag) {
6572: undef($env{'form.folderpath'}) if ($1 eq 'default');
6573: } else {
6574: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6575: }
6576: } else {
1.523 raeburn 6577: undef($env{'form.folderpath'});
6578: }
1.677 raeburn 6579: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6580: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 6581: }
1.329 droeschl 6582: }
1.706 raeburn 6583:
6584: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 6585: if ((!$allowed) && ($supplementalflag)) {
1.446 www 6586: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6587: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6588: }
6589: }
1.446 www 6590: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6591: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6592: $env{'form.folderpath'} = &supplemental_base()
6593: .'&'.
1.329 droeschl 6594: $env{'form.folderpath'};
6595: }
1.685 raeburn 6596: # If allowed and user's role is not advanced check folderpath is not hidden
6597: my $hidden_and_empty;
1.687 raeburn 6598: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 6599: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 6600: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 6601: my $folder = $pathitems[-2];
6602: if ($folder eq '') {
6603: undef($env{'form.folderpath'});
6604: } else {
6605: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 6606: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 6607: $folderurl .= '.page';
6608: } else {
6609: $folderurl .= '.sequence';
6610: }
1.685 raeburn 6611: if ($supplementalflag) {
6612: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6613: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 6614: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 6615: if (ref($supplemental) eq 'HASH') {
6616: my ($suppmap,$suppmapnum);
6617: if ($folder eq 'supplemental') {
6618: $suppmap = 'default';
6619: $suppmapnum = 0;
6620: } elsif ($folder =~ /^supplemental_(\d+)$/) {
6621: $suppmap = $1;
6622: $suppmapnum = $suppmap;
6623: }
6624: if ($hiddenfolder) {
6625: my $hascontent;
6626: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6627: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6628: $hascontent = 1;
6629: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6630: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6631: if ($id =~ /^$suppmapnum\:/) {
6632: $hascontent = 1;
6633: last;
6634: }
6635: }
6636: }
6637: last if ($hascontent);
6638: }
6639: unless ($hascontent) {
6640: if ($foldername ne '') {
6641: $hidden_and_empty = $foldername;
6642: } else {
6643: $hidden_and_empty = $folder;
6644: }
6645: }
6646: }
6647: }
6648: } else {
6649: unless (ref($navmap)) {
6650: $navmap = Apache::lonnavmaps::navmap->new();
6651: }
6652: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6653: $foldername = &HTML::Entities::decode(&unescape($foldername));
6654: if (ref($navmap)) {
6655: if ($hiddenfolder ||
6656: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6657: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6658: unless (@resources) {
6659: if ($foldername ne '') {
6660: $hidden_and_empty = $foldername;
6661: } else {
6662: $hidden_and_empty = $folder;
6663: }
6664: }
6665: }
6666: }
1.617 raeburn 6667: }
1.685 raeburn 6668: if ($hidden_and_empty ne '') {
6669: splice(@pathitems,-2);
6670: if (@pathitems) {
6671: $env{'form.folderpath'} = join('&',@pathitems);
6672: } else {
6673: undef($env{'form.folderpath'});
1.615 raeburn 6674: }
6675: }
6676: }
6677: }
6678:
1.446 www 6679: # If after all of this, we still don't have any paths, make them
1.519 raeburn 6680: unless ($env{'form.folderpath'}) {
1.446 www 6681: if ($supplementalflag) {
6682: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 6683: } elsif ($allowed) {
6684: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 6685: }
1.472 raeburn 6686: }
1.446 www 6687:
1.445 www 6688: # Store this
1.484 raeburn 6689: unless ($toolsflag) {
1.615 raeburn 6690: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 6691: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 6692: {'folderpath' => 'scalar'});
1.510 raeburn 6693: }
1.519 raeburn 6694: my $folderpath;
1.484 raeburn 6695: if ($env{'form.folderpath'}) {
1.519 raeburn 6696: $folderpath = $env{'form.folderpath'};
6697: my (@folders)=split('&',$env{'form.folderpath'});
6698: $env{'form.foldername'}=&unescape(pop(@folders));
6699: if ($env{'form.foldername'} =~ /\:1$/) {
6700: $container = 'page';
6701: } else {
6702: $container = 'sequence';
6703: }
6704: $env{'form.folder'}=pop(@folders);
1.484 raeburn 6705: } else {
1.519 raeburn 6706: if ($env{'form.folder'} eq '' ||
6707: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 6708: if ($env{'form.folder'} eq 'supplemental') {
6709: $folderpath=&supplemental_base();
6710: } elsif (!$hiddentop) {
6711: $folderpath='default&'.
6712: &escape(&mt('Main Content').':::::');
6713: }
1.484 raeburn 6714: }
6715: }
1.519 raeburn 6716: $containertag = '<input type="hidden" name="folderpath" value="" />';
6717: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 6718: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6719: $showdoc='/'.$1;
6720: }
6721: if ($showdoc) { # got called in sequence from course
6722: $allowed=0;
6723: } else {
1.611 raeburn 6724: if ($canedit) {
1.484 raeburn 6725: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6726: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 6727: }
6728: }
1.329 droeschl 6729: }
6730:
1.344 bisitz 6731: # get personal data
1.329 droeschl 6732: my $uname=$env{'user.name'};
6733: my $udom=$env{'user.domain'};
6734: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6735:
6736: if ($allowed) {
1.484 raeburn 6737: if ($toolsflag) {
6738: $script .= &inject_data_js();
6739: my ($home,$other,%outhash)=&authorhosts();
6740: if (!$home && $other) {
6741: my @hosts;
6742: foreach my $aurole (keys(%outhash)) {
6743: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6744: push(@hosts,$outhash{$aurole});
6745: }
6746: }
6747: $script .= &dump_switchserver_js(@hosts);
6748: }
1.458 raeburn 6749: } else {
1.570 raeburn 6750: my $tid = 1;
1.484 raeburn 6751: my @tabids;
6752: if ($supplementalflag) {
1.655 raeburn 6753: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 6754: $tid = 2;
1.484 raeburn 6755: } else {
6756: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 6757: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 6758: unshift(@tabids,'001');
6759: push(@tabids,('dd1','ee1'));
6760: }
1.458 raeburn 6761: }
1.484 raeburn 6762: my $tabidstr = join("','",@tabids);
1.699 raeburn 6763: my (%domtools,%crstools);
6764: my %tooltypes = &Apache::loncommon::usable_exttools();
6765: if ($tooltypes{'dom'}) {
6766: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6767: }
6768: if ($tooltypes{'crs'}) {
6769: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6770: }
6771: %ltitools = (
6772: dom => \%domtools,
6773: crs => \%crstools,
6774: );
6775: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 6776: my $hostname = $r->hostname();
1.606 raeburn 6777: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 6778: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 6779: &history_tab_js().
6780: &inject_data_js().
1.570 raeburn 6781: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 6782: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 6783: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6784: if ($hidden_and_empty ne '') {
6785: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6786: $hidden_and_empty);
6787: $onload .= "javascript:alert('".&js_escape($alert)."');";
6788: }
1.484 raeburn 6789: $addentries = {
1.685 raeburn 6790: onload => $onload,
1.484 raeburn 6791: };
1.458 raeburn 6792: }
1.538 raeburn 6793: $script .= &paste_popup_js();
1.501 raeburn 6794: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6795: &mt('Switch server?');
6796:
6797:
1.329 droeschl 6798: }
6799: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6800: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6801: .'// <![CDATA['."\n"
6802: .$script."\n"
6803: .'// ]]>'."\n"
1.595 musolffc 6804: .'</script>'."\n"
6805: .'<script type="text/javascript"
6806: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6807:
6808: # Breadcrumbs
6809: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 6810:
6811: if ($showdoc) {
1.682 raeburn 6812: my $args;
6813: if ($supplementalflag) {
1.687 raeburn 6814: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6815: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 6816: $args = {'bread_crumbs' => $brcrum,
6817: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 6818: } else {
6819: $args = {'force_register' => $showdoc};
6820: }
6821: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6822: } elsif ($toolsflag) {
1.611 raeburn 6823: my ($breadtext,$breadtitle);
1.617 raeburn 6824: $breadtext = "$crstype Editor";
1.611 raeburn 6825: if ($canedit) {
6826: $breadtitle = 'Editing '.$crstype.' Contents';
6827: } else {
6828: $breadtext .= ' (View-only mode)';
6829: $breadtitle = 'Viewing '.$crstype.' Contents';
6830: }
1.571 raeburn 6831: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6832: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6833: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6834: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6835: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6836: $breadtitle)
1.571 raeburn 6837: );
1.510 raeburn 6838: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6839: unless ($env{'request.role.adv'}) {
6840: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6841: $r->internal_redirect('/adm/navmaps');
6842: return OK;
6843: }
6844: }
1.510 raeburn 6845: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 6846: my $args = {'bread_crumbs' => $brcrum};
6847: unless (($env{'form.folderpath'} eq '') ||
6848: ($env{'form.folder'} eq 'supplemental')) {
6849: $args->{'bread_crumbs_nomenu'} = 1;
6850: }
1.510 raeburn 6851: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 6852: $args));
1.510 raeburn 6853: } else {
1.611 raeburn 6854: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6855: $breadtext = "$crstype Editor";
1.611 raeburn 6856: if ($canedit) {
6857: $breadtitle = 'Editing '.$crstype.' Contents';
6858: $helpitem = 'Docs_Adding_Course_Doc';
6859: } else {
6860: $breadtext .= ' (View-only mode)';
6861: $breadtitle = 'Viewing '.$crstype.' Contents';
6862: $helpitem = 'Docs_Viewing_Course_Doc';
6863: }
1.392 raeburn 6864: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6865: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6866: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6867: {'add_entries' => $addentries}
6868: )
1.392 raeburn 6869: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6870: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6871: $breadtitle,
6872: $helpitem)
1.392 raeburn 6873: );
6874: }
1.364 bisitz 6875:
1.329 droeschl 6876: my %allfiles = ();
6877: my %codebase = ();
1.440 raeburn 6878: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6879: if ($canedit) {
1.684 raeburn 6880: undef($suppchanges);
1.329 droeschl 6881: if (($env{'form.uploaddoc.filename'}) &&
6882: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6883: my $context = $1;
6884: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6885: undef($hadchanges);
1.440 raeburn 6886: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6887: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6888: undef($navmap);
1.329 droeschl 6889: if ($hadchanges) {
6890: &mark_hash_old();
6891: }
1.684 raeburn 6892: if ($suppchanges) {
6893: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6894: undef($suppchanges);
6895: }
1.440 raeburn 6896: $r->print($upload_output);
6897: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6898: # Process file upload - phase two - upload embedded objects
6899: $uploadphase = 'check_embedded';
6900: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6901: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6902: $env{'form.newidx'});
6903: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6904: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6905: my ($destination,$dir_root) = &embedded_destination();
6906: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6907: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6908: my ($result,$flag) =
1.440 raeburn 6909: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6910: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6911: $actionurl);
6912: $r->print($result.&return_to_editor());
6913: } elsif ($env{'form.phase'} eq 'check_embedded') {
6914: # Process file upload - phase three - modify references in HTML file
6915: $uploadphase = 'modified_orightml';
6916: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6917: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6918: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6919: my $result =
1.482 raeburn 6920: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6921: $docuname,$docudom,undef,
6922: $dir_root);
1.630 raeburn 6923: $r->print($result.&return_to_editor());
1.476 raeburn 6924: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6925: $uploadphase = 'decompress_phase_one';
6926: $r->print(&decompression_phase_one().
6927: &return_to_editor());
6928: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6929: $uploadphase = 'decompress_phase_two';
6930: $r->print(&decompression_phase_two().
6931: &return_to_editor());
1.329 droeschl 6932: }
6933: }
6934:
1.484 raeburn 6935: if ($allowed && $toolsflag) {
6936: $r->print(&startContentScreen('tools'));
1.708 raeburn 6937: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 6938: $r->print(&endContentScreen());
6939: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6940: # -----------------------------------------------------------------------------
6941: my %lt=&Apache::lonlocal::texthash(
6942: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6943: 'upfi' => 'Upload File',
1.553 raeburn 6944: 'upld' => 'Upload Content',
1.706 raeburn 6945: 'srch' => 'Search Repository',
6946: 'impo' => 'Import from Repository',
1.487 raeburn 6947: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6948: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6949: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6950: 'extr' => 'External Resource',
6951: 'extt' => 'External Tool',
1.329 droeschl 6952: 'selm' => 'Select Map',
6953: 'load' => 'Load Map',
6954: 'newf' => 'New Folder',
6955: 'newp' => 'New Composite Page',
6956: 'syll' => 'Syllabus',
1.425 raeburn 6957: 'navc' => 'Table of Contents',
1.343 biermanm 6958: 'sipa' => 'Simple Course Page',
1.329 droeschl 6959: 'sipr' => 'Simple Problem',
1.630 raeburn 6960: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6961: 'stpr' => 'Standard Problem',
6962: 'news' => 'New sub-directory',
6963: 'crpr' => 'Create Problem',
1.689 raeburn 6964: 'swit' => 'Switch Server',
1.329 droeschl 6965: 'drbx' => 'Drop Box',
1.451 www 6966: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6967: 'bull' => 'Discussion Board',
1.347 weissno 6968: 'mypi' => 'My Personal Information Page',
1.353 weissno 6969: 'grpo' => 'Group Portfolio',
1.329 droeschl 6970: 'rost' => 'Course Roster',
1.528 raeburn 6971: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6972: 'imsf' => 'IMS Upload',
6973: 'imsl' => 'Upload IMS package',
1.501 raeburn 6974: 'cms' => 'Origin of IMS package',
6975: 'se' => 'Select',
1.329 droeschl 6976: 'file' => 'File',
6977: 'title' => 'Title',
1.606 raeburn 6978: 'addp' => 'Add Placeholder to course?',
6979: 'uste' => 'Use Template?',
6980: 'fnam' => 'File Name:',
6981: 'loca' => 'Location:',
6982: 'dire' => 'Directory:',
6983: 'cate' => 'Category:',
6984: 'tmpl' => 'Template:',
1.698 raeburn 6985: 'empd' => 'No resources found',
1.329 droeschl 6986: 'comment' => 'Comment',
1.403 raeburn 6987: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6988: 'bb5' => 'Blackboard 5',
6989: 'bb6' => 'Blackboard 6',
6990: 'angel5' => 'ANGEL 5.5',
6991: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6992: 'yes' => 'Yes',
6993: 'no' => 'No',
1.618 raeburn 6994: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6995: );
1.329 droeschl 6996: # -----------------------------------------------------------------------------
1.595 musolffc 6997:
6998: # Calculate free quota space for a user or course. A javascript function checks
6999: # file size to determine if upload should be allowed.
7000: my $quotatype = 'unofficial';
7001: if ($crstype eq 'Community') {
1.601 raeburn 7002: $quotatype = 'community';
7003: } elsif ($crstype eq 'Placement') {
7004: $quotatype = 'placement';
1.595 musolffc 7005: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7006: $quotatype = 'official';
7007: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7008: $quotatype = 'textbook';
7009: }
7010: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7011: 'course',$quotatype); # expressed in MB
7012: my $current_disk_usage = 0;
7013: foreach my $subdir ('docs','supplemental') {
7014: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7015: "userfiles/$subdir",1); # expressed in kB
7016: }
7017: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7018: my $usage = $current_disk_usage/1024; # in MB
7019: my $quota = $disk_quota;
7020: my $percent;
7021: if ($disk_quota == 0) {
7022: $percent = 100.0;
7023: } else {
1.619 raeburn 7024: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7025: }
7026: $usage = sprintf("%.2f",$usage);
7027: $quota = sprintf("%.2f",$quota);
7028: $percent = sprintf("%.0f",$percent);
7029: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7030: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7031:
1.329 droeschl 7032: my $fileupload=(<<FIUP);
1.605 raeburn 7033: $quotainfo
1.329 droeschl 7034: $lt{'file'}:<br />
7035: FIUP
7036: my $checkbox=(<<CHBO);
7037: <!-- <label>$lt{'parse'}?
7038: <input type="checkbox" name="parserflag" />
7039: </label> -->
7040: <label>
1.611 raeburn 7041: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7042: </label>
7043: CHBO
1.501 raeburn 7044: my $imsfolder = $env{'form.folder'};
7045: if ($imsfolder eq '') {
7046: $imsfolder = 'default';
7047: }
7048: my $imspform=(<<IMSFORM);
7049: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7050: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7051: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7052: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7053: <legend>$lt{'imsf'}</legend>
7054: $fileupload
1.702 raeburn 7055: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7056: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7057: <br />
7058: <p>
7059: $lt{'cms'}:
1.611 raeburn 7060: <select name="source" $disabled>
1.501 raeburn 7061: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7062: <option value="bb5">$lt{'bb5'}</option>
7063: <option value="bb6">$lt{'bb6'}</option>
7064: <option value="angel5">$lt{'angel5'}</option>
7065: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7066: </select>
7067: <input type="hidden" name="folder" value="$imsfolder" />
7068: </p>
7069: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7070: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7071: </fieldset>
7072: </form>
7073: IMSFORM
1.329 droeschl 7074:
7075: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7076: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7077: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7078: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7079: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7080: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7081: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7082: $fileupload
1.702 raeburn 7083: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7084: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7085: <br />
7086: $lt{'title'}:<br />
1.611 raeburn 7087: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7088: $pathitem
1.329 droeschl 7089: <input type="hidden" name="cmd" value="upload_default" />
7090: <br />
1.458 raeburn 7091: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7092: $checkbox
7093: </span>
1.501 raeburn 7094: <br clear="all" />
1.611 raeburn 7095: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7096: </fieldset>
7097: </form>
1.383 tempelho 7098: FUFORM
1.329 droeschl 7099:
1.611 raeburn 7100: my $mapimportjs;
7101: if ($canedit) {
7102: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7103: } else {
7104: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7105: }
1.502 raeburn 7106: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7107: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7108: $lt{'impm'}</a>$help{'Load_Map'}
7109: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7110: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7111: <legend>$lt{'impm'}</legend>
1.371 tempelho 7112: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7113: $lt{'copm'}<br />
7114: <span class="LC_nobreak">
7115: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7116: onfocus="this.blur();$mapimportjs" $disabled />
7117: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7118: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7119: </fieldset>
7120: </form>
7121:
1.383 tempelho 7122: SEDFFORM
1.706 raeburn 7123: my ($importcrsresform,$checkcrsres);
7124: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7125: $checkcrsres = 1;
7126: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7127: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7128: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7129: unless (($type eq 'community') || ($type eq 'placement')) {
7130: $type = 'unofficial';
7131: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7132: $type = 'official';
7133: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7134: $type = 'textbook';
7135: } else {
7136: $type = 'unofficial';
7137: }
7138: }
7139: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7140: $checkcrsres = 1;
7141: }
7142: }
7143: if ($checkcrsres) {
7144: my ($numdirs,$pickfile) =
7145: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7146: "resize_scrollbox('contentscroll','1','0');",
7147: undef,'res');
7148: if ($pickfile) {
7149: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7150: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7151: $lt{'imcr'}</a>$help{'Course_Resources'}
7152: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7153: <fieldset id="importcrsresform" style="display: none;">
7154: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7155: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7156: <input type="hidden" name="active" value="bb" />
7157: $pickfile
7158: <p>
1.699 raeburn 7159: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7160: </p>
7161: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7162: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7163: </div>
7164: <div id="importcrsresempty" style="display: none;">
7165: <p>
7166: $lt{'empd'}
7167: </p>
7168: </div>
1.606 raeburn 7169: </fieldset>
7170: </form>
7171: CRSFORM
1.706 raeburn 7172: }
1.606 raeburn 7173: }
7174:
1.611 raeburn 7175: my $fromstoredjs;
7176: if ($canedit) {
7177: $fromstoredjs = 'open_StoredLinks_Import()';
7178: } else {
7179: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7180: }
7181:
1.502 raeburn 7182: my @importpubforma = (
1.706 raeburn 7183: { '<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 7184: { '<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 7185: { '<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 7186: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7187: );
1.706 raeburn 7188: if ($importcrsresform) {
7189: 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 7190: }
1.502 raeburn 7191: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7192: my $extresourcesform =
7193: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7194: $help{'Adding_External_Resource'},
7195: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7196: my $exttoolform =
7197: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7198: $help{'Adding_External_Tool'},undef,
7199: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7200: \%ltitools,$disabled);
1.329 droeschl 7201: if ($allowed) {
1.492 raeburn 7202: my $folder = $env{'form.folder'};
7203: if ($folder eq '') {
7204: $folder='default';
7205: }
1.615 raeburn 7206: if ($canedit) {
7207: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7208: if ($output) {
7209: $r->print($output);
7210: }
1.538 raeburn 7211: }
1.337 ehlerst 7212: $r->print(<<HIDDENFORM);
7213: <form name="renameform" method="post" action="/adm/coursedocs">
7214: <input type="hidden" name="title" />
7215: <input type="hidden" name="cmd" />
7216: <input type="hidden" name="markcopy" />
7217: <input type="hidden" name="copyfolder" />
7218: $containertag
7219: </form>
1.633 raeburn 7220: <form name="aliasform" method="post" action="/adm/coursedocs">
7221: <input type="hidden" name="alias" />
7222: <input type="hidden" name="cmd" />
7223: $containertag
7224: </form>
1.484 raeburn 7225:
1.337 ehlerst 7226: HIDDENFORM
1.508 raeburn 7227: $r->print(&makesimpleeditform($pathitem)."\n".
7228: &makedocslogform($pathitem."\n".
1.484 raeburn 7229: '<input type="hidden" name="folder" value="'.
7230: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7231: }
1.442 www 7232:
7233: # Generate the tabs
1.510 raeburn 7234: my ($mode,$needs_end);
1.472 raeburn 7235: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7236: my @folders = split('&',$env{'form.folderpath'});
7237: unless (@folders > 2) {
7238: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7239: $needs_end = 1;
7240: }
1.472 raeburn 7241: } else {
1.484 raeburn 7242: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7243: $needs_end = 1;
1.472 raeburn 7244: }
1.443 www 7245:
1.442 www 7246: #
1.622 raeburn 7247: my $hostname = $r->hostname();
1.442 www 7248: my $savefolderpath;
7249:
1.395 raeburn 7250: if ($allowed) {
1.329 droeschl 7251: my $folder=$env{'form.folder'};
1.615 raeburn 7252: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7253: $folder='default';
1.356 tempelho 7254: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7255: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7256: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7257: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7258: }
7259: my $postexec='';
7260: if ($folder eq 'default') {
1.653 raeburn 7261: my $windowname = 'loncapaclient';
7262: if ($env{'request.lti.login'}) {
7263: $windowname .= 'lti';
7264: }
1.372 bisitz 7265: $r->print('<script type="text/javascript">'."\n"
7266: .'// <![CDATA['."\n"
1.653 raeburn 7267: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7268: .'// ]]>'."\n"
7269: .'</script>'."\n"
1.369 bisitz 7270: );
1.329 droeschl 7271: } else {
7272: #$postexec='self.close();';
7273: }
1.504 raeburn 7274: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7275: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7276: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7277:
7278: my $newnavform=(<<NNFORM);
7279: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7280: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7281: $pathitem
1.329 droeschl 7282: <input type="hidden" name="importdetail"
7283: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7284: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7285: $help{'Navigate_Content'}
7286: </form>
7287: NNFORM
7288: my $newsmppageform=(<<NSPFORM);
7289: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7290: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7291: $pathitem
1.329 droeschl 7292: <input type="hidden" name="importdetail" value="" />
1.423 onken 7293: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7294: $help{'Simple Page'}
1.329 droeschl 7295: </form>
7296: NSPFORM
7297:
7298: my $newsmpproblemform=(<<NSPROBFORM);
7299: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7300: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7301: $pathitem
1.329 droeschl 7302: <input type="hidden" name="importdetail" value="" />
1.423 onken 7303: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7304: $help{'Simple_Problem'}
1.329 droeschl 7305: </form>
7306:
7307: NSPROBFORM
7308:
7309: my $newdropboxform=(<<NDBFORM);
7310: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7311: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7312: $pathitem
1.329 droeschl 7313: <input type="hidden" name="importdetail" value="" />
1.423 onken 7314: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7315: $help{'Dropbox'}
1.344 bisitz 7316: </form>
1.329 droeschl 7317: NDBFORM
7318:
7319: my $newexuploadform=(<<NEXUFORM);
7320: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7321: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7322: $pathitem
1.329 droeschl 7323: <input type="hidden" name="importdetail" value="" />
1.423 onken 7324: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7325: $help{'Score_Upload_Form'}
7326: </form>
7327: NEXUFORM
7328:
7329: my $newbulform=(<<NBFORM);
7330: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7331: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7332: $pathitem
1.329 droeschl 7333: <input type="hidden" name="importdetail" value="" />
1.423 onken 7334: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7335: $help{'Bulletin Board'}
7336: </form>
7337: NBFORM
7338:
7339: my $newaboutmeform=(<<NAMFORM);
7340: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7341: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7342: $pathitem
1.329 droeschl 7343: <input type="hidden" name="importdetail"
7344: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7345: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7346: $help{'My Personal Information Page'}
1.329 droeschl 7347: </form>
7348: NAMFORM
7349:
7350: my $newaboutsomeoneform=(<<NASOFORM);
7351: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7352: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7353: $pathitem
1.329 droeschl 7354: <input type="hidden" name="importdetail" value="" />
1.423 onken 7355: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7356: </form>
7357: NASOFORM
7358:
7359: my $newrosterform=(<<NROSTFORM);
7360: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7361: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7362: $pathitem
1.329 droeschl 7363: <input type="hidden" name="importdetail"
7364: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7365: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7366: $help{'Course_Roster'}
1.329 droeschl 7367: </form>
7368: NROSTFORM
7369:
1.534 raeburn 7370: my $newwebpage;
7371: if ($folder =~ /^default_?(\d*)$/) {
7372: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7373: if ($1) {
7374: $newwebpage .= $1;
7375: } else {
7376: $newwebpage .= 'default';
7377: }
7378: $newwebpage .= '/new.html';
7379: }
7380: my $newwebpageform =(<<NWEBFORM);
7381: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7382: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7383: $pathitem
7384: <input type="hidden" name="importdetail" value="$newwebpage" />
7385: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7386: $help{'Web_Page'}
1.534 raeburn 7387: </form>
7388: NWEBFORM
1.701 raeburn 7389: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7390: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7391: my $machines_str = "'".join("','",@ids)."'";
7392: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7393: if ($env{'user.author'}) {
7394: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7395: $is_home{'author'} = 1;
1.606 raeburn 7396: }
1.691 raeburn 7397: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7398: }
7399: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7400: ['active'],['ca','aa']);
1.691 raeburn 7401: my %by_roletype;
1.606 raeburn 7402: if (keys(%roleshash)) {
7403: foreach my $entry (keys(%roleshash)) {
7404: my ($auname,$audom,$roletype) = split(/:/,$entry);
7405: my $key = $entry;
7406: $key =~ s/:/___/g;
1.691 raeburn 7407: my $author = $auname.'___'.$audom;
7408: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7409: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7410: $toppath{$author} = "/priv/$audom/$auname";
7411: if (grep(/^\Q$rolehome\E$/,@ids)) {
7412: $is_home{$author} = 1;
1.606 raeburn 7413: }
1.691 raeburn 7414: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7415: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7416: }
1.691 raeburn 7417: }
7418: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7419: if (grep(/^\Q$crshome\E$/,@ids)) {
7420: $is_home{'course'} = 1;
7421: }
7422: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7423: my $pickdir = $lt{'loca'}.
7424: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7425: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7426: if ($env{'user.author'}) {
7427: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7428: }
7429: if (keys(%by_roletype)) {
7430: foreach my $possrole ('ca','aa') {
7431: if (ref($by_roletype{$possrole}) eq 'HASH') {
7432: my $roletitle = &Apache::lonnet::plaintext($possrole);
7433: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7434: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7435: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7436: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7437: }
7438: }
7439: }
7440: }
1.706 raeburn 7441: if ($checkcrsres) {
7442: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7443: }
7444: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7445: $lt{'dire'}.
7446: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7447: '<option value=""></option>'.
7448: '</select><br />'."\n";
1.606 raeburn 7449: my %seltemplate_menus;
7450: my @files = &Apache::lonhomework::get_template_list('problem');
7451: my @noexamplelink = ('blank.problem','blank.library','script.library');
7452: my $currentcategory = '';
7453: my @ordered = ('');
7454: my %templatehelp;
7455: my $defcategory = '';
7456: my @catorder = ($defcategory);
7457: $seltemplate_menus{$defcategory}->{'order'} = [''];
7458: $seltemplate_menus{$defcategory}->{'text'} = '';
7459: foreach my $file (@files) {
7460: if (ref($file) eq 'ARRAY') {
7461: my ($path,$title,$category,$help) = @{$file};
7462: next if ($title !~ /\S/);
7463: if (&js_escape($category) ne $currentcategory) {
7464: $currentcategory = &js_escape($category);
7465: push(@catorder,&js_escape($currentcategory));
7466: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7467: $seltemplate_menus{$currentcategory}->{'default'} = '';
7468: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7469: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7470: }
7471: if ($path) {
7472: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7473: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7474: if ($help) {
7475: $templatehelp{$path} = $help;
7476: }
7477: }
7478: }
7479: }
7480:
7481: my $templates = $lt{'cate'}.' '.
7482: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7483: $defcategory,'tempcategory','template',
7484: \%seltemplate_menus,\@catorder,
7485: "resize_scrollbox('contentscroll','1','0');",
7486: "toggleExampleText();",'template').'<br />';
7487: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 7488: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 7489: my $crsresform;
7490: if (($env{'user.author'}) || ($checkcrsres)) {
7491: $crsresform=(<<RESFORM);
1.691 raeburn 7492: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 7493: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 7494: <form action="/adm/coursedocs" method="post" name="courseresform">
7495: <fieldset id="crsresform" style="display:none;">
7496: <legend>$lt{'stpr'}</legend>
1.655 raeburn 7497: <input type="hidden" name="active" value="bb" />
1.606 raeburn 7498: <p>
7499: $pickdir
1.701 raeburn 7500: </p>
1.691 raeburn 7501: <div id="newstdproblem" style="display:none;">
1.701 raeburn 7502: <p>
1.606 raeburn 7503: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 7504: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 7505:
1.611 raeburn 7506: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 7507: </span><span id="newsubdir"></span>
7508: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 7509: </p>
1.699 raeburn 7510: </div>
1.606 raeburn 7511: $lt{'fnam'}
1.611 raeburn 7512: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 7513: <div id="newresource" style="display:none">
1.606 raeburn 7514: <p>
7515: $lt{'addp'}
1.611 raeburn 7516: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7517: $lt{'no'}</label>
1.611 raeburn 7518: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7519: $lt{'yes'}</label>
7520: <span id="newrestitle"></span>
1.611 raeburn 7521: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 7522: </p>
1.606 raeburn 7523: </div>
7524: <p>
7525: $lt{'uste'}
1.611 raeburn 7526: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7527: $lt{'no'}</label>
1.611 raeburn 7528: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7529: $lt{'yes'}</label>
1.701 raeburn 7530: </p>
1.606 raeburn 7531: <div id="newrestemplate" style="display:none">
7532: $templates
7533: $templatepreview
7534: </div>
7535: <span class="LC_nobreak">
1.701 raeburn 7536: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 7537: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 7538: </span>
1.691 raeburn 7539: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 7540: $rolehomes
7541: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7542: </div>
1.606 raeburn 7543: </fieldset>
7544: </form>
7545:
7546: RESFORM
1.706 raeburn 7547: }
1.534 raeburn 7548:
1.342 ehlerst 7549: my $specialdocumentsform;
1.383 tempelho 7550: my @specialdocumentsforma;
1.451 www 7551: my $gradingform;
7552: my @gradingforma;
7553: my $communityform;
7554: my @communityforma;
1.351 ehlerst 7555: my $newfolderform;
1.390 tempelho 7556: my $newfolderb;
1.342 ehlerst 7557:
1.451 www 7558: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 7559:
1.329 droeschl 7560: my $newpageform=(<<NPFORM);
7561: <form action="/adm/coursedocs" method="post" name="newpage">
7562: <input type="hidden" name="folderpath" value="$path" />
7563: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7564: <input type="hidden" name="active" value="ee" />
1.423 onken 7565: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 7566: $help{'Adding_Pages'}
1.329 droeschl 7567: </form>
7568: NPFORM
1.390 tempelho 7569:
7570:
1.351 ehlerst 7571: $newfolderform=(<<NFFORM);
1.329 droeschl 7572: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 7573: $pathitem
1.329 droeschl 7574: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7575: <input type="hidden" name="active" value="" />
1.422 onken 7576: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 7577: </form>
7578: NFFORM
7579:
7580: my $newsylform=(<<NSYLFORM);
7581: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 7582: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7583: $pathitem
1.329 droeschl 7584: <input type="hidden" name="importdetail"
7585: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7586: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 7587: $help{'Syllabus'}
1.383 tempelho 7588:
1.329 droeschl 7589: </form>
7590: NSYLFORM
1.364 bisitz 7591:
1.329 droeschl 7592: my $newgroupfileform=(<<NGFFORM);
7593: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 7594: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7595: $pathitem
1.329 droeschl 7596: <input type="hidden" name="importdetail"
7597: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 7598: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 7599: $help{'Group Portfolio'}
1.329 droeschl 7600: </form>
7601: NGFFORM
1.672 raeburn 7602: if ($container eq 'page') {
7603: @specialdocumentsforma=(
7604: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7605: );
7606: } else {
7607: @specialdocumentsforma=(
1.421 onken 7608: {'<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 7609: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 7610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 7611: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 7612: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 7613: );
7614: }
1.451 www 7615: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
7616:
1.655 raeburn 7617: my @external = (
7618: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 7619: );
1.699 raeburn 7620: if ($posslti) {
1.655 raeburn 7621: push(@external,
7622: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
7623: );
1.598 raeburn 7624: }
1.655 raeburn 7625: my $externalform = &create_form_ul(&create_list_elements(@external));
7626:
7627: my @importdoc = ();
1.519 raeburn 7628: unless ($container eq 'page') {
7629: push(@importdoc,
7630: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
7631: );
7632: }
7633: push(@importdoc,
1.558 raeburn 7634: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 7635: );
1.501 raeburn 7636: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 7637:
1.451 www 7638: @gradingforma=(
7639: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
7640: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 7641: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 7642: );
1.706 raeburn 7643: if ($crsresform) {
7644: push(@gradingforma,
7645: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
7646: );
7647: }
1.451 www 7648: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
7649:
7650: @communityforma=(
7651: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
7652: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
7653: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 7654: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
7655: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 7656: );
7657: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 7658:
1.330 tempelho 7659: my %orderhash = (
1.553 raeburn 7660: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 7661: 'bb' => ['External',$externalform],
7662: 'cc' => ['Import',$importpubform],
1.701 raeburn 7663: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 7664: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 7665: );
1.519 raeburn 7666: unless ($container eq 'page') {
1.434 raeburn 7667: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 7668: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 7669: }
7670:
1.341 ehlerst 7671: $hadchanges=0;
1.484 raeburn 7672: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 7673: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 7674: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 7675: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 7676: undef($navmap);
1.443 www 7677: if ($error) {
7678: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7679: }
1.639 raeburn 7680: if ($hadchanges) {
7681: unless (&is_hash_old()) {
1.638 raeburn 7682: &mark_hash_old();
7683: }
7684: }
1.341 ehlerst 7685:
1.443 www 7686: &changewarning($r,'');
7687: }
1.458 raeburn 7688: }
1.442 www 7689:
1.443 www 7690: # Supplemental documents start here
7691:
1.329 droeschl 7692: my $folder=$env{'form.folder'};
1.443 www 7693: unless ($supplementalflag) {
1.329 droeschl 7694: $folder='supplemental';
7695: }
1.685 raeburn 7696: if (($folder eq 'supplemental') &&
1.329 droeschl 7697: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 7698: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 7699: } elsif ($allowed) {
1.356 tempelho 7700: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 7701: }
1.508 raeburn 7702: $pathitem = '<input type="hidden" name="folderpath" value="'.
7703: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 7704: if ($allowed) {
7705: my $folderseq=
1.504 raeburn 7706: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 7707:
7708: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 7709: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
7710: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 7711: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 7712: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 7713: <legend>$lt{'upfi'}</legend>
1.630 raeburn 7714: <input type="hidden" name="active" value="ee" />
1.329 droeschl 7715: $fileupload
1.702 raeburn 7716: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7717: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 7718: <br />
7719: <br />
7720: <span class="LC_nobreak">
7721: $checkbox
7722: </span>
7723: <br /><br />
7724: $lt{'comment'}:<br />
1.383 tempelho 7725: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 7726: <br />
1.508 raeburn 7727: $pathitem
1.329 droeschl 7728: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 7729: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 7730: </fieldset>
1.501 raeburn 7731: </form>
1.329 droeschl 7732: SUPDOCFORM
7733:
7734: my $supnewfolderform=(<<SNFFORM);
7735: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 7736: <input type="hidden" name="active" value="" />
1.508 raeburn 7737: $pathitem
1.329 droeschl 7738: <input type="hidden" name="importdetail" value="" />
1.423 onken 7739: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 7740: $help{'Adding_Folders'}
1.329 droeschl 7741: </form>
7742: SNFFORM
1.383 tempelho 7743:
1.510 raeburn 7744: my $supextform =
7745: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 7746: $help{'Adding_External_Resource'},
7747: undef,undef,undef,undef,undef,undef,
7748: $disabled);
1.329 droeschl 7749:
1.598 raeburn 7750: my $supexttoolform =
7751: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7752: $help{'Adding_External_Tool'},
7753: undef,undef,'tool',$coursedom,
1.611 raeburn 7754: $coursenum,\%ltitools,$disabled);
1.598 raeburn 7755:
1.329 droeschl 7756: my $supnewsylform=(<<SNSFORM);
7757: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 7758: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7759: $pathitem
1.329 droeschl 7760: <input type="hidden" name="importdetail"
7761: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7762: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 7763: $help{'Syllabus'}
7764: </form>
7765: SNSFORM
7766:
7767: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 7768: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 7769: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7770: $pathitem
1.329 droeschl 7771: <input type="hidden" name="importdetail"
7772: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7773: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 7774: $help{'My Personal Information Page'}
1.329 droeschl 7775: </form>
7776: SNAMFORM
7777:
1.534 raeburn 7778: my $supwebpage;
7779: if ($folder =~ /^supplemental_?(\d*)$/) {
7780: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
7781: if ($1) {
7782: $supwebpage .= $1;
7783: } else {
7784: $supwebpage .= 'default';
7785: }
7786: $supwebpage .= '/new.html';
7787: }
7788: my $supwebpageform =(<<SWEBFORM);
7789: <form action="/adm/coursedocs" method="post" name="supwebpage">
7790: <input type="hidden" name="active" value="cc" />
7791: $pathitem
7792: <input type="hidden" name="importdetail" value="$supwebpage" />
7793: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 7794: $help{'Web_Page'}
1.534 raeburn 7795: </form>
7796: SWEBFORM
7797:
1.333 muellerd 7798:
1.383 tempelho 7799: my @specialdocs = (
1.618 raeburn 7800: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 7801: =>$supnewsylform},
1.611 raeburn 7802: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 7803: =>$supnewaboutmeform},
1.534 raeburn 7804: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7805:
1.383 tempelho 7806: );
1.655 raeburn 7807: my @supexternal = (
7808: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
7809: =>$supextform});
1.699 raeburn 7810: if ($posslti) {
1.655 raeburn 7811: push(@supexternal,
7812: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 7813: =>$supexttoolform});
7814: }
1.655 raeburn 7815: my @supimportdoc = (
1.598 raeburn 7816: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 7817: =>$supupdocform},
1.598 raeburn 7818: );
1.501 raeburn 7819:
7820: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 7821: my %suporderhash = (
1.390 tempelho 7822: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 7823: 'dd' => ['Upload',$supupdocform],
7824: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 7825: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 7826: );
1.443 www 7827: if ($supplementalflag) {
1.682 raeburn 7828: $suppchanges = 0;
7829: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7830: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7831: \%ltitools,$canedit,$hostname);
7832: if ($error) {
7833: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7834: }
7835: if ($suppchanges) {
1.684 raeburn 7836: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7837: undef($suppchanges);
7838: }
1.393 raeburn 7839: }
1.443 www 7840: } elsif ($supplementalflag) {
1.458 raeburn 7841: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7842: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7843: $hostname);
1.393 raeburn 7844: if ($error) {
7845: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7846: }
1.393 raeburn 7847: }
1.389 tempelho 7848:
1.510 raeburn 7849: if ($needs_end) {
7850: $r->print(&endContentScreen());
7851: }
1.383 tempelho 7852:
1.329 droeschl 7853: if ($allowed) {
7854: $r->print('
7855: <form method="post" name="extimport" action="/adm/coursedocs">
7856: <input type="hidden" name="title" />
7857: <input type="hidden" name="url" />
7858: <input type="hidden" name="useform" />
7859: <input type="hidden" name="residx" />
7860: </form>');
7861: }
1.484 raeburn 7862: } elsif ($showdoc) {
1.329 droeschl 7863: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7864: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7865: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7866: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7867: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7868: }
7869: }
1.630 raeburn 7870: unless ($noendpage) {
1.606 raeburn 7871: $r->print(&Apache::loncommon::end_page());
7872: }
1.329 droeschl 7873: return OK;
1.364 bisitz 7874: }
1.329 droeschl 7875:
1.440 raeburn 7876: sub embedded_form_elems {
7877: my ($phase,$primaryurl,$newidx) = @_;
7878: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7879: $newidx =~s /\D+//g;
1.440 raeburn 7880: return <<STATE;
7881: <input type="hidden" name="folderpath" value="$folderpath" />
7882: <input type="hidden" name="cmd" value="upload_embedded" />
7883: <input type="hidden" name="newidx" value="$newidx" />
7884: <input type="hidden" name="phase" value="$phase" />
7885: <input type="hidden" name="primaryurl" value="$primaryurl" />
7886: STATE
7887: }
7888:
7889: sub embedded_destination {
7890: my $folder=$env{'form.folder'};
7891: my $destination = 'docs/';
7892: if ($folder =~ /^supplemental/) {
7893: $destination = 'supplemental/';
7894: }
7895: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7896: $destination .= 'default/';
7897: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7898: $destination .= $2.'/';
7899: }
1.634 raeburn 7900: my $newidx = $env{'form.newidx'};
7901: $newidx =~s /\D+//g;
7902: if ($newidx) {
7903: $destination .= $newidx;
7904: }
1.440 raeburn 7905: my $dir_root = '/userfiles';
7906: return ($destination,$dir_root);
7907: }
7908:
7909: sub return_to_editor {
7910: my $actionurl = '/adm/coursedocs';
7911: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7912: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7913: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7914: '</a></p>';
7915: }
7916:
1.476 raeburn 7917: sub decompression_info {
7918: my ($destination,$dir_root) = &embedded_destination();
7919: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7920: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7921: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7922: my $container='sequence';
1.480 raeburn 7923: my ($pathitem,$hiddenelem);
1.583 raeburn 7924: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7925: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7926: $container='page';
7927: }
1.480 raeburn 7928: unshift(@hiddens,$pathitem);
7929: foreach my $item (@hiddens) {
1.634 raeburn 7930: if ($item eq 'newidx') {
7931: next if ($env{'form.'.$item} =~ /\D/);
7932: }
1.480 raeburn 7933: if ($env{'form.'.$item}) {
7934: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7935: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7936: }
1.477 raeburn 7937: }
1.476 raeburn 7938: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7939: $hiddenelem);
7940: }
7941:
7942: sub decompression_phase_one {
7943: my ($dir,$file,$warning,$error,$output);
7944: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7945: &decompression_info();
1.490 raeburn 7946: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7947: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7948: } else {
7949: my $file = $1;
1.630 raeburn 7950: $output =
1.481 raeburn 7951: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7952: $destination,$dir_root,
7953: $hiddenelem);
7954: if ($env{'form.autoextract_camtasia'}) {
7955: $output .= &remove_archive($docudom,$docuname,$container);
7956: }
1.476 raeburn 7957: }
7958: if ($error) {
7959: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7960: $error.'</p>'."\n";
7961: }
7962: if ($warning) {
7963: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7964: }
7965: return $output;
7966: }
7967:
7968: sub decompression_phase_two {
7969: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7970: &decompression_info();
1.481 raeburn 7971: my $output;
1.480 raeburn 7972: if ($env{'form.archivedelete'}) {
1.481 raeburn 7973: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7974: }
7975: $output .=
1.481 raeburn 7976: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7977: $destination,$dir_root,$hiddenelem);
7978: return $output;
7979: }
7980:
1.480 raeburn 7981: sub remove_archive {
7982: my ($docudom,$docuname,$container) = @_;
7983: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7984: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7985: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7986: if ($fatal) {
7987: if ($container eq 'page') {
7988: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7989: } else {
7990: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7991: }
1.583 raeburn 7992: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7993: } else {
7994: my $currcmd = $env{'form.cmd'};
7995: my $position = $env{'form.position'};
1.583 raeburn 7996: my $archiveidx = $position;
1.563 raeburn 7997: if ($position > 0) {
1.583 raeburn 7998: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7999: $archiveidx = $position-1;
8000: }
8001: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8002: my ($title,$url,@rrest) =
1.583 raeburn 8003: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8004: if ($url eq $env{'form.archiveurl'}) {
8005: if (&handle_edit_cmd($docuname,$docudom)) {
8006: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8007: if ($suppchanges) {
8008: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8009: undef($suppchanges);
8010: }
1.583 raeburn 8011: if ($fatal) {
8012: if ($container eq 'page') {
8013: $delwarning = &mt('An error occurred updating the contents of the current page.');
8014: } else {
8015: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8016: }
1.480 raeburn 8017: } else {
1.583 raeburn 8018: $delresult = &mt('Archive file removed.');
1.480 raeburn 8019: }
8020: }
1.583 raeburn 8021: } else {
8022: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8023: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8024: }
8025: }
8026: $env{'form.cmd'} = $currcmd;
8027: }
8028: if ($delwarning) {
8029: $output = '<p class="LC_warning">'.
8030: $delwarning.
8031: '</p>';
8032: }
8033: if ($delresult) {
8034: $output .= '<p class="LC_info">'.
8035: $delresult.
8036: '</p>';
8037: }
1.481 raeburn 8038: return $output;
1.480 raeburn 8039: }
8040:
1.484 raeburn 8041: sub generate_admin_menu {
1.708 raeburn 8042: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8043: my $lc_crstype = lc($crstype);
8044: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8045: my %lt= ( # do not translate here
1.484 raeburn 8046: 'vc' => 'Verify Content',
8047: 'cv' => 'Check/Set Resource Versions',
8048: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8049: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8050: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8051: 'imse' => 'Export contents to IMS Archive',
1.712 ! raeburn 8052: 'dcd' => 'Copy uploaded content to Authoring Space',
! 8053: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8054: );
1.712 ! raeburn 8055: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8056: if ($home + $other > 0) {
8057: $candump = 'F';
8058: if ($home) {
8059: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 ! raeburn 8060: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8061: } else {
8062: my @hosts;
8063: foreach my $aurole (keys(%outhash)) {
8064: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8065: push(@hosts,$outhash{$aurole});
1.538 raeburn 8066: }
1.484 raeburn 8067: }
8068: if (@hosts == 1) {
8069: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8070: '&role='.
8071: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8072: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8073: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 ! raeburn 8074: $exportcrsurl = $dumpurl;
1.484 raeburn 8075: } else {
8076: $dumpurl = "javascript:choose_switchserver_window()";
1.712 ! raeburn 8077: $exportcrsurl = $dumpurl;
1.484 raeburn 8078: }
8079: }
8080: }
8081: my @menu=
8082: ({ categorytitle=>'Administration',
8083: items =>[
8084: { linktext => $lt{'vc'},
8085: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8086: permission => 'F',
1.571 raeburn 8087: help => 'Docs_Verify_Content',
1.484 raeburn 8088: icon => 'verify.png',
8089: linktitle => 'Verify contents can be retrieved/rendered',
8090: },
8091: { linktext => $lt{'cv'},
8092: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8093: permission => 'F',
1.571 raeburn 8094: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8095: icon => 'resversion.png',
8096: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8097: },
8098: { linktext => $lt{'ls'},
8099: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8100: permission => 'F',
8101: #help => '',
8102: icon => 'symbs.png',
8103: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8104: },
1.651 raeburn 8105: { linktext => $lt{'ct'},
8106: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8107: permission => 'F',
8108: help => 'Docs_Short_URLs',
8109: icon => 'shorturls.png',
8110: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8111: },
1.484 raeburn 8112: ]
1.611 raeburn 8113: });
8114: if ($canedit) {
1.708 raeburn 8115: my ($crsauname,$crsaudom,$crshome);
8116: if (($coursenum ne '') && ($coursedom ne '')) {
8117: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8118: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8119: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8120: my @ids=&Apache::lonnet::current_machine_ids();
8121: my $linkurl;
8122: if (grep(/^\Q$crshome\E$/,@ids)) {
8123: $linkurl = $crsauthorurl;
8124: } else {
8125: $linkurl =
8126: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8127: }
8128: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
8129: push(@{$menu[0]->{items}},
8130: { linktext => $lt{'ca'},
8131: url => $linkurl,
8132: permission => 'F',
8133: help => 'Docs_Course_Authorspace',
8134: icon => 'impcrsau.png',
8135: linktitle => $lt{'ca'},
8136: });
8137: }
8138: }
8139: }
1.611 raeburn 8140: push(@menu,
1.484 raeburn 8141: { categorytitle=>'Export',
8142: items =>[
8143: { linktext => $lt{'imse'},
8144: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8145: permission => 'F',
8146: help => 'Docs_Export_Course_Docs',
8147: icon => 'imsexport.png',
8148: linktitle => $lt{'imse'},
8149: },
8150: { linktext => $lt{'dcd'},
8151: url => $dumpurl,
8152: permission => $candump,
1.571 raeburn 8153: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8154: icon => 'dump.png',
8155: linktitle => $lt{'dcd'},
8156: },
8157: ]
8158: });
1.712 ! raeburn 8159: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
! 8160: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
! 8161: push(@{$menu[1]->{items}},
! 8162: { linktext => $lt{'cpc'},
! 8163: url => $exportcrsurl,
! 8164: permission => 'F',
! 8165: help => 'Docs_Export_Course_Author',
! 8166: icon => 'res.png',
! 8167: linktitle => $lt{'cpc'},
! 8168: });
! 8169: }
! 8170: }
1.611 raeburn 8171: }
1.484 raeburn 8172: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8173: '<input type="hidden" id="dummy" />'."\n".
8174: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8175: '</form>';
1.329 droeschl 8176: }
8177:
8178: sub generate_edit_table {
1.538 raeburn 8179: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8180: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8181: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8182: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8183: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8184: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8185: $activetab = $env{'form.active'};
8186: }
1.611 raeburn 8187: unless ($canedit) {
8188: $disabled = ' disabled="disabled"';
8189: }
1.472 raeburn 8190: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8191: my $backtext = &mt('Exit Editor');
1.458 raeburn 8192: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8193: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8194: '<li class="goback">'.
1.546 raeburn 8195: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8196: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8197: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8198: '<li>'.
8199: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8200: &mt('Undo Delete').'</a></li>'."\n";
8201: if ($env{'form.docslog'}) {
8202: $form .= '<li class="active">';
8203: } else {
8204: $form .= '<li>';
8205: }
8206: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8207: &mt('History').'</a></li>'."\n";
8208: if ($env{'form.docslog'}) {
8209: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8210: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8211: }
1.458 raeburn 8212: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8213: if($name ne '00'){
1.371 tempelho 8214: if($activetab eq '' || $activetab ne $name){
8215: $active = '';
8216: }elsif($activetab eq $name){
8217: $active = 'class="active"';
8218: }
1.458 raeburn 8219: $form .= '<li style="float:right" '.$active
1.484 raeburn 8220: .' 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 8221: } else {
1.570 raeburn 8222: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8223:
8224: }
1.329 droeschl 8225: }
1.484 raeburn 8226: $form .= '</ul>'."\n";
8227: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8228:
8229: if ($to_show ne '') {
1.538 raeburn 8230: my $saveform;
8231: if ($need_save) {
8232: my $button = &mt('Make changes');
8233: my $path;
8234: if ($env{'form.folderpath'}) {
8235: $path =
8236: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8237: }
8238: $saveform = <<"END";
8239: <div id="multisave" style="display:none; clear:both;" >
8240: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8241: <input type="hidden" name="folderpath" value="$path" />
8242: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8243: <input type="hidden" name="allhiddenresource" value="" />
8244: <input type="hidden" name="allencrypturl" value="" />
8245: <input type="hidden" name="allrandompick" value="" />
8246: <input type="hidden" name="allrandomorder" value="" />
8247: <input type="hidden" name="changeparms" value="" />
8248: <input type="hidden" name="multiremove" value="" />
8249: <input type="hidden" name="multicut" value="" />
8250: <input type="hidden" name="multicopy" value="" />
8251: <input type="hidden" name="multichange" value="" />
8252: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8253: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8254: </form>
8255: </div>
8256: END
8257: }
8258: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8259: }
1.363 ehlerst 8260: foreach my $field (keys(%orderhash)){
1.390 tempelho 8261: if($field ne '00'){
1.422 onken 8262: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8263: $active = 'style="display: none;float:left"';
1.422 onken 8264: }elsif($activetab eq $field){
1.458 raeburn 8265: $active = 'style="display:block;float:left"';
1.422 onken 8266: }
8267: $form .= '<div id="'.$field.$tid.'"'
8268: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8269: .'</div>'."\n";
1.363 ehlerst 8270: }
8271: }
1.484 raeburn 8272: unless ($env{'form.docslog'}) {
8273: $form .= '</div></div>'."\n";
8274: }
1.329 droeschl 8275: return $form;
8276: }
8277:
8278: sub editing_js {
1.622 raeburn 8279: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8280: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8281: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8282: p_mnf => 'Name of New Folder',
8283: t_mnf => 'New Folder',
8284: p_mnp => 'Name of New Page',
8285: t_mnp => 'New Page',
1.451 www 8286: p_mxu => 'Title for the External Score',
1.349 biermanm 8287: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8288: p_msb => 'Title for the Problem',
8289: p_mdb => 'Title for the Drop Box',
1.336 schafran 8290: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8291: p_mwp => 'Title for Web Page',
1.606 raeburn 8292: p_mnr => 'Title for the Resource',
1.348 weissno 8293: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8294: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8295: p_mab_alrt1 => 'Not a valid user:domain',
8296: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8297: p_chn => 'New Title',
8298: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8299: p_rmr2a => 'Remove',
8300: p_rmr2b => '?',
8301: p_rmr3a => 'Remove those',
8302: p_rmr3b => 'items?',
8303: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8304: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8305: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8306: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8307: p_ctr2a => 'Cut',
8308: p_ctr2b => '?',
8309: p_ctr3a => 'Cut those',
8310: p_ctr3b => 'items?',
1.633 raeburn 8311: setal => 'Enter a (unique) alias',
8312: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8313: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8314: imsfile => 'You must choose an IMS package for import',
8315: imscms => 'You must select which Course Management System was the source of the IMS package',
8316: invurl => 'Invalid URL',
8317: titbl => 'Title is blank',
1.538 raeburn 8318: more => '(More ...)',
8319: less => '(Less ...)',
1.543 raeburn 8320: noor => 'No actions selected or changes to settings specified.',
8321: noch => 'No changes to settings specified.',
8322: noac => 'No actions selected.',
1.606 raeburn 8323: nofi => 'No file selected',
8324: tinc => 'Title in course',
8325: sunm => 'Sub-directory name',
1.618 raeburn 8326: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8327: sele => 'Select',
8328: swit => 'Switch server required',
1.329 droeschl 8329: );
1.594 damieng 8330: &js_escape(\%js_lt);
1.433 raeburn 8331: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8332: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8333: my $main_container_page;
1.519 raeburn 8334: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8335: $main_container_page = 1;
1.434 raeburn 8336: }
1.617 raeburn 8337: my $backtourl;
8338: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8339: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8340: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8341: my @ids=&Apache::lonnet::current_machine_ids();
8342: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8343: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8344: my $caller = $1;
1.525 raeburn 8345: if ($caller =~ /^supplemental/) {
8346: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8347: } else {
8348: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8349: $res = &Apache::lonnet::clutter($res);
8350: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8351: my ($url,$anchor);
8352: if ($res =~ /^([^#]+)#([^#]+)$/) {
8353: $url = $1;
8354: $anchor = $2;
8355: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8356: $caller = $1.&escape('#').$anchor;
8357: }
1.614 raeburn 8358: } else {
8359: $url = $res;
1.609 raeburn 8360: }
1.640 raeburn 8361: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8362: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8363: $backtourl .= '?navmap=1';
8364: } else {
8365: $backtourl .= '?symb='.
8366: &HTML::Entities::encode($caller,'<>&"');
8367: }
1.622 raeburn 8368: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8369: if (($ENV{'SERVER_PORT'} == 443) &&
8370: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8371: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8372: if ($hostname ne '') {
8373: $backtourl = 'http://'.$hostname.$backtourl;
8374: }
8375: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8376: }
8377: }
1.623 raeburn 8378: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8379: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8380: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8381: if ($hostname ne '') {
8382: $backtourl = 'http://'.$hostname.$backtourl;
8383: }
8384: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8385: }
1.623 raeburn 8386: }
1.622 raeburn 8387: }
1.609 raeburn 8388: if ($anchor ne '') {
8389: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8390: }
1.590 raeburn 8391: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8392: } else {
8393: $backtourl = '/adm/navmaps';
1.525 raeburn 8394: }
8395: }
8396: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8397: $backtourl = '/adm/menu';
8398: } elsif ($supplementalflag) {
1.682 raeburn 8399: if (($env{'request.role.adv'}) ||
8400: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8401: $backtourl = '/adm/supplemental';
8402: } else {
8403: $backtourl = '/adm/navmaps';
8404: }
1.525 raeburn 8405: } else {
8406: $backtourl = '/adm/navmaps';
1.472 raeburn 8407: }
8408:
1.655 raeburn 8409: my $fieldsets = "'doc'";
1.519 raeburn 8410: unless ($main_container_page) {
8411: $fieldsets .=",'ims'";
8412: }
1.655 raeburn 8413: my $extfieldsets = "'ext'";
8414: if ($posslti) {
8415: $extfieldsets .= ",'tool'";
8416: }
1.501 raeburn 8417: if ($supplementalflag) {
1.655 raeburn 8418: $fieldsets = "'suppdoc'";
8419: $extfieldsets = "'suppext'";
1.600 raeburn 8420: if ($posslti) {
1.655 raeburn 8421: $extfieldsets .= ",'supptool'";
1.600 raeburn 8422: }
1.501 raeburn 8423: }
1.655 raeburn 8424:
1.611 raeburn 8425: my $jsmakefunctions;
8426: if ($canedit) {
8427: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8428: function makenewfolder(targetform,folderseq) {
1.594 damieng 8429: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8430: if (foldername) {
1.676 raeburn 8431: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8432: targetform.submit();
8433: }
8434: }
8435:
8436: function makenewpage(targetform,folderseq) {
1.594 damieng 8437: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8438: if (pagename) {
1.676 raeburn 8439: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8440: targetform.submit();
8441: }
8442: }
8443:
8444: function makeexamupload() {
1.594 damieng 8445: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8446: if (title) {
1.329 droeschl 8447: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8448: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8449: this.document.forms.newexamupload.submit();
8450: }
8451: }
8452:
8453: function makesmppage() {
1.594 damieng 8454: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8455: if (title) {
1.329 droeschl 8456: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8457: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8458: this.document.forms.newsmppg.submit();
8459: }
8460: }
8461:
1.534 raeburn 8462: function makewebpage(type) {
1.594 damieng 8463: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8464: var formname;
8465: if (type == 'supp') {
8466: formname = this.document.forms.supwebpage;
8467: } else {
8468: formname = this.document.forms.newwebpage;
8469: }
8470: if (title) {
8471: var webpage = formname.importdetail.value;
1.675 raeburn 8472: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8473: formname.submit();
8474: }
8475: }
8476:
1.329 droeschl 8477: function makesmpproblem() {
1.594 damieng 8478: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 8479: if (title) {
1.329 droeschl 8480: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 8481: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 8482: this.document.forms.newsmpproblem.submit();
8483: }
8484: }
8485:
8486: function makedropbox() {
1.594 damieng 8487: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 8488: if (title) {
1.329 droeschl 8489: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 8490: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 8491: this.document.forms.newdropbox.submit();
8492: }
8493: }
8494:
8495: function makebulboard() {
1.594 damieng 8496: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 8497: if (title) {
8498: this.document.forms.newbul.importdetail.value=
1.676 raeburn 8499: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 8500: this.document.forms.newbul.submit();
8501: }
8502: }
8503:
8504: function makeabout() {
1.594 damieng 8505: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 8506: if (user) {
8507: var comp=new Array();
8508: comp=user.split(':');
8509: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
8510: if ((comp[0]) && (comp[1])) {
8511: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 8512: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 8513: this.document.forms.newaboutsomeone.submit();
8514: } else {
8515: alert("$js_lt{'p_mab_alrt1'}");
8516: }
8517: } else {
8518: alert("$js_lt{'p_mab_alrt2'}");
8519: }
8520: }
8521: }
8522:
8523: function makenew(targetform) {
8524: targetform.submit();
8525: }
8526:
8527: function changename(folderpath,index,oldtitle) {
8528: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8529: if (title) {
8530: this.document.forms.renameform.markcopy.value='';
8531: this.document.forms.renameform.title.value=title;
8532: this.document.forms.renameform.cmd.value='rename_'+index;
8533: this.document.forms.renameform.folderpath.value=folderpath;
8534: this.document.forms.renameform.submit();
8535: }
8536: }
8537:
1.633 raeburn 8538: function setalias(folderpath,index) {
8539: var alias = prompt('$js_lt{"setal"}');
8540: if ((alias != null) && (alias != '')) {
8541: this.document.forms.aliasform.alias.value=alias;
8542: this.document.forms.aliasform.cmd.value='setalias_'+index;
8543: this.document.forms.aliasform.folderpath.value=folderpath;
8544: this.document.forms.aliasform.submit();
8545: }
8546: }
8547:
8548: function delalias(folderpath,index) {
8549: if (confirm('$js_lt{"delal"}')) {
8550: this.document.forms.aliasform.cmd.value='delalias_'+index;
8551: this.document.forms.aliasform.folderpath.value=folderpath;
8552: this.document.forms.aliasform.submit();
8553: }
8554: }
8555:
1.611 raeburn 8556: ENDNEWSCRIPT
8557: } else {
8558: $jsmakefunctions = <<ENDNEWSCRIPT;
8559:
8560: function makenewfolder() {
8561: alert("$js_lt{'edri'}");
8562: }
8563:
8564: function makenewpage() {
8565: alert("$js_lt{'edri'}");
8566: }
8567:
8568: function makeexamupload() {
8569: alert("$js_lt{'edri'}");
8570: }
8571:
8572: function makesmppage() {
8573: alert("$js_lt{'edri'}");
8574: }
8575:
8576: function makewebpage(type) {
8577: alert("$js_lt{'edri'}");
8578: }
8579:
8580: function makesmpproblem() {
8581: alert("$js_lt{'edri'}");
8582: }
8583:
8584: function makedropbox() {
8585: alert("$js_lt{'edri'}");
8586: }
8587:
8588: function makebulboard() {
8589: alert("$js_lt{'edri'}");
8590: }
8591:
8592: function makeabout() {
8593: alert("$js_lt{'edri'}");
8594: }
8595:
8596: function changename() {
8597: alert("$js_lt{'edri'}");
8598: }
8599:
1.633 raeburn 8600: function setalias() {
8601: alert("$js_lt{'edri'}");
8602: }
8603:
8604: function delalias() {
8605: alert("$js_lt{'edri'}");
8606: }
8607:
1.611 raeburn 8608: function makenew() {
8609: alert("$js_lt{'edri'}");
8610: }
8611:
8612: function groupimport() {
8613: alert("$js_lt{'edri'}");
1.335 ehlerst 8614: }
1.611 raeburn 8615:
8616: function groupsearch() {
8617: alert("$js_lt{'edri'}");
1.335 ehlerst 8618: }
1.611 raeburn 8619:
8620: function groupopen(url,recover) {
8621: var options="scrollbars=1,resizable=1,menubar=0";
8622: idxflag=1;
8623: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
8624: idx.focus();
1.329 droeschl 8625: }
8626:
1.611 raeburn 8627: ENDNEWSCRIPT
8628:
8629: }
8630: return <<ENDSCRIPT;
8631:
8632: $jsmakefunctions
8633:
1.501 raeburn 8634: function toggleUpload(caller) {
8635: var blocks = Array($fieldsets);
8636: for (var i=0; i<blocks.length; i++) {
8637: var disp = 'none';
8638: if (caller == blocks[i]) {
8639: var curr = document.getElementById('upload'+caller+'form').style.display;
8640: if (curr == 'none') {
8641: disp='block';
8642: }
8643: }
8644: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 8645: }
8646: resize_scrollbox('contentscroll','1','1');
8647: return;
8648: }
8649:
8650: function toggleExternal(caller) {
8651: var blocks = Array($extfieldsets);
8652: for (var i=0; i<blocks.length; i++) {
8653: var disp = 'none';
8654: if (caller == blocks[i]) {
8655: var curr = document.getElementById('external'+caller+'form').style.display;
8656: if (curr == 'none') {
8657: disp='block';
8658: }
8659: }
8660: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 8661: if ((caller == 'tool') || (caller == 'supptool')) {
8662: if (disp == 'block') {
1.655 raeburn 8663: if (document.getElementById('LC_exttoolid')) {
8664: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 8665: var suppflag = 0;
8666: if (caller == 'supptool') {
8667: suppflag = 1;
8668: }
8669: currForm = document.getElementById('new'+caller);
1.655 raeburn 8670: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 8671: }
8672: }
8673: }
1.501 raeburn 8674: }
1.502 raeburn 8675: resize_scrollbox('contentscroll','1','1');
8676: return;
8677: }
8678:
1.514 raeburn 8679: function toggleMap(caller) {
1.502 raeburn 8680: var disp = 'none';
1.510 raeburn 8681: if (document.getElementById('importmapform')) {
1.514 raeburn 8682: if (caller == 'map') {
8683: var curr = document.getElementById('importmapform').style.display;
8684: if (curr == 'none') {
8685: disp='block';
8686: }
1.510 raeburn 8687: }
8688: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 8689: if (disp == 'block') {
8690: if (document.getElementById('importcrsresform')) {
8691: if (document.getElementById('importcrsresform').style.display == 'block') {
8692: document.getElementById('importcrsresform').style.display = 'none';
8693: }
8694: }
8695: }
1.510 raeburn 8696: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 8697: }
1.501 raeburn 8698: return;
1.329 droeschl 8699: }
8700:
1.691 raeburn 8701: function toggleCrsRes(caller) {
1.606 raeburn 8702: var disp = 'none';
8703: if (document.getElementById('crsresform')) {
8704: if (caller == 'res') {
1.691 raeburn 8705: var form = document.getElementById('crsresform');
8706: var curr = form.style.display;
1.606 raeburn 8707: if (curr == 'none') {
8708: disp='block';
1.691 raeburn 8709: document.courseresform.authorrole.selectedIndex = 0;
8710: document.courseresform.authorpath.selectedIndex = 0;
8711: document.courseresform.newresourceadd.selectedIndex = 0;
8712: populateDirSelects(form,'authorrole','authorpath',1,0,0);
8713: toggleNewInCourse(document.courseresform);
8714: if (document.getElementById('newresource')) {
8715: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 8716: }
8717: if (document.courseresform.newresusetemp.length) {
8718: document.courseresform.newresusetemp[0].checked = true;
8719: toggleWithTemplate(document.courseresform);
8720: }
8721: document.courseresform.newresourcename.value = '';
8722: }
8723: }
8724: if (document.courseresform.newsubdir.length) {
8725: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
8726: if (document.courseresform.newsubdir[j].value == 0) {
8727: document.courseresform.newsubdir[j].checked = true;
8728: }
8729: break;
8730: }
8731: if (document.getElementById('newsubdirname')) {
8732: document.getElementById('newsubdirname').type = "hidden";
8733: document.getElementById('newsubdirname').value = "";
8734: }
8735: if (document.getElementById('newsubdir')) {
8736: document.getElementById('newsubdir').innerHTML = "";
8737: }
8738: }
8739: document.getElementById('crsresform').style.display=disp;
8740: resize_scrollbox('contentscroll','1','0');
8741: }
8742: return;
8743: }
8744:
8745: function toggleNewsubdir(form) {
8746: if (form.newsubdir.length) {
8747: for (var j=0; j<form.newsubdir.length; j++) {
8748: if (form.newsubdir[j].checked) {
8749: if (document.getElementById('newsubdirname')) {
8750: if (form.newsubdir[j].value == '1') {
8751: document.getElementById('newsubdirname').type = "text";
8752: if (document.getElementById('newsubdir')) {
8753: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
8754: }
8755: } else {
8756: document.getElementById('newsubdirname').type = "hidden";
8757: document.getElementById('newsubdirname').value = "";
8758: document.getElementById('newsubdir').innerHTML = "";
8759: }
8760: }
8761: break;
8762: }
8763: }
8764: }
8765: }
8766:
8767: function toggleCrsResTitle() {
8768: if (document.getElementById('newresource')) {
1.691 raeburn 8769: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8770: if (selloc == 'course') {
1.606 raeburn 8771: document.getElementById('newresource').style.display = 'inline';
8772: document.courseresform.newresourceadd[0].checked = true;
8773: toggleNewInCourse(document.courseresform);
8774: } else {
8775: document.getElementById('newresource').style.display = 'none';
8776: }
1.689 raeburn 8777: }
8778: if (document.getElementById('newstdproblem')) {
8779: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8780: document.getElementById('newstdproblem').style.display = 'none';
8781: if (document.getElementById('stdprobswitch')) {
8782: document.getElementById('stdprobswitch').style.display = 'block';
8783: }
8784: } else {
8785: document.getElementById('newstdproblem').style.display = 'block';
8786: if (document.getElementById('stdprobswitch')) {
8787: document.getElementById('stdprobswitch').style.display = 'none';
8788: }
8789: }
8790: }
1.606 raeburn 8791: }
8792:
8793: function toggleNewInCourse(form) {
8794: if (form.newresourceadd.length) {
8795: for (var i=0; i<form.newresourceadd.length; i++) {
8796: if (form.newresourceadd[i].checked) {
8797: if (document.getElementById('newresourcetitle')) {
8798: if (form.newresourceadd[i].value == '1') {
8799: document.getElementById('newresourcetitle').type = 'text';
8800: if (document.getElementById('newrestitle')) {
8801: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
8802: }
8803: } else {
8804: document.getElementById('newresourcetitle').type = 'hidden';
8805: document.getElementById('newresourcetitle').value = '';
8806: if (document.getElementById('newrestitle')) {
8807: document.getElementById('newrestitle').innerHTML = '';
8808: }
8809: }
8810: }
8811: break;
8812: }
8813: }
8814: }
8815: }
8816:
8817: function toggleWithTemplate(form) {
8818: if (form.newresusetemp.length) {
8819: for (var i=0; i<form.newresusetemp.length; i++) {
8820: if (form.newresusetemp[i].checked) {
8821: if (document.getElementById('newrestemplate')) {
8822: if (form.newresusetemp[i].value == '1') {
8823: document.getElementById('newrestemplate').style.display = 'inline';
8824: toggleExampleText();
8825: } else {
8826: form.tempcategory.selectedIndex = 0;
8827: select1template_changed();
8828: document.getElementById('newrestemplate').style.display = 'none';
8829: }
8830: }
8831: }
8832: }
8833: }
8834: }
8835:
8836: function toggleExampleText() {
8837: if (document.getElementById('newresexample')) {
8838: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8839: if (url == '') {
8840: document.getElementById('newresexample').style.fontWeight = 'normal';
8841: } else {
8842: document.getElementById('newresexample').style.fontWeight = 'bold';
8843: }
8844: }
8845: }
8846:
8847: function getExample(width,height,scrolling,transparency) {
8848: var url;
8849: if (document.courseresform.newresusetemp.length) {
8850: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
8851: if (document.courseresform.newresusetemp[i].checked) {
8852: if (document.courseresform.newresusetemp[i].value == '1') {
8853: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8854: if (url == '') {
8855: alert('Pick a category and template');
8856: } else {
8857: url = url.replace("$londocroot","");
8858: url += '?inhibitmenu=yes';
8859: }
8860: }
8861: break;
8862: }
8863: }
8864: }
8865: if (url != '') {
8866: openMyModal(url,width,height,scrolling,transparency,'');
8867: }
8868: }
8869:
1.690 raeburn 8870: function toggleImportCrsres(caller) {
1.606 raeburn 8871: var disp = 'none';
8872: if (document.getElementById('importcrsresform')) {
8873: if (caller == 'res') {
8874: var curr = document.getElementById('importcrsresform').style.display;
8875: if (curr == 'none') {
8876: disp='block';
1.698 raeburn 8877: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
8878: if ((document.getElementById('importcrsrescontent')) &&
8879: (document.getElementById('importcrsresempty'))) {
8880: var selelem = document.crsresimportform.elements['coursepath'];
8881: var numdirs = 0;
8882: if (selelem.options.length) {
8883: numdirs = selelem.options.length - 1;
8884: }
8885: if (numdirs) {
8886: document.getElementById('importcrsrescontent').style.display='block';
8887: document.getElementById('importcrsresempty').style.display='none';
8888: } else {
8889: document.getElementById('importcrsrescontent').style.display='none';
8890: document.getElementById('importcrsresempty').style.display='block';
8891: }
8892: }
1.606 raeburn 8893: }
8894: }
8895: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 8896: if (disp == 'block') {
8897: if (document.getElementById('importmapform')) {
8898: if (document.getElementById('importmapform').style.display == 'block') {
8899: document.getElementById('importmapform').style.display = 'none';
8900: }
8901: }
8902: }
1.606 raeburn 8903: resize_scrollbox('contentscroll','1','0');
8904: }
8905: return;
8906: }
8907:
1.690 raeburn 8908: $showfile_js
8909:
1.691 raeburn 8910: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8911: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8912: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8913: var selelem = form.elements[dirsel];
8914: var i, numfiles = selelem.options.length -1;
8915: if (numfiles >=0) {
8916: for (i = numfiles; i >= 0; i--) {
8917: selelem.remove(i);
8918: }
8919: }
8920: if ((location == '') || (location == null) || (location == 'undefined')) {
8921: if (selelem.options.length == 0) {
8922: selelem.options[selelem.options.length] = new Option('','');
8923: selelem.selectedIndex = 0;
8924: }
8925: if (document.getElementById('newstdproblem')) {
8926: document.getElementById('newstdproblem').style.display = 'none';
8927: }
8928: return;
8929: }
8930: var machineIds = new Array($machines_str);
8931: var athome = 0;
8932: var role = location;
8933: if ((location == 'author') || (location == 'course')) {
8934: if (document.getElementById('rolehome_'+location)) {
8935: var currhome = document.getElementById('rolehome_'+location).value;
8936: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8937: if (machineIds.includes(currhome)) {
8938: athome = 1;
8939: }
8940: }
8941: }
8942: } else {
8943: const roleinfo = location.split('___');
8944: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8945: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8946: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8947: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8948: if (machineIds.includes(currhome)) {
8949: athome = 1;
8950: }
8951: }
8952: }
8953: }
1.706 raeburn 8954: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 8955: if (athome) {
8956: if (document.getElementById('stdprobswitch')) {
8957: document.getElementById('stdprobswitch').style.display = 'none';
8958: }
8959: if (document.getElementById('newstdproblem')) {
8960: document.getElementById('newstdproblem').style.display = 'none';
8961: }
1.706 raeburn 8962: var canedit = '$canedit';
8963: if (canedit) {
8964: if (templateradio.length > 1) {
8965: for (var i=0; i<templateradio.length; i++) {
8966: templateradio[i].disabled = false;
8967: }
8968: }
8969: document.courseresform.newresourcename.disabled = false;
8970: document.courseresform.newcrs.disabled = false;
8971: }
1.691 raeburn 8972: var http = new XMLHttpRequest();
8973: var url = "/adm/courseauthor";
1.698 raeburn 8974: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8975: http.open("POST", url, true);
8976: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8977: http.onreadystatechange = function() {
8978: if (http.readyState == 4 && http.status == 200) {
8979: var data = JSON.parse(http.responseText);
8980: if (Array.isArray(data.dirs)) {
8981: var len = data.dirs.length;
8982: if (len) {
8983: if (len > 1) {
8984: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8985: }
8986: }
8987: if (len) {
8988: var j;
8989: for (j = 0; j < len; j++) {
8990: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8991: }
8992: selelem.selectedIndex = 0;
1.697 raeburn 8993: if (len == 1) {
8994: toggleCrsResTitle();
8995: }
1.691 raeburn 8996: }
8997: }
8998: }
8999: }
9000: http.send(params);
9001: } else {
9002: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9003: selelem.selectedIndex = 0;
9004: if (document.getElementById('stdprobswitch')) {
9005: document.getElementById('stdprobswitch').style.display = 'block';
9006: }
9007: if (document.getElementById('newstdproblem')) {
9008: document.getElementById('newstdproblem').style.display = 'none';
9009: }
1.706 raeburn 9010: if (templateradio.length > 1) {
9011: for (var i=0; i<templateradio.length; i++) {
9012: templateradio[i].disabled = true;
9013: }
9014: }
9015: document.courseresform.newresourcename.disabled = true;
9016: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9017: }
9018: }
9019: return;
9020: }
9021:
1.689 raeburn 9022: function switchForProb() {
9023: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9024: var url = '/adm/switchserver?otherserver=';
9025: var newhostid = '';
9026: var role = '';
9027: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9028: if (selloc == 'author') {
9029: newhostid = document.courseresform.rolehome_author.value;
9030: role = "au./&js_escape($env{'user.domain'})/";
9031: } else if (selloc == 'course') {
9032: newhostid = document.courseresform.rolehome_course.value;
9033: role = "&js_escape($env{'request.role'})";
9034: } else {
9035: var items = new Array();
9036: items = selloc.split('___');
9037: var len = document.courseresform.rolehome_coauthor.length;
9038: if (null == len) {
9039: var currval = document.courseresform.rolehome_coauthor.value;
9040: if (null != currval) {
9041: var info = new Array();
9042: info = currval.split('=');
9043: newhostid = info[2];
9044: role = info[0]+'./'+info[1];
9045: }
9046: } else {
9047: for (var i=0; i<len; i++) {
9048: var currval = document.courseresform.rolehome_coauthor[i].value;
9049: if (null != currval) {
9050: var info = new Array();
9051: info = currval.split('=');
9052: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9053: newhostid = info[2];
9054: role = info[0]+'./'+info[1];
9055: break;
9056: }
9057: }
9058: }
9059: }
9060: }
9061: if (newhostid != '') {
9062: url += newhostid;
9063: if (role != '') {
9064: url += '&role='+role;
9065: }
9066: document.location.href = url;
9067: }
9068: }
9069: return;
9070: }
9071:
1.501 raeburn 9072: function makeims(imsform) {
9073: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9074: alert("$js_lt{'imsfile'}");
1.501 raeburn 9075: return;
9076: }
9077: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9078: alert("$js_lt{'imscms'}");
1.501 raeburn 9079: return;
9080: }
9081: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9082: imsform.submit();
9083: }
9084:
1.478 raeburn 9085: function updatePick(targetform,index,caller) {
1.537 raeburn 9086: var pickitem;
9087: var picknumitem;
9088: var picknumtext;
9089: if (index == 'all') {
9090: pickitem = document.getElementById('randompickall');
9091: picknumitem = document.getElementById('rpicknumall');
9092: picknumtext = document.getElementById('rpicktextall');
9093: } else {
9094: pickitem = document.getElementById('randompick_'+index);
9095: picknumitem = document.getElementById('rpicknum_'+index);
9096: picknumtext = document.getElementById('randompicknum_'+index);
9097: }
1.478 raeburn 9098: if (pickitem.checked) {
1.594 damieng 9099: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9100: if (picknum == '' || picknum == null) {
9101: if (caller == 'check') {
9102: pickitem.checked=false;
1.537 raeburn 9103: if (index == 'all') {
9104: picknumtext.innerHTML = '';
9105: if (caller == 'link') {
9106: propagateState(targetform,'rpicknum');
9107: }
9108: } else {
1.538 raeburn 9109: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9110: }
1.478 raeburn 9111: }
9112: } else {
9113: picknum.toString();
9114: var regexdigit=/^\\d+\$/;
9115: if (regexdigit.test(picknum)) {
9116: picknumitem.value = picknum;
1.537 raeburn 9117: if (index == 'all') {
1.538 raeburn 9118: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9119: if (caller == 'link') {
9120: propagateState(targetform,'rpicknum');
9121: }
9122: } else {
9123: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9124: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9125: }
1.478 raeburn 9126: } else {
9127: if (caller == 'check') {
1.537 raeburn 9128: if (index == 'all') {
9129: picknumtext.innerHTML = '';
9130: if (caller == 'link') {
9131: propagateState(targetform,'rpicknum');
9132: }
9133: } else {
9134: pickitem.checked=false;
1.538 raeburn 9135: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9136: }
1.478 raeburn 9137: }
9138: return;
9139: }
9140: }
9141: } else {
1.537 raeburn 9142: picknumitem.value = '';
9143: picknumtext.innerHTML = '';
9144: if (index == 'all') {
9145: if (caller == 'link') {
9146: propagateState(targetform,'rpicknum');
9147: }
9148: } else {
1.538 raeburn 9149: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9150: }
9151: }
9152: }
9153:
9154: function propagateState(form,param) {
9155: if (document.getElementById(param+'all')) {
9156: var setcheck = 0;
9157: var rpick = 0;
9158: if (param == 'rpicknum') {
9159: if (document.getElementById('randompickall')) {
9160: if (document.getElementById('randompickall').checked) {
9161: if (document.getElementById('rpicknumall')) {
9162: rpick = document.getElementById('rpicknumall').value;
9163: }
9164: }
9165: }
9166: } else {
9167: if (document.getElementById(param+'all').checked) {
9168: setcheck = 1;
9169: }
9170: }
1.538 raeburn 9171: var allidxlist;
9172: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9173: if (document.getElementById('all'+param+'idx')) {
9174: allidxlist = document.getElementById('all'+param+'idx').value;
9175: }
9176: var actions = new Array ('remove','cut','copy');
9177: for (var i=0; i<actions.length; i++) {
9178: if (actions[i] != param) {
9179: if (document.getElementById(actions[i]+'all')) {
9180: document.getElementById(actions[i]+'all').checked = false;
9181: }
9182: }
9183: }
9184: }
1.537 raeburn 9185: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9186: allidxlist = form.allidx.value;
9187: }
9188: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9189: allidxlist = form.allmapidx.value;
9190: }
9191: if ((allidxlist != '') && (allidxlist != null)) {
9192: var allidxs = allidxlist.split(',');
9193: if (allidxs.length > 1) {
9194: for (var i=0; i<allidxs.length; i++) {
9195: if (document.getElementById(param+'_'+allidxs[i])) {
9196: if (param == 'rpicknum') {
9197: if (document.getElementById('randompick_'+allidxs[i])) {
9198: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9199: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9200: if (rpick > 0) {
9201: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9202: } else {
9203: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9204: }
9205: }
9206: }
9207: } else {
1.537 raeburn 9208: if (setcheck == 1) {
9209: document.getElementById(param+'_'+allidxs[i]).checked = true;
9210: } else {
9211: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9212: if (param == 'randompick') {
9213: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9214: }
1.537 raeburn 9215: }
9216: }
9217: }
9218: }
1.538 raeburn 9219: if (setcheck == 1) {
9220: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9221: var actions = new Array('copy','cut','remove');
9222: for (var i=0; i<actions.length; i++) {
9223: var otheractions;
9224: var otheridxs;
9225: if (actions[i] === param) {
9226: continue;
9227: } else {
9228: if (document.getElementById('all'+actions[i]+'idx')) {
9229: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9230: otheridxs = otheractions.split(',');
9231: if (otheridxs.length > 1) {
9232: for (var j=0; j<otheridxs.length; j++) {
9233: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9234: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9235: }
1.537 raeburn 9236: }
9237: }
9238: }
1.538 raeburn 9239: }
9240: }
9241: }
9242: }
9243: }
9244: }
9245: }
9246: return;
9247: }
9248:
1.603 raeburn 9249: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9250: var canedit = '$canedit';
9251: if (canedit == '') {
9252: alert("$js_lt{'edri'}");
9253: return;
9254: }
1.539 raeburn 9255: var dosettings;
9256: var doaction;
1.538 raeburn 9257: var control = document.togglemultsettings;
9258: if (context == 'actions') {
9259: control = document.togglemultactions;
1.539 raeburn 9260: doaction = 1;
9261: } else {
9262: dosettings = 1;
1.538 raeburn 9263: }
1.539 raeburn 9264: if (control) {
9265: if (control.showmultpick.length) {
9266: for (var i=0; i<control.showmultpick.length; i++) {
9267: if (control.showmultpick[i].checked) {
9268: if (control.showmultpick[i].value == 1) {
9269: if (context == 'settings') {
9270: dosettings = 0;
9271: } else {
9272: doaction = 0;
1.538 raeburn 9273: }
9274: }
9275: }
1.537 raeburn 9276: }
9277: }
1.539 raeburn 9278: }
9279: if (context == 'settings') {
9280: if (dosettings == 1) {
1.538 raeburn 9281: targetform.changeparms.value=param;
9282: targetform.submit();
9283: }
1.537 raeburn 9284: }
1.539 raeburn 9285: if (context == 'actions') {
9286: if (doaction == 1) {
9287: targetform.cmd.value=param+'_'+index;
9288: targetform.folderpath.value=folderpath;
9289: targetform.markcopy.value=idx+':'+param;
9290: targetform.copyfolder.value=folder+'.'+container;
9291: if (param == 'remove') {
1.603 raeburn 9292: var doremove = 0;
9293: if (skip_confirm) {
9294: if (confirm_removal) {
9295: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9296: doremove = 1;
9297: }
9298: } else {
9299: doremove = 1;
9300: }
9301: } else {
9302: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9303: doremove = 1;
9304: }
9305: }
9306: if (doremove) {
1.539 raeburn 9307: targetform.markcopy.value='';
9308: targetform.copyfolder.value='';
9309: targetform.submit();
9310: }
9311: }
9312: if (param == 'cut') {
1.594 damieng 9313: 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 9314: targetform.submit();
9315: return;
9316: }
9317: }
9318: if (param == 'copy') {
9319: targetform.submit();
9320: return;
9321: }
9322: targetform.markcopy.value='';
9323: targetform.copyfolder.value='';
9324: targetform.cmd.value='';
9325: targetform.folderpath.value='';
9326: return;
9327: } else {
9328: if (document.getElementById(param+'_'+idx)) {
9329: item = document.getElementById(param+'_'+idx);
9330: if (item.type == 'checkbox') {
9331: if (item.checked) {
9332: item.checked = false;
9333: } else {
9334: item.checked = true;
9335: singleCheck(item,idx,param);
9336: }
9337: }
9338: }
9339: }
9340: }
1.537 raeburn 9341: return;
9342: }
9343:
1.538 raeburn 9344: function singleCheck(caller,idx,action) {
9345: actions = new Array('cut','copy','remove');
9346: if (caller.checked) {
9347: for (var i=0; i<actions.length; i++) {
9348: if (actions[i] != action) {
9349: if (document.getElementById(actions[i]+'_'+idx)) {
9350: if (document.getElementById(actions[i]+'_'+idx).checked) {
9351: document.getElementById(actions[i]+'_'+idx).checked = false;
9352: }
1.537 raeburn 9353: }
9354: }
9355: }
1.478 raeburn 9356: }
1.537 raeburn 9357: return;
1.478 raeburn 9358: }
9359:
1.334 muellerd 9360: function unselectInactive(nav) {
1.335 ehlerst 9361: currentNav = document.getElementById(nav);
9362: currentLis = currentNav.getElementsByTagName('LI');
9363: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9364: if (currentLis[i].className == 'goback') {
9365: currentLis[i].className = 'goback';
9366: } else {
9367: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9368: currentLis[i].className = 'right';
1.472 raeburn 9369: } else {
1.374 tempelho 9370: currentLis[i].className = 'i';
1.472 raeburn 9371: }
9372: }
1.335 ehlerst 9373: }
1.332 tempelho 9374: }
9375:
1.334 muellerd 9376: function hideAll(current, nav, data) {
1.335 ehlerst 9377: unselectInactive(nav);
1.570 raeburn 9378: if (current) {
9379: if (current.className == 'right'){
9380: current.className = 'right active'
9381: } else {
9382: current.className = 'active';
9383: }
1.374 tempelho 9384: }
1.335 ehlerst 9385: currentData = document.getElementById(data);
9386: currentDivs = currentData.getElementsByTagName('DIV');
9387: for (i = 0; i < currentDivs.length; i++) {
9388: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9389: currentDivs[i].style.display = 'none';
1.330 tempelho 9390: }
9391: }
1.335 ehlerst 9392: }
1.330 tempelho 9393:
1.374 tempelho 9394: function openTabs(pageId) {
9395: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9396: if(tabnav.length > 2 ){
1.389 tempelho 9397: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9398: currentLis = currentNav.getElementsByTagName('LI');
9399: for(i = 0; i< currentLis.length; i++){
9400: if(currentLis[i].className == 'active') {
1.375 tempelho 9401: funcString = currentLis[i].onclick.toString();
9402: tab = funcString.split('"');
1.420 onken 9403: if(tab.length < 2) {
9404: tab = funcString.split("'");
9405: }
1.375 tempelho 9406: currentData = document.getElementById(tab[1]);
9407: currentData.style.display = 'block';
1.374 tempelho 9408: }
9409: }
9410: }
9411: }
9412:
1.334 muellerd 9413: function showPage(current, pageId, nav, data) {
1.570 raeburn 9414: currstate = current.className;
1.334 muellerd 9415: hideAll(current, nav, data);
1.375 tempelho 9416: openTabs(pageId);
1.334 muellerd 9417: unselectInactive(nav);
1.570 raeburn 9418: if ((currstate == 'active') || (currstate == 'right active')) {
9419: if (currstate == 'active') {
9420: current.className = '';
9421: } else {
9422: current.className = 'right';
9423: }
9424: activeTab = '';
1.656 raeburn 9425: toggleExternal();
1.570 raeburn 9426: toggleUpload();
9427: toggleMap();
1.606 raeburn 9428: toggleCrsRes();
9429: toggleImportCrsres();
1.570 raeburn 9430: resize_scrollbox('contentscroll','1','0');
9431: return;
9432: } else {
9433: current.className = 'active';
9434: }
1.330 tempelho 9435: currentData = document.getElementById(pageId);
9436: currentData.style.display = 'block';
1.458 raeburn 9437: activeTab = pageId;
1.656 raeburn 9438: toggleExternal();
1.501 raeburn 9439: toggleUpload();
1.503 raeburn 9440: toggleMap();
1.606 raeburn 9441: toggleCrsRes();
9442: toggleImportCrsres();
1.433 raeburn 9443: if (nav == 'mainnav') {
9444: var storedpath = "$docs_folderpath";
1.434 raeburn 9445: var storedpage = "$main_container_page";
1.433 raeburn 9446: var reg = new RegExp("^supplemental");
9447: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9448: if (storedpage == 1) {
9449: document.simpleedit.folderpath.value = '';
9450: document.uploaddocument.folderpath.value = '';
9451: } else {
9452: if (reg.test(storedpath)) {
9453: document.simpleedit.folderpath.value = '$toplevelmain';
9454: document.uploaddocument.folderpath.value = '$toplevelmain';
9455: document.newext.folderpath.value = '$toplevelmain';
9456: } else {
9457: document.simpleedit.folderpath.value = storedpath;
9458: document.uploaddocument.folderpath.value = storedpath;
9459: document.newext.folderpath.value = storedpath;
9460: }
1.433 raeburn 9461: }
9462: } else {
1.434 raeburn 9463: if (reg.test(storedpath)) {
9464: document.simpleedit.folderpath.value = storedpath;
9465: document.supuploaddocument.folderpath.value = storedpath;
9466: document.supnewext.folderpath.value = storedpath;
9467: } else {
1.433 raeburn 9468: document.simpleedit.folderpath.value = '$toplevelsupp';
9469: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9470: document.supnewext.folderpath.value = '$toplevelsupp';
9471: }
9472: }
9473: }
1.485 raeburn 9474: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9475: return false;
9476: }
1.329 droeschl 9477:
1.472 raeburn 9478: function toContents(jumpto) {
9479: var newurl = '$backtourl';
1.525 raeburn 9480: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 9481: newurl = newurl+'?postdata='+jumpto;
9482: }
9483: location.href=newurl;
9484: }
9485:
1.538 raeburn 9486: function togglePick(caller,value) {
9487: var disp = 'none';
9488: if (document.getElementById('multi'+caller)) {
9489: var curr = document.getElementById('multi'+caller).style.display;
9490: if (value == 1) {
9491: disp='block';
9492: }
9493: if (curr == disp) {
9494: return;
9495: }
9496: document.getElementById('multi'+caller).style.display=disp;
9497: if (value == 1) {
1.594 damieng 9498: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9499: } else {
9500: document.getElementById('more'+caller).innerHTML = '';
9501: }
9502: if (caller == 'actions') {
9503: setClass(value);
9504: setBoxes(value);
9505: }
9506: }
9507: var showButton = multiSettings();
9508: if (showButton != 1) {
9509: showButton = multiActions();
9510: }
9511: if (document.getElementById('multisave')) {
9512: if (showButton == 1) {
9513: document.getElementById('multisave').style.display='block';
9514: } else {
9515: document.getElementById('multisave').style.display='none';
9516: }
9517: }
9518: resize_scrollbox('contentscroll','1','1');
9519: return;
9520: }
9521:
9522: function toggleCheckUncheck(caller,more) {
9523: if (more == 1) {
1.594 damieng 9524: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 9525: document.getElementById('allfields'+caller).style.display='block';
9526: } else {
1.594 damieng 9527: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9528: document.getElementById('allfields'+caller).style.display='none';
9529: }
9530: resize_scrollbox('contentscroll','1','1');
9531: }
9532:
9533: function multiSettings() {
9534: var inuse = 0;
9535: var settingsform = document.togglemultsettings;
9536: if (settingsform.showmultpick.length > 1) {
9537: for (var i=0; i<settingsform.showmultpick.length; i++) {
9538: if (settingsform.showmultpick[i].checked) {
9539: if (settingsform.showmultpick[i].value == 1) {
9540: inuse = 1;
9541: }
9542: }
9543: }
9544: }
9545: return inuse;
9546: }
9547:
9548: function multiActions() {
9549: var inuse = 0;
9550: var actionsform = document.togglemultactions;
9551: if (actionsform.showmultpick.length > 1) {
9552: for (var i=0; i<actionsform.showmultpick.length; i++) {
9553: if (actionsform.showmultpick[i].checked) {
9554: if (actionsform.showmultpick[i].value == 1) {
9555: inuse = 1;
9556: }
9557: }
9558: }
9559: }
9560: return inuse;
9561: }
9562:
9563: function checkSubmits() {
9564: var numchanges = 0;
9565: var form = document.saveactions;
9566: var doactions = multiActions();
1.542 raeburn 9567: var cutwarnings = 0;
9568: var remwarnings = 0;
1.603 raeburn 9569: var removalinfo = 0;
1.538 raeburn 9570: if (doactions == 1) {
9571: var remidxlist = document.cumulativeactions.allremoveidx.value;
9572: if ((remidxlist != '') && (remidxlist != null)) {
9573: var remidxs = remidxlist.split(',');
9574: for (var i=0; i<remidxs.length; i++) {
9575: if (document.getElementById('remove_'+remidxs[i])) {
9576: if (document.getElementById('remove_'+remidxs[i]).checked) {
9577: form.multiremove.value += remidxs[i]+',';
9578: numchanges ++;
1.542 raeburn 9579: if (document.getElementById('skip_remove_'+remidxs[i])) {
9580: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9581: remwarnings ++;
9582: }
9583: }
1.603 raeburn 9584: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9585: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9586: removalinfo ++;
9587: }
9588: }
1.537 raeburn 9589: }
9590: }
1.538 raeburn 9591: }
9592: }
9593: var cutidxlist = document.cumulativeactions.allcutidx.value;
9594: if ((cutidxlist != '') && (cutidxlist != null)) {
9595: var cutidxs = cutidxlist.split(',');
9596: for (var i=0; i<cutidxs.length; i++) {
9597: if (document.getElementById('cut_'+cutidxs[i])) {
9598: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9599: form.multicut.value += cutidxs[i]+',';
9600: numchanges ++;
1.542 raeburn 9601: if (document.getElementById('skip_cut_'+cutidxs[i])) {
9602: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
9603: cutwarnings ++;
9604: }
9605: }
1.537 raeburn 9606: }
9607: }
9608: }
9609: }
1.538 raeburn 9610: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9611: if ((copyidxlist != '') && (copyidxlist != null)) {
9612: var copyidxs = copyidxlist.split(',');
9613: for (var i=0; i<copyidxs.length; i++) {
9614: if (document.getElementById('copy_'+copyidxs[i])) {
9615: if (document.getElementById('copy_'+copyidxs[i]).checked) {
9616: form.multicopy.value += copyidxs[i]+',';
9617: numchanges ++;
9618: }
9619: }
9620: }
9621: }
9622: if (numchanges > 0) {
9623: form.multichange.value = numchanges;
9624: }
1.537 raeburn 9625: }
1.538 raeburn 9626: var dosettings = multiSettings();
1.543 raeburn 9627: var haschanges = 0;
1.538 raeburn 9628: if (dosettings == 1) {
9629: form.allencrypturl.value = '';
9630: form.allhiddenresource.value = '';
1.543 raeburn 9631: form.changeparms.value = 'all';
9632: var patt=new RegExp(",\$");
1.538 raeburn 9633: var allidxlist = document.cumulativesettings.allidx.value;
9634: if ((allidxlist != '') && (allidxlist != null)) {
9635: var allidxs = allidxlist.split(',');
9636: if (allidxs.length > 1) {
9637: for (var i=0; i<allidxs.length; i++) {
9638: if (document.getElementById('hiddenresource_'+allidxs[i])) {
9639: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
9640: form.allhiddenresource.value += allidxs[i]+',';
9641: }
9642: }
9643: if (document.getElementById('encrypturl_'+allidxs[i])) {
9644: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
9645: form.allencrypturl.value += allidxs[i]+',';
9646: }
9647: }
9648: }
1.543 raeburn 9649: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
9650: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 9651: }
1.538 raeburn 9652: }
9653: form.allrandompick.value = '';
9654: form.allrandomorder.value = '';
9655: var allmapidxlist = document.cumulativesettings.allmapidx.value;
9656: if ((allmapidxlist != '') && (allmapidxlist != null)) {
9657: var allmapidxs = allmapidxlist.split(',');
9658: for (var i=0; i<allmapidxs.length; i++) {
9659: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
9660: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
9661: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
9662: if ((randompick.checked) && (rpicknum.value != '')) {
9663: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
9664: }
9665: if (randorder.checked) {
9666: form.allrandomorder.value += allmapidxs[i]+',';
9667: }
1.537 raeburn 9668: }
1.543 raeburn 9669: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
9670: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
9671: }
9672: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
9673: haschanges = 1;
9674: }
9675: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
9676: haschanges = 1;
9677: }
9678: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
9679: haschanges = 1;
9680: }
9681: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
9682: haschanges = 1;
1.537 raeburn 9683: }
9684: }
1.543 raeburn 9685: if (doactions == 1) {
1.542 raeburn 9686: if (numchanges > 0) {
1.603 raeburn 9687: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 9688: if (remwarnings > 0) {
1.594 damieng 9689: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 9690: return false;
9691: }
9692: }
1.603 raeburn 9693: if (removalinfo > 0) {
9694: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
9695: return false;
9696: }
9697: }
1.542 raeburn 9698: if (cutwarnings > 0) {
1.594 damieng 9699: 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 9700: return false;
9701: }
9702: }
9703: }
9704: form.submit();
9705: return true;
1.543 raeburn 9706: }
9707: }
9708: if (dosettings == 1) {
9709: if (haschanges == 1) {
1.542 raeburn 9710: form.submit();
9711: return true;
9712: }
1.543 raeburn 9713: }
9714: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 9715: alert("$js_lt{'noor'}");
1.543 raeburn 9716: } else {
9717: if (dosettings == 1) {
1.594 damieng 9718: alert("$js_lt{'noch'}");
1.543 raeburn 9719: } else {
1.594 damieng 9720: alert("$js_lt{'noac'}");
1.543 raeburn 9721: }
9722: }
1.538 raeburn 9723: return false;
9724: }
9725:
9726: function setClass(value) {
9727: var cutclass = 'LC_docs_cut';
9728: var copyclass = 'LC_docs_copy';
9729: var removeclass = 'LC_docs_remove';
9730: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
9731: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
9732: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
9733: var links = document.getElementsByTagName('a');
9734: for (var i=0; i<links.length; i++) {
9735: var classes = links[i].className;
9736: if (cutreg.test(classes)) {
9737: links[i].className = cutclass;
9738: if (value == 1) {
9739: links[i].className += " LC_menubuttons_link";
9740: }
9741: } else {
9742: if (copyreg.test(classes)) {
9743: links[i].className = copyclass;
9744: if (value == 1) {
9745: links[i].className += " LC_menubuttons_link";
9746: }
9747: } else {
9748: if (removereg.test(classes)) {
9749: links[i].className = removeclass;
9750: if (value == 1) {
9751: links[i].className += " LC_menubuttons_link";
9752: }
9753: }
9754: }
9755: }
9756: }
9757: return;
1.537 raeburn 9758: }
9759:
1.538 raeburn 9760: function setBoxes(value) {
9761: var remidxlist = document.cumulativeactions.allremoveidx.value;
9762: if ((remidxlist != '') && (remidxlist != null)) {
9763: var remidxs = remidxlist.split(',');
9764: for (var i=0; i<remidxs.length; i++) {
9765: if (document.getElementById('remove_'+remidxs[i])) {
9766: var item = document.getElementById('remove_'+remidxs[i]);
9767: if (value == 1) {
9768: item.className = 'LC_docs_remove';
9769: } else {
9770: item.className = 'LC_hidden';
9771: }
9772: }
9773: }
9774: }
9775: var cutidxlist = document.cumulativeactions.allcutidx.value;
9776: if ((cutidxlist != '') && (cutidxlist != null)) {
9777: var cutidxs = cutidxlist.split(',');
9778: for (var i=0; i<cutidxs.length; i++) {
9779: if (document.getElementById('cut_'+cutidxs[i])) {
9780: var item = document.getElementById('cut_'+cutidxs[i]);
9781: if (value == 1) {
9782: item.className = 'LC_docs_cut';
9783: } else {
9784: item.className = 'LC_hidden';
9785: }
9786: }
1.537 raeburn 9787: }
9788: }
1.538 raeburn 9789: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9790: if ((copyidxlist != '') && (copyidxlist != null)) {
9791: var copyidxs = copyidxlist.split(',');
9792: for (var i=0; i<copyidxs.length; i++) {
9793: if (document.getElementById('copy_'+copyidxs[i])) {
9794: var item = document.getElementById('copy_'+copyidxs[i]);
9795: if (value == 1) {
9796: item.className = 'LC_docs_copy';
9797: } else {
9798: item.className = 'LC_hidden';
9799: }
9800: }
1.537 raeburn 9801: }
9802: }
9803: return;
9804: }
9805:
1.606 raeburn 9806: function validImportCrsRes() {
9807: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
9808: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
9809: if ((fname == '') || (fname == null)) {
9810: alert("$js_lt{'nofi'}");
9811: return false;
9812: }
9813: var url = '/res/$coursedom/$coursenum/';
9814: if (path && path != '/') {
9815: url += path+'/';
9816: }
9817: if (fname != '') {
9818: url += fname;
9819: }
9820: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 9821: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 9822: return true;
9823: }
9824:
9825: function validateNewRes(caller) {
9826: if (caller == 'single') {
9827: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9828: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
9829: var resname = document.courseresform.newresourcename.value;
9830: }
9831: }
9832:
1.611 raeburn 9833: ENDSCRIPT
1.329 droeschl 9834: }
1.457 raeburn 9835:
1.483 raeburn 9836: sub history_tab_js {
9837: return <<"ENDHIST";
9838: function toggleHistoryDisp(choice) {
9839: document.docslogform.docslog.value = choice;
9840: document.docslogform.submit();
9841: return;
9842: }
9843:
9844: ENDHIST
9845: }
9846:
1.484 raeburn 9847: sub inject_data_js {
9848: return <<ENDINJECT;
9849:
9850: function injectData(current, hiddenField, name, value) {
9851: currentElement = document.getElementById(hiddenField);
9852: currentElement.name = name;
9853: currentElement.value = value;
9854: current.submit();
9855: }
9856:
9857: ENDINJECT
9858: }
9859:
9860: sub dump_switchserver_js {
9861: my @hosts = @_;
1.594 damieng 9862: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 9863: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 9864: swit => 'Switch server?',
1.594 damieng 9865: );
9866: my %html_js_lt = &Apache::lonlocal::texthash(
9867: swit => 'Switch server?',
1.709 raeburn 9868: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 9869: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
9870: chos => 'Choose server',
9871: );
1.594 damieng 9872: &js_escape(\%js_lt);
9873: &html_escape(\%html_js_lt);
9874: &js_escape(\%html_js_lt);
1.484 raeburn 9875: my $role = $env{'request.role'};
9876: my $js = <<"ENDSWJS";
9877: <script type="text/javascript">
9878: function write_switchserver() {
9879: var server;
9880: if (document.setserver.posshosts.length > 0) {
9881: for (var i=0; i<document.setserver.posshosts.length; i++) {
9882: if (document.setserver.posshosts[i].checked) {
9883: server = document.setserver.posshosts[i].value;
9884: }
9885: }
9886: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
9887: }
9888: window.close();
9889: }
9890: </script>
9891:
9892: ENDSWJS
9893:
9894: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
9895: {'only_body' => 1,
9896: 'js_ready' => 1,});
9897: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
9898:
9899: my $hostpicker;
9900: my $count = 0;
9901: foreach my $host (sort(@hosts)) {
9902: my $checked;
9903: if ($count == 0) {
9904: $checked = ' checked="checked"';
9905: }
9906: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9907: $host.'"'.$checked.' />'.$host.'</label> ';
9908: $count++;
9909: }
9910:
9911: return <<"ENDSWITCHJS";
9912:
9913: function dump_needs_switchserver(url) {
9914: if (url!='' && url!= null) {
1.594 damieng 9915: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 9916: go(url);
9917: }
9918: }
9919: return;
9920: }
9921:
9922: function choose_switchserver_window() {
9923: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9924: newWindow.document.open();
9925: newWindow.document.writeln('$startpage');
1.594 damieng 9926: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9927: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9928: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9929: '<form name="setserver" method="post" action="" \\/>\\n'+
9930: '$hostpicker\\n'+
9931: '<br \\/><br \\/>\\n'+
1.594 damieng 9932: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9933: 'onclick="write_switchserver();" \\/>\\n'+
9934: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9935: newWindow.document.writeln('$endpage');
9936: newWindow.document.close();
9937: newWindow.focus();
9938: }
9939:
9940: ENDSWITCHJS
9941: }
9942:
9943: sub makedocslogform {
9944: my ($formelems,$docslog) = @_;
9945: return <<"LOGSFORM";
9946: <form action="/adm/coursedocs" method="post" name="docslogform">
9947: <input type="hidden" name="docslog" value="$docslog" />
9948: $formelems
9949: </form>
9950: LOGSFORM
9951: }
9952:
9953: sub makesimpleeditform {
9954: my ($formelems) = @_;
9955: return <<"SIMPFORM";
9956: <form name="simpleedit" method="post" action="/adm/coursedocs">
9957: <input type="hidden" name="importdetail" value="" />
9958: $formelems
9959: </form>
9960: SIMPFORM
9961: }
9962:
1.606 raeburn 9963: sub makenewproblem {
9964: my ($r,$coursedom,$coursenum) = @_;
9965: # Creating a new problem
9966: my ($redirect,$error);
9967: if ($env{'form.authorrole'}) {
9968: my ($newsubdir,$filename);
9969: if ($env{'form.newsubdir'}) {
9970: if ($env{'form.newsubdirname'} ne '') {
9971: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9972: }
1.606 raeburn 9973: }
9974: if ($env{'form.newresourcename'}) {
9975: $filename = $env{'form.newresourcename'};
9976: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9977: $filename =~ s/`//g;
9978: $filename =~ s{/\.\./}{_}g;
9979: $filename =~ s/\.+/./g;
9980: $filename =~ s{/+}{_}g;
9981: if ($filename ne '') {
9982: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9983: if (($ext) && ($ext ne '.problem')) {
9984: $filename = $name.'.problem';
9985: } elsif ($ext eq '') {
9986: $filename .= '.problem';
9987: }
9988: my $docroot = $r->dir_config('lonDocRoot');
9989: my @ids=&Apache::lonnet::current_machine_ids();
9990: if ($env{'form.authorrole'} eq 'author') {
9991: if ($env{'user.author'}) {
9992: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9993: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9994: my $path = $docroot.$url;
9995: my $subdir = $env{'form.authorpath'};
9996: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9997: }
9998: }
9999: } elsif ($env{'form.authorrole'} eq 'course') {
10000: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10001: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10002: my $url = "/priv/$coursedom/$coursenum";
10003: my $path=$docroot.$url;
10004: my $subdir = $env{'form.authorpath'};
10005: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10006: if ($redirect) {
10007: my $rightsfile = 'default.rights';
10008: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10009: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10010: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10011: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10012: if (!-e "$docroot/res/$coursedom") {
10013: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10014: }
1.654 raeburn 10015: if (!-e "$docroot/res/$coursedom/$coursenum") {
10016: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10017: }
10018: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10019: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10020: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10021: }
10022: }
1.654 raeburn 10023: my $source = $docroot.$redirect;
10024: if (!-e "$source.meta") {
10025: my $cid = $coursedom.'_'.$coursenum;
10026: my $now = time;
10027: if (open(my $fh,">$source.meta")) {
10028: my $author=$env{'environment.firstname'}.' '.
10029: $env{'environment.middlename'}.' '.
10030: $env{'environment.lastname'}.' '.
10031: $env{'environment.generation'};
10032: $author =~ s/\s+$//;
10033: my $title = $env{'form.newresourcetitle'};
10034: $title =~ s/^\s+|\s+$//g;
10035: print $fh <<END;
1.606 raeburn 10036:
10037: <abstract></abstract>
10038: <author>$author</author>
10039: <authorspace>$coursenum:$coursedom</authorspace>
10040: <copyright>custom</copyright>
10041: <creationdate>$now</creationdate>
10042: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10043: <dependencies></dependencies>
10044: <domain>$coursedom</domain>
10045: <highestgradelevel>0</highestgradelevel>
10046: <keywords></keywords>
10047: <language>notset </language>
10048: <lastrevisiondate>$now</lastrevisiondate>
10049: <lowestgradelevel>0</lowestgradelevel>
10050: <mime>problem</mime>
10051: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10052: <notes></notes>
10053: <obsolete></obsolete>
10054: <obsoletereplacement></obsoletereplacement>
10055: <owner>$coursenum:$coursedom</owner>
10056: <sourceavail></sourceavail>
10057: <standards></standards>
10058: <subject></subject>
10059: <title>$title</title>
10060: END
1.654 raeburn 10061: close($fh);
1.606 raeburn 10062: }
10063: }
10064: }
10065: }
10066: } else {
10067: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10068: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10069: if (grep(/^\Q$rolehome\E$/,@ids)) {
10070: my $now = time;
10071: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10072: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10073: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10074: my $url = "/priv/$audom/$auname";
10075: my $path = $r->dir_config('lonDocRoot').$url;
10076: my $subdir = $env{'form.authorpath'};
10077: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10078: }
10079: }
10080: }
10081: }
10082: }
10083: }
10084: }
10085: return ($redirect,$error);
10086: }
10087:
10088: sub finishnewprob {
1.654 raeburn 10089: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10090: unless (-d $path) {
10091: unless (mkdir($path,02770)) {
10092: return;
10093: }
10094: }
1.606 raeburn 10095: my $redirect;
10096: if ($subdir ne '/') {
10097: $subdir = &cleandir($subdir);
10098: if (($subdir ne '') && (-d "$path/$subdir")) {
10099: $path .= "/$subdir";
10100: $url .= "/$subdir";
10101: }
10102: }
10103: my $dest;
10104: if ($newsubdir ne '') {
10105: $newsubdir = &cleandir($newsubdir);
10106: }
10107: if ($newsubdir ne '') {
10108: if (-d "$path/$newsubdir") {
10109: $dest = "$path/$newsubdir/$filename";
10110: } else {
10111: my $dirok;
10112: unless (-e "$path/$newsubdir") {
10113: if (mkdir("$path/$newsubdir",02770)) {
10114: if (chmod(02770,"$path/$newsubdir")) {
10115: $dirok = 1;
10116: }
10117: }
10118: }
10119: if ($dirok) {
10120: $dest = "$path/$newsubdir/$filename";
10121: }
10122: }
10123: if (($dest ne '') && (!-e $dest)) {
10124: $redirect = "$url/$newsubdir/$filename";
10125: }
10126: } else {
10127: $dest = "$path/$filename";
10128: if (($dest ne '') && (!-e $dest)) {
10129: $redirect = "$url/$filename";
10130: }
10131: }
1.654 raeburn 10132: if ((!-e $dest) && ($context ne 'upload')) {
10133: my $template = $env{'form.template'};
10134: my $copyfrom;
10135: if ($template ne '') {
10136: my %templates;
10137: my @files = &Apache::lonhomework::get_template_list('problem');
10138: foreach my $poss (@files) {
10139: if (ref($poss) eq 'ARRAY') {
10140: if ($template eq $poss->[0]) {
10141: $templates{$template} = 1;
10142: last;
10143: }
10144: }
10145: }
10146: if ($templates{$template}) {
10147: $copyfrom = $template;
10148: }
10149: }
10150: if ($filename =~ /\.problem$/) {
10151: unless ($copyfrom) {
10152: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10153: }
10154: &File::Copy::copy($copyfrom,$dest);
10155: }
10156: }
1.606 raeburn 10157: return $redirect;
10158: }
10159:
10160: sub cleandir {
10161: my ($dir) = @_;
10162: $dir =~ s/^\s+//;
10163: $dir =~ s/\s+$//;
10164: $dir =~ s/\.+//g;
10165: $dir =~ s/[\#\?&%\":]//g;
10166: return $dir;
10167: }
10168:
1.329 droeschl 10169: 1;
10170: __END__
10171:
10172:
10173: =head1 NAME
10174:
10175: Apache::londocs.pm
10176:
10177: =head1 SYNOPSIS
10178:
10179: This is part of the LearningOnline Network with CAPA project
10180: described at http://www.lon-capa.org.
10181:
10182: =head1 SUBROUTINES
10183:
10184: =over
10185:
10186: =item %help=()
10187:
10188: Available help topics
10189:
10190: =item mapread()
10191:
1.344 bisitz 10192: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10193: @order and @resources, determines status
10194: sets @order - pointer to resources in right order
10195: sets @resources - array with the resources with correct idx
10196:
10197: =item authorhosts()
10198:
10199: Return hash with valid author names
10200:
10201: =item clean()
10202:
10203: =item dumpcourse()
10204:
10205: Actually dump course
10206:
10207: =item group_import()
10208:
10209: Imports the given (name, url) resources into the course
10210: coursenum, coursedom, and folder must precede the list
10211:
10212: =item breadcrumbs()
10213:
10214: =item log_docs()
10215:
10216: =item docs_change_log()
10217:
10218: =item update_paste_buffer()
10219:
10220: =item print_paste_buffer()
10221:
10222: =item do_paste_from_buffer()
10223:
1.538 raeburn 10224: =item do_buffer_empty()
10225:
10226: =item clear_from_buffer()
10227:
1.492 raeburn 10228: =item get_newmap_url()
10229:
10230: =item dbcopy()
10231:
10232: =item uniqueness_check()
10233:
10234: =item contained_map_check()
10235:
10236: =item url_paste_fixups()
10237:
10238: =item apply_fixups()
10239:
10240: =item copy_dependencies()
10241:
1.329 droeschl 10242: =item update_parameter()
10243:
10244: =item handle_edit_cmd()
10245:
10246: =item editor()
10247:
10248: =item process_file_upload()
10249:
10250: =item process_secondary_uploads()
10251:
10252: =item is_supplemental_title()
10253:
10254: =item entryline()
10255:
10256: =item tiehash()
10257:
10258: =item untiehash()
10259:
10260: =item checkonthis()
10261:
10262: check on this
10263:
10264: =item verifycontent()
10265:
10266: Verify Content
10267:
1.636 raeburn 10268: =item devalidateversioncache()
10269:
10270: =item checkversions()
1.329 droeschl 10271:
10272: Check Versions
10273:
10274: =item mark_hash_old()
10275:
10276: =item is_hash_old()
10277:
10278: =item changewarning()
10279:
10280: =item init_breadcrumbs()
10281:
10282: Breadcrumbs for special functions
10283:
1.484 raeburn 10284: =item create_list_elements()
10285:
10286: =item create_form_ul()
10287:
10288: =item startContentScreen()
10289:
10290: =item endContentScreen()
10291:
10292: =item supplemental_base()
10293:
10294: =item embedded_form_elems()
10295:
10296: =item embedded_destination()
10297:
10298: =item return_to_editor()
10299:
10300: =item decompression_info()
10301:
10302: =item decompression_phase_one()
10303:
10304: =item decompression_phase_two()
10305:
10306: =item remove_archive()
10307:
10308: =item generate_admin_menu()
10309:
10310: =item generate_edit_table()
10311:
10312: =item editing_js()
10313:
10314: =item history_tab_js()
10315:
10316: =item inject_data_js()
10317:
10318: =item dump_switchserver_js()
10319:
1.485 raeburn 10320: =item resize_scrollbox_js()
1.484 raeburn 10321:
10322: =item makedocslogform()
10323:
1.485 raeburn 10324: =item makesimpleeditform()
10325:
1.329 droeschl 10326: =back
10327:
10328: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>