Annotation of loncom/interface/londocs.pm, revision 1.711
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.711 ! raeburn 4: # $Id: londocs.pm,v 1.710 2024/06/07 14:37:55 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.651 raeburn 48: use Apache::loncourserespicker();
1.329 droeschl 49: use HTML::Entities;
1.488 raeburn 50: use HTML::TokeParser;
1.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) {
271: $r->print(&endContentScreen());
272: return '';
273: }
1.329 droeschl 274: my $origcrsid=$env{'request.course.id'};
275: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
276: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
277: # Do the dumping
1.484 raeburn 278: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
279: $r->print(&endContentScreen());
280: return '';
281: }
1.531 raeburn 282: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 283: $r->print('<h3>'.&mt('Copying Files').'</h3>');
284: my $title=$env{'form.authorfolder'};
285: $title=&clean($title);
1.567 raeburn 286: my ($navmap,$errormsg) =
287: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
288: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
289: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
290: my (%maps,%resources,%titles);
291: if (!ref($navmap)) {
292: $r->print($errormsg.
293: &endContentScreen());
294: return '';
295: } else {
296: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
297: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 298: }
1.567 raeburn 299: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
300: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
301: %newcontent,%has_simpleprobs);
302: foreach my $item (sort {$a <=> $b} (@todump)) {
303: my $name = $env{'form.namefor_'.$item};
304: if ($resources{$item}) {
305: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
306: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
307: $tocopy{$1} = $name;
308: $display{$item} = $1;
309: $lookup{$1} = $item;
310: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
311: $simpleproblems{$item} = {
312: symb => $resources{$item},
313: name => $name,
314: };
315: $display{$item} = 'simpleproblem_'.$name;
316: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
317: $has_simpleprobs{$1}{$id} = $item;
318: }
319: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
320: my $marker = $1;
321: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
322: $simplepages{$item} = {
323: res => $res,
324: title => $titles{$item},
325: db => $db_name,
326: marker => $marker,
327: symb => $resources{$item},
328: name => $name,
329: };
330: $display{$item} = '/'.$res;
331: }
332: } elsif ($maps{$item}) {
333: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
334: $tocopy{$1} = $name;
335: $display{$item} = $1;
336: $lookup{$1} = $item;
337: }
338: } else {
339: next;
340: }
341: }
1.329 droeschl 342: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
343: $crs=~s/\_/\//g;
1.567 raeburn 344: my $mm = new File::MMagic;
345: my $prefix = "/uploaded/$cdom/$cnum/";
346: %replacehash = %tocopy;
347: foreach my $item (sort(keys(%simpleproblems))) {
348: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
349: $newcontent{$display{$item}} = $content;
350: }
351: my $gateway = Apache::lonhtmlgateway->new('web');
352: foreach my $item (sort(keys(%simplepages))) {
353: if (ref($simplepages{$item}) eq 'HASH') {
354: my $pagetitle = $simplepages{$item}{'title'};
355: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
356: my %contents;
357: foreach my $field (keys(%fields)) {
358: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
359: my $name = $1;
360: my $msg = $fields{$field};
361: if ($name eq 'webreferences') {
362: if ($msg =~ m{^https?://}) {
363: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
364: }
365: } else {
366: $msg = &Encode::decode('utf8',$msg);
367: $msg = $gateway->process_outgoing_html($msg,1);
368: $contents{$name} = $msg;
369: }
370: } elsif ($field eq 'uploaded.photourl') {
371: my $marker = $simplepages{$item}{marker};
372: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
373: my $filepath = $1;
374: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
375: if ($fname ne '') {
376: $fname=~s/\.(\w+)$//;
377: my $ext=$1;
378: $fname = &clean($fname);
379: $fname.='.'.$ext;
380: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
381: $replacehash{$filepath} = $relpath.$fname;
382: $deps{$item}{$filepath} = 1;
383: }
384: }
385: }
386: }
387: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
388: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
389: my $content = '
390: <html>
391: <head>
392: <title>'.$pagetitle.'</title>
393: </head>
394: <body bgcolor="#ffffff">';
395: if ($contents{title}) {
396: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
397: }
398: if ($contents{image}) {
399: $content .= "\n".$contents{image};
400: }
401: if ($contents{content}) {
402: $content .= '
403: <div class="LC_Box">
1.577 bisitz 404: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 405: $contents{content}.'
406: </div>';
407: }
408: if ($contents{webreferences}) {
409: $content .= '
410: <div class="LC_Box">
1.577 bisitz 411: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 412: $contents{webreferences}.'
413: </div>';
414: }
415: $content .= '
416: </body>
417: </html>
418: ';
419: $newcontent{'/'.$simplepages{$item}{res}} = $content;
420: }
421: }
422: foreach my $item (keys(%tocopy)) {
423: unless ($item=~/\.(sequence|page)$/) {
424: my $currurlpath = $prefix.$item;
425: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
426: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
427: }
428: }
429: foreach my $num (sort {$a <=> $b} (@todump)) {
430: my $src = $display{$num};
431: next if ($src eq '');
432: my @needcopy = ();
433: if ($replacehash{$src}) {
434: push(@needcopy,$src);
435: if (ref($deps{$num}) eq 'HASH') {
436: foreach my $dep (sort(keys(%{$deps{$num}}))) {
437: if ($replacehash{$dep}) {
438: push(@needcopy,$dep);
439: }
440: }
441: }
442: } elsif ($src =~ /^simpleproblem_/) {
443: push(@needcopy,$src);
444: }
445: next if (@needcopy == 0);
446: my ($result,$depresult);
447: for (my $i=0; $i<@needcopy; $i++) {
448: my $item = $needcopy[$i];
449: my $newfilename;
450: if ($simpleproblems{$num}) {
451: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
452: } else {
453: $newfilename=$title.'/'.$replacehash{$item};
454: }
455: $newfilename=~s/\.(\w+)$//;
456: my $ext=$1;
457: $newfilename=&clean($newfilename);
458: $newfilename.='.'.$ext;
459: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
460: if ($newrelpath ne $replacehash{$item}) {
461: $replacehash{$item} = $newrelpath;
462: }
463: my @dirs=split(/\//,$newfilename);
464: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
465: my $makepath=$path;
466: my $fail;
467: my $origin;
468: for (my $i=0;$i<$#dirs;$i++) {
469: $makepath.='/'.$dirs[$i];
470: unless (-e $makepath) {
471: unless(mkdir($makepath,0755)) {
472: $fail = &mt('Directory creation failed.');
473: }
474: }
475: }
476: if ($i == 0) {
477: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
478: } else {
479: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
480: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
481: &mt('(dependency)').'</span>: ';
482: }
483: if (-e $path.'/'.$newfilename) {
484: $fail = &mt('Destination already exists -- not overwriting.');
485: } else {
486: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
487: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
488: ($item =~ /^simpleproblem_/)) {
489: print $fh $newcontent{$item};
490: } else {
491: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
492: if (-e $fileloc) {
493: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
494: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
495: (ref($has_simpleprobs{$item}) eq 'HASH')) {
496: my %changes = %{$has_simpleprobs{$item}};
497: my $content = &Apache::lonclonecourse::rewritefile(
498: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
499: (%replacehash,$crs => '')
500: );
501: my $updatedcontent = '';
502: my $parser = HTML::TokeParser->new(\$content);
503: $parser->attr_encoded(1);
504: while (my $token = $parser->get_token) {
505: if ($token->[0] eq 'S') {
506: if (($token->[1] eq 'resource') &&
507: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
508: ($changes{$token->[2]->{'id'}})) {
509: my $id = $token->[2]->{'id'};
510: $updatedcontent .= '<'.$token->[1];
511: foreach my $attrib (@{$token->[3]}) {
512: next unless ($attrib =~ /^(src|type|title|id)$/);
513: if ($attrib eq 'src') {
514: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
515: if ($file) {
516: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
517: } else {
518: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
519: }
520: } else {
521: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
522: }
523: }
524: $updatedcontent .= ' />'."\n";
525: } else {
526: $updatedcontent .= $token->[4]."\n";
527: }
528: } else {
529: $updatedcontent .= $token->[2];
530: }
531: }
532: print $fh $updatedcontent;
533: } else {
534: print $fh &Apache::lonclonecourse::rewritefile(
535: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
536: (%replacehash,$crs => '')
537: );
538: }
539: } else {
540: print $fh
541: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
542: }
543: } else {
544: $fail = &mt('Source does not exist.');
545: }
546: }
547: $fh->close();
548: } else {
549: $fail = &mt('Could not write to destination.');
550: }
551: }
552: my $text;
553: if ($fail) {
554: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
555: } else {
556: $text = '<span class="LC_success">'.&mt('ok').'</span>';
557: }
558: if ($i == 0) {
559: $result .= $text;
560: } else {
561: $depresult .= $text.'</li>';
562: }
563: }
564: $r->print($result);
565: if ($depresult) {
566: $r->print('<ul>'.$depresult.'</ul>');
567: }
568: }
569: } else {
570: my ($navmap,$errormsg) =
571: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
572: if (!ref($navmap)) {
573: $r->print($errormsg);
574: } else {
575: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
576: $r->rflush();
577: my ($preamble,$formname);
578: $formname = 'dumpdoc';
579: unless ($home==1) {
580: $preamble = '<div class="LC_left_float">'.
581: '<fieldset><legend>'.
582: &mt('Select the Authoring Space').
583: '</legend><select name="authorspace">';
1.329 droeschl 584: }
1.567 raeburn 585: my @orderspaces = ();
586: foreach my $key (sort(keys(%outhash))) {
587: if ($key=~/^home_(.+)$/) {
588: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
589: unshift(@orderspaces,$1);
590: } else {
591: push(@orderspaces,$1);
592: }
593: }
594: }
1.569 raeburn 595: if ($home>1) {
596: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
597: }
1.567 raeburn 598: foreach my $user (@orderspaces) {
1.329 droeschl 599: if ($home==1) {
1.567 raeburn 600: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 601: } else {
1.567 raeburn 602: $preamble .= '<option value="'.$user.'">'.$user.' - '.
603: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
604: }
1.329 droeschl 605: }
1.567 raeburn 606: unless ($home==1) {
607: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 608: }
1.567 raeburn 609: my $title=$origcrsdata{'description'};
610: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 611: $title=&clean($title);
1.567 raeburn 612: $preamble .= '<div class="LC_left_float">'.
613: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
614: '<input type="text" size="50" name="authorfolder" value="'.
615: $title.'" />'.
616: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
617: my %uploadedfiles;
618: &tiehash();
619: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
620: my ($ext)=($file=~/\.(\w+)$/);
621: # FIXME Check supplemental here
622: my $title=$hash{'title_'.$hash{
623: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
624: if (!$title) {
625: $title=$file;
626: } else {
627: $title=~s|/|_|g;
628: }
629: $title=~s/\.(\w+)$//;
630: $title=&clean($title);
631: $title.='.'.$ext;
632: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
633: $uploadedfiles{$file} = $title;
634: }
635: &untiehash();
636: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
637: undef,undef,$preamble,$home,\%uploadedfiles));
638: }
1.329 droeschl 639: }
1.484 raeburn 640: $r->print(&endContentScreen());
1.329 droeschl 641: }
642:
1.567 raeburn 643: sub recurse_html {
644: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
645: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
646: my (%allfiles,%codebase);
647: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
648: if (keys(%allfiles)) {
649: foreach my $dependency (keys(%allfiles)) {
650: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
651: my ($depurl,$relfile,$newcontainer);
652: if ($dependency =~ m{^/}) {
653: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
654: $relfile = $1;
655: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
656: $newcontainer = $1;
657: next if ($replacehash->{$newcontainer});
658: }
659: $depurl = $dependency;
660: } else {
661: next;
662: }
663: } else {
664: $relfile = $dependency;
665: $depurl = $currurlpath;
1.630 raeburn 666: $depurl =~ s{[^/]+$}{};
1.567 raeburn 667: $depurl .= $dependency;
1.630 raeburn 668: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 669: }
670: next if ($relfile eq '');
671: my $newname = $replacehash->{$container};
672: $newname =~ s{[^/]+$}{};
673: $replacehash->{$newcontainer} = $newname.$relfile;
674: $deps->{$item}{$newcontainer} = 1;
675: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
676: my $depfile = &Apache::lonnet::filelocation('',$depurl);
677: my $type = $mm->checktype_filename($depfile);
678: if ($type eq 'text/html') {
679: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
680: }
681: }
682: }
683: }
684: return;
685: }
686:
1.329 droeschl 687: sub group_import {
1.598 raeburn 688: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 689: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
690: %removeparam,$importuploaded,$fixuperrors);
691: $allmaps = {};
1.329 droeschl 692: while (@files) {
693: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 694: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 695: && ($caller eq 'londocs')
696: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 697:
1.329 droeschl 698: my $errtext = '';
699: my $fatal = 0;
700: my $newmapstr = '<map>'."\n".
701: '<resource id="1" src="" type="start"></resource>'."\n".
702: '<link from="1" to="2" index="1"></link>'."\n".
703: '<resource id="2" src="" type="finish"></resource>'."\n".
704: '</map>';
705: $env{'form.output'}=$newmapstr;
706: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
707: 'output',$1.$2);
1.534 raeburn 708: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 709: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
710: $fatal = 2;
711: }
712: if ($fatal) {
713: return ($errtext,$fatal);
714: }
715: }
716: if ($url) {
1.626 raeburn 717: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 718: $url = $1;
719: my $marker = $2;
720: my $info = $3;
1.699 raeburn 721: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 722: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 723: my @toolinfo = split(/:/,$info);
724: if ($residx) {
1.604 raeburn 725: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 726: $toolid = $toolsettings{'id'};
727: } else {
1.604 raeburn 728: $toolid = shift(@toolinfo);
1.598 raeburn 729: }
1.699 raeburn 730: if ($toolid =~ /^c/) {
731: $tooltype = 'crs';
732: $toolprefix = 'c';
733: } else {
734: $tooltype = 'dom';
735: }
1.598 raeburn 736: $toolid =~ s/\D//g;
1.604 raeburn 737: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 738: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
739: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 740: foreach my $item (@extras) {
741: $toolhash{$item} = &unescape($toolhash{$item});
742: }
1.645 raeburn 743: if ($folder =~ /^supplemental/) {
1.648 raeburn 744: delete($toolhash{'gradable'});
745: } else {
746: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 747: }
1.598 raeburn 748: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 749: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
750: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
751: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
752: my @deleted;
753: $toolhash{'id'} = $toolprefix.$toolid;
754: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
755: ($toolhash{'target'} eq 'window')) {
756: if ($toolhash{'target'} eq 'window') {
757: foreach my $item ('width','height') {
758: $toolhash{$item} =~ s/^\s+//;
759: $toolhash{$item} =~ s/\s+$//;
760: if ($toolhash{$item} =~ /\D/) {
761: delete($toolhash{$item});
762: if ($residx) {
763: if ($toolsettings{$item}) {
764: push(@deleted,$item);
765: }
1.624 raeburn 766: }
767: }
768: }
1.604 raeburn 769: }
1.699 raeburn 770: } elsif ($residx) {
771: $toolhash{'target'} = $toolsettings{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: foreach my $item ('width','height') {
774: $toolhash{$item} = $toolsettings{$item};
775: }
776: }
777: } elsif (ref($tools{'display'}) eq 'HASH') {
778: $toolhash{'target'} = $tools{'display'}{'target'};
779: if ($toolhash{'target'} eq 'window') {
780: $toolhash{'width'} = $tools{'display'}{'width'};
781: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 782: }
1.604 raeburn 783: }
1.699 raeburn 784: if ($toolhash{'target'} eq 'iframe') {
785: foreach my $item ('width','height','linktext','explanation') {
786: delete($toolhash{$item});
787: if ($residx) {
788: if ($toolsettings{$item}) {
789: push(@deleted,$item);
790: }
1.624 raeburn 791: }
1.604 raeburn 792: }
1.699 raeburn 793: } elsif ($toolhash{'target'} eq 'tab') {
794: foreach my $item ('width','height') {
795: delete($toolhash{$item});
796: if ($residx) {
797: if ($toolsettings{$item}) {
798: push(@deleted,$item);
799: }
1.628 raeburn 800: }
801: }
802: }
1.699 raeburn 803: if (ref($tools{'crsconf'}) eq 'HASH') {
804: foreach my $item ('label','title','linktext','explanation') {
805: my $crsitem;
806: if (($item eq 'label') || ($item eq 'title')) {
807: $crsitem = 'crs'.$item;
808: } else {
809: $crsitem = $item;
810: }
811: if ($tools{'crsconf'}{$item}) {
812: $toolhash{$crsitem} =~ s/^\s+//;
813: $toolhash{$crsitem} =~ s/\s+$//;
814: if ($toolhash{$crsitem} eq '') {
815: delete($toolhash{$crsitem});
816: }
817: } else {
1.624 raeburn 818: delete($toolhash{$crsitem});
1.604 raeburn 819: }
1.699 raeburn 820: if (($residx) && (exists($toolsettings{$crsitem}))) {
821: unless (exists($toolhash{$crsitem})) {
822: push(@deleted,$crsitem);
823: }
824: }
1.604 raeburn 825: }
1.699 raeburn 826: }
827: if ($toolhash{'passback'}) {
828: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
829: $toolhash{'gradesecret'} = $gradesecret;
830: $toolhash{'gradesecretdate'} = time;
831: }
832: if ($toolhash{'roster'}) {
833: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
834: $toolhash{'rostersecret'} = $rostersecret;
835: $toolhash{'rostersecretdate'} = time;
836: }
837: my $changegradable;
838: if (($residx) && ($folder =~ /^default/)) {
839: if ($toolsettings{'gradable'}) {
840: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
841: push(@deleted,'gradable');
842: $changegradable = 1;
1.604 raeburn 843: }
1.699 raeburn 844: } elsif ($toolhash{'gradable'}) {
845: $changegradable = 1;
1.604 raeburn 846: }
1.699 raeburn 847: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 848: $changegradable = 1;
1.699 raeburn 849: if ($toolsettings{'gradable'}) {
850: $toolhash{'gradable'} = 1;
851: }
1.645 raeburn 852: }
1.648 raeburn 853: }
1.699 raeburn 854: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
855: if ($putres eq 'ok') {
856: if (@deleted) {
857: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 858: }
1.699 raeburn 859: if (($changegradable) && ($folder =~ /^default/)) {
860: my $val;
861: if ($toolhash{'gradable'}) {
862: $val = 'yes';
863: } else {
864: $val = 'no';
865: }
866: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
867: 'string_yesno');
868: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 869: }
1.699 raeburn 870: } else {
871: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 872: }
1.604 raeburn 873: }
1.598 raeburn 874: }
875: }
876: }
1.529 raeburn 877: if (($caller eq 'londocs') &&
878: ($folder =~ /^default/)) {
1.534 raeburn 879: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 880: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
881: my $cid = $coursedom.'_'.$coursenum;
882: $allmaps =
883: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
884: $chome,$cid);
885: $donechk = 1;
886: }
887: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 888: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
889: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 890: $importuploaded = 1;
891: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
892: next if ($allmaps->{$url});
893: }
894: }
1.344 bisitz 895: if (!$residx
1.329 droeschl 896: || defined($LONCAPA::map::zombies[$residx])) {
897: $residx = &LONCAPA::map::getresidx($url,$residx);
898: push(@LONCAPA::map::order, $residx);
899: }
900: my $ext = 'false';
901: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 902: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
903: my $filepath = $1;
1.675 raeburn 904: my $fname;
905: if ($name eq '') {
906: $name = &mt('Web Page');
1.534 raeburn 907: $fname = 'web';
908: } else {
1.675 raeburn 909: $fname = $name;
910: $fname=&Apache::lonnet::clean_filename($fname);
911: if ($fname eq '') {
912: $fname = 'web';
913: } elsif (length($fname) > 15) {
914: $fname = substr($fname,0,14);
915: }
1.534 raeburn 916: }
1.675 raeburn 917: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 918: my $initialtext = &mt('Replace with your own content.');
919: my $newhtml = <<END;
1.545 raeburn 920: <html>
1.534 raeburn 921: <head>
1.675 raeburn 922: <title>$title</title>
1.534 raeburn 923: </head>
924: <body bgcolor="#ffffff">
925: $initialtext
926: </body>
927: </html>
928: END
929: $env{'form.output'}=$newhtml;
1.630 raeburn 930: my $result =
1.534 raeburn 931: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
932: 'output',
933: "$filepath/$residx/$fname.html");
934: if ($result =~ m{^/uploaded/}) {
935: $url = $result;
936: if ($filepath =~ /^supplemental/) {
937: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
938: $env{'user.domain'}.'___&&&___'.$name;
939: }
940: } else {
941: return (&mt('Failed to save new web page.'),1);
942: }
943: }
1.675 raeburn 944: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 945: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 946: $LONCAPA::map::resources[$residx] =
1.329 droeschl 947: join(':', ($name, $url, $ext, 'normal', 'res'));
948: }
949: }
1.529 raeburn 950: if ($importuploaded) {
951: my %import_errors;
952: my %updated = (
953: removefrommap => \%removefrommap,
954: removeparam => \%removeparam,
955: );
1.533 raeburn 956: my ($result,$msgsarray,$lockerror) =
957: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 958: if (keys(%import_errors) > 0) {
1.530 raeburn 959: $fixuperrors =
1.529 raeburn 960: '<p span class="LC_warning">'."\n".
961: &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".
962: '<ul>'."\n";
963: foreach my $key (sort(keys(%import_errors))) {
964: $fixuperrors .= '<li>'.$key.'</li>'."\n";
965: }
966: $fixuperrors .= '</ul></p>'."\n";
967: }
1.533 raeburn 968: if (ref($msgsarray) eq 'ARRAY') {
969: if (@{$msgsarray} > 0) {
970: $fixuperrors .= '<p class="LC_info">'.
971: join('<br />',@{$msgsarray}).
972: '</p>';
973: }
974: }
975: if ($lockerror) {
976: $fixuperrors .= '<p class="LC_error">'.
977: $lockerror.
978: '</p>';
979: }
1.529 raeburn 980: }
981: my ($errtext,$fatal) =
982: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 983: unless ($fatal) {
984: if ($folder =~ /^supplemental/) {
1.561 raeburn 985: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
986: $folder.'.'.$container);
1.557 raeburn 987: }
988: }
1.529 raeburn 989: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 990: }
991:
992: sub log_docs {
1.494 raeburn 993: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 994: }
995:
996: {
997: my @oldresources=();
998: my @oldorder=();
999: my $parmidx;
1000: my %parmaction=();
1001: my %parmvalue=();
1002: my $changedflag;
1003:
1004: sub snapshotbefore {
1005: @oldresources=@LONCAPA::map::resources;
1006: @oldorder=@LONCAPA::map::order;
1007: $parmidx=undef;
1008: %parmaction=();
1009: %parmvalue=();
1010: $changedflag=0;
1011: }
1012:
1013: sub remember_parms {
1014: my ($idx,$parameter,$action,$value)=@_;
1015: $parmidx=$idx;
1016: $parmaction{$parameter}=$action;
1017: $parmvalue{$parameter}=$value;
1018: $changedflag=1;
1019: }
1020:
1021: sub log_differences {
1022: my ($plain)=@_;
1023: my %storehash=('folder' => $plain,
1024: 'currentfolder' => $env{'form.folder'});
1025: if ($parmidx) {
1026: $storehash{'parameter_res'}=$oldresources[$parmidx];
1027: foreach my $parm (keys(%parmaction)) {
1028: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1029: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1030: }
1031: }
1032: my $maxidx=$#oldresources;
1033: if ($#LONCAPA::map::resources>$#oldresources) {
1034: $maxidx=$#LONCAPA::map::resources;
1035: }
1036: for (my $idx=0; $idx<=$maxidx; $idx++) {
1037: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1038: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1039: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1040: $changedflag=1;
1041: }
1042: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1043: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1044: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1045: $changedflag=1;
1046: }
1047: }
1048: $storehash{'maxidx'}=$maxidx;
1049: if ($changedflag) { &log_docs(\%storehash); }
1050: }
1051: }
1052:
1053: sub docs_change_log {
1.611 raeburn 1054: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1055: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1056: my $navmap;
1.483 raeburn 1057: my $js = '<script type="text/javascript">'."\n".
1058: '// <![CDATA['."\n".
1059: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1060: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1061: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1062: &history_tab_js()."\n".
1.484 raeburn 1063: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1064: '// ]]>'."\n".
1065: '</script>'."\n";
1.484 raeburn 1066: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1067: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1068: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1069: my %orderhash;
1070: my $container='sequence';
1071: my $pathitem;
1.519 raeburn 1072: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1073: $container='page';
1074: }
1.519 raeburn 1075: my $folderpath=$env{'form.folderpath'};
1076: if ($folderpath eq '') {
1.617 raeburn 1077: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1078: }
1.617 raeburn 1079: undef($navmap);
1.519 raeburn 1080: $pathitem = '<input type="hidden" name="folderpath" value="'.
1081: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1082: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1083: my $jumpto = $readfile;
1084: $jumpto =~ s{^/}{};
1085: my $tid = 1;
1.489 raeburn 1086: if ($supplementalflag) {
1087: $tid = 2;
1088: }
1.630 raeburn 1089: my ($breadcrumbtrail) =
1.509 raeburn 1090: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1091: $r->print($breadcrumbtrail.
1092: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1093: $readfile));
1.329 droeschl 1094: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1095: $env{'course.'.$env{'request.course.id'}.'.domain'},
1096: $env{'course.'.$env{'request.course.id'}.'.num'});
1097:
1098: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1099:
1100: my %saveable_parameters = ('show' => 'scalar',);
1101: &Apache::loncommon::store_course_settings('docs_log',
1102: \%saveable_parameters);
1103: &Apache::loncommon::restore_course_settings('docs_log',
1104: \%saveable_parameters);
1105: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1106: # FIXME: internationalization seems wrong here
1.329 droeschl 1107: my %lt=('hiddenresource' => 'Resources hidden',
1108: 'encrypturl' => 'URL hidden',
1109: 'randompick' => 'Randomly pick',
1110: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1111: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1112: 'set' => 'set to',
1113: 'del' => 'deleted');
1.484 raeburn 1114: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1115: $pathitem."\n".
1116: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1117: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1118: $r->print('<div class="LC_left_float">'.
1119: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1120: &makedocslogform($filter,1).
1121: '</fieldset></div><br clear="all" />');
1.329 droeschl 1122: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1123: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1124: &mt('After').'</th>'.
1125: &Apache::loncommon::end_data_table_header_row());
1126: my $shown=0;
1127: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1128: if ($env{'form.displayfilter'} eq 'currentfolder') {
1129: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1130: }
1131: my @changes=keys(%{$docslog{$id}{'logentry'}});
1132: if ($env{'form.displayfilter'} eq 'containing') {
1133: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1134: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1135: foreach my $key (@changes) {
1136: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1137: }
1.344 bisitz 1138: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1139: }
1140: my $count = 0;
1141: my $time =
1142: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1143: my $plainname =
1144: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1145: $docslog{$id}{'exe_udom'});
1146: my $about_me_link =
1147: &Apache::loncommon::aboutmewrapper($plainname,
1148: $docslog{$id}{'exe_uname'},
1149: $docslog{$id}{'exe_udom'});
1150: my $send_msg_link='';
1151: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1152: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1153: $send_msg_link ='<br />'.
1154: &Apache::loncommon::messagewrapper(&mt('Send message'),
1155: $docslog{$id}{'exe_uname'},
1156: $docslog{$id}{'exe_udom'});
1157: }
1158: $r->print(&Apache::loncommon::start_data_table_row());
1159: $r->print('<td>'.$time.'</td>
1160: <td>'.$about_me_link.
1161: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1162: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1163: $send_msg_link.'</td><td>'.
1164: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1165: my $is_supp = 0;
1166: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1167: $is_supp = 1;
1168: }
1.329 droeschl 1169: # Before
1170: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1171: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1172: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1173: if ($oldname ne $newname) {
1.488 raeburn 1174: my $shown = &LONCAPA::map::qtescape($oldname);
1175: if ($is_supp) {
1176: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1177: }
1178: $r->print($shown);
1.329 droeschl 1179: }
1180: }
1181: $r->print('<ul>');
1182: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1183: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1184: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1185: if ($is_supp) {
1186: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1187: }
1188: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1189: }
1190: }
1191: $r->print('</ul>');
1192: # After
1193: $r->print('</td><td>');
1194:
1195: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1196: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1197: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1198: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1199: my $shown = &LONCAPA::map::qtescape($newname);
1200: if ($is_supp) {
1201: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1202: }
1203: $r->print($shown);
1.329 droeschl 1204: }
1.364 bisitz 1205: }
1.329 droeschl 1206: $r->print('<ul>');
1207: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1208: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1209: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1210: if ($is_supp) {
1211: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1212: }
1213: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1214: }
1215: }
1216: $r->print('</ul>');
1217: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1218: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1219: if ($title eq '') {
1220: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1221: } elsif ($is_supp) {
1222: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1223: }
1224: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1225: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1226: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1227: # FIXME: internationalization seems wrong here
1.329 droeschl 1228: $r->print('<li>'.
1229: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1230: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1231: .'</li>');
1232: }
1233: }
1234: $r->print('</ul>');
1235: }
1236: # End
1237: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1238: $shown++;
1239: if (!($env{'form.show'} eq &mt('all')
1240: || $shown<=$env{'form.show'})) { last; }
1241: }
1.484 raeburn 1242: $r->print(&Apache::loncommon::end_data_table()."\n".
1243: &makesimpleeditform($pathitem)."\n".
1244: '</div></div>');
1245: $r->print(&endContentScreen());
1.329 droeschl 1246: }
1247:
1248: sub update_paste_buffer {
1.492 raeburn 1249: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1250: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1251: if ($env{'form.multiremove'}) {
1252: $env{'form.multiremove'} =~ s/,$//;
1253: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1254: }
1255: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1256: if ($env{'form.multicut'}) {
1257: $env{'form.multicut'} =~ s/,$//;
1258: foreach my $item (split(/,/,$env{'form.multicut'})) {
1259: unless ($removals{$item}) {
1260: $cuts{$item} = 1;
1261: push(@possibles,$item.':cut');
1262: }
1263: }
1264: }
1265: if ($env{'form.multicopy'}) {
1266: $env{'form.multicopy'} =~ s/,$//;
1267: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1268: unless ($removals{$item} || $cuts{$item}) {
1269: push(@possibles,$item.':copy');
1270: }
1271: }
1272: }
1273: } elsif ($env{'form.markcopy'}) {
1274: @possibles = split(/,/,$env{'form.markcopy'});
1275: }
1.329 droeschl 1276:
1.538 raeburn 1277: return if (@possibles == 0);
1.329 droeschl 1278: return if (!defined($env{'form.copyfolder'}));
1279:
1280: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1281: $env{'form.copyfolder'});
1.538 raeburn 1282: return if ($fatal);
1283:
1284: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1285:
1.538 raeburn 1286: # Retrieve current paste buffer suffixes.
1287: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1288: my (%pasteurls,@newpaste);
1289:
1290: # Construct identifiers for current contents of user's paste buffer
1291: if (@currpaste) {
1292: foreach my $suffix (@currpaste) {
1.667 raeburn 1293: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1294: my $url = $env{'docs.markedcopy_url_'.$suffix};
1295: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1296: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1297: ($url ne '')) {
1298: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1299: $pasteurls{$cid.'_'.$mapidx} = 1;
1300: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1301: $pasteurls{$url} = 1;
1302: } else {
1.669 raeburn 1303: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1304: }
1305: }
1.538 raeburn 1306: }
1307: }
1308:
1309: # Mark items for copying (skip any items already in user's paste buffer)
1310: my %addtoenv;
1.597 raeburn 1311:
1312: my @pathitems = split(/\&/,$env{'form.folderpath'});
1313: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1314: my $ispage = $folderconf[5];
1.597 raeburn 1315:
1.538 raeburn 1316: foreach my $item (@possibles) {
1317: my ($orderidx,$cmd) = split(/:/,$item);
1318: next if ($orderidx =~ /\D/);
1319: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1320: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1321: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1322: my %denied = &action_restrictions($coursenum,$coursedom,
1323: &LONCAPA::map::qtescape($url),
1324: $env{'form.folderpath'},\%curr_groups);
1325: next if ($denied{'copy'});
1326: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1327: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1328: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1329: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1330: next if (exists($pasteurls{$url}));
1331: } else {
1332: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1333: }
1.538 raeburn 1334: my ($suffix,$errortxt,$locknotfreed) =
1335: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1336: if ($suffix ne '') {
1337: push(@newpaste,$suffix);
1338: } else {
1339: if ($locknotfreed) {
1340: return $locknotfreed;
1341: }
1.538 raeburn 1342: }
1343: if (&is_supplemental_title($title)) {
1344: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1345: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1346: }
1.329 droeschl 1347:
1.538 raeburn 1348: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1349: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1350: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1351: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1352: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1353: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1354: my $prefix = $1;
1355: my $subdir =$2;
1356: if ($subdir eq '') {
1357: $subdir = $prefix;
1.492 raeburn 1358: }
1.538 raeburn 1359: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1360: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1361: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1362: if (ref($hierarchy{$url}) eq 'HASH') {
1363: my ($nested,$nestednames);
1364: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1365: $nested =~ s/\&$//;
1366: $nestednames =~ s/\Q___&&&___\E$//;
1367: if ($nested ne '') {
1368: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1369: }
1370: if ($nestednames ne '') {
1371: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1372: }
1.492 raeburn 1373: }
1374: }
1.591 raeburn 1375: if ($locknotfreed) {
1376: $output = $locknotfreed;
1377: last;
1378: }
1.492 raeburn 1379: }
1.538 raeburn 1380: if (@newpaste) {
1381: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1382: }
1.492 raeburn 1383: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1384: delete($env{'form.markcopy'});
1.591 raeburn 1385: return $output;
1.329 droeschl 1386: }
1387:
1.492 raeburn 1388: sub recurse_uploaded_maps {
1389: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1390: if (ref($hierarchy->{$url}) eq 'HASH') {
1391: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1392: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1393: my (@uploaded,@names,%shorter);
1394: for (my $i=0; $i<@maps; $i++) {
1395: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1396: if ($inner ne '') {
1397: push(@uploaded,$inner);
1398: push(@names,&escape($titles[$i]));
1399: $shorter{$maps[$i]} = $inner;
1400: }
1401: }
1402: $$nestref .= "$dir:".join(',',@uploaded).'&';
1403: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1404: foreach my $map (@maps) {
1405: if ($shorter{$map} ne '') {
1406: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1407: }
1408: }
1409: }
1410: return;
1411: }
1412:
1.329 droeschl 1413: sub print_paste_buffer {
1.492 raeburn 1414: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1415: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1416:
1.538 raeburn 1417: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1418: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1419: }
1420:
1.538 raeburn 1421: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 1422: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 1423: my $clipboardcount = 0;
1.488 raeburn 1424:
1.538 raeburn 1425: # Construct identifiers for current contents of user's paste buffer
1426: foreach my $suffix (@currpaste) {
1427: next if ($suffix =~ /\D/);
1428: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1429: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1430: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1431: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1432: ($url ne '')) {
1.575 raeburn 1433: $clipboardcount ++;
1.538 raeburn 1434: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 1435: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
1436: $toolcnum,$marker);
1.538 raeburn 1437: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1438: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1439: $is_external = 1;
1.704 raeburn 1440: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1441: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 1442: $is_exttool = 1;
1.538 raeburn 1443: }
1444: if ($folder =~ /^supplemental/) {
1445: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1446: unless ($canpaste) {
1447: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1448: }
1449: } else {
1450: $canpaste = 1;
1451: }
1452: if ($canpaste) {
1453: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1454: my $srcdom = $1;
1455: my $srcnum = $2;
1456: my $rem = $3;
1457: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1458: $othercourse = 1;
1459: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1460: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1461: } else {
1462: $canpaste = 0;
1463: $nopaste = &mt('Paste from another course unavailable.');
1464: }
1465: }
1466: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1467: my $prefix = $1;
1468: $parent = $2;
1469: if ($folder !~ /^\Q$prefix\E/) {
1470: $areachange = 1;
1471: }
1472: $is_uploaded_map = 1;
1.492 raeburn 1473: }
1.597 raeburn 1474: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1475: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1476: if ($cid ne $env{'request.course.id'}) {
1477: my ($srcdom,$srcnum) = split(/_/,$cid);
1478: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 1479: if ($is_exttool) {
1480: if ($toolcdom ne $coursedom) {
1481: $canpaste = 0;
1482: $nopaste = &mt('Paste from another domain unavailable.');
1483: } elsif ($toolcnum ne $coursenum) {
1484: my %toolsettings =
1485: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1486: my %tooltypes = &Apache::loncommon::usable_exttools();
1487: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1488: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1489: $canpaste = 0;
1490: $nopaste = &mt('Paste from another course unavailable.');
1491: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
1492: unless ($checkedsameinst) {
1493: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
1494: my $intdom = &Apache::lonnet::internet_dom($primary_id);
1495: if ($intdom ne '') {
1496: my $internet_names =
1497: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
1498: if (ref($internet_names) eq 'ARRAY') {
1499: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
1500: $same_institution = 1;
1501: }
1502: }
1503: }
1504: $checkedsameinst = 1;
1505: }
1506: if ($same_institution) {
1507: $othercrs = '<br />'.&mt('(from another course)');
1508: } else {
1509: $nopaste = &mt('Paste from another course unavailable.');
1510: }
1511: } else {
1512: $othercrs = '<br />'.&mt('(from another course)');
1513: }
1514: }
1.627 raeburn 1515: }
1.596 raeburn 1516: } else {
1517: $canpaste = 0;
1518: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1519: }
1.596 raeburn 1520: }
1.703 raeburn 1521: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
1522: my ($audom,$auname) = ($1,$2);
1523: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1524: if (&Apache::lonnet::is_course($audom,$auname)) {
1525: $canpaste = 0;
1526: $nopaste = &mt('Paste from another course unavailable.');
1527: }
1528: }
1.492 raeburn 1529: }
1.596 raeburn 1530: if ($canpaste) {
1531: push(@pasteable,$suffix);
1.629 raeburn 1532: }
1.538 raeburn 1533: }
1534: my $buffer;
1.627 raeburn 1535: if ($is_external) {
1.538 raeburn 1536: $buffer = &mt('External Resource').': '.
1537: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1538: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1539: } elsif ($is_exttool) {
1540: $buffer = &mt('External Tool').': '.
1541: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1542: } else {
1543: my $icon = &Apache::loncommon::icon($extension);
1544: if ($extension eq 'sequence' &&
1545: $url =~ m{/default_\d+\.sequence$}x) {
1546: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1547: $icon .= '/navmap.folder.closed.gif';
1548: }
1.589 raeburn 1549: my $title = $env{'docs.markedcopy_title_'.$suffix};
1550: if ($title eq '') {
1551: ($title) = ($url =~ m{/([^/]+)$});
1552: }
1.538 raeburn 1553: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1554: ': '.
1555: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1556: &LONCAPA::map::qtescape($title));
1.538 raeburn 1557: }
1558: $pasteitems .= '<div class="LC_left_float">';
1559: my ($options,$onclick);
1560: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1561: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1562: if (($is_uploaded_map) ||
1563: ($url =~ /(bulletinboard|smppg)$/) ||
1564: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1565: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1566: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1567: }
1568: }
1569: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1570: if ($nopaste) {
1.681 raeburn 1571: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1572: } else {
1573: if ($othercrs) {
1574: $pasteitems .= $othercrs;
1575: }
1576: if ($options) {
1577: $pasteitems .= $options;
1.492 raeburn 1578: }
1579: }
1.538 raeburn 1580: $pasteitems .= '</div>';
1581: }
1582: }
1583: if ($pasteitems eq '') {
1584: &Apache::lonnet::delenv('docs.markedcopies');
1585: }
1586: my ($pasteform,$form_start,$buttons,$form_end);
1587: if ($pasteitems) {
1588: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1589: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1590: if (@pasteable) {
1.575 raeburn 1591: my $value = &mt('Paste to current folder');
1592: if ($container eq 'page') {
1593: $value = &mt('Paste to current page');
1594: }
1595: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1596: }
1597: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1598: if ($clipboardcount > 1) {
1599: $buttons .=
1600: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1601: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1602: (' 'x2).
1603: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1604: (' 'x2);
1.492 raeburn 1605: }
1.575 raeburn 1606: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1607: '</form>';
1.538 raeburn 1608: } else {
1609: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1610: }
1.538 raeburn 1611: $r->print($form_start
1612: .'<fieldset>'
1613: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1614: .$pasteitems
1615: .'</fieldset>'
1616: .$form_end);
1617: }
1618:
1619: sub paste_options {
1620: my ($suffix,$is_uploaded_map,$parent) = @_;
1621: my ($copytext,$movetext);
1622: if ($is_uploaded_map) {
1623: $copytext = &mt('Copy to new folder');
1624: $movetext = &mt('Move old');
1625: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1626: $copytext = &mt('Copy to new board');
1627: $movetext = &mt('Move (not posts)');
1628: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1629: $copytext = &mt('Copy to new page');
1630: $movetext = &mt('Move');
1.533 raeburn 1631: } else {
1.538 raeburn 1632: $copytext = &mt('Copy to new file');
1633: $movetext = &mt('Move');
1634: }
1635: my $output = '<br />'.
1636: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1637: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1638: '<label>'.
1639: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1640: $copytext.'</label></span>'.(' 'x2).' '.
1641: '<span class="LC_nobreak"><label>'.
1642: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1643: $movetext.'</label></span>';
1644: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1645: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1646: '</legend><table border="0">';
1647: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1648: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1649: my $lastdir = $parent;
1650: my %depths = (
1651: $lastdir => 0,
1652: );
1653: my (%display,%deps);
1654: for (my $i=0; $i<@pastemaps; $i++) {
1655: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1656: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1657: my @subfolders = split(/,/,$subfolderstr);
1658: $deps{$lastdir} = \@subfolders;
1659: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1660: my $depth = $depths{$lastdir} + 1;
1661: my $offset = int($depth * 4);
1662: my $indent = (' ' x $offset);
1663: for (my $j=0; $j<@subfolders; $j++) {
1664: $depths{$subfolders[$j]} = $depth;
1665: $display{$subfolders[$j]} =
1666: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1667: '<td><label>'.
1668: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1669: '<label>'.
1670: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1671: &mt('Move old').'</label>'.
1672: '</td></tr>';
1673: }
1.492 raeburn 1674: }
1.538 raeburn 1675: &recurse_print(\$output,$parent,\%deps,\%display);
1676: $output .= '</table></fieldset>';
1.329 droeschl 1677: }
1.538 raeburn 1678: $output .= '</div>';
1679: return $output;
1.488 raeburn 1680: }
1681:
1.492 raeburn 1682: sub recurse_print {
1.538 raeburn 1683: my ($outputref,$dir,$deps,$display) = @_;
1684: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1685: if (ref($deps->{$dir}) eq 'ARRAY') {
1686: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1687: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1688: }
1689: }
1690: }
1691:
1.488 raeburn 1692: sub supp_pasteable {
1693: my ($url) = @_;
1694: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1695: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1696: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1697: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1698: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1699: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1700: return 1;
1701: }
1702: return;
1.329 droeschl 1703: }
1704:
1.492 raeburn 1705: sub paste_popup_js {
1.594 damieng 1706: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1707: show => 'Show Options',
1708: hide => 'Hide Options',
1.594 damieng 1709: );
1710: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1711: none => 'No items selected from clipboard.',
1.492 raeburn 1712: );
1.594 damieng 1713: &html_escape(\%html_js_lt);
1714: &js_escape(\%html_js_lt);
1715: &js_escape(\%js_lt);
1.492 raeburn 1716: return <<"END";
1717:
1.538 raeburn 1718: function showPasteOptions(suffix) {
1719: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1720: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1721: return;
1722: }
1723:
1.538 raeburn 1724: function hidePasteOptions(suffix) {
1725: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1726: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1727: return;
1728: }
1729:
1730: function showOptions(caller,suffix) {
1731: if (document.getElementById('pasteoptionstext_'+suffix)) {
1732: if (caller.checked) {
1.594 damieng 1733: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1734: } else {
1735: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1736: }
1737: if (document.getElementById('pasteoptions_'+suffix)) {
1738: document.getElementById('pasteoptions_'+suffix).style.display='none';
1739: }
1740: }
1.492 raeburn 1741: return;
1742: }
1743:
1.541 raeburn 1744: function validateClipboard() {
1745: var numchk = 0;
1746: if (document.pasteform.pasting.length > 1) {
1747: for (var i=0; i<document.pasteform.pasting.length; i++) {
1748: if (document.pasteform.pasting[i].checked) {
1749: numchk ++;
1750: }
1751: }
1752: } else {
1753: if (document.pasteform.pasting.type == 'checkbox') {
1754: if (document.pasteform.pasting.checked) {
1755: numchk ++;
1756: }
1757: }
1758: }
1759: if (numchk > 0) {
1760: return true;
1761: } else {
1.594 damieng 1762: alert("$js_lt{'none'}");
1.541 raeburn 1763: return false;
1764: }
1765: }
1766:
1.575 raeburn 1767: function checkClipboard() {
1768: if (document.pasteform.pasting.length > 1) {
1769: for (var i=0; i<document.pasteform.pasting.length; i++) {
1770: document.pasteform.pasting[i].checked = true;
1771: }
1772: }
1773: return;
1774: }
1775:
1776: function uncheckClipboard() {
1777: if (document.pasteform.pasting.length >1) {
1778: for (var i=0; i<document.pasteform.pasting.length; i++) {
1779: document.pasteform.pasting[i].checked = false;
1780: }
1781: }
1782: return;
1783: }
1784:
1.492 raeburn 1785: END
1786:
1787: }
1788:
1.329 droeschl 1789: sub do_paste_from_buffer {
1.492 raeburn 1790: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1791:
1.538 raeburn 1792: # Array of items in paste buffer
1793: my (@currpaste,%pastebuffer,%allerrors);
1794: @currpaste = split(/,/,$env{'docs.markedcopies'});
1795:
1.492 raeburn 1796: # Early out if paste buffer is empty
1.538 raeburn 1797: if (@currpaste == 0) {
1.492 raeburn 1798: return ();
1.538 raeburn 1799: }
1800: map { $pastebuffer{$_} = 1; } @currpaste;
1801:
1802: # Array of items selected items to paste
1803: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1804:
1805: # Early out if nothing selected to paste
1806: if (@reqpaste == 0) {
1807: return();
1808: }
1809: my @topaste;
1810: foreach my $suffix (@reqpaste) {
1811: next if ($suffix =~ /\D/);
1812: next unless (exists($pastebuffer{$suffix}));
1813: push(@topaste,$suffix);
1814: }
1815:
1816: # Early out if nothing available to paste
1817: if (@topaste == 0) {
1818: return();
1.329 droeschl 1819: }
1820:
1.704 raeburn 1821: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
1822: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
1823: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
1824: %currltititles,$currltimax,$gotcrsltitools);
1825: $currltimax = 0;
1826: $gotcrsltitools = 0;
1.538 raeburn 1827: foreach my $suffix (@topaste) {
1828: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1829: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1830: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1831: # Supplemental content may only include certain types of content
1832: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1833: if ($folder =~ /^supplemental/) {
1834: unless (&supp_pasteable($url)) {
1835: $notinsupp{$suffix} = 1;
1836: next;
1837: }
1.492 raeburn 1838: }
1.538 raeburn 1839: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1840: my $srcd = $1;
1841: my $srcn = $2;
1.492 raeburn 1842: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1843: # check for mdc privilege in the course from which the resource was pasted
1844: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1845: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1846: $notincrs{$suffix} = 1;
1847: next;
1848: }
1.491 raeburn 1849: }
1.538 raeburn 1850: $srcdom{$suffix} = $srcd;
1851: $srcnum{$suffix} = $srcn;
1.597 raeburn 1852: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1853: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1854: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1855: my ($srcd,$srcn) = split(/_/,$cid);
1856: # When paste buffer was populated using an active role in a different course
1857: # check for mdc privilege in the course from which the resource was pasted
1858: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1859: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1860: $notincrs{$suffix} = 1;
1861: next;
1862: }
1863: }
1.632 raeburn 1864: # When buffer was populated using an active role in a different course
1.704 raeburn 1865: # disallow pasting of External Tool if course is in a different domain,
1866: # or if External Tool use is not permitted in this course.
1867: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1868: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1869: if ($toolcdom ne $coursedom) {
1870: $notindom{$suffix} = 1;
1871: next;
1872: } elsif ($toolcnum ne $coursenum) {
1873: my %toolsettings =
1874: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1875: my %tooltypes = &Apache::loncommon::usable_exttools();
1876: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1877: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1878: $othcrstool{$suffix} = 1;
1879: next;
1880: }
1881: if ($toolsettings{'id'} =~ /^c\d+$/) {
1882: unless ($gotcrsltitools) {
1883: %currcrsltitools =
1884: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
1885: foreach my $item (sort(keys(%currcrsltitools))) {
1886: if (ref($currcrsltitools{$item}) eq 'HASH') {
1887: $currltimax ++;
1888: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
1889: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
1890: } else {
1891: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
1892: }
1893: }
1894: }
1895: $gotcrsltitools = 1;
1896: }
1897: }
1898: }
1.627 raeburn 1899: }
1.596 raeburn 1900: $srcdom{$suffix} = $srcd;
1901: $srcnum{$suffix} = $srcn;
1.703 raeburn 1902: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
1903: my ($audom,$auname) = ($1,$2);
1904: # When buffer was populated using an active role in a different course
1905: # disallow pasting of published resources from Course Authoring Space
1906: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1907: if (&Apache::lonnet::is_course($audom,$auname)) {
1908: $othcrsres{$suffix} = 1;
1909: next;
1910: }
1911: }
1.491 raeburn 1912: }
1.597 raeburn 1913: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1914: push(@dopaste,$suffix);
1915: if ($url=~/\.(page|sequence)$/) {
1916: $is_map{$suffix} = 1;
1917: }
1918: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1919: my $oldprefix = $1;
1.492 raeburn 1920: # When pasting content from Main Content to Supplemental Content and vice versa
1921: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1922: # a folder/page or a document).
1.538 raeburn 1923: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1924: $prefixchg{$suffix} = 'docstosupp';
1925: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1926: $prefixchg{$suffix} = 'supptodocs';
1927: }
1.491 raeburn 1928:
1.492 raeburn 1929: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1930: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1931: my @nested;
1932: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1933: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1934: my @deps = map { /\d+:([\d,]+$)/ } @items;
1935: foreach my $dep (@deps) {
1936: if ($dep =~ /,/) {
1937: push(@nested,split(/,/,$dep));
1938: } else {
1939: push(@nested,$dep);
1940: }
1.492 raeburn 1941: }
1.538 raeburn 1942: foreach my $item (@nested) {
1943: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1944: push(@{$marktomove{$suffix}},$type.'_'.$item);
1945: }
1.492 raeburn 1946: }
1947: }
1.488 raeburn 1948: }
1949: }
1950:
1.538 raeburn 1951: # Early out if nothing available to paste
1952: if (@dopaste == 0) {
1953: return ();
1954: }
1955:
1956: # Populate message hash and hashes used for main content <=> supplemental content
1957: # changes
1958:
1959: %msgs = &Apache::lonlocal::texthash (
1960: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1961: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1962: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 1963: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 1964: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 1965: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1966: );
1967:
1968: %before = (
1969: docstosupp => {
1970: map => 'default',
1971: doc => 'docs',
1972: },
1973: supptodocs => {
1974: map => 'supplemental',
1975: doc => 'supplemental',
1976: },
1977: );
1978:
1979: %after = (
1980: docstosupp => {
1981: map => 'supplemental',
1982: doc => 'supplemental'
1983: },
1984: supptodocs => {
1985: map => 'default',
1986: doc => 'docs',
1987: },
1988: );
1989:
1990: # Retrieve information about all course maps in main content area
1991:
1992: my $allmaps = {};
1.704 raeburn 1993: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
1994: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
1995: $same_institution);
1.538 raeburn 1996:
1997: # Loop over the items to paste
1998: foreach my $suffix (@dopaste) {
1.329 droeschl 1999: # Maps need to be copied first
1.538 raeburn 2000: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2001: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2002: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2003: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2004: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2005: }
2006: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2007: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2008: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2009: my $oldurl = $url;
2010: if ($is_map{$suffix}) {
1.491 raeburn 2011: # If pasting a map, check if map contains other maps
1.538 raeburn 2012: my (%hierarchy,%titles);
1.660 raeburn 2013: if (($folder =~ /^default/) && (!$donechk)) {
2014: $allmaps =
2015: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2016: $env{"course.$env{'request.course.id'}.home"},
2017: $env{'request.course.id'});
2018: $donechk = 1;
2019: }
1.627 raeburn 2020: &contained_map_check($url,$folder,$coursenum,$coursedom,
2021: \%removefrommap,\%removeparam,\%addedmaps,
2022: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2023: if ($url=~ m{^/uploaded/}) {
2024: my $newurl;
2025: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2026: ($newurl,my $error) =
2027: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2028: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2029: \$title,$allmaps,\%newurls);
2030: if ($error) {
2031: $allerrors{$suffix} = $error;
2032: next;
2033: }
2034: if ($newurl ne '') {
2035: if ($newurl ne $url) {
2036: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2037: $newsubdir{$url} = $1;
2038: }
2039: $mapchanges{$url} = 1;
1.492 raeburn 2040: }
1.538 raeburn 2041: }
2042: }
2043: if (($srcdom{$suffix} ne $coursedom) ||
2044: ($srcnum{$suffix} ne $coursenum) ||
2045: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2046: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2047: $coursedom,$coursenum,$srcdom{$suffix},
2048: $srcnum{$suffix},$allmaps,\%rewrites,
2049: \%retitles,\%copies,\%dbcopies,
2050: \%zombies,\%params,\%mapmoves,
2051: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2052: \%newurls,\%resdatacopy)) {
1.538 raeburn 2053: $mapmoves{$url} = 1;
2054: }
2055: $url = $newurl;
2056: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2057: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2058: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2059: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2060: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 2061: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 2062: }
2063: } elsif ($url=~m {^/res/}) {
1.597 raeburn 2064: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 2065: push(@toclear,$suffix);
2066: # if pasting published map (main content area only) check map not already in course
2067: if ($folder =~ /^default/) {
2068: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2069: $duplicate{$suffix} = 1;
2070: next;
1.492 raeburn 2071: }
1.491 raeburn 2072: }
2073: }
1.538 raeburn 2074: }
1.627 raeburn 2075: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2076: my $prefix = $1;
1.648 raeburn 2077: my $fromothercrs;
1.538 raeburn 2078: #need to copy the db contents to a new one, unless this is a move.
2079: my %info = (
2080: src => $url,
2081: cdom => $coursedom,
2082: cnum => $coursenum,
1.596 raeburn 2083: );
1.649 raeburn 2084: if ($prefix eq 'ext.tool') {
1.655 raeburn 2085: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2086: $info{'delgradable'} = 1;
2087: }
2088: }
1.596 raeburn 2089: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2090: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2091: $fromothercrs = 1;
2092: $info{'cdom'} = $srcdom{$suffix};
2093: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 2094: unless ($checkedsameinst) {
2095: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2096: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2097: if ($intdom ne '') {
2098: my $internet_names =
2099: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2100: if (ref($internet_names) eq 'ARRAY') {
2101: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2102: $same_institution = 1;
2103: }
2104: }
2105: }
2106: $checkedsameinst = 1;
2107: }
1.596 raeburn 2108: }
2109: }
2110: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2111: my (%lockerr,$msg);
1.538 raeburn 2112: my ($newurl,$result,$errtext) =
1.704 raeburn 2113: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2114: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 2115: if ($result eq 'ok') {
2116: $url = $newurl;
2117: $title=&mt('Copy of').' '.$title;
2118: } else {
2119: if ($prefix eq 'smppg') {
2120: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2121: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2122: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2123: } elsif ($prefix eq 'ext.tool') {
2124: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2125: }
2126: $results{$suffix} = $result;
2127: $msgerrs{$suffix} = $msg;
2128: $lockerrs{$suffix} = $lockerr{$prefix};
2129: next;
2130: }
2131: if ($lockerr{$prefix}) {
2132: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2133: }
1.489 raeburn 2134: }
2135: }
1.538 raeburn 2136: $title = &LONCAPA::map::qtunescape($title);
2137: my $ext='false';
2138: if ($url=~m{^http(|s)://}) { $ext='true'; }
2139: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2140: if ($folder !~ /^supplemental/) {
2141: (undef,undef,$title) =
2142: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2143: }
2144: } else {
2145: if ($folder=~/^supplemental/) {
2146: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2147: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2148: }
1.533 raeburn 2149: }
1.491 raeburn 2150:
2151: # For uploaded files (excluding pages/sequences) path in copied file is changed
2152: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2153: # courses.
2154:
1.538 raeburn 2155: unless ($is_map{$suffix}) {
2156: my $newidx;
1.492 raeburn 2157: # Now insert the URL at the bottom
1.538 raeburn 2158: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2159: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2160: my $relpath = $1;
2161: if ($relpath ne '') {
2162: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2163: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2164: my $newprefix = $newloc;
2165: if ($newloc eq 'default') {
2166: $newprefix = 'docs';
2167: }
2168: if ($newdocsdir eq '') {
2169: $newdocsdir = 'default';
2170: }
1.630 raeburn 2171: if (($prefixchg{$suffix}) ||
2172: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2173: ($srcnum{$suffix} ne $coursenum) ||
2174: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2175: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2176: $url =
2177: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2178: &Apache::lonnet::getfile($oldurl));
2179: if ($url eq '/adm/notfound.html') {
2180: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2181: next;
2182: } else {
2183: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2184: $newsubpath =~ s{/+$}{/};
2185: $docmoves{$oldurl} = $newsubpath;
2186: }
1.491 raeburn 2187: }
2188: }
1.597 raeburn 2189: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2190: my $template = $1;
2191: if ($newidx) {
2192: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2193: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2194: }
1.649 raeburn 2195: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2196: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2197: my $marker = (split(m{/},$url))[4];
2198: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2199: my $val = 'no';
2200: if ($toolsettings{'gradable'}) {
2201: $val = 'yes';
2202: }
2203: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2204: 'string_yesno');
2205: &remember_parms($newidx,'gradable','set',$val);
2206: }
1.491 raeburn 2207: }
1.538 raeburn 2208: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2209: ':'.$ext.':normal:res';
2210: push(@LONCAPA::map::order,$newidx);
2211: # Store the result
2212: my ($errtext,$fatal) =
2213: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2214: if ($fatal) {
2215: $save_err .= $errtext;
2216: $allresult = 'fail';
2217: }
1.488 raeburn 2218: }
1.538 raeburn 2219:
1.597 raeburn 2220: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2221: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2222: unless ($allresult eq 'fail') {
2223: my %updated = (
2224: rewrites => \%rewrites,
2225: zombies => \%zombies,
2226: removefrommap => \%removefrommap,
2227: removeparam => \%removeparam,
2228: dbcopies => \%dbcopies,
1.597 raeburn 2229: resdatacopy => \%resdatacopy,
1.538 raeburn 2230: retitles => \%retitles,
2231: );
2232: my %info = (
2233: newsubdir => \%newsubdir,
2234: params => \%params,
2235: );
2236: if ($prefixchg{$suffix}) {
2237: $info{'before'} = $before{$prefixchg{$suffix}};
2238: $info{'after'} = $after{$prefixchg{$suffix}};
2239: }
2240: my %moves = (
2241: copies => \%copies,
2242: docmoves => \%docmoves,
2243: mapmoves => \%mapmoves,
2244: );
2245: (my $result,$msgs{$suffix},my $lockerror) =
2246: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2247: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2248: $url,'paste');
2249: $lockerrors .= $lockerror;
2250: if ($result eq 'ok') {
2251: if ($is_map{$suffix}) {
2252: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2253: $folder.'.'.$container);
2254: if ($fatal) {
2255: $allresult = 'failread';
2256: } else {
2257: if ($#LONCAPA::map::order<1) {
2258: my $idx=&LONCAPA::map::getresidx();
2259: if ($idx<=0) { $idx=1; }
2260: $LONCAPA::map::order[0]=$idx;
2261: $LONCAPA::map::resources[$idx]='';
2262: }
2263: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2264: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2265: ':'.$ext.':normal:res';
2266: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2267:
2268: # Store the result
1.538 raeburn 2269: my ($errtext,$fatal) =
2270: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2271: if ($fatal) {
2272: $save_err .= $errtext;
2273: $allresult = 'failstore';
2274: }
2275: }
2276: }
2277: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2278: push(@toclear,$suffix);
2279: }
2280: }
1.492 raeburn 2281: }
2282: }
1.704 raeburn 2283: if (($updatetoolscache) || (@updatetoolsenc)) {
2284: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2285: \@updatetoolsenc);
2286: }
1.538 raeburn 2287: &clear_from_buffer(\@toclear,\@currpaste);
2288: my $msgsarray;
2289: foreach my $suffix (keys(%msgs)) {
2290: if (ref($msgs{$suffix}) eq 'ARRAY') {
2291: $msgsarray .= join(',',@{$msgs{$suffix}});
2292: }
2293: }
2294: return ($allresult,$save_err,$msgsarray,$lockerrors);
2295: }
1.533 raeburn 2296:
1.538 raeburn 2297: sub do_buffer_empty {
2298: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2299: if (@currpaste == 0) {
2300: return &mt('Clipboard is already empty');
2301: }
2302: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2303: if (@toclear == 0) {
2304: return &mt('Nothing selected to clear from clipboard');
2305: }
2306: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2307: if ($numdel) {
2308: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2309: } else {
2310: return &mt('Clipboard unchanged');
1.492 raeburn 2311: }
1.538 raeburn 2312: return;
2313: }
2314:
2315: sub clear_from_buffer {
2316: my ($toclear,$currpaste) = @_;
2317: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2318: my %pastebuffer;
2319: map { $pastebuffer{$_} = 1; } @{$currpaste};
2320: my $numdel = 0;
2321: foreach my $suffix (@{$toclear}) {
2322: next if ($suffix =~ /\D/);
2323: next unless (exists($pastebuffer{$suffix}));
2324: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2325: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2326: delete($pastebuffer{$suffix});
2327: $numdel ++;
2328: }
2329: }
2330: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2331: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2332: return $numdel;
1.492 raeburn 2333: }
2334:
1.704 raeburn 2335: sub update_ltitools_caches {
2336: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2337: my $hashid=$coursedom.'_'.$coursenum;
2338: if ($updatetoolscache) {
2339: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2340: }
2341: if ((ref($updatetoolsenc) eq 'ARRAY') &&
2342: (@{$updatetoolsenc})) {
2343: my @ids=&Apache::lonnet::current_machine_ids();
2344: my $updatedone;
2345: foreach my $lonhost (@{$updatetoolsenc}) {
2346: if (grep(/^\Q$lonhost\E$/,@ids)) {
2347: unless ($updatedone) {
2348: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2349: }
2350: $updatedone = 1;
2351: } else {
2352: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2353: }
2354: }
2355: }
2356: return;
2357: }
2358:
1.492 raeburn 2359: sub get_newmap_url {
2360: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2361: $titleref,$allmaps,$newurls) = @_;
2362: my $newurl;
2363: if ($url=~ m{^/uploaded/}) {
2364: $$titleref=&mt('Copy of').' '.$$titleref;
2365: }
2366: my $now = time;
2367: my $suffix=$$.int(rand(100)).$now;
2368: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2369: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2370: my $path = $1;
2371: my $prefix = $2;
2372: my $ancestor = $3;
2373: if (length($ancestor) > 10) {
2374: $ancestor = substr($ancestor,-10,10);
2375: }
2376: my $newid;
2377: if ($prefixchg) {
2378: if ($folder =~ /^supplemental/) {
2379: $prefix =~ s/^default/supplemental/;
2380: } else {
2381: $prefix =~ s/^supplemental/default/;
2382: }
2383: }
2384: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2385: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2386: } else {
2387: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2388: }
2389: my $counter = 0;
2390: my $is_unique = &uniqueness_check($newurl);
2391: if ($folder =~ /^default/) {
2392: if ($allmaps->{$newurl}) {
2393: $is_unique = 0;
2394: }
2395: }
2396: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2397: $counter ++;
2398: $suffix ++;
2399: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2400: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2401: } else {
2402: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2403: }
2404: $is_unique = &uniqueness_check($newurl);
2405: }
2406: if ($is_unique) {
2407: $newurls->{$newurl} = 1;
2408: } else {
2409: if ($url=~/\.page$/) {
2410: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2411: } else {
2412: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2413: }
2414: }
1.329 droeschl 2415: }
1.492 raeburn 2416: return ($newurl);
1.329 droeschl 2417: }
2418:
1.488 raeburn 2419: sub dbcopy {
1.704 raeburn 2420: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
2421: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 2422: my ($url,$result,$errtext);
2423: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2424: $url = $dbref->{'src'};
1.627 raeburn 2425: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2426: my $prefix = $1;
1.627 raeburn 2427: if ($prefix eq 'ext.tool') {
2428: $prefix = 'exttool';
2429: }
1.533 raeburn 2430: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2431: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2432: my $db_name;
2433: my $marker = (split(m{/},$url))[4];
2434: $marker=~s/\D//g;
2435: if ($dbref->{'src'} =~ m{/smppg$}) {
2436: $db_name =
2437: &Apache::lonsimplepage::get_db_name($url,$marker,
2438: $dbref->{'cdom'},
2439: $dbref->{'cnum'});
1.627 raeburn 2440: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2441: $db_name = 'exttool_'.$marker;
1.533 raeburn 2442: } else {
2443: $db_name = 'bulletinpage_'.$marker;
2444: }
2445: my ($suffix,$freedlock,$error) =
2446: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2447: $coursedom,$coursenum,
2448: 'concat');
2449: if (!$suffix) {
2450: if ($prefix eq 'smppg') {
2451: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2452: } elsif ($prefix eq 'exttool') {
2453: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2454: } else {
1.565 bisitz 2455: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2456: }
2457: if ($error) {
2458: $errtext .= '<br />'.$error;
2459: }
2460: } else {
2461: #need to copy the db contents to a new one.
2462: my %contents=&Apache::lonnet::dump($db_name,
2463: $dbref->{'cdom'},
2464: $dbref->{'cnum'});
1.704 raeburn 2465: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
2466: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
2467: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
2468: $oldtoolid = $2;
2469: if ($1 eq 'c') {
2470: $defincrs = 1;
2471: %toolinfo =
2472: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
2473: } else {
2474: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
2475: }
2476: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
2477: if ($toolinfo{$oldtoolid}{'passback'}) {
2478: $toolpassback = 1;
2479: }
2480: if ($toolinfo{$oldtoolid}{'roster'}) {
2481: $toolroster = 1;
2482: }
2483: } else {
2484: $toolcopyerror = 1;
2485: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
2486: }
2487: }
2488: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
2489: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
2490: if ($contents{'crstitle'} ne '') {
2491: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
2492: }
2493: if (($defincrs) && (!$toolcopyerror)) {
2494: my %newtool;
2495: my $oldcdom = $dbref->{'cdom'};
2496: my $oldcnum = $dbref->{'cnum'};
2497: my $title = $toolinfo{$oldtoolid}{'title'};
2498: if (ref($currltititles) eq 'HASH') {
2499: if (exists($currltititles->{$title})) {
2500: $title .= ' (copied from another course)';
2501: }
2502: }
2503: my ($newid,$iderror) =
2504: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
2505: if ($newid =~ /^\d+$/) {
2506: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
2507: $newtool{$newid}{'title'} = $title;
2508: if (ref($currltimax)) {
2509: $newtool{$newid}{'order'} = $$currltimax;
2510: }
2511: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
2512: my $fname = $1;
2513: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
2514: if ($content eq '-1') {
2515: delete($newtool{$newid}{'image'});
2516: } else {
2517: $env{'form.'.$suffix.'.image'} = $content;
2518: my $newlogo =
2519: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
2520: delete($env{'form.'.$suffix.'.image'});
2521: if ($newlogo =~ m{^/uploaded/}) {
2522: $newtool{$newid}{'image'} = $newlogo;
2523: } else {
2524: delete($newtool{$newid}{'image'});
2525: }
2526: }
2527: }
2528: my $newusable;
2529: if ($same_institution) {
2530: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
2531: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
2532: my %newtoolsenc;
2533: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
2534: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
2535: if ($putres eq 'ok') {
2536: if (ref($updatetoolsenc) eq 'ARRAY') {
2537: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
2538: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
2539: push(@{$updatetoolsenc},$newhome);
2540: }
2541: }
2542: $newusable = 1;
2543: }
2544: }
2545: }
2546: if ($newtool{$newid}{'usable'}) {
2547: unless ($newusable) {
2548: delete($newtool{$newid}{'usable'});
2549: }
2550: }
2551: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
2552: if ($putres eq 'ok') {
2553: $contents{'id'} = "c$newid";
2554: if (ref($updatetoolscache)) {
2555: $$updatetoolscache ++;
2556: }
2557: if (ref($currltititles->{$title}) eq 'ARRAY') {
2558: push(@{$currltititles->{$title}},$newid);
2559: } else {
2560: $currltititles->{$title} = [$newid];
2561: }
2562: if (ref($currltimax)) {
2563: $$currltimax ++;
2564: }
2565: } else {
2566: $toolcopyerror = 1;
2567: $errtext = &mt('Unable to save external tool definition in Course Settings.');
2568: }
2569: } else {
2570: $toolcopyerror = 1;
2571: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
2572: }
2573: }
2574: }
2575: }
1.533 raeburn 2576: if (exists($contents{'uploaded.photourl'})) {
2577: my $photo = $contents{'uploaded.photourl'};
2578: my ($subdir,$fname) =
2579: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2580: my $newphoto;
1.533 raeburn 2581: if ($fname ne '') {
2582: my $content = &Apache::lonnet::getfile($photo);
2583: unless ($content eq '-1') {
2584: $env{'form.'.$suffix.'.photourl'} = $content;
2585: $newphoto =
2586: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2587: delete($env{'form.'.$suffix.'.photourl'});
2588: }
2589: }
2590: if ($newphoto =~ m{^/uploaded/}) {
2591: $contents{'uploaded.photourl'} = $newphoto;
2592: }
2593: }
2594: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 2595: if ($prefix eq 'exttool') {
2596: unless ($toolcopyerror) {
2597: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
2598: if (exists($contents{$key})) {
2599: delete($contents{$key});
2600: }
2601: }
2602: if ($dbref->{'delgradable'}) {
2603: if (exists($contents{'gradable'})) {
2604: delete($contents{'gradable'});
2605: }
2606: }
2607: if ($toolpassback) {
2608: if ($contents{'gradable'}) {
2609: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2610: $contents{'gradesecret'} = $gradesecret;
2611: $contents{'gradesecretdate'} = time;
2612: }
2613: }
2614: if ($toolroster) {
2615: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2616: $contents{'rostersecret'} = $rostersecret;
2617: $contents{'rostersecretdate'} = time;
2618: }
2619: }
1.649 raeburn 2620: }
1.704 raeburn 2621: if (($prefix eq 'exttool') && ($toolcopyerror)) {
2622: $result = 'error';
2623: } else {
2624: $result=&Apache::lonnet::put($db_name,\%contents,
2625: $coursedom,$coursenum);
2626: if ($result eq 'ok') {
2627: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2628: }
1.533 raeburn 2629: }
2630: }
2631: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2632: $lockerrorsref->{$prefix} =
1.533 raeburn 2633: '<div class="LC_error">'.
2634: &mt('There was a problem removing a lockfile.');
2635: if ($prefix eq 'smppg') {
1.560 raeburn 2636: $lockerrorsref->{$prefix} .=
1.559 raeburn 2637: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2638: } elsif ($prefix eq 'exttool') {
2639: $lockerrorsref->{$prefix} .=
2640: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2641: } else {
1.565 bisitz 2642: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2643: }
1.560 raeburn 2644: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2645: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2646: '</div>';
1.533 raeburn 2647: }
2648: }
2649: } elsif ($url =~ m{/syllabus$}) {
2650: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2651: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2652: if (($dbref->{'cdom'} ne $coursedom) ||
2653: ($dbref->{'cnum'} ne $coursenum)) {
2654: my %contents=&Apache::lonnet::dump('syllabus',
2655: $dbref->{'cdom'},
2656: $dbref->{'cnum'});
2657: $result=&Apache::lonnet::put('syllabus',\%contents,
2658: $coursedom,$coursenum);
2659: }
2660: }
1.488 raeburn 2661: }
2662: }
1.533 raeburn 2663: return ($url,$result,$errtext);
1.488 raeburn 2664: }
2665:
1.597 raeburn 2666: sub copy_templated_files {
2667: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2668: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2669: my $srccontainer = 'sequence';
2670: if ($srcwaspage) {
2671: $srccontainer = 'page';
2672: }
2673: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2674: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2675: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2676: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2677: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2678: $template.'.problem';
2679: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2680: if ($template eq 'simpleproblem') {
2681: $srcprefix .= '.0.';
2682: my $weightprefix = $newprefix;
2683: $newprefix .= '.0.';
2684: my @simpleprobqtypes = qw(radio option string essay numerical);
2685: my $qtype=$srcparms{$srcprefix.'questiontype'};
2686: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2687: my %newdata = (
2688: $newprefix.'questiontype' => $qtype,
2689: );
1.597 raeburn 2690: foreach my $type (@simpleprobqtypes) {
2691: if ($type eq $qtype) {
2692: $newdata{"$weightprefix.$type.weight"}=1;
2693: } else {
2694: $newdata{"$weightprefix.$type.weight"}=0;
2695: }
2696: }
2697: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2698: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2699: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2700: if ($qtype eq 'numerical') {
2701: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2702: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2703: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2704: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2705: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2706: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2707: unless (defined($maxfoils)) { $maxfoils=10; }
2708: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2709: if ($maxfoils<=0) { $maxfoils=10; }
2710: my $randomize=$srcparms{$srcprefix.'randomize'};
2711: unless (defined($randomize)) { $randomize='yes'; }
2712: unless ($randomize eq 'no') { $randomize='yes'; }
2713: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2714: $newdata{$newprefix.'randomize'} = $randomize;
2715: if ($qtype eq 'option') {
2716: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2717: }
2718: for (my $i=1; $i<=10; $i++) {
2719: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2720: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2721: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2722: }
2723:
2724: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2725: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2726: unless (defined($maxfoils)) { $maxfoils=10; }
2727: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2728: if ($maxfoils<=0) { $maxfoils=10; }
2729: my $randomize=$srcparms{$srcprefix.'randomize'};
2730: unless (defined($randomize)) { $randomize='yes'; }
2731: unless ($randomize eq 'no') { $randomize='yes'; }
2732: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2733: $newdata{$newprefix.'randomize'} = $randomize;
2734: if ($qtype eq 'option') {
2735: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2736: }
2737: for (my $i=1; $i<=10; $i++) {
2738: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2739: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2740: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2741: }
2742: } elsif ($qtype eq 'string') {
2743: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2744: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2745: }
2746: if (keys(%newdata)) {
2747: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2748: $coursenum);
2749: if ($putres eq 'ok') {
2750: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2751: }
2752: }
2753: }
2754: }
2755: }
2756:
1.329 droeschl 2757: sub uniqueness_check {
2758: my ($newurl) = @_;
2759: my $unique = 1;
2760: foreach my $res (@LONCAPA::map::order) {
2761: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2762: $url=&LONCAPA::map::qtescape($url);
2763: if ($newurl eq $url) {
2764: $unique = 0;
1.344 bisitz 2765: last;
1.329 droeschl 2766: }
2767: }
2768: return $unique;
2769: }
2770:
1.488 raeburn 2771: sub contained_map_check {
1.627 raeburn 2772: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2773: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2774: my $content = &Apache::lonnet::getfile($url);
2775: unless ($content eq '-1') {
2776: my $parser = HTML::TokeParser->new(\$content);
2777: $parser->attr_encoded(1);
2778: while (my $token = $parser->get_token) {
2779: next if ($token->[0] ne 'S');
2780: if ($token->[1] eq 'resource') {
2781: next if ($token->[2]->{'type'} eq 'zombie');
2782: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 2783: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2784: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 2785: unless ($srcdom eq $coursedom) {
2786: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2787: next;
2788: }
1.704 raeburn 2789: unless ($srcnum eq $coursenum) {
2790: my %toolsettings =
2791: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
2792: my %tooltypes = &Apache::loncommon::usable_exttools();
2793: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2794: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2795: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2796: next;
2797: }
2798: }
1.627 raeburn 2799: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2800: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2801: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2802: next;
2803: }
2804: }
1.703 raeburn 2805: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
2806: my ($srcdom,$srcnum) = ($1,$2);
2807: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
2808: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
2809: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2810: next;
2811: }
2812: }
2813: }
1.492 raeburn 2814: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2815: if ($1 eq 'uploaded') {
2816: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2817: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2818: } else {
1.492 raeburn 2819: if ($allmaps->{$ressrc}) {
1.529 raeburn 2820: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2821: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2822: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2823: } else {
2824: $addedmaps->{$ressrc} = [$url];
2825: }
1.488 raeburn 2826: }
1.627 raeburn 2827: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2828: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2829: }
1.492 raeburn 2830: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2831: if ($folder =~ /^supplemental/) {
1.492 raeburn 2832: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2833: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2834: } else {
2835: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2836: }
1.488 raeburn 2837: }
2838: }
2839: }
2840: }
2841: return;
2842: }
2843:
2844: sub url_paste_fixups {
1.533 raeburn 2845: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2846: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2847: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2848: my $checktitle;
2849: if (($prefixchg) &&
1.492 raeburn 2850: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2851: $checktitle = 1;
2852: }
1.492 raeburn 2853: my $skip;
2854: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2855: my $mapid = $1.$2;
2856: if ($tomove->{$mapid}) {
2857: $skip = 1;
2858: }
2859: }
1.491 raeburn 2860: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2861: return if ($file eq '-1');
2862: my $parser = HTML::TokeParser->new(\$file);
2863: $parser->attr_encoded(1);
1.491 raeburn 2864: my $changed = 0;
1.488 raeburn 2865: while (my $token = $parser->get_token) {
2866: next if ($token->[0] ne 'S');
2867: if ($token->[1] eq 'resource') {
2868: my $ressrc = $token->[2]->{'src'};
2869: next if ($ressrc eq '');
1.491 raeburn 2870: my $id = $token->[2]->{'id'};
1.492 raeburn 2871: my $title = $token->[2]->{'title'};
1.491 raeburn 2872: if ($checktitle) {
2873: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2874: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2875: }
2876: }
1.488 raeburn 2877: next if ($token->[2]->{'type'} eq 'external');
2878: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2879: next if ($skip);
1.532 raeburn 2880: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2881: $changed = 1;
2882: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2883: my $srcdom = $1;
2884: my $srcnum = $2;
1.488 raeburn 2885: my $rem = $3;
1.492 raeburn 2886: my $newurl;
2887: my $mapname;
2888: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2889: my $prefix = $1;
2890: $mapname = $prefix.$2;
2891: if ($tomove->{$mapname}) {
1.533 raeburn 2892: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2893: $srcdom,$srcnum,$allmaps,$rewrites,
2894: $retitles,$copies,$dbcopies,$zombies,
2895: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2896: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2897: next;
2898: } else {
2899: ($newurl,my $error) =
2900: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2901: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2902: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2903: $newsubdir->{$ressrc} = $1;
2904: }
2905: if ($error) {
2906: next;
2907: }
2908: }
2909: }
2910: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2911: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2912:
1.488 raeburn 2913: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2914: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2915: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2916: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2917: $cnum,$srcdom,$srcnum,$allmaps,
2918: $rewrites,$retitles,$copies,$dbcopies,
2919: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2920: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2921: $mapmoves->{$ressrc} = 1;
2922: }
2923: $changed = 1;
1.488 raeburn 2924: } else {
1.532 raeburn 2925: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2926: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2927: $changed = 1;
1.488 raeburn 2928: }
2929: }
1.649 raeburn 2930: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2931: next if ($skip);
1.492 raeburn 2932: my $srcdom = $1;
2933: my $srcnum = $2;
1.649 raeburn 2934: my $rem = $3;
2935: my ($is_exttool,$exttoolchg);
2936: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2937: $is_exttool = 1;
1.649 raeburn 2938: }
1.492 raeburn 2939: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2940: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2941: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2942: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2943: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2944: $changed = 1;
1.649 raeburn 2945: if ($is_exttool) {
2946: $exttoolchg = 1;
2947: }
1.700 raeburn 2948: } elsif (($is_exttool) &&
1.649 raeburn 2949: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2950: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2951: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2952: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2953: $changed = 1;
2954: $exttoolchg = 1;
2955: }
2956: if (($is_exttool) && ($prefixchg)) {
2957: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2958: if ($exttoolchg) {
2959: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2960: }
2961: }
1.533 raeburn 2962: }
2963: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2964: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2965: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2966: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2967: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2968: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2969: $changed = 1;
1.488 raeburn 2970: }
1.597 raeburn 2971: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2972: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2973: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2974: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2975: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2976: }
1.488 raeburn 2977: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2978: next if ($skip);
2979: my $srcdom = $1;
2980: my $srcnum = $2;
2981: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2982: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2983: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2984: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2985: $changed = 1;
1.488 raeburn 2986: }
2987: }
2988: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2989: next if ($skip);
1.488 raeburn 2990: my $to = $token->[2]->{'to'};
2991: if ($to ne '') {
2992: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2993: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2994: } else {
2995: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2996: }
2997: }
2998: }
2999: }
1.491 raeburn 3000: return $changed;
1.488 raeburn 3001: }
3002:
3003: sub apply_fixups {
1.529 raeburn 3004: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3005: $oldurl,$url,$caller) = @_;
3006: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3007: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3008: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3009: %currltititles,$currltimax);
3010: $currltimax = 0;
1.529 raeburn 3011: if (ref($updated) eq 'HASH') {
3012: if (ref($updated->{'rewrites'}) eq 'HASH') {
3013: %rewrites = %{$updated->{'rewrites'}};
3014: }
3015: if (ref($updated->{'zombies'}) eq 'HASH') {
3016: %zombies = %{$updated->{'zombies'}};
3017: }
3018: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3019: %removefrommap = %{$updated->{'removefrommap'}};
3020: }
3021: if (ref($updated->{'removeparam'}) eq 'HASH') {
3022: %removeparam = %{$updated->{'removeparam'}};
3023: }
3024: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3025: %dbcopies = %{$updated->{'dbcopies'}};
3026: }
3027: if (ref($updated->{'retitles'}) eq 'HASH') {
3028: %retitles = %{$updated->{'retitles'}};
3029: }
1.597 raeburn 3030: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3031: %resdatacopy = %{$updated->{'resdatacopy'}};
3032: }
1.529 raeburn 3033: }
3034: if (ref($info) eq 'HASH') {
3035: if (ref($info->{'newsubdir'}) eq 'HASH') {
3036: %newsubdir = %{$info->{'newsubdir'}};
3037: }
3038: if (ref($info->{'params'}) eq 'HASH') {
3039: %params = %{$info->{'params'}};
3040: }
3041: if (ref($info->{'before'}) eq 'HASH') {
3042: %before = %{$info->{'before'}};
3043: }
3044: if (ref($info->{'after'}) eq 'HASH') {
3045: %after = %{$info->{'after'}};
3046: }
3047: }
3048: if (ref($moves) eq 'HASH') {
3049: if (ref($moves->{'copies'}) eq 'HASH') {
3050: %copies = %{$moves->{'copies'}};
3051: }
3052: if (ref($moves->{'docmoves'}) eq 'HASH') {
3053: %docmoves = %{$moves->{'docmoves'}};
3054: }
3055: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3056: %mapmoves = %{$moves->{'mapmoves'}};
3057: }
3058: }
3059: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 3060: my @allcopies;
1.529 raeburn 3061: if (exists($copies{$key})) {
3062: if (ref($copies{$key}) eq 'HASH') {
3063: my %added;
3064: foreach my $innerkey (keys(%{$copies{$key}})) {
3065: if (($innerkey ne '') && (!$added{$innerkey})) {
3066: push(@allcopies,$innerkey);
3067: $added{$innerkey} = 1;
3068: }
1.491 raeburn 3069: }
1.529 raeburn 3070: undef(%added);
1.491 raeburn 3071: }
3072: }
3073: if ($key eq $oldurl) {
1.529 raeburn 3074: if ((exists($docmoves{$key}))) {
1.532 raeburn 3075: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 3076: push(@allcopies,$oldurl);
3077: }
3078: }
3079: }
3080: if (@allcopies > 0) {
3081: foreach my $item (@allcopies) {
1.492 raeburn 3082: my ($relpath,$oldsubdir,$fname) =
3083: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 3084: if ($fname ne '') {
3085: my $content = &Apache::lonnet::getfile($item);
3086: unless ($content eq '-1') {
3087: my $storefn;
1.529 raeburn 3088: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3089: $storefn = $docmoves{$key};
1.491 raeburn 3090: } else {
3091: $storefn = $relpath;
3092: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3093: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3094: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 3095: }
1.529 raeburn 3096: if ($newsubdir{$key}) {
1.532 raeburn 3097: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 3098: }
3099: }
3100: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3101: my $copyurl =
3102: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3103: $storefn.$fname,$content);
3104: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 3105: if (exists($docmoves{$oldurl})) {
1.491 raeburn 3106: return &mt('Paste failed: an error occurred copying the file.');
3107: } elsif (ref($errors) eq 'HASH') {
3108: $errors->{$item} = 1;
1.489 raeburn 3109: }
3110: }
1.488 raeburn 3111: }
3112: }
1.491 raeburn 3113: }
3114: }
3115: }
1.529 raeburn 3116: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 3117: my $storefn=$key;
3118: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3119: if ($prefixchg && $before{'map'} && $after{'map'}) {
3120: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3121: }
1.529 raeburn 3122: if ($newsubdir{$key}) {
3123: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3124: }
1.491 raeburn 3125: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 3126: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3127: ($after{'map'} eq 'default') &&
3128: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3129: $mapcontent = '<map>'."\n".
3130: '<resource id="1" src="" type="start" />'."\n".
3131: '<link from="1" to="2" index="1" />'."\n".
3132: '<resource id="2" src="" type="finish" />'."\n".
3133: '</map>';
3134: }
1.491 raeburn 3135: if ($mapcontent eq '-1') {
3136: if (ref($errors) eq 'HASH') {
3137: $errors->{$key} = 1;
3138: }
3139: } else {
3140: my $newmap =
3141: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3142: $mapcontent);
3143: if ($newmap eq '/adm/notfound.html') {
3144: if (ref($errors) eq 'HASH') {
3145: $errors->{$key} = 1;
1.489 raeburn 3146: }
1.488 raeburn 3147: }
3148: }
3149: }
1.491 raeburn 3150: my %updates;
3151: if ($is_map) {
1.529 raeburn 3152: if (ref($updated) eq 'HASH') {
3153: foreach my $type (keys(%{$updated})) {
3154: if (ref($updated->{$type}) eq 'HASH') {
3155: foreach my $key (keys(%{$updated->{$type}})) {
3156: $updates{$key} = 1;
3157: }
3158: }
3159: }
1.491 raeburn 3160: }
1.704 raeburn 3161: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 3162: foreach my $key (keys(%updates)) {
1.492 raeburn 3163: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 3164: if (ref($rewrites{$key}) eq 'HASH') {
3165: %torewrite = %{$rewrites{$key}};
1.491 raeburn 3166: }
1.529 raeburn 3167: if (ref($retitles{$key}) eq 'HASH') {
3168: %toretitle = %{$retitles{$key}};
1.491 raeburn 3169: }
1.529 raeburn 3170: if (ref($removefrommap{$key}) eq 'HASH') {
3171: %toremove = %{$removefrommap{$key}};
1.491 raeburn 3172: }
1.529 raeburn 3173: if (ref($removeparam{$key}) eq 'HASH') {
3174: %remparam = %{$removeparam{$key}};
1.492 raeburn 3175: }
1.529 raeburn 3176: if (ref($zombies{$key}) eq 'HASH') {
3177: %zombie = %{$zombies{$key}};
1.491 raeburn 3178: }
1.529 raeburn 3179: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 3180: foreach my $idx (keys(%{$dbcopies{$key}})) {
3181: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 3182: my $oldurl = $dbcopies{$key}{$idx}{'src'};
3183: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3184: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3185: my $oldmarker;
3186: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3187: $oldmarker = $1;
3188: unless (($gotcrsltitools) ||
3189: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3190: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3191: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3192: unless ($gotcrsltitools) {
3193: %currcrsltitools =
3194: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3195: foreach my $item (sort(keys(%currcrsltitools))) {
3196: if (ref($currcrsltitools{$item}) eq 'HASH') {
3197: $currltimax ++;
3198: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3199: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3200: } else {
3201: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3202: }
3203: }
3204: }
3205: $gotcrsltitools = 1;
3206: }
3207: unless ($checkedsameinst) {
3208: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3209: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3210: if ($intdom ne '') {
3211: my $internet_names =
3212: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3213: if (ref($internet_names) eq 'ARRAY') {
3214: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3215: $same_institution = 1;
3216: }
3217: }
3218: }
3219: $checkedsameinst = 1;
3220: }
3221: }
3222: }
3223: }
1.533 raeburn 3224: my ($newurl,$result,$errtext) =
1.704 raeburn 3225: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3226: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 3227: if ($result eq 'ok') {
3228: $newdb{$idx} = $newurl;
1.704 raeburn 3229: if ($newurl =~ /ext\.tool$/) {
3230: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3231: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3232: my $newmarker = $1;
3233: unless ($oldmarker eq $newmarker) {
3234: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3235: }
3236: }
3237: }
3238: }
1.533 raeburn 3239: } elsif (ref($errors) eq 'HASH') {
3240: $errors->{$key} = 1;
3241: }
3242: push(@msgs,$errtext);
3243: }
1.491 raeburn 3244: }
3245: }
1.597 raeburn 3246: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 3247: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 3248: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3249: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3250: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3251: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3252: my $template = $1;
3253: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3254: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3255: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3256: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 3257: unless ($gotnewmapname) {
3258: ($newmapname) = ($key =~ m{/([^/]+)$});
3259: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3260: if ($newsubdir{$key}) {
3261: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3262: }
3263: $gotnewmapname = 1;
3264: }
1.597 raeburn 3265: my $srcmapinfo = $srcfolder.':'.$idx;
3266: if ($srccontainer eq 'page') {
3267: $srcmapinfo .= ':1';
3268: }
3269: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3270: $cnum,$template,$idx,$newmapname);
3271: }
3272: }
3273: }
3274: }
3275: }
1.529 raeburn 3276: if (ref($params{$key}) eq 'HASH') {
3277: %currparam = %{$params{$key}};
1.492 raeburn 3278: }
3279: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3280: if ($fatal) {
1.533 raeburn 3281: return ($errtext);
1.492 raeburn 3282: }
3283: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3284: if (defined($LONCAPA::map::zombies[$i])) {
3285: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 3286: if ($zombie{$i} eq $src) {
1.492 raeburn 3287: undef($LONCAPA::map::zombies[$i]);
3288: }
3289: }
3290: }
1.646 raeburn 3291: my $total = scalar(@LONCAPA::map::order) - 1;
3292: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 3293: my $idx = $LONCAPA::map::order[$i];
3294: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 3295: my $changed;
1.529 raeburn 3296: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 3297: if ((exists($toremove{$idx})) &&
3298: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 3299: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 3300: if (ref($currparam{$idx}) eq 'ARRAY') {
3301: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 3302: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 3303: }
3304: }
3305: next;
3306: }
3307: my $origsrc = $src;
1.532 raeburn 3308: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 3309: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3310: $changed = 1;
1.491 raeburn 3311: }
1.492 raeburn 3312: }
1.532 raeburn 3313: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 3314: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3315: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 3316: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 3317: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 3318: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 3319: } else {
1.529 raeburn 3320: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 3321: }
1.491 raeburn 3322: }
1.532 raeburn 3323: if ($origsrc =~ /\.(page|sequence)$/) {
3324: if ($newsubdir{$origsrc}) {
1.529 raeburn 3325: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 3326: }
1.532 raeburn 3327: } elsif ($newsubdir{$key}) {
3328: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 3329: }
3330: }
1.492 raeburn 3331: $changed = 1;
1.533 raeburn 3332: } elsif ($newdb{$idx} ne '') {
3333: $src = $newdb{$idx};
1.492 raeburn 3334: $changed = 1;
3335: }
3336: if ($changed) {
1.538 raeburn 3337: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 3338: }
3339: }
3340: }
3341: foreach my $idx (keys(%remparam)) {
3342: if (ref($remparam{$idx}) eq 'ARRAY') {
3343: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3344: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3345: }
3346: }
3347: }
1.533 raeburn 3348: if (values(%lockerrors) > 0) {
3349: $lockmsg = join('<br />',values(%lockerrors));
3350: }
1.491 raeburn 3351: my $storefn;
3352: if ($key eq $oldurl) {
3353: $storefn = $url;
3354: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3355: } else {
3356: $storefn = $key;
3357: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3358: if ($prefixchg && $before{'map'} && $after{'map'}) {
3359: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3360: }
1.529 raeburn 3361: if ($newsubdir{$key}) {
3362: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3363: }
1.491 raeburn 3364: }
1.492 raeburn 3365: my $report;
3366: if ($folder !~ /^supplemental/) {
3367: $report = 1;
3368: }
1.527 raeburn 3369: (my $outtext,$errtext) =
1.492 raeburn 3370: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3371: if ($errtext) {
1.529 raeburn 3372: if ($caller eq 'paste') {
1.533 raeburn 3373: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3374: }
1.491 raeburn 3375: }
3376: }
1.704 raeburn 3377: if (($updatetoolscache) || (@updatetoolsenc)) {
3378: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
3379: \@updatetoolsenc);
3380: }
1.491 raeburn 3381: }
1.533 raeburn 3382: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3383: }
3384:
3385: sub copy_dependencies {
3386: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3387: my $content;
3388: if (ref($contentref)) {
3389: $content = $$contentref;
3390: } else {
3391: $content = &Apache::lonnet::getfile($item);
3392: }
3393: unless ($content eq '-1') {
3394: my $mm = new File::MMagic;
3395: my $mimetype = $mm->checktype_contents($content);
3396: if ($mimetype eq 'text/html') {
3397: my (%allfiles,%codebase,$state);
3398: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3399: if ($res eq 'ok') {
3400: my ($numexisting,$numpathchanges,$existing);
3401: (undef,$numexisting,$numpathchanges,$existing) =
3402: &Apache::loncommon::ask_for_embedded_content(
3403: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3404: {'error_on_invalid_names' => 1,
3405: 'ignore_remote_references' => 1,
3406: 'docs_url' => $item,
3407: 'context' => 'paste'});
3408: if ($numexisting > 0) {
3409: if (ref($existing) eq 'HASH') {
3410: foreach my $dep (keys(%{$existing})) {
3411: my $depfile = $dep;
3412: unless ($depfile =~ m{^\Q$relpath\E}) {
3413: $depfile = $relpath.$dep;
3414: }
3415: my $depcontent = &Apache::lonnet::getfile($depfile);
3416: unless ($depcontent eq '-1') {
3417: my $storedep = $dep;
3418: $storedep =~ s{^\Q$relpath\E}{};
3419: my $dep_url =
3420: &Apache::lonclonecourse::writefile(
3421: $env{'request.course.id'},
3422: $storefn.$storedep,$depcontent);
3423: if ($dep_url eq '/adm/notfound.html') {
3424: if (ref($errors) eq 'HASH') {
3425: $errors->{$depfile} = 1;
3426: }
3427: } else {
3428: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3429: }
3430: }
3431: }
1.488 raeburn 3432: }
3433: }
3434: }
3435: }
3436: }
3437: return;
3438: }
3439:
1.329 droeschl 3440: my %parameter_type = ( 'randompick' => 'int_pos',
3441: 'hiddenresource' => 'string_yesno',
3442: 'encrypturl' => 'string_yesno',
3443: 'randomorder' => 'string_yesno',);
3444: my $valid_parameters_re = join('|',keys(%parameter_type));
3445: # set parameters
3446: sub update_parameter {
1.537 raeburn 3447: if ($env{'form.changeparms'} eq 'all') {
3448: my (@allidx,@allmapidx,%allchecked,%currchecked);
3449: %allchecked = (
3450: 'hiddenresource' => {},
3451: 'encrypturl' => {},
3452: 'randompick' => {},
3453: 'randomorder' => {},
3454: );
3455: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3456: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3457: if ($which eq 'randompick') {
3458: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3459: my ($res,$value) = split(/:/,$item);
3460: if ($value =~ /^\d+$/) {
3461: $allchecked{$which}{$res} = $value;
3462: }
3463: }
3464: } else {
1.539 raeburn 3465: if ($env{'form.all'.$which}) {
3466: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3467: }
1.537 raeburn 3468: }
3469: }
3470: my $haschanges = 0;
3471: foreach my $res (@LONCAPA::map::order) {
3472: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3473: $name=&LONCAPA::map::qtescape($name);
3474: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3475: next unless $url;
1.537 raeburn 3476: my $is_map;
3477: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3478: $is_map = 1;
3479: }
3480: foreach my $which (keys(%allchecked)) {
3481: if (($which eq 'randompick' || $which eq 'randomorder')) {
3482: next if (!$is_map);
3483: }
3484: my $oldvalue = 0;
3485: my $newvalue = 0;
3486: if ($allchecked{$which}{$res}) {
3487: $newvalue = $allchecked{$which}{$res};
3488: }
3489: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3490: if ($which eq 'randompick') {
3491: if ($current =~ /^(\d+)$/) {
3492: $oldvalue = $1;
3493: }
3494: } else {
3495: if ($current =~ /^yes$/i) {
3496: $oldvalue = 1;
3497: }
3498: }
3499: if ($oldvalue ne $newvalue) {
3500: $haschanges = 1;
3501: if ($newvalue) {
3502: my $storeval = 'yes';
3503: if ($which eq 'randompick') {
3504: $storeval = $newvalue;
3505: }
3506: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3507: $storeval,
3508: $parameter_type{$which});
3509: &remember_parms($res,$which,'set',$storeval);
3510: } elsif ($oldvalue) {
3511: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3512: &remember_parms($res,$which,'del');
3513: }
3514: }
3515: }
3516: }
3517: return $haschanges;
3518: } else {
1.588 raeburn 3519: my $haschanges = 0;
3520: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3521:
1.537 raeburn 3522: my $which = $env{'form.changeparms'};
3523: my $idx = $env{'form.setparms'};
1.588 raeburn 3524: my $oldvalue = 0;
3525: my $newvalue = 0;
3526: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3527: if ($which eq 'randompick') {
3528: if ($current =~ /^(\d+)$/) {
3529: $oldvalue = $1;
3530: }
3531: } elsif ($current =~ /^yes$/i) {
3532: $oldvalue = 1;
3533: }
1.537 raeburn 3534: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3535: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3536: : 1;
3537: }
3538: if ($oldvalue ne $newvalue) {
3539: $haschanges = 1;
3540: if ($newvalue) {
3541: my $storeval = 'yes';
3542: if ($which eq 'randompick') {
3543: $storeval = $newvalue;
3544: }
3545: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3546: $parameter_type{$which});
3547: &remember_parms($idx,$which,'set',$storeval);
3548: } else {
3549: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3550: &remember_parms($idx,$which,'del');
3551: }
1.537 raeburn 3552: }
1.588 raeburn 3553: return $haschanges;
1.329 droeschl 3554: }
3555: }
3556:
3557: sub handle_edit_cmd {
3558: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3559: my $haschanges = 0;
1.543 raeburn 3560: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3561: return $haschanges;
1.543 raeburn 3562: }
1.329 droeschl 3563: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3564:
3565: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3566: my ($title, $url, @rrest) = split(':', $ratstr);
3567:
1.538 raeburn 3568: if ($cmd eq 'remove') {
1.329 droeschl 3569: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3570: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3571: &Apache::lonnet::removeuploadedurl($url);
3572: } else {
3573: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3574: }
3575: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3576: $haschanges = 1;
1.329 droeschl 3577: } elsif ($cmd eq 'cut') {
3578: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3579: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3580: $haschanges = 1;
1.344 bisitz 3581: } elsif ($cmd eq 'up'
1.329 droeschl 3582: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3583: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3584: $haschanges = 1;
1.329 droeschl 3585: } elsif ($cmd eq 'down'
3586: && defined($LONCAPA::map::order[$idx+1])) {
3587: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3588: $haschanges = 1;
1.329 droeschl 3589: } elsif ($cmd eq 'rename') {
3590: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3591: if ($comment=~/\S/) {
3592: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3593: $comment.':'.join(':', $url, @rrest);
3594: }
3595: # Devalidate title cache
3596: my $renamed_url=&LONCAPA::map::qtescape($url);
3597: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3598: $haschanges = 1;
3599: } elsif ($cmd eq 'setalias') {
3600: my $newvalue = $env{'form.alias'};
3601: if ($newvalue ne '') {
3602: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3603: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3604: 'string');
3605: &remember_parms($idx,'mapalias','set',$newvalue);
3606: $haschanges = 1;
3607: }
3608: }
3609: } elsif ($cmd eq 'delalias') {
3610: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3611: if ($current ne '') {
3612: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3613: &remember_parms($idx,'mapalias','del');
3614: $haschanges = 1;
3615: }
1.329 droeschl 3616: }
1.633 raeburn 3617: return $haschanges;
1.329 droeschl 3618: }
3619:
3620: sub editor {
1.458 raeburn 3621: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3622: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3623: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3624: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3625: if ($allowed) {
1.519 raeburn 3626: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3627: $is_random_order,$container) =
1.510 raeburn 3628: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3629: $r->print($breadcrumbtrail);
1.519 raeburn 3630: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3631: $container = 'page';
3632: } else {
3633: $container = 'sequence';
1.510 raeburn 3634: }
1.484 raeburn 3635:
1.525 raeburn 3636: my $jumpto;
3637:
3638: unless ($supplementalflag) {
1.546 raeburn 3639: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3640: }
1.484 raeburn 3641:
3642: unless ($allowed) {
3643: $randompick = -1;
3644: }
3645:
1.615 raeburn 3646: my ($errtext,$fatal);
3647: if (($folder eq '') && (!$supplementalflag)) {
3648: if (@LONCAPA::map::order) {
3649: undef(@LONCAPA::map::order);
3650: undef(@LONCAPA::map::resources);
3651: undef(@LONCAPA::map::resparms);
3652: undef(@LONCAPA::map::zombies);
3653: }
3654: $folder = 'default';
3655: $container = 'sequence';
3656: } else {
3657: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3658: $folder.'.'.$container);
3659: return $errtext if ($fatal);
3660: }
1.329 droeschl 3661:
3662: if ($#LONCAPA::map::order<1) {
3663: my $idx=&LONCAPA::map::getresidx();
3664: if ($idx<=0) { $idx=1; }
3665: $LONCAPA::map::order[0]=$idx;
3666: $LONCAPA::map::resources[$idx]='';
3667: }
1.364 bisitz 3668:
1.329 droeschl 3669: # ------------------------------------------------------------ Process commands
3670:
3671: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3672: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3673: # set parameters and change order
3674: &snapshotbefore();
3675:
3676: if (&update_parameter()) {
1.588 raeburn 3677: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3678: return $errtext if ($fatal);
3679: }
3680:
3681: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3682: # change order
3683: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3684: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3685:
3686: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3687: return $errtext if ($fatal);
3688: }
1.364 bisitz 3689:
1.329 droeschl 3690: if ($env{'form.pastemarked'}) {
1.491 raeburn 3691: my %paste_errors;
1.533 raeburn 3692: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3693: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3694: \%paste_errors);
1.541 raeburn 3695: if (ref($pastemsgarray) eq 'ARRAY') {
3696: if (@{$pastemsgarray} > 0) {
3697: $r->print('<p class="LC_info">'.
3698: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3699: '</p>');
3700: }
1.541 raeburn 3701: }
3702: if ($lockerror) {
3703: $r->print('<p class="LC_error">'.
3704: $lockerror.
3705: '</p>');
3706: }
3707: if ($save_error ne '') {
3708: return $save_error;
3709: }
3710: if ($paste_res) {
3711: my %errortext = &Apache::lonlocal::texthash (
3712: fail => 'Storage of folder contents failed',
3713: failread => 'Reading folder contents failed',
3714: failstore => 'Storage of folder contents failed',
3715: );
3716: if ($errortext{$paste_res}) {
3717: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3718: }
1.329 droeschl 3719: }
1.491 raeburn 3720: if (keys(%paste_errors) > 0) {
1.538 raeburn 3721: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3722: &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".
3723: '<ul>'."\n");
3724: foreach my $key (sort(keys(%paste_errors))) {
3725: $r->print('<li>'.$key.'</li>'."\n");
3726: }
3727: $r->print('</ul></p>'."\n");
3728: }
1.538 raeburn 3729: } elsif ($env{'form.clearmarked'}) {
3730: my $output = &do_buffer_empty();
3731: if ($output) {
3732: $r->print('<p class="LC_info">'.$output.'</p>');
3733: }
3734: }
1.329 droeschl 3735:
3736: $r->print($upload_output);
3737:
1.538 raeburn 3738: # Rename, cut, copy or remove a single resource
1.602 raeburn 3739: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3740: my $contentchg;
1.633 raeburn 3741: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3742: $contentchg = 1;
3743: }
3744: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3745: return $errtext if ($fatal);
3746: }
1.538 raeburn 3747:
3748: # Cut, copy and/or remove multiple resources
3749: if ($env{'form.multichange'}) {
3750: my %allchecked = (
3751: cut => {},
3752: remove => {},
3753: );
3754: my $needsupdate;
3755: foreach my $which (keys(%allchecked)) {
3756: $env{'form.multi'.$which} =~ s/,$//;
3757: if ($env{'form.multi'.$which}) {
3758: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3759: if (ref($allchecked{$which}) eq 'HASH') {
3760: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3761: }
3762: }
3763: }
3764: if ($needsupdate) {
3765: my $haschanges = 0;
3766: my %curr_groups = &Apache::longroup::coursegroups();
3767: my $total = scalar(@LONCAPA::map::order) - 1;
3768: for (my $i=$total; $i>=0; $i--) {
3769: my $res = $LONCAPA::map::order[$i];
3770: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3771: $name=&LONCAPA::map::qtescape($name);
3772: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3773: next unless $url;
1.538 raeburn 3774: my %denied =
3775: &action_restrictions($coursenum,$coursedom,$url,
3776: $env{'form.folderpath'},\%curr_groups);
3777: foreach my $which (keys(%allchecked)) {
3778: next if ($denied{$which});
3779: next unless ($allchecked{$which}{$res});
3780: if ($which eq 'remove') {
3781: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3782: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3783: &Apache::lonnet::removeuploadedurl($url);
3784: } else {
3785: &LONCAPA::map::makezombie($res);
3786: }
3787: splice(@LONCAPA::map::order,$i,1);
3788: $haschanges ++;
3789: } elsif ($which eq 'cut') {
3790: &LONCAPA::map::makezombie($res);
3791: splice(@LONCAPA::map::order,$i,1);
3792: $haschanges ++;
3793: }
3794: }
3795: }
3796: if ($haschanges) {
3797: ($errtext,$fatal) =
3798: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3799: return $errtext if ($fatal);
3800: }
3801: }
3802: }
3803:
1.329 droeschl 3804: # Group import/search
3805: if ($env{'form.importdetail'}) {
3806: my @imports;
3807: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3808: if (defined($item)) {
3809: my ($name,$url,$residx)=
1.533 raeburn 3810: map { &unescape($_); } split(/\=/,$item);
3811: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3812: my ($suffix,$errortxt,$locknotfreed) =
3813: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3814: if ($locknotfreed) {
3815: $r->print($locknotfreed);
3816: }
3817: if ($suffix) {
3818: $url =~ s/_new\./_$suffix./;
3819: } else {
3820: return $errortxt;
3821: }
1.533 raeburn 3822: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3823: my $type = $1;
3824: my ($suffix,$errortxt,$locknotfreed) =
3825: &new_timebased_suffix($coursedom,$coursenum,$type);
3826: if ($locknotfreed) {
3827: $r->print($locknotfreed);
3828: }
3829: if ($suffix) {
3830: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3831: } else {
3832: return $errortxt;
3833: }
1.626 raeburn 3834: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3835: my ($suffix,$errortxt,$locknotfreed) =
3836: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3837: if ($locknotfreed) {
3838: $r->print($locknotfreed);
3839: }
3840: if ($suffix) {
3841: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3842: } else {
3843: return $errortxt;
3844: }
1.534 raeburn 3845: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3846: if ($supplementalflag) {
3847: next unless ($1 eq 'supplemental');
3848: if ($folder eq 'supplemental') {
3849: next unless ($2 eq 'default');
3850: } else {
3851: next unless ($folder eq 'supplemental_'.$2);
3852: }
3853: } else {
3854: next unless ($1 eq 'docs');
3855: if ($folder eq 'default') {
3856: next unless ($2 eq 'default');
3857: } else {
3858: next unless ($folder eq 'default_'.$2);
3859: }
3860: }
1.504 raeburn 3861: }
1.329 droeschl 3862: push(@imports, [$name, $url, $residx]);
3863: }
3864: }
1.530 raeburn 3865: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3866: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3867: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3868: return $errtext if ($fatal);
1.529 raeburn 3869: if ($fixuperrors) {
3870: $r->print($fixuperrors);
3871: }
1.329 droeschl 3872: }
3873: # Loading a complete map
3874: if ($env{'form.loadmap'}) {
3875: if ($env{'form.importmap'}=~/\w/) {
3876: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3877: my ($title,$url,$ext,$type)=split(/\:/,$res);
3878: my $idx=&LONCAPA::map::getresidx($url);
3879: $LONCAPA::map::resources[$idx]=$res;
3880: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3881: }
3882: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3883: $folder.'.'.$container,1);
1.329 droeschl 3884: return $errtext if ($fatal);
3885: } else {
3886: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3887:
1.329 droeschl 3888: }
3889: }
3890: &log_differences($plain);
3891: }
3892: # ---------------------------------------------------------------- End commands
3893: # ---------------------------------------------------------------- Print screen
3894: my $idx=0;
3895: my $shown=0;
3896: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3897: $r->print('<div class="LC_Box">'.
1.432 raeburn 3898: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3899: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3900: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3901: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3902: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3903: '</ol>');
1.381 bisitz 3904: if ($randompick>=0) {
3905: $r->print('<p class="LC_warning">'
3906: .&mt('Caution: this folder is set to randomly pick a subset'
3907: .' of resources. Adding or removing resources from this'
3908: .' folder will change the set of resources that the'
3909: .' students see, resulting in spurious or missing credit'
3910: .' for completed problems, not limited to ones you'
3911: .' modify. Do not modify the contents of this folder if'
3912: .' it is in active student use.')
3913: .'</p>'
3914: );
3915: }
3916: if ($is_random_order) {
3917: $r->print('<p class="LC_warning">'
3918: .&mt('Caution: this folder is set to randomly order its'
3919: .' contents. Adding or removing resources from this folder'
3920: .' will change the order of resources shown.')
3921: .'</p>'
3922: );
3923: }
3924: $r->print('</div>');
1.364 bisitz 3925: }
1.381 bisitz 3926:
1.685 raeburn 3927: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3928: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3929: if (ref($supplemental) eq 'HASH') {
3930: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3931: (ref($supplemental->{'ids'}) eq 'HASH')) {
3932: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3933: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3934: if ($supplemental->{'hidden'}->{$mapnum}) {
3935: $ishidden = 1;
3936: }
3937: }
3938: }
3939: }
3940: }
3941:
1.538 raeburn 3942: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3943: %filters = (
1.543 raeburn 3944: canremove => [],
3945: cancut => [],
3946: cancopy => [],
3947: hiddenresource => [],
3948: encrypturl => [],
3949: randomorder => [],
3950: randompick => [],
1.538 raeburn 3951: );
3952: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3953: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3954: foreach my $res (@LONCAPA::map::order) {
3955: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3956: $name=&LONCAPA::map::qtescape($name);
3957: $url=&LONCAPA::map::qtescape($url);
3958: unless ($name) { $name=(split(/\//,$url))[-1]; }
3959: unless ($name) { $idx++; next; }
1.537 raeburn 3960: push(@allidx,$res);
3961: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3962: push(@allmapidx,$res);
3963: }
1.617 raeburn 3964:
1.682 raeburn 3965: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3966: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3967: $idx++;
3968: next;
3969: }
1.682 raeburn 3970: }
1.381 bisitz 3971: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3972: $coursenum,$coursedom,$crstype,
1.538 raeburn 3973: $pathitem,$supplementalflag,$container,
1.620 raeburn 3974: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3975: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3976: $idx++;
3977: $shown++;
1.329 droeschl 3978: }
1.424 onken 3979: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3980:
1.538 raeburn 3981: my $need_save;
1.611 raeburn 3982: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3983: my $toolslink;
1.682 raeburn 3984: if ($allowed || $canedit) {
3985: my $helpitem = 'Navigation_Screen';
3986: if (!$allowed) {
3987: $helpitem = 'Supplemental_Navigation';
3988: }
1.544 raeburn 3989: $toolslink = '<table><tr><td>'
1.520 raeburn 3990: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3991: $helpitem,undef,'RAT')
1.520 raeburn 3992: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3993: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3994: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3995: .'id="LC_content_toolbar_edittoplevel" '
3996: .'class="LC_toolbarItem" '
3997: .'title="'.&mt('Supplemental Content Editor').'">'
3998: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3999: }
1.510 raeburn 4000: if ($shown) {
4001: if ($allowed) {
4002: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4003: .&Apache::loncommon::start_data_table(undef,'contentlist')
4004: .&Apache::loncommon::start_data_table_header_row()
4005: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4006: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4007: .'<th>'.&mt('Document').'</th>'
4008: .'<th colspan="2">'.&mt('Settings').'</th>'
4009: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4010: if ($folder !~ /^supplemental/) {
1.538 raeburn 4011: $lists{'canhide'} = join(',',@allidx);
4012: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4013: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4014: 'randomorder','randompick');
4015: foreach my $item (@possfilters) {
1.538 raeburn 4016: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4017: if (@{$filters{$item}} > 0) {
4018: $lists{$item} = join(',',@{$filters{$item}});
4019: }
1.538 raeburn 4020: }
4021: }
1.537 raeburn 4022: if (@allidx > 0) {
4023: my $path;
4024: if ($env{'form.folderpath'}) {
1.630 raeburn 4025: $path =
1.537 raeburn 4026: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4027: }
1.538 raeburn 4028: if (@allidx > 1) {
1.630 raeburn 4029: $to_show .=
1.538 raeburn 4030: &Apache::loncommon::continue_data_table_row().
4031: '<td colspan="2"> </td>'.
4032: '<td>'.
1.611 raeburn 4033: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4034: '</td>'.
1.633 raeburn 4035: '<td colspan="3"> </td>'.
4036: '<td colspan="2">'.
1.611 raeburn 4037: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4038: '</td>'.
4039: &Apache::loncommon::end_data_table_row();
4040: $need_save = 1;
4041: }
1.537 raeburn 4042: }
4043: }
4044: $to_show .= $output.' '
1.510 raeburn 4045: .&Apache::loncommon::end_data_table()
4046: .'<br style="line-height:2px;" />'
4047: .&Apache::loncommon::end_scrollbox();
4048: } else {
1.520 raeburn 4049: $to_show .= $toolslink
1.510 raeburn 4050: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4051: .$output.' '
4052: .&Apache::loncommon::end_data_table();
1.393 raeburn 4053: }
1.510 raeburn 4054: } else {
1.520 raeburn 4055: if (!$allowed) {
4056: $to_show .= $toolslink;
4057: }
1.615 raeburn 4058: my $noresmsg;
4059: if ($allowed && $hiddentop && !$supplementalflag) {
4060: $noresmsg = &mt('Main Content Hidden');
4061: } else {
4062: $noresmsg = &mt('Currently empty');
4063: }
1.510 raeburn 4064: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4065: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 4066: .$noresmsg
1.510 raeburn 4067: .'</div>'
4068: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4069: }
4070: } else {
1.510 raeburn 4071: if ($shown) {
4072: $to_show = '<div>'
4073: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4074: .$output
4075: .&Apache::loncommon::end_data_table()
4076: .'</div>';
4077: } else {
4078: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 4079: .&mt('Currently empty')
1.510 raeburn 4080: .'</div>'
4081: }
1.458 raeburn 4082: }
4083: my $tid = 1;
4084: if ($supplementalflag) {
4085: $tid = 2;
1.329 droeschl 4086: }
4087: if ($allowed) {
1.484 raeburn 4088: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 4089: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 4090: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4091: if ($canedit) {
4092: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4093: }
1.460 raeburn 4094: } else {
4095: $r->print($to_show);
1.329 droeschl 4096: }
4097: return;
4098: }
4099:
1.538 raeburn 4100: sub multiple_check_form {
1.611 raeburn 4101: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 4102: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 4103: my $disabled;
4104: unless ($canedit) {
1.700 raeburn 4105: $disabled = ' disabled="disabled"';
1.611 raeburn 4106: }
1.538 raeburn 4107: my $output =
4108: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4109: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4110: '<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>'.
4111: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4112: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4113: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4114: if ($caller eq 'settings') {
4115: $output .=
4116: '<table><tr>'.
4117: '<td class="LC_docs_entry_parameter">'.
4118: '<span class="LC_nobreak"><label>'.
1.611 raeburn 4119: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 4120: '</label></span></td>'.
4121: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4122: '<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 4123: '</span></td>'.
4124: '</tr>'."\n".
4125: '<tr>'.
4126: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4127: '<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 4128: '</label></span>'.
4129: '</td></tr></table>'."\n";
4130: } else {
4131: $output .=
4132: '<table><tr>'.
4133: '<td class="LC_docs_entry_parameter">'.
4134: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 4135: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 4136: '</label></span></td>'.
4137: '<td class="LC_docs_entry_parameter">'.
4138: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 4139: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 4140: '</label></span></td>'."\n".
4141: '<td class="LC_docs_entry_parameter">'.
4142: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 4143: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 4144: '</label></span></td>'.
4145: '</tr></table>'."\n";
4146: }
4147: $output .=
4148: '</fieldset>'.
4149: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4150: if ($caller eq 'settings') {
4151: $output .=
1.543 raeburn 4152: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4153: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4154: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4155: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4156: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 4157: } elsif ($caller eq 'actions') {
4158: $output .=
4159: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4160: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4161: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4162: }
4163: $output .=
4164: '</form>'.
4165: '</div>';
4166: return $output;
4167: }
4168:
1.329 droeschl 4169: sub process_file_upload {
1.552 raeburn 4170: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4171: # upload a file, if present
1.552 raeburn 4172: my $filesize = length($env{'form.uploaddoc'});
4173: if (!$filesize) {
4174: $$upload_output = '<div class="LC_error">'.
4175: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4176: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4177: $filesize).'<br />'.
4178: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4179: '</div>';
4180: return;
4181: }
4182: my $quotatype = 'unofficial';
4183: if ($crstype eq 'Community') {
1.601 raeburn 4184: $quotatype = 'community';
4185: } elsif ($crstype eq 'Placement') {
4186: $quotatype = 'placement';
1.580 raeburn 4187: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 4188: $quotatype = 'official';
1.573 raeburn 4189: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4190: $quotatype = 'textbook';
1.552 raeburn 4191: }
4192: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4193: $filesize = int($filesize/1000); #expressed in kb
4194: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 4195: $env{'form.uploaddoc.filename'},$filesize,
4196: 'upload',$quotatype);
1.552 raeburn 4197: return if ($$upload_output);
4198: }
1.440 raeburn 4199: my ($parseaction,$showupload,$nextphase,$mimetype);
4200: if ($env{'form.parserflag'}) {
1.329 droeschl 4201: $parseaction = 'parse';
4202: }
4203: my $folder=$env{'form.folder'};
4204: if ($folder eq '') {
4205: $folder='default';
4206: }
4207: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4208: my $errtext='';
4209: my $fatal=0;
4210: my $container='sequence';
1.519 raeburn 4211: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 4212: $container='page';
4213: }
4214: ($errtext,$fatal)=
1.534 raeburn 4215: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 4216: if ($#LONCAPA::map::order<1) {
4217: $LONCAPA::map::order[0]=1;
4218: $LONCAPA::map::resources[1]='';
4219: }
4220: my $destination = 'docs/';
4221: if ($folder =~ /^supplemental/) {
4222: $destination = 'supplemental/';
4223: }
4224: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4225: $destination .= 'default/';
4226: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4227: $destination .= $2.'/';
4228: }
1.534 raeburn 4229: if ($fatal) {
4230: $$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>';
4231: return;
4232: }
1.440 raeburn 4233: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 4234: my $newidx=&LONCAPA::map::getresidx();
4235: $destination .= $newidx;
1.439 raeburn 4236: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 4237: $parseaction,$allfiles,
1.440 raeburn 4238: $codebase,undef,undef,undef,undef,
4239: undef,undef,\$mimetype);
4240: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4241: my $stored = $1;
4242: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4243: $stored.'</span>').'</p>';
4244: } else {
4245: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4246:
1.457 raeburn 4247: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 4248: return;
4249: }
1.329 droeschl 4250: my $ext='false';
4251: if ($url=~m{^http://}) { $ext='true'; }
4252: $url = &LONCAPA::map::qtunescape($url);
4253: my $comment=$env{'form.comment'};
4254: $comment = &LONCAPA::map::qtunescape($comment);
4255: if ($folder=~/^supplemental/) {
4256: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4257: $env{'user.domain'}.'___&&&___'.$comment;
4258: }
4259:
4260: $LONCAPA::map::resources[$newidx]=
4261: $comment.':'.$url.':'.$ext.':normal:res';
4262: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4263: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4264: $folder.'.'.$container,1);
1.329 droeschl 4265: if ($fatal) {
1.457 raeburn 4266: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 4267: return;
1.329 droeschl 4268: } else {
1.440 raeburn 4269: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4270: $$upload_output = $showupload;
1.384 raeburn 4271: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 4272: if ($total_embedded > 0) {
1.440 raeburn 4273: my $uploadphase = 'upload_embedded';
4274: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4275: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 4276: my ($embedded,$num) =
1.440 raeburn 4277: &Apache::loncommon::ask_for_embedded_content(
4278: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4279: if ($embedded) {
4280: if ($num) {
4281: $$upload_output .=
4282: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4283: $nextphase = $uploadphase;
4284: } else {
4285: $$upload_output .= $embedded;
4286: }
4287: } else {
4288: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4289: }
1.329 droeschl 4290: } else {
1.440 raeburn 4291: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 4292: }
1.457 raeburn 4293: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 4294: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4295: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 4296: $nextphase = 'decompress_uploaded';
4297: my $position = scalar(@LONCAPA::map::order)-1;
4298: my $noextract = &return_to_editor();
4299: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4300: my %archiveitems = (
4301: folderpath => $env{'form.folderpath'},
4302: cmd => $nextphase,
4303: newidx => $newidx,
4304: position => $position,
4305: phase => $nextphase,
1.477 raeburn 4306: comment => $comment,
1.480 raeburn 4307: );
4308: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4309: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 4310: $$upload_output = $showupload.
4311: &Apache::loncommon::decompress_form($mimetype,
4312: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 4313: \%archiveitems,\@current);
1.329 droeschl 4314: }
4315: }
4316: }
1.440 raeburn 4317: return $nextphase;
1.329 droeschl 4318: }
4319:
1.480 raeburn 4320: sub get_dir_list {
4321: my ($url,$coursenum,$coursedom,$newidx) = @_;
4322: my ($destination,$dir_root) = &embedded_destination();
4323: my ($dirlistref,$listerror) =
4324: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4325: my @dir_lines;
4326: my $dirptr=16384;
4327: if (ref($dirlistref) eq 'ARRAY') {
4328: foreach my $dir_line (sort
4329: {
4330: my ($afile)=split('&',$a,2);
4331: my ($bfile)=split('&',$b,2);
4332: return (lc($afile) cmp lc($bfile));
4333: } (@{$dirlistref})) {
4334: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4335: $filename =~ s/\s+$//;
4336: next if ($filename =~ /^\.\.?$/);
4337: my $isdir = 0;
4338: if ($dirptr&$testdir) {
4339: $isdir = 1;
4340: }
4341: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4342: }
4343: }
4344: return @dir_lines;
4345: }
4346:
1.329 droeschl 4347: sub is_supplemental_title {
4348: my ($title) = @_;
4349: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4350: }
4351:
4352: # --------------------------------------------------------------- An entry line
4353:
4354: sub entryline {
1.501 raeburn 4355: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4356: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4357: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4358: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4359: if (&is_supplemental_title($title)) {
1.488 raeburn 4360: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4361: $encodedtitle=$title;
1.329 droeschl 4362: } else {
4363: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4364: $encodedtitle=$title;
1.329 droeschl 4365: $renametitle=$title;
4366: $foldertitle=$title;
4367: }
4368:
1.611 raeburn 4369: my ($disabled,$readonly,$js_lt);
4370: unless ($canedit) {
4371: $disabled = 'disabled="disabled"';
4372: $readonly = 1;
4373: }
4374:
1.329 droeschl 4375: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4376:
1.329 droeschl 4377: $renametitle=~s/\\/\\\\/g;
4378: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4379: $renametitle=~s/"/%22/g;
1.581 raeburn 4380: $renametitle=~s/ /%20/g;
4381: $oldtitle = $renametitle;
1.576 raeburn 4382: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4383: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4384: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4385: # Edit commands
1.679 raeburn 4386: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4387: if ($env{'form.folderpath'}) {
4388: $esc_path=&escape($env{'form.folderpath'});
4389: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4390: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4391: }
1.505 raeburn 4392: my $isexternal;
1.510 raeburn 4393: if ($residx) {
1.501 raeburn 4394: my $currurl = $url;
4395: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4396: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4397: $isexternal = 1;
4398: }
1.510 raeburn 4399: if (!$supplementalflag) {
4400: my $path = 'uploaded/'.
4401: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4402: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4403: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4404: $residx,
4405: &Apache::lonnet::declutter($currurl));
4406: }
1.501 raeburn 4407: }
1.538 raeburn 4408: my ($renamelink,%lt,$ishash);
4409: if (ref($filtersref) eq 'HASH') {
4410: $ishash = 1;
4411: }
4412:
1.329 droeschl 4413: if ($allowed) {
1.538 raeburn 4414: $form_start = '
4415: <form action="/adm/coursedocs" method="post">
4416: ';
4417: $form_common=(<<END);
4418: <input type="hidden" name="folderpath" value="$path" />
4419: <input type="hidden" name="symb" value="$symb" />
4420: END
4421: $form_param=(<<END);
4422: <input type="hidden" name="setparms" value="$orderidx" />
4423: <input type="hidden" name="changeparms" value="0" />
4424: END
4425: $form_end = '</form>';
4426:
1.329 droeschl 4427: my $incindex=$index+1;
4428: my $selectbox='';
1.471 raeburn 4429: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4430: ((split(/\:/,
1.344 bisitz 4431: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4432: ne '') &&
1.329 droeschl 4433: ((split(/\:/,
1.344 bisitz 4434: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4435: ne '')) {
4436: $selectbox=
4437: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4438: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4439: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4440: if ($i==$incindex) {
1.358 bisitz 4441: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4442: } else {
4443: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4444: }
4445: }
4446: $selectbox.='</select>';
4447: }
1.501 raeburn 4448: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4449: 'up' => 'Move Up',
4450: 'dw' => 'Move Down',
4451: 'rm' => 'Remove',
4452: 'ct' => 'Cut',
4453: 'rn' => 'Rename',
1.501 raeburn 4454: 'cp' => 'Copy',
1.633 raeburn 4455: 'da' => 'Unset alias',
4456: 'sa' => 'Set alias',
1.501 raeburn 4457: 'ex' => 'External Resource',
1.598 raeburn 4458: 'et' => 'External Tool',
1.501 raeburn 4459: 'ed' => 'Edit',
4460: 'pr' => 'Preview',
4461: 'sv' => 'Save',
4462: 'ul' => 'URL',
1.611 raeburn 4463: 'ti' => 'Title',
1.618 raeburn 4464: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4465: );
1.538 raeburn 4466: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4467: $env{'form.folderpath'},
4468: $currgroups);
1.517 raeburn 4469: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4470: my $skip_confirm = 0;
1.603 raeburn 4471: my $confirm_removal = 0;
1.329 droeschl 4472: if ( $folder =~ /^supplemental/
4473: || ($url =~ m{( /smppg$
4474: |/syllabus$
4475: |/aboutme$
4476: |/navmaps$
4477: |/bulletinboard$
1.626 raeburn 4478: |/ext\.tool$
1.505 raeburn 4479: |\.html$)}x)
4480: || $isexternal) {
1.329 droeschl 4481: $skip_confirm = 1;
4482: }
1.603 raeburn 4483: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4484: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4485: $confirm_removal = 1;
4486: }
1.633 raeburn 4487: if ($url =~ /$LONCAPA::assess_re/) {
4488: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4489: }
1.329 droeschl 4490:
1.538 raeburn 4491: if ($denied{'copy'}) {
1.543 raeburn 4492: $copylink=(<<ENDCOPY)
1.507 raeburn 4493: <span style="visibility: hidden;">$lt{'cp'}</span>
4494: ENDCOPY
4495: } else {
1.538 raeburn 4496: my $formname = 'edit_copy_'.$orderidx;
4497: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4498: $copylink=(<<ENDCOPY);
1.538 raeburn 4499: <form name="$formname" method="post" action="/adm/coursedocs">
4500: $form_common
1.611 raeburn 4501: <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 4502: $form_end
1.329 droeschl 4503: ENDCOPY
1.538 raeburn 4504: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4505: push(@{$filtersref->{'cancopy'}},$orderidx);
4506: }
1.329 droeschl 4507: }
1.538 raeburn 4508: if ($denied{'cut'}) {
1.507 raeburn 4509: $cutlink=(<<ENDCUT);
4510: <span style="visibility: hidden;">$lt{'ct'}</span>
4511: ENDCUT
4512: } else {
1.538 raeburn 4513: my $formname = 'edit_cut_'.$orderidx;
4514: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4515: $cutlink=(<<ENDCUT);
1.538 raeburn 4516: <form name="$formname" method="post" action="/adm/coursedocs">
4517: $form_common
1.542 raeburn 4518: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4519: <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 4520: $form_end
1.329 droeschl 4521: ENDCUT
1.538 raeburn 4522: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4523: push(@{$filtersref->{'cancut'}},$orderidx);
4524: }
1.329 droeschl 4525: }
1.538 raeburn 4526: if ($denied{'remove'}) {
1.507 raeburn 4527: $removelink=(<<ENDREM);
4528: <span style="visibility: hidden;">$lt{'rm'}</a>
4529: ENDREM
4530: } else {
1.538 raeburn 4531: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4532: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4533: $removelink=(<<ENDREM);
1.538 raeburn 4534: <form name="$formname" method="post" action="/adm/coursedocs">
4535: $form_common
1.542 raeburn 4536: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4537: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4538: <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 4539: $form_end
1.497 raeburn 4540: ENDREM
1.538 raeburn 4541: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4542: push(@{$filtersref->{'canremove'}},$orderidx);
4543: }
1.497 raeburn 4544: }
1.551 raeburn 4545: $renamelink=(<<ENDREN);
1.581 raeburn 4546: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4547: ENDREN
1.611 raeburn 4548: my ($uplink,$downlink);
4549: if ($canedit) {
4550: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4551: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4552: } else {
4553: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4554: $downlink = $uplink;
4555: }
1.329 droeschl 4556: $line.=(<<END);
4557: <td>
1.379 bisitz 4558: <div class="LC_docs_entry_move">
1.611 raeburn 4559: <a href="$uplink">
1.501 raeburn 4560: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4561: </a>
4562: </div>
4563: <div class="LC_docs_entry_move">
1.611 raeburn 4564: <a href="$downlink">
1.501 raeburn 4565: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4566: </a>
4567: </div>
1.329 droeschl 4568: </td>
4569: <td>
4570: $form_start
1.538 raeburn 4571: $form_param
1.478 raeburn 4572: $form_common
1.329 droeschl 4573: $selectbox
4574: $form_end
4575: </td>
1.540 raeburn 4576: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4577: $removelink
1.329 droeschl 4578: $cutlink
4579: $copylink
4580: </td>
4581: END
4582: }
4583: # Figure out what kind of a resource this is
4584: my ($extension)=($url=~/\.(\w+)$/);
4585: my $uploaded=($url=~/^\/*uploaded\//);
4586: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4587: my $isfolder;
4588: my $ispage;
4589: my $containerarg;
1.615 raeburn 4590: my $folderurl;
1.685 raeburn 4591: my $plainurl;
1.329 droeschl 4592: if ($uploaded) {
1.472 raeburn 4593: if (($extension eq 'sequence') || ($extension eq 'page')) {
4594: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4595: $containerarg = $1;
1.472 raeburn 4596: if ($extension eq 'sequence') {
4597: $icon=$iconpath.'navmap.folder.closed.gif';
4598: $isfolder=1;
4599: } else {
4600: $icon=$iconpath.'page.gif';
4601: $ispage=1;
4602: }
1.615 raeburn 4603: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4604: if ($allowed) {
4605: $url='/adm/coursedocs?';
4606: } else {
4607: $url='/adm/supplemental?';
4608: }
1.329 droeschl 4609: } else {
1.685 raeburn 4610: $plainurl = $url;
1.329 droeschl 4611: }
4612: }
1.364 bisitz 4613:
1.621 raeburn 4614: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4615: my $orig_url = $url;
1.340 raeburn 4616: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4617: if ($container eq 'page') {
4618: $url=~s{^http(|s)(:|:)//}{/ext/};
4619: } else {
4620: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4621: }
1.501 raeburn 4622: if (!$supplementalflag && $residx && $symb) {
4623: if ((!$isfolder) && (!$ispage)) {
4624: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4625: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4626: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4627: } else {
4628: $url=&Apache::lonnet::clutter($url);
4629: }
1.501 raeburn 4630: if ($url=~/^\/*uploaded\//) {
4631: $url=~/\.(\w+)$/;
4632: my $embstyle=&Apache::loncommon::fileembstyle($1);
4633: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4634: $url='/adm/wrapper'.$url;
4635: } elsif ($embstyle eq 'ssi') {
4636: #do nothing with these
4637: } elsif ($url!~/\.(sequence|page)$/) {
4638: $url='/adm/coursedocs/showdoc'.$url;
4639: }
1.623 raeburn 4640: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4641: my $wrapped = $1;
4642: my $exturl = $2;
1.668 raeburn 4643: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4644: $url='/adm/wrapper'.$url;
4645: }
4646: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4647: $nomodal = 1;
4648: }
1.626 raeburn 4649: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4650: $url='/adm/wrapper'.$url;
1.621 raeburn 4651: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4652: if (($ENV{'SERVER_PORT'} == 443) &&
4653: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4654: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4655: $url .= '?usehttp=1';
4656: }
1.621 raeburn 4657: $nomodal = 1;
4658: }
1.598 raeburn 4659: }
1.696 raeburn 4660: my $checkencrypt;
1.680 raeburn 4661: if (!$env{'request.role.adv'}) {
1.615 raeburn 4662: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4663: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4664: $checkencrypt = 1;
1.620 raeburn 4665: } elsif (ref($navmapref)) {
1.615 raeburn 4666: unless (ref($$navmapref)) {
4667: $$navmapref = Apache::lonnavmaps::navmap->new();
4668: }
4669: if (ref($$navmapref)) {
4670: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4671: $checkencrypt = 1;
1.615 raeburn 4672: }
4673: }
4674: }
1.680 raeburn 4675: }
4676: if ($checkencrypt) {
4677: my $currenc = $env{'request.enc'};
4678: $env{'request.enc'} = 1;
4679: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 4680: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 4681: if (&Apache::lonnet::symbverify($symb,$url)) {
4682: $url = $shownurl;
4683: } else {
4684: $url = '';
4685: }
4686: $env{'request.enc'} = $currenc;
4687: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4688: $shownsymb = $symb;
4689: if ($isexternal) {
4690: $url =~ s/\#[^#]+$//;
4691: if ($container eq 'page') {
4692: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4693: }
1.612 raeburn 4694: }
1.696 raeburn 4695: } else {
4696: $url = '';
1.680 raeburn 4697: }
4698: unless ($env{'request.role.adv'}) {
4699: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4700: $url = '';
4701: }
4702: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4703: $url = '';
4704: $hiddenres = 1;
4705: }
4706: }
1.696 raeburn 4707: if (($url ne '') && ($shownsymb ne '')) {
4708: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4709: }
1.329 droeschl 4710: }
1.621 raeburn 4711: } elsif ($supplementalflag) {
1.610 raeburn 4712: if ($isexternal) {
4713: if ($url =~ /^([^#]+)#([^#]+)$/) {
4714: $url = $1;
4715: $anchor = $2;
1.623 raeburn 4716: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4717: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4718: if ($hostname ne '') {
4719: $url = 'http://'.$hostname.$url;
4720: }
4721: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4722: }
4723: $nomodal = 1;
4724: }
1.610 raeburn 4725: }
1.621 raeburn 4726: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4727: if (($ENV{'SERVER_PORT'} == 443) &&
4728: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4729: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4730: if ($hostname ne '') {
4731: $url = 'http://'.$hostname.$url;
4732: }
4733: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4734: }
1.621 raeburn 4735: $nomodal = 1;
4736: }
1.705 raeburn 4737: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 4738: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4739: unless ($embstyle eq 'ssi') {
4740: if (($embstyle eq 'img')
4741: || ($embstyle eq 'emb')
4742: || ($embstyle eq 'wrp')) {
4743: $url='/adm/wrapper'.$url;
4744: } elsif ($url !~ /\.(sequence|page)$/) {
4745: $url='/adm/coursedocs/showdoc'.$url;
4746: }
4747: }
1.610 raeburn 4748: }
1.685 raeburn 4749: unless ($allowed && $env{'request.role.adv'}) {
4750: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4751: $hiddenres = 1;
4752: }
4753: }
1.329 droeschl 4754: }
1.615 raeburn 4755: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4756: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4757: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4758: my $foldername=&escape($foldertitle);
4759: my $folderpath=$env{'form.folderpath'};
4760: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4761: if (!$allowed && $supplementalflag) {
1.519 raeburn 4762: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4763: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4764: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4765: $hiddenfolder = 1;
1.682 raeburn 4766: }
1.510 raeburn 4767: } else {
1.617 raeburn 4768: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4769: 'parameter_randompick'))[0];
4770: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4771: 'parameter_randomorder'))[0]=~/^yes$/i);
4772: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4773: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4774: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4775: 'parameter_encrypturl'))[0]=~/^yes$/i);
4776: unless ($hiddenmap) {
1.620 raeburn 4777: if (ref($navmapref)) {
4778: unless (ref($$navmapref)) {
4779: $$navmapref = Apache::lonnavmaps::navmap->new();
4780: }
4781: if (ref($$navmapref)) {
4782: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4783: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4784: unless (@resources) {
4785: $hiddenmap = 1;
4786: unless ($env{'request.role.adv'}) {
4787: $url = '';
4788: $hiddenfolder = 1;
4789: }
1.617 raeburn 4790: }
1.615 raeburn 4791: }
4792: }
4793: }
4794: }
1.617 raeburn 4795: unless ($encryptmap) {
1.620 raeburn 4796: if ((ref($navmapref)) && (ref($$navmapref))) {
4797: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4798: $encryptmap = 1;
4799: }
1.617 raeburn 4800: }
4801: }
1.630 raeburn 4802:
1.617 raeburn 4803: # Append randompick number, hidden, and encrypted with ":" to foldername,
4804: # so it gets transferred between levels
4805: $folderpath.=$containerarg.'&'.$foldername.
4806: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4807: unless ($url eq '') {
1.612 raeburn 4808: $url.='folderpath='.&escape($folderpath);
4809: }
1.510 raeburn 4810: my $rpckchk;
4811: if ($rpicknum) {
4812: $rpckchk = ' checked="checked"';
1.543 raeburn 4813: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4814: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4815: }
1.510 raeburn 4816: }
1.537 raeburn 4817: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4818: $rand_pick_text =
1.478 raeburn 4819: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4820: $form_param."\n".
1.478 raeburn 4821: $form_common."\n".
1.611 raeburn 4822: '<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 4823: if ($rpicknum ne '') {
4824: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4825: }
1.537 raeburn 4826: $rand_pick_text .= '</span></span>'.
4827: $form_end;
1.543 raeburn 4828: my $ro_set;
1.617 raeburn 4829: if ($randorder) {
1.543 raeburn 4830: $ro_set = 'checked="checked"';
4831: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4832: push(@{$filtersref->{'randomorder'}},$orderidx);
4833: }
4834: }
1.564 raeburn 4835: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4836: $rand_order_text =
1.537 raeburn 4837: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4838: $form_param."\n".
1.537 raeburn 4839: $form_common."\n".
1.611 raeburn 4840: '<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 4841: $form_end;
1.510 raeburn 4842: }
1.705 raeburn 4843: } elsif ($supplementalflag) {
1.598 raeburn 4844: my $isexttool;
1.626 raeburn 4845: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4846: $url='/adm/wrapper'.$url;
4847: $isexttool = 1;
4848: }
1.510 raeburn 4849: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4850: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4851: if ($title) {
1.687 raeburn 4852: $url .= '&title='.$encodedtitle;
1.510 raeburn 4853: }
1.598 raeburn 4854: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4855: $url .= '&idx='.$orderidx;
4856: }
1.610 raeburn 4857: if ($anchor ne '') {
4858: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4859: }
1.329 droeschl 4860: }
1.519 raeburn 4861: my ($tdalign,$tdwidth);
1.501 raeburn 4862: if ($allowed) {
1.630 raeburn 4863: my $fileloc =
1.501 raeburn 4864: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4865: if ($isexternal) {
1.630 raeburn 4866: ($editlink,$extresform) =
1.611 raeburn 4867: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4868: undef,undef,undef,undef,undef,undef,
4869: undef,$disabled);
1.626 raeburn 4870: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4871: ($editlink,$extresform) =
4872: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4873: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4874: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4875: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4876: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4877: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4878: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4879: my $suppanchor;
4880: if ($supplementalflag) {
4881: $suppanchor = $anchor;
4882: }
1.630 raeburn 4883: my $jscall =
1.501 raeburn 4884: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4885: $switchserver,
1.503 raeburn 4886: $forceedit,
1.679 raeburn 4887: undef,$symb,$shownsymb,
1.511 raeburn 4888: &escape($env{'form.folderpath'}),
1.622 raeburn 4889: $renametitle,$hostname,
4890: '','',1,$suppanchor);
1.501 raeburn 4891: if ($jscall) {
1.518 raeburn 4892: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4893: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4894: }
4895: }
4896: }
1.519 raeburn 4897: $tdalign = ' align="right" valign="top"';
4898: $tdwidth = ' width="80%"';
1.329 droeschl 4899: }
1.408 raeburn 4900: my $reinit;
4901: if ($crstype eq 'Community') {
4902: $reinit = &mt('(re-initialize community to access)');
4903: } else {
4904: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4905: }
1.702 raeburn 4906: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 4907: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4908: $line.= '<br />';
4909: if ($curralias ne '') {
4910: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4911: $lt{'da'}.'</a></span>';
4912: } else {
4913: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4914: $lt{'sa'}.'</a></span>';
4915: }
4916: }
1.701 raeburn 4917: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 4918: my ($link,$nolink);
1.472 raeburn 4919: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4920: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4921: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4922: $nolink = 1;
4923: }
4924: }
4925: if ($nolink) {
4926: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4927: } else {
4928: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4929: }
1.469 www 4930: } elsif ($url) {
1.610 raeburn 4931: if ($anchor ne '') {
4932: if ($supplementalflag) {
4933: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4934: } else {
4935: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4936: }
4937: }
1.705 raeburn 4938: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 4939: $link = 'http://'.$hostname.$url;
4940: } else {
4941: $link = $url;
4942: }
1.705 raeburn 4943: my $inhibitmenu;
4944: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
4945: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
4946: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
4947: $inhibitmenu = 'only_body=1';
4948: } else {
4949: $inhibitmenu = 'inhibitmenu=yes';
4950: }
4951: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 4952: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4953: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4954: $nolink = 1;
4955: }
4956: }
4957: if ($nolink) {
4958: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4959: } elsif ($nomodal) {
1.621 raeburn 4960: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4961: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4962: } else {
4963: $line.=&Apache::loncommon::modal_link($link,
4964: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4965: }
1.469 www 4966: } else {
4967: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4968: }
1.519 raeburn 4969: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4970: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4971: if ($nolink) {
4972: $line.=$title;
4973: } else {
4974: $line.='<a href="'.$url.'">'.$title.'</a>';
4975: }
1.682 raeburn 4976: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4977: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4978: my $editurl = $url;
4979: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4980: $line .= ' '.'<a href="'.$editurl.'">'.
4981: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4982: '</a>';
4983: }
4984: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4985: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4986: }
1.469 www 4987: } elsif ($url) {
1.685 raeburn 4988: if ($nolink) {
4989: $line.=$title;
4990: } elsif ($nomodal) {
1.621 raeburn 4991: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4992: $title.'</a>';
4993: } else {
4994: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4995: }
1.617 raeburn 4996: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4997: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4998: } else {
4999: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5000: }
1.633 raeburn 5001: if (($allowed) && ($curralias ne '')) {
5002: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5003: } else {
5004: $line .= $extresform;
5005: }
5006: $line .= '</td>';
1.478 raeburn 5007: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5008: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5009: if ($uploaded && $url && !$isfolder && !$ispage) {
5010: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5011: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5012: }
5013: }
1.682 raeburn 5014: if ($allowed) {
5015: my %lt=&Apache::lonlocal::texthash(
5016: 'hd' => 'Hidden',
5017: 'ec' => 'URL hidden');
5018: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5019: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5020: $hidtext = ' checked="checked"';
1.694 raeburn 5021: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5022: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5023: }
5024: }
1.682 raeburn 5025: $formhidden = 'edit_hiddenresource_'.$orderidx;
5026: $line.=(<<ENDPARMS);
1.329 droeschl 5027: <td class="LC_docs_entry_parameter">
1.537 raeburn 5028: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5029: $form_param
1.478 raeburn 5030: $form_common
1.611 raeburn 5031: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5032: $form_end
1.682 raeburn 5033: ENDPARMS
5034: if ($folder =~/^supplemental/) {
5035: $line.= "\n <td>";
5036: } else {
5037: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5038: $enctext = ' checked="checked"';
5039: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5040: push(@{$filtersref->{'encrypturl'}},$orderidx);
5041: }
5042: }
5043: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5044: $line.=(<<ENDPARMS);
1.458 raeburn 5045: <br />
1.537 raeburn 5046: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5047: $form_param
1.478 raeburn 5048: $form_common
1.611 raeburn 5049: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5050: $form_end
5051: </td>
1.478 raeburn 5052: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5053: $rand_order_text</td>
1.329 droeschl 5054: ENDPARMS
1.682 raeburn 5055: }
1.329 droeschl 5056: }
1.379 bisitz 5057: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 5058: return $line;
5059: }
5060:
1.538 raeburn 5061: sub action_restrictions {
5062: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5063: my %denied = (
5064: cut => 0,
5065: copy => 0,
5066: remove => 0,
5067: );
5068: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5069: # no copy for published maps
5070: $denied{'copy'} = 1;
1.597 raeburn 5071: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5072: unless ($1 eq 'simpleproblem') {
5073: $denied{'copy'} = 1;
5074: }
5075: $denied{'cut'} = 1;
1.538 raeburn 5076: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5077: if ($folderpath =~ /^default&[^\&]+$/) {
5078: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5079: $denied{'remove'} = 1;
5080: }
5081: $denied{'cut'} = 1;
5082: $denied{'copy'} = 1;
5083: }
5084: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5085: my $group = $1;
5086: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5087: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5088: $denied{'remove'} = 1;
5089: }
5090: }
5091: $denied{'cut'} = 1;
5092: $denied{'copy'} = 1;
5093: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5094: my $group = $1;
5095: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5096: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5097: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5098: if (keys(%groupsettings) > 0) {
5099: $denied{'remove'} = 1;
5100: }
5101: $denied{'cut'} = 1;
5102: $denied{'copy'} = 1;
5103: }
5104: }
5105: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5106: my $group = $1;
5107: if ($url =~ /group_boards_\Q$group\E/) {
5108: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5109: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5110: if (keys(%groupsettings) > 0) {
5111: if (ref($groupsettings{'functions'}) eq 'HASH') {
5112: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5113: $denied{'remove'} = 1;
5114: }
5115: }
5116: }
5117: $denied{'cut'} = 1;
5118: $denied{'copy'} = 1;
5119: }
5120: }
5121: }
5122: return %denied;
5123: }
5124:
1.533 raeburn 5125: sub new_timebased_suffix {
1.538 raeburn 5126: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 5127: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 5128: if ($type eq 'paste') {
5129: $prefix = $type;
5130: $namespace = 'courseeditor';
1.587 raeburn 5131: $idtype = 'addcode';
1.538 raeburn 5132: } elsif ($type eq 'map') {
1.533 raeburn 5133: $prefix = 'docs';
5134: if ($area eq 'supplemental') {
5135: $prefix = 'supp';
5136: }
5137: $prefix .= $container;
5138: $namespace = 'uploadedmaps';
5139: } else {
5140: $prefix = $type;
5141: $namespace = 'templated';
1.504 raeburn 5142: }
5143: my ($suffix,$freedlock,$error) =
1.587 raeburn 5144: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 5145: if (!$suffix) {
1.538 raeburn 5146: if ($type eq 'paste') {
5147: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5148: } elsif ($type eq 'map') {
1.533 raeburn 5149: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5150: } elsif ($type eq 'smppg') {
5151: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 5152: } elsif ($type eq 'exttool') {
5153: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 5154: } else {
1.565 bisitz 5155: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 5156: }
1.504 raeburn 5157: if ($error) {
5158: $errtext .= '<br />'.$error;
5159: }
5160: }
5161: if ($freedlock ne 'ok') {
1.630 raeburn 5162: $locknotfreed =
1.533 raeburn 5163: '<div class="LC_error">'.
5164: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 5165: if ($type eq 'paste') {
1.591 raeburn 5166: if ($freedlock eq 'nolock') {
5167: $locknotfreed =
5168: '<div class="LC_error">'.
5169: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5170:
1.593 droeschl 5171: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 5172: } else {
5173: $locknotfreed .=
5174: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5175: }
1.538 raeburn 5176: } elsif ($type eq 'map') {
1.591 raeburn 5177: $locknotfreed .=
5178: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 5179: } elsif ($type eq 'smppg') {
5180: $locknotfreed .=
5181: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 5182: } elsif ($type eq 'exttool') {
5183: $locknotfreed .=
5184: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 5185: } else {
5186: $locknotfreed .=
1.565 bisitz 5187: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 5188: }
1.538 raeburn 5189: unless ($type eq 'paste') {
5190: $locknotfreed .=
1.560 raeburn 5191: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5192: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 5193: }
5194: $locknotfreed .= '</div>';
1.504 raeburn 5195: }
5196: return ($suffix,$errtext,$locknotfreed);
5197: }
5198:
1.329 droeschl 5199: =pod
5200:
5201: =item tiehash()
5202:
5203: tie the hash
5204:
5205: =cut
5206:
5207: sub tiehash {
5208: my ($mode)=@_;
5209: $hashtied=0;
5210: if ($env{'request.course.fn'}) {
5211: if ($mode eq 'write') {
5212: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5213: &GDBM_WRCREAT(),0640)) {
5214: $hashtied=2;
5215: }
5216: } else {
5217: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5218: &GDBM_READER(),0640)) {
5219: $hashtied=1;
5220: }
5221: }
1.364 bisitz 5222: }
1.329 droeschl 5223: }
5224:
5225: sub untiehash {
5226: if ($hashtied) { untie %hash; }
5227: $hashtied=0;
5228: return OK;
5229: }
5230:
5231:
5232:
5233:
5234: sub checkonthis {
1.637 raeburn 5235: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 5236: $url=&unescape($url);
5237: $alreadyseen{$url}=1;
5238: $r->rflush();
5239: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5240: $r->print("\n<br />");
5241: if ($level==0) {
5242: $r->print("<br />");
5243: }
5244: for (my $i=0;$i<=$level*5;$i++) {
5245: $r->print(' ');
5246: }
5247: $r->print('<a href="'.$url.'" target="cat">'.
5248: ($title?$title:$url).'</a> ');
5249: if ($url=~/^\/res\//) {
1.637 raeburn 5250: my $updated;
5251: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5252: ($url !~ /\.\d+\.\w+$/)) {
5253: $updated = &Apache::lonnet::remove_stale_resfile($url);
5254: }
1.329 droeschl 5255: my $result=&Apache::lonnet::repcopy(
5256: &Apache::lonnet::filelocation('',$url));
5257: if ($result eq 'ok') {
5258: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 5259: if ($updated) {
5260: $r->print('<br />');
5261: for (my $i=0;$i<=$level*5;$i++) {
5262: $r->print(' ');
5263: }
5264: $r->print('- '.&mt('Outdated copy removed'));
5265: }
1.329 droeschl 5266: $r->rflush();
5267: &Apache::lonnet::countacc($url);
5268: $url=~/\.(\w+)$/;
5269: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5270: $r->print('<br />');
5271: $r->rflush();
5272: for (my $i=0;$i<=$level*5;$i++) {
5273: $r->print(' ');
5274: }
5275: $r->print('- '.&mt('Rendering:').' ');
5276: my ($errorcount,$warningcount)=split(/:/,
5277: &Apache::lonnet::ssi_body($url,
5278: ('grade_target'=>'web',
5279: 'return_only_error_and_warning_counts' => 1)));
5280: if (($errorcount) ||
5281: ($warningcount)) {
5282: if ($errorcount) {
1.369 bisitz 5283: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 5284: &mt('[quant,_1,error]',$errorcount).'</span>');
5285: }
5286: if ($warningcount) {
5287: $r->print('<span class="LC_warning">'.
5288: &mt('[quant,_1,warning]',$warningcount).'</span>');
5289: }
5290: } else {
5291: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5292: }
5293: $r->rflush();
5294: }
5295: my $dependencies=
5296: &Apache::lonnet::metadata($url,'dependencies');
5297: foreach my $dep (split(/\,/,$dependencies)) {
5298: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 5299: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 5300: }
5301: }
5302: } elsif ($result eq 'unavailable') {
5303: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5304: } elsif ($result eq 'not_found') {
5305: unless ($url=~/\$/) {
1.521 bisitz 5306: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 5307: } else {
1.366 bisitz 5308: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 5309: }
5310: } else {
5311: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5312: }
1.637 raeburn 5313: if (($updated) && ($result ne 'ok')) {
5314: $r->print('<br />'.&mt('Outdated copy removed'));
5315: }
1.329 droeschl 5316: }
5317: }
5318: }
5319:
5320:
5321:
5322: =pod
5323:
5324: =item list_symbs()
5325:
1.485 raeburn 5326: List Content Identifiers
1.329 droeschl 5327:
5328: =cut
5329:
5330: sub list_symbs {
5331: my ($r) = @_;
5332:
1.408 raeburn 5333: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5334: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5335: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5336: $r->print(&startContentScreen('tools'));
1.329 droeschl 5337: my $navmap = Apache::lonnavmaps::navmap->new();
5338: if (!defined($navmap)) {
5339: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5340: '<div class="LC_error">'.
5341: &mt('Unable to retrieve information about course contents').
5342: '</div>');
1.408 raeburn 5343: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5344: } else {
1.484 raeburn 5345: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5346: &Apache::loncommon::start_data_table().
5347: &Apache::loncommon::start_data_table_header_row().
5348: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5349: &Apache::loncommon::end_data_table_header_row()."\n");
5350: my $count;
1.329 droeschl 5351: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5352: $r->print(&Apache::loncommon::start_data_table_row().
5353: '<td>'.$res->compTitle().'</td>'.
5354: '<td>'.$res->symb().'</td>'.
1.521 bisitz 5355: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5356: $count ++;
5357: }
5358: if (!$count) {
5359: $r->print(&Apache::loncommon::start_data_table_row().
5360: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5361: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5362: }
1.484 raeburn 5363: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5364: }
1.521 bisitz 5365: $r->print(&endContentScreen());
1.329 droeschl 5366: }
5367:
1.651 raeburn 5368: sub short_urls {
5369: my ($r,$canedit) = @_;
5370: my $crstype = &Apache::loncommon::course_type();
5371: my $formname = 'shortenurl';
5372: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5373: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5374: $r->print(&startContentScreen('tools'));
5375: my ($navmap,$errormsg) =
5376: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5377: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5378: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5379: my (%maps,%resources,%titles);
5380: if (!ref($navmap)) {
5381: $r->print($errormsg.
5382: &endContentScreen());
5383: return '';
5384: } else {
1.652 raeburn 5385: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5386: $r->rflush();
5387: my $readonly;
5388: if ($canedit) {
1.671 raeburn 5389: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5390: if ($numnew) {
5391: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5392: }
5393: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5394: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5395: foreach my $error (@{$errors}) {
5396: $r->print('<li>'.$error.'</li>');
5397: }
5398: $r->print('</ul><br />');
5399: }
5400: } else {
5401: $readonly = 1;
5402: }
5403: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5404: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 ! raeburn 5405: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 5406: }
5407: $r->print(&endContentScreen());
5408: }
5409:
1.637 raeburn 5410: sub contentverifyform {
5411: my ($r) = @_;
5412: my $crstype = &Apache::loncommon::course_type();
5413: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5414: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5415: $r->print(&startContentScreen('tools'));
5416: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5417: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5418: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5419: ' <span class="LC_nobreak">'.
5420: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5421: &mt('No').'</label>'.(' 'x2).
5422: '<label><input type="radio" name="checkstale" value="1" />'.
5423: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5424: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5425: '<input type="hidden" value="1" name="tools" />'.
5426: '<input type="hidden" value="1" name="verify" /></p></form>');
5427: $r->print(&endContentScreen());
5428: return;
5429: }
1.329 droeschl 5430:
5431: sub verifycontent {
1.637 raeburn 5432: my ($r,$checkstale) = @_;
1.408 raeburn 5433: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5434: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5435: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5436: $r->print(&startContentScreen('tools'));
5437: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5438: $hashtied=0;
5439: undef %alreadyseen;
5440: %alreadyseen=();
5441: &tiehash();
1.484 raeburn 5442:
1.329 droeschl 5443: foreach my $key (keys(%hash)) {
5444: if ($hash{$key}=~/\.(page|sequence)$/) {
5445: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5446: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5447: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5448: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5449: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5450: }
5451: }
5452: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5453: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5454: }
5455: }
5456: &untiehash();
1.442 www 5457: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5458: $r->print(&endContentScreen());
1.329 droeschl 5459: }
5460:
5461: sub devalidateversioncache {
5462: my $src=shift;
5463: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5464: &Apache::lonnet::clutter($src));
5465: }
5466:
5467: sub checkversions {
1.611 raeburn 5468: my ($r,$canedit) = @_;
1.408 raeburn 5469: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5470: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5471: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5472: $r->print(&startContentScreen('tools'));
1.442 www 5473:
1.329 droeschl 5474: my $header='';
5475: my $startsel='';
5476: my $monthsel='';
5477: my $weeksel='';
5478: my $daysel='';
5479: my $allsel='';
5480: my %changes=();
5481: my $starttime=0;
5482: my $haschanged=0;
5483: my %setversions=&Apache::lonnet::dump('resourceversions',
5484: $env{'course.'.$env{'request.course.id'}.'.domain'},
5485: $env{'course.'.$env{'request.course.id'}.'.num'});
5486:
5487: $hashtied=0;
5488: &tiehash();
1.611 raeburn 5489: if ($canedit) {
5490: my %newsetversions=();
5491: if ($env{'form.setmostrecent'}) {
5492: $haschanged=1;
5493: foreach my $key (keys(%hash)) {
5494: if ($key=~/^ids\_(\/res\/.+)$/) {
5495: $newsetversions{$1}='mostrecent';
5496: &devalidateversioncache($1);
5497: }
5498: }
5499: } elsif ($env{'form.setcurrent'}) {
5500: $haschanged=1;
5501: foreach my $key (keys(%hash)) {
5502: if ($key=~/^ids\_(\/res\/.+)$/) {
5503: my $getvers=&Apache::lonnet::getversion($1);
5504: if ($getvers>0) {
5505: $newsetversions{$1}=$getvers;
5506: &devalidateversioncache($1);
5507: }
5508: }
1.329 droeschl 5509: }
1.611 raeburn 5510: } elsif ($env{'form.setversions'}) {
5511: $haschanged=1;
5512: foreach my $key (keys(%env)) {
5513: if ($key=~/^form\.set_version_(.+)$/) {
5514: my $src=$1;
5515: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5516: $newsetversions{$src}=$env{$key};
5517: &devalidateversioncache($src);
5518: }
5519: }
1.329 droeschl 5520: }
1.611 raeburn 5521: }
5522: if ($haschanged) {
5523: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5524: $env{'course.'.$env{'request.course.id'}.'.domain'},
5525: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5526: $r->print(&Apache::loncommon::confirmwrapper(
5527: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5528: } else {
5529: $r->print(&Apache::loncommon::confirmwrapper(
5530: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5531: }
1.611 raeburn 5532: &mark_hash_old();
5533: }
5534: &changewarning($r,'');
1.329 droeschl 5535: }
5536: if ($env{'form.timerange'} eq 'all') {
5537: # show all documents
1.549 raeburn 5538: $header=&mt('All content in '.$crstype);
1.521 bisitz 5539: $allsel=' selected="selected"';
1.329 droeschl 5540: foreach my $key (keys(%hash)) {
5541: if ($key=~/^ids\_(\/res\/.+)$/) {
5542: my $src=$1;
5543: $changes{$src}=1;
5544: }
5545: }
5546: } else {
5547: # show documents which changed
5548: %changes=&Apache::lonnet::dump
5549: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5550: $env{'course.'.$env{'request.course.id'}.'.num'});
5551: my $firstkey=(keys(%changes))[0];
5552: unless ($firstkey=~/^error\:/) {
5553: unless ($env{'form.timerange'}) {
5554: $env{'form.timerange'}=604800;
5555: }
5556: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5557: .&mt('seconds');
5558: if ($env{'form.timerange'}==-1) {
5559: $seltext='since start of course';
1.521 bisitz 5560: $startsel=' selected="selected"';
1.329 droeschl 5561: $env{'form.timerange'}=time;
5562: }
5563: $starttime=time-$env{'form.timerange'};
5564: if ($env{'form.timerange'}==2592000) {
5565: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5566: $monthsel=' selected="selected"';
1.329 droeschl 5567: } elsif ($env{'form.timerange'}==604800) {
5568: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5569: $weeksel=' selected="selected"';
1.329 droeschl 5570: } elsif ($env{'form.timerange'}==86400) {
5571: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5572: $daysel=' selected="selected"';
1.329 droeschl 5573: }
5574: $header=&mt('Content changed').' '.$seltext;
5575: } else {
5576: $header=&mt('No content modifications yet.');
5577: }
5578: }
5579: %setversions=&Apache::lonnet::dump('resourceversions',
5580: $env{'course.'.$env{'request.course.id'}.'.domain'},
5581: $env{'course.'.$env{'request.course.id'}.'.num'});
5582: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5583: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5584: 'lm' => 'Version changes since last Month',
5585: 'lw' => 'Version changes since last Week',
5586: 'sy' => 'Version changes since Yesterday',
5587: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5588: 'cd' => 'Change display',
1.329 droeschl 5589: 'sd' => 'Display',
5590: 'fi' => 'File',
5591: 'md' => 'Modification Date',
5592: 'mr' => 'Most recently published Version',
1.408 raeburn 5593: 've' => 'Version used in '.$crstype,
5594: 'vu' => 'Set Version to be used in '.$crstype,
5595: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5596: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5597: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5598: 'di' => 'Differences',
1.484 raeburn 5599: 'save' => 'Save changes',
5600: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5601: 'act' => 'Actions');
1.611 raeburn 5602: my ($disabled,$readonly);
5603: unless ($canedit) {
5604: $disabled = 'disabled="disabled"';
5605: $readonly = 1;
5606: }
1.329 droeschl 5607: $r->print(<<ENDHEADERS);
1.484 raeburn 5608: <h4 class="LC_info">$header</h4>
1.329 droeschl 5609: <form action="/adm/coursedocs" method="post">
5610: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5611: <div class="LC_left_float">
1.479 golterma 5612: <fieldset>
1.484 raeburn 5613: <legend>$lt{'cd'}</legend>
1.329 droeschl 5614: <select name="timerange">
1.521 bisitz 5615: <option value='all'$allsel>$lt{'al'}</option>
5616: <option value="-1"$startsel>$lt{'st'}</option>
5617: <option value="2592000"$monthsel>$lt{'lm'}</option>
5618: <option value="604800"$weeksel>$lt{'lw'}</option>
5619: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5620: </select>
5621: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5622: </fieldset>
5623: </div>
5624: <div class="LC_left_float">
5625: <fieldset>
5626: <legend>$lt{'act'}</legend>
1.611 raeburn 5627: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5628: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5629: </fieldset>
5630: </div>
5631: <br clear="all" />
5632: <hr />
5633: <h4>$lt{'vers'}</h4>
1.329 droeschl 5634: ENDHEADERS
1.479 golterma 5635: #number of columns for version history
1.571 raeburn 5636: my %changedbytime;
5637: foreach my $key (keys(%changes)) {
5638: #excludes not versionable problems from resource version history:
5639: next if ($key =~ /^\/res\/lib\/templates/);
5640: my $chg;
5641: if ($env{'form.timerange'} eq 'all') {
5642: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5643: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5644: } else {
5645: $chg = $changes{$key};
5646: next if ($chg < $starttime);
5647: }
5648: push(@{$changedbytime{$chg}},$key);
5649: }
5650: if (keys(%changedbytime) == 0) {
5651: &untiehash();
5652: $r->print(&mt('No content changes in imported content in specified time frame').
5653: &endContentScreen());
5654: return;
5655: }
1.479 golterma 5656: $r->print(
1.611 raeburn 5657: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5658: &Apache::loncommon::start_data_table().
5659: &Apache::loncommon::start_data_table_header_row().
5660: '<th>'.&mt('Resources').'</th>'.
5661: "<th>$lt{'mr'}</th>".
5662: "<th>$lt{'ve'}</th>".
5663: "<th>$lt{'vu'}</th>".
5664: '<th>'.&mt('History').'</th>'.
5665: &Apache::loncommon::end_data_table_header_row()
5666: );
1.571 raeburn 5667: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5668: foreach my $key (sort(@{$changedbytime{$chg}})) {
5669: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5670: my $currentversion=&Apache::lonnet::getversion($key);
5671: if ($currentversion<0) {
5672: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5673: }
5674: my $linkurl=&Apache::lonnet::clutter($key);
5675: $r->print(
5676: &Apache::loncommon::start_data_table_row().
5677: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5678: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5679: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5680: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5681: '<td align="right">'
5682: );
5683: # Used in course
5684: my $usedversion=$hash{'version_'.$linkurl};
5685: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5686: if ($usedversion != $currentversion) {
1.479 golterma 5687: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5688: } else {
1.479 golterma 5689: $r->print($usedversion);
5690: }
1.329 droeschl 5691: } else {
1.521 bisitz 5692: $r->print($currentversion);
1.329 droeschl 5693: }
1.571 raeburn 5694: $r->print('</td><td title="'.$lt{'vu'}.'">');
5695: # Set version
5696: $r->print(&Apache::loncommon::select_form(
5697: $setversions{$linkurl},
5698: 'set_version_'.$linkurl,
5699: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5700: '' => '',
5701: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5702: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5703: my $lastold=1;
5704: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5705: my $url=$root.'.'.$prevvers.'.'.$extension;
5706: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5707: $lastold=$prevvers;
5708: }
5709: }
5710: $r->print('</td>');
5711: # List all available versions
5712: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5713: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5714: my $url=$root.'.'.$prevvers.'.'.$extension;
5715: $r->print(
5716: '<span class="LC_nobreak">'
5717: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5718: .&mt('Version [_1]',$prevvers).'</a>'
5719: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5720: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5721: .')');
5722: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5723: $r->print(
5724: ' <a href="/adm/diff?filename='.
5725: &Apache::lonnet::clutter($root.'.'.$extension).
5726: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5727: '" target="diffs">'.&mt('Diffs').'</a>');
5728: }
5729: $r->print('</span><br />');
1.329 droeschl 5730: }
1.571 raeburn 5731: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5732: }
1.329 droeschl 5733: }
1.521 bisitz 5734: $r->print(
5735: &Apache::loncommon::end_data_table().
1.611 raeburn 5736: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5737: '</form>'
5738: );
1.329 droeschl 5739:
5740: &untiehash();
1.521 bisitz 5741: $r->print(&endContentScreen());
1.571 raeburn 5742: return;
1.329 droeschl 5743: }
5744:
5745: sub mark_hash_old {
5746: my $retie_hash=0;
5747: if ($hashtied) {
5748: $retie_hash=1;
5749: &untiehash();
5750: }
5751: &tiehash('write');
5752: $hash{'old'}=1;
5753: &untiehash();
5754: if ($retie_hash) { &tiehash(); }
5755: }
5756:
5757: sub is_hash_old {
5758: my $untie_hash=0;
5759: if (!$hashtied) {
5760: $untie_hash=1;
5761: &tiehash();
5762: }
5763: my $return=$hash{'old'};
5764: if ($untie_hash) { &untiehash(); }
5765: return $return;
5766: }
5767:
5768: sub changewarning {
5769: my ($r,$postexec,$message,$url)=@_;
5770: if (!&is_hash_old()) { return; }
5771: my $pathvar='folderpath';
5772: my $path=&escape($env{'form.folderpath'});
5773: if (!defined($url)) {
5774: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5775: }
5776: my $course_type = &Apache::loncommon::course_type();
5777: if (!defined($message)) {
5778: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5779: }
1.653 raeburn 5780: my $windowname = 'loncapaclient';
5781: if ($env{'request.lti.login'}) {
5782: $windowname .= 'lti';
5783: }
1.329 droeschl 5784: $r->print("\n\n".
1.372 bisitz 5785: '<script type="text/javascript">'."\n".
5786: '// <![CDATA['."\n".
5787: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5788: '// ]]>'."\n".
1.369 bisitz 5789: '</script>'."\n".
1.653 raeburn 5790: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5791: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5792: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5793: &mt($message,' <input type="hidden" name="'.
5794: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5795: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5796: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5797: }
5798:
5799:
5800: sub init_breadcrumbs {
1.571 raeburn 5801: my ($form,$text,$help)=@_;
1.329 droeschl 5802: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5803: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5804: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5805: faq=>273,
5806: bug=>'Instructor Interface',
1.571 raeburn 5807: help => $help});
1.329 droeschl 5808: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5809: text=>$text,
5810: faq=>273,
5811: bug=>'Instructor Interface'});
5812: }
5813:
1.441 www 5814: # subroutine to list form elements
5815: sub create_list_elements {
5816: my @formarr = @_;
5817: my $list = '';
1.501 raeburn 5818: foreach my $button (@formarr){
5819: foreach my $picture (keys(%{$button})) {
5820: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5821: }
5822: }
5823: return $list;
5824: }
1.329 droeschl 5825:
1.441 www 5826: # subroutine to create ul from list elements
5827: sub create_form_ul {
5828: my $list = shift;
5829: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5830: return $ul;
5831: }
1.329 droeschl 5832:
1.442 www 5833: #
5834: # Start tabs
5835: #
5836:
5837: sub startContentScreen {
1.484 raeburn 5838: my ($mode) = @_;
5839: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5840: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5841: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5842: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5843: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5844: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5845: } else {
1.549 raeburn 5846: $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 5847: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5848: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5849: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5850: }
5851: $output .= "\n".'</ul>'."\n";
5852: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5853: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5854: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5855: return $output;
1.442 www 5856: }
5857:
5858: #
5859: # End tabs
5860: #
5861:
5862: sub endContentScreen {
1.484 raeburn 5863: return '</div></div></div>';
1.442 www 5864: }
1.329 droeschl 5865:
1.446 www 5866: sub supplemental_base {
1.548 raeburn 5867: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5868: }
5869:
1.329 droeschl 5870: sub handler {
5871: my $r = shift;
5872: &Apache::loncommon::content_type($r,'text/html');
5873: $r->send_http_header;
5874: return OK if $r->header_only;
1.484 raeburn 5875:
5876: # get course data
1.408 raeburn 5877: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5878: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5879: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5880:
1.606 raeburn 5881: # get docroot
5882: my $londocroot = $r->dir_config('lonDocRoot');
5883:
1.484 raeburn 5884: # graphics settings
5885: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5886:
1.443 www 5887: #
1.329 droeschl 5888: # --------------------------------------------- Initialize help topics for this
5889: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5890: 'Adding_External_Resource','Adding_External_Tool',
5891: 'Navigate_Content','Adding_Folders','Docs_Overview',
5892: 'Load_Map','Supplemental','Score_Upload_Form',
5893: 'Adding_Pages','Importing_LON-CAPA_Resource',
5894: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 5895: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
5896: 'Standard_Problem','Course_Resources',
5897: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 5898: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5899: }
5900: # Composite help files
5901: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5902: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5903: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5904: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5905: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5906: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5907: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5908: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5909: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5910: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5911:
1.611 raeburn 5912: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5913: # does this user have privileges to modify content.
5914: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5915: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5916: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5917: $allowed = 1;
1.682 raeburn 5918: }
5919: $canedit = 1;
5920: $canview = 1;
5921: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5922: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5923: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5924: $allowed = 1;
5925: }
1.682 raeburn 5926: $canview = 1;
1.611 raeburn 5927: }
5928: unless ($canedit) {
5929: $disabled = ' disabled="disabled"';
1.472 raeburn 5930: }
1.582 raeburn 5931: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5932: if ($env{'form.inhibitmenu'}) {
5933: unless ($env{'form.inhibitmenu'} eq 'yes') {
5934: delete($env{'form.inhibitmenu'});
5935: }
5936: }
5937:
1.582 raeburn 5938: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5939: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5940: if (!$canedit) {
5941: &verifycontent($r);
5942: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5943: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5944: text=>'Results',
5945: faq=>273,
5946: bug=>'Instructor Interface'});
5947: &verifycontent($r,$env{'form.checkstale'});
5948: } else {
5949: &contentverifyform($r);
5950: }
1.329 droeschl 5951: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5952: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5953: &list_symbs($r);
1.651 raeburn 5954: } elsif ($allowed && $env{'form.shorturls'}) {
5955: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5956: &short_urls($r,$canedit);
1.329 droeschl 5957: } elsif ($allowed && $env{'form.docslog'}) {
5958: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5959: my $folder = $env{'form.folder'};
5960: if ($folder eq '') {
5961: $folder='default';
5962: }
1.611 raeburn 5963: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5964: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5965: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5966: &checkversions($r,$canedit);
5967: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 5968: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 5969: &dumpcourse($r);
1.611 raeburn 5970: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5971: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5972: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5973: } else {
1.611 raeburn 5974: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5975: $noendpage = 1;
5976: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5977: if ($redirect) {
5978: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5979: my $container = 'sequence';
5980: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5981: $is_random_order,$container) =
5982: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5983: my (@folders)=split('&',$env{'form.folderpath'});
5984: $env{'form.foldername'}=&unescape(pop(@folders));
5985: my $folder=pop(@folders);
5986: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5987: $folder.'.'.$container);
5988: my $warning;
5989: if ($fatal) {
5990: if ($container eq 'page') {
5991: $warning = &mt('An error occurred retrieving the contents of the current page.');
5992: } else {
5993: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5994: }
5995: } else {
5996: my $url = $redirect;
5997: my $srcfile = $londocroot.$url;
5998: $url =~ s{^/priv/}{/res/};
5999: my $targetfile = $londocroot.$url;
6000: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6001: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6002: $env{'form.folder'} = $folder;
6003: &snapshotbefore();
6004: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6005: my $ext = 'false';
6006: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6007: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6008: ':'.$ext.':normal:res';
6009: push(@LONCAPA::map::order,$newidx);
6010: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6011: 'string_yesno');
6012: &remember_parms($newidx,'hiddenresource','set','yes');
6013: ($errtext,$fatal) =
6014: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6015: &log_differences($plain);
6016: &mark_hash_old();
6017: $r->internal_redirect($redirect);
6018: return OK;
6019: }
1.654 raeburn 6020: } else {
6021: $r->internal_redirect($redirect);
1.606 raeburn 6022: }
6023: }
6024: }
1.445 www 6025: #
6026: # Done catching special calls
1.484 raeburn 6027: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6028: # Get the parameters that may be needed
6029: #
6030: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6031: ['folderpath','title',
1.519 raeburn 6032: 'forcesupplement','forcestandard',
1.510 raeburn 6033: 'tools','symb','command','supppath']);
1.445 www 6034:
1.635 raeburn 6035: foreach my $item ('forcesupplement','forcestandard','tools') {
6036: next if ($env{'form.'.$item} eq '');
6037: unless ($env{'form.'.$item} eq '1') {
6038: delete($env{'form.'.$item});
6039: }
6040: }
6041:
6042: if ($env{'form.command'}) {
6043: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6044: delete($env{'form.command'});
6045: }
6046: }
6047:
6048: if ($env{'form.symb'}) {
6049: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6050: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6051: delete($env{'form.symb'});
6052: }
6053: }
6054:
1.445 www 6055: # standard=1: this is a "new-style" course with an uploaded map as top level
6056: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 6057:
6058: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 6059:
1.484 raeburn 6060: # Decide whether this should display supplemental or main content or utilities
1.445 www 6061: # supplementalflag=1: show supplemental documents
6062: # supplementalflag=0: show standard documents
1.484 raeburn 6063: # toolsflag=1: show utilities
1.445 www 6064:
1.561 raeburn 6065: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6066: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6067: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 6068: $supplementalflag=0;
6069: }
6070: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6071: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 6072: unless (($supplementalflag) ||
6073: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
6074: unless ($allowed) { $supplementalflag=1; }
6075: unless ($standard) { $supplementalflag=1; }
6076: }
1.484 raeburn 6077: my $toolsflag=0;
6078: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 6079:
1.635 raeburn 6080: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6081: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 6082: }
6083:
1.685 raeburn 6084: my $backto_supppath;
1.635 raeburn 6085: if ($env{'form.supppath'} ne '') {
1.685 raeburn 6086: if ($supplementalflag && $allowed) {
6087: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6088: }
1.635 raeburn 6089: }
6090:
1.329 droeschl 6091: my $script='';
6092: my $showdoc=0;
1.457 raeburn 6093: my $addentries = {};
1.475 raeburn 6094: my $container;
1.329 droeschl 6095: my $containertag;
1.508 raeburn 6096: my $pathitem;
1.598 raeburn 6097: my %ltitools;
1.699 raeburn 6098: my $posslti;
1.617 raeburn 6099: my $hiddentop;
1.615 raeburn 6100: my $navmap;
1.617 raeburn 6101: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 6102:
1.464 www 6103: # Do we directly jump somewhere?
1.525 raeburn 6104: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 6105: if ($env{'form.symb'} ne '') {
1.522 raeburn 6106: $env{'form.folderpath'}=
1.617 raeburn 6107: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 6108: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 6109: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 6110: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 6111: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 6112: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 6113: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 6114: }
1.472 raeburn 6115: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 6116: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 6117: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 6118: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 6119: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 6120: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6121: } elsif ($env{'form.command'} eq 'contents') {
6122: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6123: } elsif ($env{'form.command'} eq 'home') {
6124: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 6125: }
6126:
1.525 raeburn 6127:
1.445 www 6128: # Where do we store these for when we come back?
6129: my $stored_folderpath='docs_folderpath';
6130: if ($supplementalflag) {
6131: $stored_folderpath='docs_sup_folderpath';
6132: }
1.464 www 6133:
1.519 raeburn 6134: # No folderpath, and in edit mode, see if we have something stored
6135: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6136: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 6137: {'folderpath' => 'scalar'});
1.615 raeburn 6138:
6139: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6140: if ($supplementalflag) {
6141: undef($env{'form.folderpath'}) if ($1 eq 'default');
6142: } else {
6143: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6144: }
6145: } else {
1.523 raeburn 6146: undef($env{'form.folderpath'});
6147: }
1.677 raeburn 6148: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6149: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 6150: }
1.329 droeschl 6151: }
1.706 raeburn 6152:
6153: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 6154: if ((!$allowed) && ($supplementalflag)) {
1.446 www 6155: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6156: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6157: }
6158: }
1.446 www 6159: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6160: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6161: $env{'form.folderpath'} = &supplemental_base()
6162: .'&'.
1.329 droeschl 6163: $env{'form.folderpath'};
6164: }
1.685 raeburn 6165: # If allowed and user's role is not advanced check folderpath is not hidden
6166: my $hidden_and_empty;
1.687 raeburn 6167: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 6168: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 6169: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 6170: my $folder = $pathitems[-2];
6171: if ($folder eq '') {
6172: undef($env{'form.folderpath'});
6173: } else {
6174: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 6175: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 6176: $folderurl .= '.page';
6177: } else {
6178: $folderurl .= '.sequence';
6179: }
1.685 raeburn 6180: if ($supplementalflag) {
6181: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6182: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 6183: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 6184: if (ref($supplemental) eq 'HASH') {
6185: my ($suppmap,$suppmapnum);
6186: if ($folder eq 'supplemental') {
6187: $suppmap = 'default';
6188: $suppmapnum = 0;
6189: } elsif ($folder =~ /^supplemental_(\d+)$/) {
6190: $suppmap = $1;
6191: $suppmapnum = $suppmap;
6192: }
6193: if ($hiddenfolder) {
6194: my $hascontent;
6195: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6196: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6197: $hascontent = 1;
6198: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6199: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6200: if ($id =~ /^$suppmapnum\:/) {
6201: $hascontent = 1;
6202: last;
6203: }
6204: }
6205: }
6206: last if ($hascontent);
6207: }
6208: unless ($hascontent) {
6209: if ($foldername ne '') {
6210: $hidden_and_empty = $foldername;
6211: } else {
6212: $hidden_and_empty = $folder;
6213: }
6214: }
6215: }
6216: }
6217: } else {
6218: unless (ref($navmap)) {
6219: $navmap = Apache::lonnavmaps::navmap->new();
6220: }
6221: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6222: $foldername = &HTML::Entities::decode(&unescape($foldername));
6223: if (ref($navmap)) {
6224: if ($hiddenfolder ||
6225: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6226: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6227: unless (@resources) {
6228: if ($foldername ne '') {
6229: $hidden_and_empty = $foldername;
6230: } else {
6231: $hidden_and_empty = $folder;
6232: }
6233: }
6234: }
6235: }
1.617 raeburn 6236: }
1.685 raeburn 6237: if ($hidden_and_empty ne '') {
6238: splice(@pathitems,-2);
6239: if (@pathitems) {
6240: $env{'form.folderpath'} = join('&',@pathitems);
6241: } else {
6242: undef($env{'form.folderpath'});
1.615 raeburn 6243: }
6244: }
6245: }
6246: }
6247:
1.446 www 6248: # If after all of this, we still don't have any paths, make them
1.519 raeburn 6249: unless ($env{'form.folderpath'}) {
1.446 www 6250: if ($supplementalflag) {
6251: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 6252: } elsif ($allowed) {
6253: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 6254: }
1.472 raeburn 6255: }
1.446 www 6256:
1.445 www 6257: # Store this
1.484 raeburn 6258: unless ($toolsflag) {
1.615 raeburn 6259: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 6260: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 6261: {'folderpath' => 'scalar'});
1.510 raeburn 6262: }
1.519 raeburn 6263: my $folderpath;
1.484 raeburn 6264: if ($env{'form.folderpath'}) {
1.519 raeburn 6265: $folderpath = $env{'form.folderpath'};
6266: my (@folders)=split('&',$env{'form.folderpath'});
6267: $env{'form.foldername'}=&unescape(pop(@folders));
6268: if ($env{'form.foldername'} =~ /\:1$/) {
6269: $container = 'page';
6270: } else {
6271: $container = 'sequence';
6272: }
6273: $env{'form.folder'}=pop(@folders);
1.484 raeburn 6274: } else {
1.519 raeburn 6275: if ($env{'form.folder'} eq '' ||
6276: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 6277: if ($env{'form.folder'} eq 'supplemental') {
6278: $folderpath=&supplemental_base();
6279: } elsif (!$hiddentop) {
6280: $folderpath='default&'.
6281: &escape(&mt('Main Content').':::::');
6282: }
1.484 raeburn 6283: }
6284: }
1.519 raeburn 6285: $containertag = '<input type="hidden" name="folderpath" value="" />';
6286: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 6287: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6288: $showdoc='/'.$1;
6289: }
6290: if ($showdoc) { # got called in sequence from course
6291: $allowed=0;
6292: } else {
1.611 raeburn 6293: if ($canedit) {
1.484 raeburn 6294: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6295: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 6296: }
6297: }
1.329 droeschl 6298: }
6299:
1.344 bisitz 6300: # get personal data
1.329 droeschl 6301: my $uname=$env{'user.name'};
6302: my $udom=$env{'user.domain'};
6303: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6304:
6305: if ($allowed) {
1.484 raeburn 6306: if ($toolsflag) {
6307: $script .= &inject_data_js();
6308: my ($home,$other,%outhash)=&authorhosts();
6309: if (!$home && $other) {
6310: my @hosts;
6311: foreach my $aurole (keys(%outhash)) {
6312: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6313: push(@hosts,$outhash{$aurole});
6314: }
6315: }
6316: $script .= &dump_switchserver_js(@hosts);
6317: }
1.458 raeburn 6318: } else {
1.570 raeburn 6319: my $tid = 1;
1.484 raeburn 6320: my @tabids;
6321: if ($supplementalflag) {
1.655 raeburn 6322: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 6323: $tid = 2;
1.484 raeburn 6324: } else {
6325: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 6326: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 6327: unshift(@tabids,'001');
6328: push(@tabids,('dd1','ee1'));
6329: }
1.458 raeburn 6330: }
1.484 raeburn 6331: my $tabidstr = join("','",@tabids);
1.699 raeburn 6332: my (%domtools,%crstools);
6333: my %tooltypes = &Apache::loncommon::usable_exttools();
6334: if ($tooltypes{'dom'}) {
6335: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6336: }
6337: if ($tooltypes{'crs'}) {
6338: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6339: }
6340: %ltitools = (
6341: dom => \%domtools,
6342: crs => \%crstools,
6343: );
6344: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 6345: my $hostname = $r->hostname();
1.606 raeburn 6346: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 6347: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 6348: &history_tab_js().
6349: &inject_data_js().
1.570 raeburn 6350: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 6351: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 6352: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6353: if ($hidden_and_empty ne '') {
6354: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6355: $hidden_and_empty);
6356: $onload .= "javascript:alert('".&js_escape($alert)."');";
6357: }
1.484 raeburn 6358: $addentries = {
1.685 raeburn 6359: onload => $onload,
1.484 raeburn 6360: };
1.458 raeburn 6361: }
1.538 raeburn 6362: $script .= &paste_popup_js();
1.501 raeburn 6363: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6364: &mt('Switch server?');
6365:
6366:
1.329 droeschl 6367: }
6368: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6369: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6370: .'// <![CDATA['."\n"
6371: .$script."\n"
6372: .'// ]]>'."\n"
1.595 musolffc 6373: .'</script>'."\n"
6374: .'<script type="text/javascript"
6375: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6376:
6377: # Breadcrumbs
6378: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 6379:
6380: if ($showdoc) {
1.682 raeburn 6381: my $args;
6382: if ($supplementalflag) {
1.687 raeburn 6383: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6384: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 6385: $args = {'bread_crumbs' => $brcrum,
6386: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 6387: } else {
6388: $args = {'force_register' => $showdoc};
6389: }
6390: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6391: } elsif ($toolsflag) {
1.611 raeburn 6392: my ($breadtext,$breadtitle);
1.617 raeburn 6393: $breadtext = "$crstype Editor";
1.611 raeburn 6394: if ($canedit) {
6395: $breadtitle = 'Editing '.$crstype.' Contents';
6396: } else {
6397: $breadtext .= ' (View-only mode)';
6398: $breadtitle = 'Viewing '.$crstype.' Contents';
6399: }
1.571 raeburn 6400: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6401: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6402: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6403: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6404: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6405: $breadtitle)
1.571 raeburn 6406: );
1.510 raeburn 6407: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6408: unless ($env{'request.role.adv'}) {
6409: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6410: $r->internal_redirect('/adm/navmaps');
6411: return OK;
6412: }
6413: }
1.510 raeburn 6414: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 6415: my $args = {'bread_crumbs' => $brcrum};
6416: unless (($env{'form.folderpath'} eq '') ||
6417: ($env{'form.folder'} eq 'supplemental')) {
6418: $args->{'bread_crumbs_nomenu'} = 1;
6419: }
1.510 raeburn 6420: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 6421: $args));
1.510 raeburn 6422: } else {
1.611 raeburn 6423: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6424: $breadtext = "$crstype Editor";
1.611 raeburn 6425: if ($canedit) {
6426: $breadtitle = 'Editing '.$crstype.' Contents';
6427: $helpitem = 'Docs_Adding_Course_Doc';
6428: } else {
6429: $breadtext .= ' (View-only mode)';
6430: $breadtitle = 'Viewing '.$crstype.' Contents';
6431: $helpitem = 'Docs_Viewing_Course_Doc';
6432: }
1.392 raeburn 6433: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6434: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6435: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6436: {'add_entries' => $addentries}
6437: )
1.392 raeburn 6438: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6439: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6440: $breadtitle,
6441: $helpitem)
1.392 raeburn 6442: );
6443: }
1.364 bisitz 6444:
1.329 droeschl 6445: my %allfiles = ();
6446: my %codebase = ();
1.440 raeburn 6447: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6448: if ($canedit) {
1.684 raeburn 6449: undef($suppchanges);
1.329 droeschl 6450: if (($env{'form.uploaddoc.filename'}) &&
6451: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6452: my $context = $1;
6453: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6454: undef($hadchanges);
1.440 raeburn 6455: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6456: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6457: undef($navmap);
1.329 droeschl 6458: if ($hadchanges) {
6459: &mark_hash_old();
6460: }
1.684 raeburn 6461: if ($suppchanges) {
6462: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6463: undef($suppchanges);
6464: }
1.440 raeburn 6465: $r->print($upload_output);
6466: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6467: # Process file upload - phase two - upload embedded objects
6468: $uploadphase = 'check_embedded';
6469: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6470: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6471: $env{'form.newidx'});
6472: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6473: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6474: my ($destination,$dir_root) = &embedded_destination();
6475: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6476: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6477: my ($result,$flag) =
1.440 raeburn 6478: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6479: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6480: $actionurl);
6481: $r->print($result.&return_to_editor());
6482: } elsif ($env{'form.phase'} eq 'check_embedded') {
6483: # Process file upload - phase three - modify references in HTML file
6484: $uploadphase = 'modified_orightml';
6485: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6486: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6487: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6488: my $result =
1.482 raeburn 6489: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6490: $docuname,$docudom,undef,
6491: $dir_root);
1.630 raeburn 6492: $r->print($result.&return_to_editor());
1.476 raeburn 6493: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6494: $uploadphase = 'decompress_phase_one';
6495: $r->print(&decompression_phase_one().
6496: &return_to_editor());
6497: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6498: $uploadphase = 'decompress_phase_two';
6499: $r->print(&decompression_phase_two().
6500: &return_to_editor());
1.329 droeschl 6501: }
6502: }
6503:
1.484 raeburn 6504: if ($allowed && $toolsflag) {
6505: $r->print(&startContentScreen('tools'));
1.708 raeburn 6506: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 6507: $r->print(&endContentScreen());
6508: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6509: # -----------------------------------------------------------------------------
6510: my %lt=&Apache::lonlocal::texthash(
6511: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6512: 'upfi' => 'Upload File',
1.553 raeburn 6513: 'upld' => 'Upload Content',
1.706 raeburn 6514: 'srch' => 'Search Repository',
6515: 'impo' => 'Import from Repository',
1.487 raeburn 6516: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6517: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6518: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6519: 'extr' => 'External Resource',
6520: 'extt' => 'External Tool',
1.329 droeschl 6521: 'selm' => 'Select Map',
6522: 'load' => 'Load Map',
6523: 'newf' => 'New Folder',
6524: 'newp' => 'New Composite Page',
6525: 'syll' => 'Syllabus',
1.425 raeburn 6526: 'navc' => 'Table of Contents',
1.343 biermanm 6527: 'sipa' => 'Simple Course Page',
1.329 droeschl 6528: 'sipr' => 'Simple Problem',
1.630 raeburn 6529: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6530: 'stpr' => 'Standard Problem',
6531: 'news' => 'New sub-directory',
6532: 'crpr' => 'Create Problem',
1.689 raeburn 6533: 'swit' => 'Switch Server',
1.329 droeschl 6534: 'drbx' => 'Drop Box',
1.451 www 6535: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6536: 'bull' => 'Discussion Board',
1.347 weissno 6537: 'mypi' => 'My Personal Information Page',
1.353 weissno 6538: 'grpo' => 'Group Portfolio',
1.329 droeschl 6539: 'rost' => 'Course Roster',
1.528 raeburn 6540: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6541: 'imsf' => 'IMS Upload',
6542: 'imsl' => 'Upload IMS package',
1.501 raeburn 6543: 'cms' => 'Origin of IMS package',
6544: 'se' => 'Select',
1.329 droeschl 6545: 'file' => 'File',
6546: 'title' => 'Title',
1.606 raeburn 6547: 'addp' => 'Add Placeholder to course?',
6548: 'uste' => 'Use Template?',
6549: 'fnam' => 'File Name:',
6550: 'loca' => 'Location:',
6551: 'dire' => 'Directory:',
6552: 'cate' => 'Category:',
6553: 'tmpl' => 'Template:',
1.698 raeburn 6554: 'empd' => 'No resources found',
1.329 droeschl 6555: 'comment' => 'Comment',
1.403 raeburn 6556: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6557: 'bb5' => 'Blackboard 5',
6558: 'bb6' => 'Blackboard 6',
6559: 'angel5' => 'ANGEL 5.5',
6560: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6561: 'yes' => 'Yes',
6562: 'no' => 'No',
1.618 raeburn 6563: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6564: );
1.329 droeschl 6565: # -----------------------------------------------------------------------------
1.595 musolffc 6566:
6567: # Calculate free quota space for a user or course. A javascript function checks
6568: # file size to determine if upload should be allowed.
6569: my $quotatype = 'unofficial';
6570: if ($crstype eq 'Community') {
1.601 raeburn 6571: $quotatype = 'community';
6572: } elsif ($crstype eq 'Placement') {
6573: $quotatype = 'placement';
1.595 musolffc 6574: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6575: $quotatype = 'official';
6576: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6577: $quotatype = 'textbook';
6578: }
6579: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6580: 'course',$quotatype); # expressed in MB
6581: my $current_disk_usage = 0;
6582: foreach my $subdir ('docs','supplemental') {
6583: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6584: "userfiles/$subdir",1); # expressed in kB
6585: }
6586: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6587: my $usage = $current_disk_usage/1024; # in MB
6588: my $quota = $disk_quota;
6589: my $percent;
6590: if ($disk_quota == 0) {
6591: $percent = 100.0;
6592: } else {
1.619 raeburn 6593: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6594: }
6595: $usage = sprintf("%.2f",$usage);
6596: $quota = sprintf("%.2f",$quota);
6597: $percent = sprintf("%.0f",$percent);
6598: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6599: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6600:
1.329 droeschl 6601: my $fileupload=(<<FIUP);
1.605 raeburn 6602: $quotainfo
1.329 droeschl 6603: $lt{'file'}:<br />
6604: FIUP
6605: my $checkbox=(<<CHBO);
6606: <!-- <label>$lt{'parse'}?
6607: <input type="checkbox" name="parserflag" />
6608: </label> -->
6609: <label>
1.611 raeburn 6610: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6611: </label>
6612: CHBO
1.501 raeburn 6613: my $imsfolder = $env{'form.folder'};
6614: if ($imsfolder eq '') {
6615: $imsfolder = 'default';
6616: }
6617: my $imspform=(<<IMSFORM);
6618: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6619: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6620: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6621: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6622: <legend>$lt{'imsf'}</legend>
6623: $fileupload
1.702 raeburn 6624: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6625: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 6626: <br />
6627: <p>
6628: $lt{'cms'}:
1.611 raeburn 6629: <select name="source" $disabled>
1.501 raeburn 6630: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6631: <option value="bb5">$lt{'bb5'}</option>
6632: <option value="bb6">$lt{'bb6'}</option>
6633: <option value="angel5">$lt{'angel5'}</option>
6634: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6635: </select>
6636: <input type="hidden" name="folder" value="$imsfolder" />
6637: </p>
6638: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6639: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6640: </fieldset>
6641: </form>
6642: IMSFORM
1.329 droeschl 6643:
6644: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6645: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6646: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6647: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6648: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6649: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6650: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6651: $fileupload
1.702 raeburn 6652: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6653: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6654: <br />
6655: $lt{'title'}:<br />
1.611 raeburn 6656: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6657: $pathitem
1.329 droeschl 6658: <input type="hidden" name="cmd" value="upload_default" />
6659: <br />
1.458 raeburn 6660: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6661: $checkbox
6662: </span>
1.501 raeburn 6663: <br clear="all" />
1.611 raeburn 6664: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6665: </fieldset>
6666: </form>
1.383 tempelho 6667: FUFORM
1.329 droeschl 6668:
1.611 raeburn 6669: my $mapimportjs;
6670: if ($canedit) {
6671: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6672: } else {
6673: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6674: }
1.502 raeburn 6675: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6676: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6677: $lt{'impm'}</a>$help{'Load_Map'}
6678: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6679: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6680: <legend>$lt{'impm'}</legend>
1.371 tempelho 6681: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6682: $lt{'copm'}<br />
6683: <span class="LC_nobreak">
6684: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6685: onfocus="this.blur();$mapimportjs" $disabled />
6686: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6687: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6688: </fieldset>
6689: </form>
6690:
1.383 tempelho 6691: SEDFFORM
1.706 raeburn 6692: my ($importcrsresform,$checkcrsres);
6693: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
6694: $checkcrsres = 1;
6695: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
6696: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 6697: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
6698: unless (($type eq 'community') || ($type eq 'placement')) {
6699: $type = 'unofficial';
6700: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
6701: $type = 'official';
6702: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
6703: $type = 'textbook';
6704: } else {
6705: $type = 'unofficial';
6706: }
6707: }
6708: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 6709: $checkcrsres = 1;
6710: }
6711: }
6712: if ($checkcrsres) {
6713: my ($numdirs,$pickfile) =
6714: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
6715: "resize_scrollbox('contentscroll','1','0');",
6716: undef,'res');
6717: if ($pickfile) {
6718: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6719: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6720: $lt{'imcr'}</a>$help{'Course_Resources'}
6721: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6722: <fieldset id="importcrsresform" style="display: none;">
6723: <legend>$lt{'imcr'}</legend>
1.698 raeburn 6724: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 6725: <input type="hidden" name="active" value="bb" />
6726: $pickfile
6727: <p>
1.699 raeburn 6728: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 6729: </p>
6730: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6731: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 6732: </div>
6733: <div id="importcrsresempty" style="display: none;">
6734: <p>
6735: $lt{'empd'}
6736: </p>
6737: </div>
1.606 raeburn 6738: </fieldset>
6739: </form>
6740: CRSFORM
1.706 raeburn 6741: }
1.606 raeburn 6742: }
6743:
1.611 raeburn 6744: my $fromstoredjs;
6745: if ($canedit) {
6746: $fromstoredjs = 'open_StoredLinks_Import()';
6747: } else {
6748: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6749: }
6750:
1.502 raeburn 6751: my @importpubforma = (
1.706 raeburn 6752: { '<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 6753: { '<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 6754: { '<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 6755: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6756: );
1.706 raeburn 6757: if ($importcrsresform) {
6758: 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 6759: }
1.502 raeburn 6760: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6761: my $extresourcesform =
6762: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6763: $help{'Adding_External_Resource'},
6764: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6765: my $exttoolform =
6766: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6767: $help{'Adding_External_Tool'},undef,
6768: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6769: \%ltitools,$disabled);
1.329 droeschl 6770: if ($allowed) {
1.492 raeburn 6771: my $folder = $env{'form.folder'};
6772: if ($folder eq '') {
6773: $folder='default';
6774: }
1.615 raeburn 6775: if ($canedit) {
6776: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6777: if ($output) {
6778: $r->print($output);
6779: }
1.538 raeburn 6780: }
1.337 ehlerst 6781: $r->print(<<HIDDENFORM);
6782: <form name="renameform" method="post" action="/adm/coursedocs">
6783: <input type="hidden" name="title" />
6784: <input type="hidden" name="cmd" />
6785: <input type="hidden" name="markcopy" />
6786: <input type="hidden" name="copyfolder" />
6787: $containertag
6788: </form>
1.633 raeburn 6789: <form name="aliasform" method="post" action="/adm/coursedocs">
6790: <input type="hidden" name="alias" />
6791: <input type="hidden" name="cmd" />
6792: $containertag
6793: </form>
1.484 raeburn 6794:
1.337 ehlerst 6795: HIDDENFORM
1.508 raeburn 6796: $r->print(&makesimpleeditform($pathitem)."\n".
6797: &makedocslogform($pathitem."\n".
1.484 raeburn 6798: '<input type="hidden" name="folder" value="'.
6799: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6800: }
1.442 www 6801:
6802: # Generate the tabs
1.510 raeburn 6803: my ($mode,$needs_end);
1.472 raeburn 6804: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6805: my @folders = split('&',$env{'form.folderpath'});
6806: unless (@folders > 2) {
6807: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6808: $needs_end = 1;
6809: }
1.472 raeburn 6810: } else {
1.484 raeburn 6811: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6812: $needs_end = 1;
1.472 raeburn 6813: }
1.443 www 6814:
1.442 www 6815: #
1.622 raeburn 6816: my $hostname = $r->hostname();
1.442 www 6817: my $savefolderpath;
6818:
1.395 raeburn 6819: if ($allowed) {
1.329 droeschl 6820: my $folder=$env{'form.folder'};
1.615 raeburn 6821: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6822: $folder='default';
1.356 tempelho 6823: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6824: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6825: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6826: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6827: }
6828: my $postexec='';
6829: if ($folder eq 'default') {
1.653 raeburn 6830: my $windowname = 'loncapaclient';
6831: if ($env{'request.lti.login'}) {
6832: $windowname .= 'lti';
6833: }
1.372 bisitz 6834: $r->print('<script type="text/javascript">'."\n"
6835: .'// <![CDATA['."\n"
1.653 raeburn 6836: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6837: .'// ]]>'."\n"
6838: .'</script>'."\n"
1.369 bisitz 6839: );
1.329 droeschl 6840: } else {
6841: #$postexec='self.close();';
6842: }
1.504 raeburn 6843: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6844: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6845: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6846:
6847: my $newnavform=(<<NNFORM);
6848: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6849: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6850: $pathitem
1.329 droeschl 6851: <input type="hidden" name="importdetail"
6852: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6853: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6854: $help{'Navigate_Content'}
6855: </form>
6856: NNFORM
6857: my $newsmppageform=(<<NSPFORM);
6858: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6859: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6860: $pathitem
1.329 droeschl 6861: <input type="hidden" name="importdetail" value="" />
1.423 onken 6862: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6863: $help{'Simple Page'}
1.329 droeschl 6864: </form>
6865: NSPFORM
6866:
6867: my $newsmpproblemform=(<<NSPROBFORM);
6868: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6869: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6870: $pathitem
1.329 droeschl 6871: <input type="hidden" name="importdetail" value="" />
1.423 onken 6872: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6873: $help{'Simple_Problem'}
1.329 droeschl 6874: </form>
6875:
6876: NSPROBFORM
6877:
6878: my $newdropboxform=(<<NDBFORM);
6879: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6880: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6881: $pathitem
1.329 droeschl 6882: <input type="hidden" name="importdetail" value="" />
1.423 onken 6883: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6884: $help{'Dropbox'}
1.344 bisitz 6885: </form>
1.329 droeschl 6886: NDBFORM
6887:
6888: my $newexuploadform=(<<NEXUFORM);
6889: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6890: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6891: $pathitem
1.329 droeschl 6892: <input type="hidden" name="importdetail" value="" />
1.423 onken 6893: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6894: $help{'Score_Upload_Form'}
6895: </form>
6896: NEXUFORM
6897:
6898: my $newbulform=(<<NBFORM);
6899: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6900: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6901: $pathitem
1.329 droeschl 6902: <input type="hidden" name="importdetail" value="" />
1.423 onken 6903: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6904: $help{'Bulletin Board'}
6905: </form>
6906: NBFORM
6907:
6908: my $newaboutmeform=(<<NAMFORM);
6909: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6910: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6911: $pathitem
1.329 droeschl 6912: <input type="hidden" name="importdetail"
6913: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6914: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6915: $help{'My Personal Information Page'}
1.329 droeschl 6916: </form>
6917: NAMFORM
6918:
6919: my $newaboutsomeoneform=(<<NASOFORM);
6920: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6921: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6922: $pathitem
1.329 droeschl 6923: <input type="hidden" name="importdetail" value="" />
1.423 onken 6924: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6925: </form>
6926: NASOFORM
6927:
6928: my $newrosterform=(<<NROSTFORM);
6929: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6930: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6931: $pathitem
1.329 droeschl 6932: <input type="hidden" name="importdetail"
6933: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6934: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6935: $help{'Course_Roster'}
1.329 droeschl 6936: </form>
6937: NROSTFORM
6938:
1.534 raeburn 6939: my $newwebpage;
6940: if ($folder =~ /^default_?(\d*)$/) {
6941: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6942: if ($1) {
6943: $newwebpage .= $1;
6944: } else {
6945: $newwebpage .= 'default';
6946: }
6947: $newwebpage .= '/new.html';
6948: }
6949: my $newwebpageform =(<<NWEBFORM);
6950: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6951: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6952: $pathitem
6953: <input type="hidden" name="importdetail" value="$newwebpage" />
6954: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6955: $help{'Web_Page'}
1.534 raeburn 6956: </form>
6957: NWEBFORM
1.701 raeburn 6958: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 6959: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6960: my $machines_str = "'".join("','",@ids)."'";
6961: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6962: if ($env{'user.author'}) {
6963: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6964: $is_home{'author'} = 1;
1.606 raeburn 6965: }
1.691 raeburn 6966: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6967: }
6968: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6969: ['active'],['ca','aa']);
1.691 raeburn 6970: my %by_roletype;
1.606 raeburn 6971: if (keys(%roleshash)) {
6972: foreach my $entry (keys(%roleshash)) {
6973: my ($auname,$audom,$roletype) = split(/:/,$entry);
6974: my $key = $entry;
6975: $key =~ s/:/___/g;
1.691 raeburn 6976: my $author = $auname.'___'.$audom;
6977: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6978: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6979: $toppath{$author} = "/priv/$audom/$auname";
6980: if (grep(/^\Q$rolehome\E$/,@ids)) {
6981: $is_home{$author} = 1;
1.606 raeburn 6982: }
1.691 raeburn 6983: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6984: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6985: }
1.691 raeburn 6986: }
6987: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6988: if (grep(/^\Q$crshome\E$/,@ids)) {
6989: $is_home{'course'} = 1;
6990: }
6991: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6992: my $pickdir = $lt{'loca'}.
6993: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6994: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6995: if ($env{'user.author'}) {
6996: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6997: }
6998: if (keys(%by_roletype)) {
6999: foreach my $possrole ('ca','aa') {
7000: if (ref($by_roletype{$possrole}) eq 'HASH') {
7001: my $roletitle = &Apache::lonnet::plaintext($possrole);
7002: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7003: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7004: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7005: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7006: }
7007: }
7008: }
7009: }
1.706 raeburn 7010: if ($checkcrsres) {
7011: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7012: }
7013: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7014: $lt{'dire'}.
7015: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7016: '<option value=""></option>'.
7017: '</select><br />'."\n";
1.606 raeburn 7018: my %seltemplate_menus;
7019: my @files = &Apache::lonhomework::get_template_list('problem');
7020: my @noexamplelink = ('blank.problem','blank.library','script.library');
7021: my $currentcategory = '';
7022: my @ordered = ('');
7023: my %templatehelp;
7024: my $defcategory = '';
7025: my @catorder = ($defcategory);
7026: $seltemplate_menus{$defcategory}->{'order'} = [''];
7027: $seltemplate_menus{$defcategory}->{'text'} = '';
7028: foreach my $file (@files) {
7029: if (ref($file) eq 'ARRAY') {
7030: my ($path,$title,$category,$help) = @{$file};
7031: next if ($title !~ /\S/);
7032: if (&js_escape($category) ne $currentcategory) {
7033: $currentcategory = &js_escape($category);
7034: push(@catorder,&js_escape($currentcategory));
7035: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7036: $seltemplate_menus{$currentcategory}->{'default'} = '';
7037: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7038: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7039: }
7040: if ($path) {
7041: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7042: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7043: if ($help) {
7044: $templatehelp{$path} = $help;
7045: }
7046: }
7047: }
7048: }
7049:
7050: my $templates = $lt{'cate'}.' '.
7051: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7052: $defcategory,'tempcategory','template',
7053: \%seltemplate_menus,\@catorder,
7054: "resize_scrollbox('contentscroll','1','0');",
7055: "toggleExampleText();",'template').'<br />';
7056: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 7057: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 7058: my $crsresform;
7059: if (($env{'user.author'}) || ($checkcrsres)) {
7060: $crsresform=(<<RESFORM);
1.691 raeburn 7061: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 7062: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 7063: <form action="/adm/coursedocs" method="post" name="courseresform">
7064: <fieldset id="crsresform" style="display:none;">
7065: <legend>$lt{'stpr'}</legend>
1.655 raeburn 7066: <input type="hidden" name="active" value="bb" />
1.606 raeburn 7067: <p>
7068: $pickdir
1.701 raeburn 7069: </p>
1.691 raeburn 7070: <div id="newstdproblem" style="display:none;">
1.701 raeburn 7071: <p>
1.606 raeburn 7072: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 7073: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 7074:
1.611 raeburn 7075: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 7076: </span><span id="newsubdir"></span>
7077: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 7078: </p>
1.699 raeburn 7079: </div>
1.606 raeburn 7080: $lt{'fnam'}
1.611 raeburn 7081: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 7082: <div id="newresource" style="display:none">
1.606 raeburn 7083: <p>
7084: $lt{'addp'}
1.611 raeburn 7085: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7086: $lt{'no'}</label>
1.611 raeburn 7087: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7088: $lt{'yes'}</label>
7089: <span id="newrestitle"></span>
1.611 raeburn 7090: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 7091: </p>
1.606 raeburn 7092: </div>
7093: <p>
7094: $lt{'uste'}
1.611 raeburn 7095: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7096: $lt{'no'}</label>
1.611 raeburn 7097: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7098: $lt{'yes'}</label>
1.701 raeburn 7099: </p>
1.606 raeburn 7100: <div id="newrestemplate" style="display:none">
7101: $templates
7102: $templatepreview
7103: </div>
7104: <span class="LC_nobreak">
1.701 raeburn 7105: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 7106: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 7107: </span>
1.691 raeburn 7108: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 7109: $rolehomes
7110: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7111: </div>
1.606 raeburn 7112: </fieldset>
7113: </form>
7114:
7115: RESFORM
1.706 raeburn 7116: }
1.534 raeburn 7117:
1.342 ehlerst 7118: my $specialdocumentsform;
1.383 tempelho 7119: my @specialdocumentsforma;
1.451 www 7120: my $gradingform;
7121: my @gradingforma;
7122: my $communityform;
7123: my @communityforma;
1.351 ehlerst 7124: my $newfolderform;
1.390 tempelho 7125: my $newfolderb;
1.342 ehlerst 7126:
1.451 www 7127: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 7128:
1.329 droeschl 7129: my $newpageform=(<<NPFORM);
7130: <form action="/adm/coursedocs" method="post" name="newpage">
7131: <input type="hidden" name="folderpath" value="$path" />
7132: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7133: <input type="hidden" name="active" value="ee" />
1.423 onken 7134: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 7135: $help{'Adding_Pages'}
1.329 droeschl 7136: </form>
7137: NPFORM
1.390 tempelho 7138:
7139:
1.351 ehlerst 7140: $newfolderform=(<<NFFORM);
1.329 droeschl 7141: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 7142: $pathitem
1.329 droeschl 7143: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7144: <input type="hidden" name="active" value="" />
1.422 onken 7145: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 7146: </form>
7147: NFFORM
7148:
7149: my $newsylform=(<<NSYLFORM);
7150: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 7151: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7152: $pathitem
1.329 droeschl 7153: <input type="hidden" name="importdetail"
7154: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7155: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 7156: $help{'Syllabus'}
1.383 tempelho 7157:
1.329 droeschl 7158: </form>
7159: NSYLFORM
1.364 bisitz 7160:
1.329 droeschl 7161: my $newgroupfileform=(<<NGFFORM);
7162: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 7163: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7164: $pathitem
1.329 droeschl 7165: <input type="hidden" name="importdetail"
7166: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 7167: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 7168: $help{'Group Portfolio'}
1.329 droeschl 7169: </form>
7170: NGFFORM
1.672 raeburn 7171: if ($container eq 'page') {
7172: @specialdocumentsforma=(
7173: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7174: );
7175: } else {
7176: @specialdocumentsforma=(
1.421 onken 7177: {'<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 7178: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 7179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 7180: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 7181: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 7182: );
7183: }
1.451 www 7184: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
7185:
1.655 raeburn 7186: my @external = (
7187: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 7188: );
1.699 raeburn 7189: if ($posslti) {
1.655 raeburn 7190: push(@external,
7191: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
7192: );
1.598 raeburn 7193: }
1.655 raeburn 7194: my $externalform = &create_form_ul(&create_list_elements(@external));
7195:
7196: my @importdoc = ();
1.519 raeburn 7197: unless ($container eq 'page') {
7198: push(@importdoc,
7199: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
7200: );
7201: }
7202: push(@importdoc,
1.558 raeburn 7203: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 7204: );
1.501 raeburn 7205: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 7206:
1.451 www 7207: @gradingforma=(
7208: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
7209: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 7210: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 7211: );
1.706 raeburn 7212: if ($crsresform) {
7213: push(@gradingforma,
7214: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
7215: );
7216: }
1.451 www 7217: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
7218:
7219: @communityforma=(
7220: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
7221: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
7222: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 7223: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
7224: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 7225: );
7226: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 7227:
1.330 tempelho 7228: my %orderhash = (
1.553 raeburn 7229: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 7230: 'bb' => ['External',$externalform],
7231: 'cc' => ['Import',$importpubform],
1.701 raeburn 7232: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 7233: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 7234: );
1.519 raeburn 7235: unless ($container eq 'page') {
1.434 raeburn 7236: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 7237: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 7238: }
7239:
1.341 ehlerst 7240: $hadchanges=0;
1.484 raeburn 7241: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 7242: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 7243: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 7244: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 7245: undef($navmap);
1.443 www 7246: if ($error) {
7247: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7248: }
1.639 raeburn 7249: if ($hadchanges) {
7250: unless (&is_hash_old()) {
1.638 raeburn 7251: &mark_hash_old();
7252: }
7253: }
1.341 ehlerst 7254:
1.443 www 7255: &changewarning($r,'');
7256: }
1.458 raeburn 7257: }
1.442 www 7258:
1.443 www 7259: # Supplemental documents start here
7260:
1.329 droeschl 7261: my $folder=$env{'form.folder'};
1.443 www 7262: unless ($supplementalflag) {
1.329 droeschl 7263: $folder='supplemental';
7264: }
1.685 raeburn 7265: if (($folder eq 'supplemental') &&
1.329 droeschl 7266: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 7267: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 7268: } elsif ($allowed) {
1.356 tempelho 7269: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 7270: }
1.508 raeburn 7271: $pathitem = '<input type="hidden" name="folderpath" value="'.
7272: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 7273: if ($allowed) {
7274: my $folderseq=
1.504 raeburn 7275: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 7276:
7277: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 7278: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
7279: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 7280: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 7281: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 7282: <legend>$lt{'upfi'}</legend>
1.630 raeburn 7283: <input type="hidden" name="active" value="ee" />
1.329 droeschl 7284: $fileupload
1.702 raeburn 7285: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7286: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 7287: <br />
7288: <br />
7289: <span class="LC_nobreak">
7290: $checkbox
7291: </span>
7292: <br /><br />
7293: $lt{'comment'}:<br />
1.383 tempelho 7294: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 7295: <br />
1.508 raeburn 7296: $pathitem
1.329 droeschl 7297: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 7298: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 7299: </fieldset>
1.501 raeburn 7300: </form>
1.329 droeschl 7301: SUPDOCFORM
7302:
7303: my $supnewfolderform=(<<SNFFORM);
7304: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 7305: <input type="hidden" name="active" value="" />
1.508 raeburn 7306: $pathitem
1.329 droeschl 7307: <input type="hidden" name="importdetail" value="" />
1.423 onken 7308: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 7309: $help{'Adding_Folders'}
1.329 droeschl 7310: </form>
7311: SNFFORM
1.383 tempelho 7312:
1.510 raeburn 7313: my $supextform =
7314: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 7315: $help{'Adding_External_Resource'},
7316: undef,undef,undef,undef,undef,undef,
7317: $disabled);
1.329 droeschl 7318:
1.598 raeburn 7319: my $supexttoolform =
7320: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7321: $help{'Adding_External_Tool'},
7322: undef,undef,'tool',$coursedom,
1.611 raeburn 7323: $coursenum,\%ltitools,$disabled);
1.598 raeburn 7324:
1.329 droeschl 7325: my $supnewsylform=(<<SNSFORM);
7326: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 7327: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7328: $pathitem
1.329 droeschl 7329: <input type="hidden" name="importdetail"
7330: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7331: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 7332: $help{'Syllabus'}
7333: </form>
7334: SNSFORM
7335:
7336: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 7337: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 7338: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7339: $pathitem
1.329 droeschl 7340: <input type="hidden" name="importdetail"
7341: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7342: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 7343: $help{'My Personal Information Page'}
1.329 droeschl 7344: </form>
7345: SNAMFORM
7346:
1.534 raeburn 7347: my $supwebpage;
7348: if ($folder =~ /^supplemental_?(\d*)$/) {
7349: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
7350: if ($1) {
7351: $supwebpage .= $1;
7352: } else {
7353: $supwebpage .= 'default';
7354: }
7355: $supwebpage .= '/new.html';
7356: }
7357: my $supwebpageform =(<<SWEBFORM);
7358: <form action="/adm/coursedocs" method="post" name="supwebpage">
7359: <input type="hidden" name="active" value="cc" />
7360: $pathitem
7361: <input type="hidden" name="importdetail" value="$supwebpage" />
7362: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 7363: $help{'Web_Page'}
1.534 raeburn 7364: </form>
7365: SWEBFORM
7366:
1.333 muellerd 7367:
1.383 tempelho 7368: my @specialdocs = (
1.618 raeburn 7369: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 7370: =>$supnewsylform},
1.611 raeburn 7371: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 7372: =>$supnewaboutmeform},
1.534 raeburn 7373: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7374:
1.383 tempelho 7375: );
1.655 raeburn 7376: my @supexternal = (
7377: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
7378: =>$supextform});
1.699 raeburn 7379: if ($posslti) {
1.655 raeburn 7380: push(@supexternal,
7381: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 7382: =>$supexttoolform});
7383: }
1.655 raeburn 7384: my @supimportdoc = (
1.598 raeburn 7385: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 7386: =>$supupdocform},
1.598 raeburn 7387: );
1.501 raeburn 7388:
7389: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 7390: my %suporderhash = (
1.390 tempelho 7391: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 7392: 'dd' => ['Upload',$supupdocform],
7393: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 7394: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 7395: );
1.443 www 7396: if ($supplementalflag) {
1.682 raeburn 7397: $suppchanges = 0;
7398: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7399: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7400: \%ltitools,$canedit,$hostname);
7401: if ($error) {
7402: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7403: }
7404: if ($suppchanges) {
1.684 raeburn 7405: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7406: undef($suppchanges);
7407: }
1.393 raeburn 7408: }
1.443 www 7409: } elsif ($supplementalflag) {
1.458 raeburn 7410: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7411: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7412: $hostname);
1.393 raeburn 7413: if ($error) {
7414: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7415: }
1.393 raeburn 7416: }
1.389 tempelho 7417:
1.510 raeburn 7418: if ($needs_end) {
7419: $r->print(&endContentScreen());
7420: }
1.383 tempelho 7421:
1.329 droeschl 7422: if ($allowed) {
7423: $r->print('
7424: <form method="post" name="extimport" action="/adm/coursedocs">
7425: <input type="hidden" name="title" />
7426: <input type="hidden" name="url" />
7427: <input type="hidden" name="useform" />
7428: <input type="hidden" name="residx" />
7429: </form>');
7430: }
1.484 raeburn 7431: } elsif ($showdoc) {
1.329 droeschl 7432: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7433: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7434: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7435: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7436: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7437: }
7438: }
1.630 raeburn 7439: unless ($noendpage) {
1.606 raeburn 7440: $r->print(&Apache::loncommon::end_page());
7441: }
1.329 droeschl 7442: return OK;
1.364 bisitz 7443: }
1.329 droeschl 7444:
1.440 raeburn 7445: sub embedded_form_elems {
7446: my ($phase,$primaryurl,$newidx) = @_;
7447: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7448: $newidx =~s /\D+//g;
1.440 raeburn 7449: return <<STATE;
7450: <input type="hidden" name="folderpath" value="$folderpath" />
7451: <input type="hidden" name="cmd" value="upload_embedded" />
7452: <input type="hidden" name="newidx" value="$newidx" />
7453: <input type="hidden" name="phase" value="$phase" />
7454: <input type="hidden" name="primaryurl" value="$primaryurl" />
7455: STATE
7456: }
7457:
7458: sub embedded_destination {
7459: my $folder=$env{'form.folder'};
7460: my $destination = 'docs/';
7461: if ($folder =~ /^supplemental/) {
7462: $destination = 'supplemental/';
7463: }
7464: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7465: $destination .= 'default/';
7466: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7467: $destination .= $2.'/';
7468: }
1.634 raeburn 7469: my $newidx = $env{'form.newidx'};
7470: $newidx =~s /\D+//g;
7471: if ($newidx) {
7472: $destination .= $newidx;
7473: }
1.440 raeburn 7474: my $dir_root = '/userfiles';
7475: return ($destination,$dir_root);
7476: }
7477:
7478: sub return_to_editor {
7479: my $actionurl = '/adm/coursedocs';
7480: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7481: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7482: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7483: '</a></p>';
7484: }
7485:
1.476 raeburn 7486: sub decompression_info {
7487: my ($destination,$dir_root) = &embedded_destination();
7488: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7489: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7490: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7491: my $container='sequence';
1.480 raeburn 7492: my ($pathitem,$hiddenelem);
1.583 raeburn 7493: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7494: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7495: $container='page';
7496: }
1.480 raeburn 7497: unshift(@hiddens,$pathitem);
7498: foreach my $item (@hiddens) {
1.634 raeburn 7499: if ($item eq 'newidx') {
7500: next if ($env{'form.'.$item} =~ /\D/);
7501: }
1.480 raeburn 7502: if ($env{'form.'.$item}) {
7503: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7504: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7505: }
1.477 raeburn 7506: }
1.476 raeburn 7507: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7508: $hiddenelem);
7509: }
7510:
7511: sub decompression_phase_one {
7512: my ($dir,$file,$warning,$error,$output);
7513: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7514: &decompression_info();
1.490 raeburn 7515: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7516: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7517: } else {
7518: my $file = $1;
1.630 raeburn 7519: $output =
1.481 raeburn 7520: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7521: $destination,$dir_root,
7522: $hiddenelem);
7523: if ($env{'form.autoextract_camtasia'}) {
7524: $output .= &remove_archive($docudom,$docuname,$container);
7525: }
1.476 raeburn 7526: }
7527: if ($error) {
7528: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7529: $error.'</p>'."\n";
7530: }
7531: if ($warning) {
7532: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7533: }
7534: return $output;
7535: }
7536:
7537: sub decompression_phase_two {
7538: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7539: &decompression_info();
1.481 raeburn 7540: my $output;
1.480 raeburn 7541: if ($env{'form.archivedelete'}) {
1.481 raeburn 7542: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7543: }
7544: $output .=
1.481 raeburn 7545: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7546: $destination,$dir_root,$hiddenelem);
7547: return $output;
7548: }
7549:
1.480 raeburn 7550: sub remove_archive {
7551: my ($docudom,$docuname,$container) = @_;
7552: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7553: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7554: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7555: if ($fatal) {
7556: if ($container eq 'page') {
7557: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7558: } else {
7559: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7560: }
1.583 raeburn 7561: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7562: } else {
7563: my $currcmd = $env{'form.cmd'};
7564: my $position = $env{'form.position'};
1.583 raeburn 7565: my $archiveidx = $position;
1.563 raeburn 7566: if ($position > 0) {
1.583 raeburn 7567: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7568: $archiveidx = $position-1;
7569: }
7570: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7571: my ($title,$url,@rrest) =
1.583 raeburn 7572: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7573: if ($url eq $env{'form.archiveurl'}) {
7574: if (&handle_edit_cmd($docuname,$docudom)) {
7575: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7576: if ($suppchanges) {
7577: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7578: undef($suppchanges);
7579: }
1.583 raeburn 7580: if ($fatal) {
7581: if ($container eq 'page') {
7582: $delwarning = &mt('An error occurred updating the contents of the current page.');
7583: } else {
7584: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7585: }
1.480 raeburn 7586: } else {
1.583 raeburn 7587: $delresult = &mt('Archive file removed.');
1.480 raeburn 7588: }
7589: }
1.583 raeburn 7590: } else {
7591: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7592: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7593: }
7594: }
7595: $env{'form.cmd'} = $currcmd;
7596: }
7597: if ($delwarning) {
7598: $output = '<p class="LC_warning">'.
7599: $delwarning.
7600: '</p>';
7601: }
7602: if ($delresult) {
7603: $output .= '<p class="LC_info">'.
7604: $delresult.
7605: '</p>';
7606: }
1.481 raeburn 7607: return $output;
1.480 raeburn 7608: }
7609:
1.484 raeburn 7610: sub generate_admin_menu {
1.708 raeburn 7611: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 7612: my $lc_crstype = lc($crstype);
7613: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7614: my %lt= ( # do not translate here
1.484 raeburn 7615: 'vc' => 'Verify Content',
7616: 'cv' => 'Check/Set Resource Versions',
7617: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7618: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 7619: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 7620: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7621: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7622: );
1.484 raeburn 7623: my ($candump,$dumpurl);
7624: if ($home + $other > 0) {
7625: $candump = 'F';
7626: if ($home) {
7627: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7628: } else {
7629: my @hosts;
7630: foreach my $aurole (keys(%outhash)) {
7631: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7632: push(@hosts,$outhash{$aurole});
1.538 raeburn 7633: }
1.484 raeburn 7634: }
7635: if (@hosts == 1) {
7636: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7637: '&role='.
7638: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7639: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7640: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7641: } else {
7642: $dumpurl = "javascript:choose_switchserver_window()";
7643: }
7644: }
7645: }
7646: my @menu=
7647: ({ categorytitle=>'Administration',
7648: items =>[
7649: { linktext => $lt{'vc'},
7650: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7651: permission => 'F',
1.571 raeburn 7652: help => 'Docs_Verify_Content',
1.484 raeburn 7653: icon => 'verify.png',
7654: linktitle => 'Verify contents can be retrieved/rendered',
7655: },
7656: { linktext => $lt{'cv'},
7657: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7658: permission => 'F',
1.571 raeburn 7659: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7660: icon => 'resversion.png',
7661: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7662: },
7663: { linktext => $lt{'ls'},
7664: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7665: permission => 'F',
7666: #help => '',
7667: icon => 'symbs.png',
7668: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7669: },
1.651 raeburn 7670: { linktext => $lt{'ct'},
7671: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7672: permission => 'F',
7673: help => 'Docs_Short_URLs',
7674: icon => 'shorturls.png',
7675: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7676: },
1.484 raeburn 7677: ]
1.611 raeburn 7678: });
7679: if ($canedit) {
1.708 raeburn 7680: my ($crsauname,$crsaudom,$crshome);
7681: if (($coursenum ne '') && ($coursedom ne '')) {
7682: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
7683: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
7684: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
7685: my @ids=&Apache::lonnet::current_machine_ids();
7686: my $linkurl;
7687: if (grep(/^\Q$crshome\E$/,@ids)) {
7688: $linkurl = $crsauthorurl;
7689: } else {
7690: $linkurl =
7691: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
7692: }
7693: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
7694: push(@{$menu[0]->{items}},
7695: { linktext => $lt{'ca'},
7696: url => $linkurl,
7697: permission => 'F',
7698: help => 'Docs_Course_Authorspace',
7699: icon => 'impcrsau.png',
7700: linktitle => $lt{'ca'},
7701: });
7702: }
7703: }
7704: }
1.611 raeburn 7705: push(@menu,
1.484 raeburn 7706: { categorytitle=>'Export',
7707: items =>[
7708: { linktext => $lt{'imse'},
7709: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7710: permission => 'F',
7711: help => 'Docs_Export_Course_Docs',
7712: icon => 'imsexport.png',
7713: linktitle => $lt{'imse'},
7714: },
7715: { linktext => $lt{'dcd'},
7716: url => $dumpurl,
7717: permission => $candump,
1.571 raeburn 7718: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7719: icon => 'dump.png',
7720: linktitle => $lt{'dcd'},
7721: },
7722: ]
7723: });
1.611 raeburn 7724: }
1.484 raeburn 7725: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7726: '<input type="hidden" id="dummy" />'."\n".
7727: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7728: '</form>';
1.329 droeschl 7729: }
7730:
7731: sub generate_edit_table {
1.538 raeburn 7732: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7733: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7734: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7735: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7736: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7737: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7738: $activetab = $env{'form.active'};
7739: }
1.611 raeburn 7740: unless ($canedit) {
7741: $disabled = ' disabled="disabled"';
7742: }
1.472 raeburn 7743: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7744: my $backtext = &mt('Exit Editor');
1.458 raeburn 7745: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7746: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7747: '<li class="goback">'.
1.546 raeburn 7748: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7749: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7750: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7751: '<li>'.
7752: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7753: &mt('Undo Delete').'</a></li>'."\n";
7754: if ($env{'form.docslog'}) {
7755: $form .= '<li class="active">';
7756: } else {
7757: $form .= '<li>';
7758: }
7759: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7760: &mt('History').'</a></li>'."\n";
7761: if ($env{'form.docslog'}) {
7762: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7763: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7764: }
1.458 raeburn 7765: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7766: if($name ne '00'){
1.371 tempelho 7767: if($activetab eq '' || $activetab ne $name){
7768: $active = '';
7769: }elsif($activetab eq $name){
7770: $active = 'class="active"';
7771: }
1.458 raeburn 7772: $form .= '<li style="float:right" '.$active
1.484 raeburn 7773: .' 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 7774: } else {
1.570 raeburn 7775: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7776:
7777: }
1.329 droeschl 7778: }
1.484 raeburn 7779: $form .= '</ul>'."\n";
7780: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7781:
7782: if ($to_show ne '') {
1.538 raeburn 7783: my $saveform;
7784: if ($need_save) {
7785: my $button = &mt('Make changes');
7786: my $path;
7787: if ($env{'form.folderpath'}) {
7788: $path =
7789: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7790: }
7791: $saveform = <<"END";
7792: <div id="multisave" style="display:none; clear:both;" >
7793: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7794: <input type="hidden" name="folderpath" value="$path" />
7795: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7796: <input type="hidden" name="allhiddenresource" value="" />
7797: <input type="hidden" name="allencrypturl" value="" />
7798: <input type="hidden" name="allrandompick" value="" />
7799: <input type="hidden" name="allrandomorder" value="" />
7800: <input type="hidden" name="changeparms" value="" />
7801: <input type="hidden" name="multiremove" value="" />
7802: <input type="hidden" name="multicut" value="" />
7803: <input type="hidden" name="multicopy" value="" />
7804: <input type="hidden" name="multichange" value="" />
7805: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7806: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7807: </form>
7808: </div>
7809: END
7810: }
7811: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7812: }
1.363 ehlerst 7813: foreach my $field (keys(%orderhash)){
1.390 tempelho 7814: if($field ne '00'){
1.422 onken 7815: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7816: $active = 'style="display: none;float:left"';
1.422 onken 7817: }elsif($activetab eq $field){
1.458 raeburn 7818: $active = 'style="display:block;float:left"';
1.422 onken 7819: }
7820: $form .= '<div id="'.$field.$tid.'"'
7821: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7822: .'</div>'."\n";
1.363 ehlerst 7823: }
7824: }
1.484 raeburn 7825: unless ($env{'form.docslog'}) {
7826: $form .= '</div></div>'."\n";
7827: }
1.329 droeschl 7828: return $form;
7829: }
7830:
7831: sub editing_js {
1.622 raeburn 7832: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7833: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7834: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7835: p_mnf => 'Name of New Folder',
7836: t_mnf => 'New Folder',
7837: p_mnp => 'Name of New Page',
7838: t_mnp => 'New Page',
1.451 www 7839: p_mxu => 'Title for the External Score',
1.349 biermanm 7840: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7841: p_msb => 'Title for the Problem',
7842: p_mdb => 'Title for the Drop Box',
1.336 schafran 7843: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7844: p_mwp => 'Title for Web Page',
1.606 raeburn 7845: p_mnr => 'Title for the Resource',
1.348 weissno 7846: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7847: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7848: p_mab_alrt1 => 'Not a valid user:domain',
7849: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7850: p_chn => 'New Title',
7851: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7852: p_rmr2a => 'Remove',
7853: p_rmr2b => '?',
7854: p_rmr3a => 'Remove those',
7855: p_rmr3b => 'items?',
7856: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7857: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7858: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7859: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7860: p_ctr2a => 'Cut',
7861: p_ctr2b => '?',
7862: p_ctr3a => 'Cut those',
7863: p_ctr3b => 'items?',
1.633 raeburn 7864: setal => 'Enter a (unique) alias',
7865: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7866: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7867: imsfile => 'You must choose an IMS package for import',
7868: imscms => 'You must select which Course Management System was the source of the IMS package',
7869: invurl => 'Invalid URL',
7870: titbl => 'Title is blank',
1.538 raeburn 7871: more => '(More ...)',
7872: less => '(Less ...)',
1.543 raeburn 7873: noor => 'No actions selected or changes to settings specified.',
7874: noch => 'No changes to settings specified.',
7875: noac => 'No actions selected.',
1.606 raeburn 7876: nofi => 'No file selected',
7877: tinc => 'Title in course',
7878: sunm => 'Sub-directory name',
1.618 raeburn 7879: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7880: sele => 'Select',
7881: swit => 'Switch server required',
1.329 droeschl 7882: );
1.594 damieng 7883: &js_escape(\%js_lt);
1.433 raeburn 7884: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7885: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7886: my $main_container_page;
1.519 raeburn 7887: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7888: $main_container_page = 1;
1.434 raeburn 7889: }
1.617 raeburn 7890: my $backtourl;
7891: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7892: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7893: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7894: my @ids=&Apache::lonnet::current_machine_ids();
7895: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7896: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7897: my $caller = $1;
1.525 raeburn 7898: if ($caller =~ /^supplemental/) {
7899: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7900: } else {
7901: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7902: $res = &Apache::lonnet::clutter($res);
7903: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7904: my ($url,$anchor);
7905: if ($res =~ /^([^#]+)#([^#]+)$/) {
7906: $url = $1;
7907: $anchor = $2;
7908: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7909: $caller = $1.&escape('#').$anchor;
7910: }
1.614 raeburn 7911: } else {
7912: $url = $res;
1.609 raeburn 7913: }
1.640 raeburn 7914: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7915: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7916: $backtourl .= '?navmap=1';
7917: } else {
7918: $backtourl .= '?symb='.
7919: &HTML::Entities::encode($caller,'<>&"');
7920: }
1.622 raeburn 7921: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7922: if (($ENV{'SERVER_PORT'} == 443) &&
7923: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7924: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7925: if ($hostname ne '') {
7926: $backtourl = 'http://'.$hostname.$backtourl;
7927: }
7928: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7929: }
7930: }
1.623 raeburn 7931: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7932: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7933: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7934: if ($hostname ne '') {
7935: $backtourl = 'http://'.$hostname.$backtourl;
7936: }
7937: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7938: }
1.623 raeburn 7939: }
1.622 raeburn 7940: }
1.609 raeburn 7941: if ($anchor ne '') {
7942: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7943: }
1.590 raeburn 7944: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7945: } else {
7946: $backtourl = '/adm/navmaps';
1.525 raeburn 7947: }
7948: }
7949: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7950: $backtourl = '/adm/menu';
7951: } elsif ($supplementalflag) {
1.682 raeburn 7952: if (($env{'request.role.adv'}) ||
7953: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7954: $backtourl = '/adm/supplemental';
7955: } else {
7956: $backtourl = '/adm/navmaps';
7957: }
1.525 raeburn 7958: } else {
7959: $backtourl = '/adm/navmaps';
1.472 raeburn 7960: }
7961:
1.655 raeburn 7962: my $fieldsets = "'doc'";
1.519 raeburn 7963: unless ($main_container_page) {
7964: $fieldsets .=",'ims'";
7965: }
1.655 raeburn 7966: my $extfieldsets = "'ext'";
7967: if ($posslti) {
7968: $extfieldsets .= ",'tool'";
7969: }
1.501 raeburn 7970: if ($supplementalflag) {
1.655 raeburn 7971: $fieldsets = "'suppdoc'";
7972: $extfieldsets = "'suppext'";
1.600 raeburn 7973: if ($posslti) {
1.655 raeburn 7974: $extfieldsets .= ",'supptool'";
1.600 raeburn 7975: }
1.501 raeburn 7976: }
1.655 raeburn 7977:
1.611 raeburn 7978: my $jsmakefunctions;
7979: if ($canedit) {
7980: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7981: function makenewfolder(targetform,folderseq) {
1.594 damieng 7982: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7983: if (foldername) {
1.676 raeburn 7984: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7985: targetform.submit();
7986: }
7987: }
7988:
7989: function makenewpage(targetform,folderseq) {
1.594 damieng 7990: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7991: if (pagename) {
1.676 raeburn 7992: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7993: targetform.submit();
7994: }
7995: }
7996:
7997: function makeexamupload() {
1.594 damieng 7998: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7999: if (title) {
1.329 droeschl 8000: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8001: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8002: this.document.forms.newexamupload.submit();
8003: }
8004: }
8005:
8006: function makesmppage() {
1.594 damieng 8007: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8008: if (title) {
1.329 droeschl 8009: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8010: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8011: this.document.forms.newsmppg.submit();
8012: }
8013: }
8014:
1.534 raeburn 8015: function makewebpage(type) {
1.594 damieng 8016: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8017: var formname;
8018: if (type == 'supp') {
8019: formname = this.document.forms.supwebpage;
8020: } else {
8021: formname = this.document.forms.newwebpage;
8022: }
8023: if (title) {
8024: var webpage = formname.importdetail.value;
1.675 raeburn 8025: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8026: formname.submit();
8027: }
8028: }
8029:
1.329 droeschl 8030: function makesmpproblem() {
1.594 damieng 8031: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 8032: if (title) {
1.329 droeschl 8033: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 8034: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 8035: this.document.forms.newsmpproblem.submit();
8036: }
8037: }
8038:
8039: function makedropbox() {
1.594 damieng 8040: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 8041: if (title) {
1.329 droeschl 8042: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 8043: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 8044: this.document.forms.newdropbox.submit();
8045: }
8046: }
8047:
8048: function makebulboard() {
1.594 damieng 8049: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 8050: if (title) {
8051: this.document.forms.newbul.importdetail.value=
1.676 raeburn 8052: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 8053: this.document.forms.newbul.submit();
8054: }
8055: }
8056:
8057: function makeabout() {
1.594 damieng 8058: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 8059: if (user) {
8060: var comp=new Array();
8061: comp=user.split(':');
8062: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
8063: if ((comp[0]) && (comp[1])) {
8064: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 8065: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 8066: this.document.forms.newaboutsomeone.submit();
8067: } else {
8068: alert("$js_lt{'p_mab_alrt1'}");
8069: }
8070: } else {
8071: alert("$js_lt{'p_mab_alrt2'}");
8072: }
8073: }
8074: }
8075:
8076: function makenew(targetform) {
8077: targetform.submit();
8078: }
8079:
8080: function changename(folderpath,index,oldtitle) {
8081: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8082: if (title) {
8083: this.document.forms.renameform.markcopy.value='';
8084: this.document.forms.renameform.title.value=title;
8085: this.document.forms.renameform.cmd.value='rename_'+index;
8086: this.document.forms.renameform.folderpath.value=folderpath;
8087: this.document.forms.renameform.submit();
8088: }
8089: }
8090:
1.633 raeburn 8091: function setalias(folderpath,index) {
8092: var alias = prompt('$js_lt{"setal"}');
8093: if ((alias != null) && (alias != '')) {
8094: this.document.forms.aliasform.alias.value=alias;
8095: this.document.forms.aliasform.cmd.value='setalias_'+index;
8096: this.document.forms.aliasform.folderpath.value=folderpath;
8097: this.document.forms.aliasform.submit();
8098: }
8099: }
8100:
8101: function delalias(folderpath,index) {
8102: if (confirm('$js_lt{"delal"}')) {
8103: this.document.forms.aliasform.cmd.value='delalias_'+index;
8104: this.document.forms.aliasform.folderpath.value=folderpath;
8105: this.document.forms.aliasform.submit();
8106: }
8107: }
8108:
1.611 raeburn 8109: ENDNEWSCRIPT
8110: } else {
8111: $jsmakefunctions = <<ENDNEWSCRIPT;
8112:
8113: function makenewfolder() {
8114: alert("$js_lt{'edri'}");
8115: }
8116:
8117: function makenewpage() {
8118: alert("$js_lt{'edri'}");
8119: }
8120:
8121: function makeexamupload() {
8122: alert("$js_lt{'edri'}");
8123: }
8124:
8125: function makesmppage() {
8126: alert("$js_lt{'edri'}");
8127: }
8128:
8129: function makewebpage(type) {
8130: alert("$js_lt{'edri'}");
8131: }
8132:
8133: function makesmpproblem() {
8134: alert("$js_lt{'edri'}");
8135: }
8136:
8137: function makedropbox() {
8138: alert("$js_lt{'edri'}");
8139: }
8140:
8141: function makebulboard() {
8142: alert("$js_lt{'edri'}");
8143: }
8144:
8145: function makeabout() {
8146: alert("$js_lt{'edri'}");
8147: }
8148:
8149: function changename() {
8150: alert("$js_lt{'edri'}");
8151: }
8152:
1.633 raeburn 8153: function setalias() {
8154: alert("$js_lt{'edri'}");
8155: }
8156:
8157: function delalias() {
8158: alert("$js_lt{'edri'}");
8159: }
8160:
1.611 raeburn 8161: function makenew() {
8162: alert("$js_lt{'edri'}");
8163: }
8164:
8165: function groupimport() {
8166: alert("$js_lt{'edri'}");
1.335 ehlerst 8167: }
1.611 raeburn 8168:
8169: function groupsearch() {
8170: alert("$js_lt{'edri'}");
1.335 ehlerst 8171: }
1.611 raeburn 8172:
8173: function groupopen(url,recover) {
8174: var options="scrollbars=1,resizable=1,menubar=0";
8175: idxflag=1;
8176: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
8177: idx.focus();
1.329 droeschl 8178: }
8179:
1.611 raeburn 8180: ENDNEWSCRIPT
8181:
8182: }
8183: return <<ENDSCRIPT;
8184:
8185: $jsmakefunctions
8186:
1.501 raeburn 8187: function toggleUpload(caller) {
8188: var blocks = Array($fieldsets);
8189: for (var i=0; i<blocks.length; i++) {
8190: var disp = 'none';
8191: if (caller == blocks[i]) {
8192: var curr = document.getElementById('upload'+caller+'form').style.display;
8193: if (curr == 'none') {
8194: disp='block';
8195: }
8196: }
8197: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 8198: }
8199: resize_scrollbox('contentscroll','1','1');
8200: return;
8201: }
8202:
8203: function toggleExternal(caller) {
8204: var blocks = Array($extfieldsets);
8205: for (var i=0; i<blocks.length; i++) {
8206: var disp = 'none';
8207: if (caller == blocks[i]) {
8208: var curr = document.getElementById('external'+caller+'form').style.display;
8209: if (curr == 'none') {
8210: disp='block';
8211: }
8212: }
8213: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 8214: if ((caller == 'tool') || (caller == 'supptool')) {
8215: if (disp == 'block') {
1.655 raeburn 8216: if (document.getElementById('LC_exttoolid')) {
8217: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 8218: var suppflag = 0;
8219: if (caller == 'supptool') {
8220: suppflag = 1;
8221: }
8222: currForm = document.getElementById('new'+caller);
1.655 raeburn 8223: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 8224: }
8225: }
8226: }
1.501 raeburn 8227: }
1.502 raeburn 8228: resize_scrollbox('contentscroll','1','1');
8229: return;
8230: }
8231:
1.514 raeburn 8232: function toggleMap(caller) {
1.502 raeburn 8233: var disp = 'none';
1.510 raeburn 8234: if (document.getElementById('importmapform')) {
1.514 raeburn 8235: if (caller == 'map') {
8236: var curr = document.getElementById('importmapform').style.display;
8237: if (curr == 'none') {
8238: disp='block';
8239: }
1.510 raeburn 8240: }
8241: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 8242: if (disp == 'block') {
8243: if (document.getElementById('importcrsresform')) {
8244: if (document.getElementById('importcrsresform').style.display == 'block') {
8245: document.getElementById('importcrsresform').style.display = 'none';
8246: }
8247: }
8248: }
1.510 raeburn 8249: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 8250: }
1.501 raeburn 8251: return;
1.329 droeschl 8252: }
8253:
1.691 raeburn 8254: function toggleCrsRes(caller) {
1.606 raeburn 8255: var disp = 'none';
8256: if (document.getElementById('crsresform')) {
8257: if (caller == 'res') {
1.691 raeburn 8258: var form = document.getElementById('crsresform');
8259: var curr = form.style.display;
1.606 raeburn 8260: if (curr == 'none') {
8261: disp='block';
1.691 raeburn 8262: document.courseresform.authorrole.selectedIndex = 0;
8263: document.courseresform.authorpath.selectedIndex = 0;
8264: document.courseresform.newresourceadd.selectedIndex = 0;
8265: populateDirSelects(form,'authorrole','authorpath',1,0,0);
8266: toggleNewInCourse(document.courseresform);
8267: if (document.getElementById('newresource')) {
8268: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 8269: }
8270: if (document.courseresform.newresusetemp.length) {
8271: document.courseresform.newresusetemp[0].checked = true;
8272: toggleWithTemplate(document.courseresform);
8273: }
8274: document.courseresform.newresourcename.value = '';
8275: }
8276: }
8277: if (document.courseresform.newsubdir.length) {
8278: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
8279: if (document.courseresform.newsubdir[j].value == 0) {
8280: document.courseresform.newsubdir[j].checked = true;
8281: }
8282: break;
8283: }
8284: if (document.getElementById('newsubdirname')) {
8285: document.getElementById('newsubdirname').type = "hidden";
8286: document.getElementById('newsubdirname').value = "";
8287: }
8288: if (document.getElementById('newsubdir')) {
8289: document.getElementById('newsubdir').innerHTML = "";
8290: }
8291: }
8292: document.getElementById('crsresform').style.display=disp;
8293: resize_scrollbox('contentscroll','1','0');
8294: }
8295: return;
8296: }
8297:
8298: function toggleNewsubdir(form) {
8299: if (form.newsubdir.length) {
8300: for (var j=0; j<form.newsubdir.length; j++) {
8301: if (form.newsubdir[j].checked) {
8302: if (document.getElementById('newsubdirname')) {
8303: if (form.newsubdir[j].value == '1') {
8304: document.getElementById('newsubdirname').type = "text";
8305: if (document.getElementById('newsubdir')) {
8306: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
8307: }
8308: } else {
8309: document.getElementById('newsubdirname').type = "hidden";
8310: document.getElementById('newsubdirname').value = "";
8311: document.getElementById('newsubdir').innerHTML = "";
8312: }
8313: }
8314: break;
8315: }
8316: }
8317: }
8318: }
8319:
8320: function toggleCrsResTitle() {
8321: if (document.getElementById('newresource')) {
1.691 raeburn 8322: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8323: if (selloc == 'course') {
1.606 raeburn 8324: document.getElementById('newresource').style.display = 'inline';
8325: document.courseresform.newresourceadd[0].checked = true;
8326: toggleNewInCourse(document.courseresform);
8327: } else {
8328: document.getElementById('newresource').style.display = 'none';
8329: }
1.689 raeburn 8330: }
8331: if (document.getElementById('newstdproblem')) {
8332: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8333: document.getElementById('newstdproblem').style.display = 'none';
8334: if (document.getElementById('stdprobswitch')) {
8335: document.getElementById('stdprobswitch').style.display = 'block';
8336: }
8337: } else {
8338: document.getElementById('newstdproblem').style.display = 'block';
8339: if (document.getElementById('stdprobswitch')) {
8340: document.getElementById('stdprobswitch').style.display = 'none';
8341: }
8342: }
8343: }
1.606 raeburn 8344: }
8345:
8346: function toggleNewInCourse(form) {
8347: if (form.newresourceadd.length) {
8348: for (var i=0; i<form.newresourceadd.length; i++) {
8349: if (form.newresourceadd[i].checked) {
8350: if (document.getElementById('newresourcetitle')) {
8351: if (form.newresourceadd[i].value == '1') {
8352: document.getElementById('newresourcetitle').type = 'text';
8353: if (document.getElementById('newrestitle')) {
8354: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
8355: }
8356: } else {
8357: document.getElementById('newresourcetitle').type = 'hidden';
8358: document.getElementById('newresourcetitle').value = '';
8359: if (document.getElementById('newrestitle')) {
8360: document.getElementById('newrestitle').innerHTML = '';
8361: }
8362: }
8363: }
8364: break;
8365: }
8366: }
8367: }
8368: }
8369:
8370: function toggleWithTemplate(form) {
8371: if (form.newresusetemp.length) {
8372: for (var i=0; i<form.newresusetemp.length; i++) {
8373: if (form.newresusetemp[i].checked) {
8374: if (document.getElementById('newrestemplate')) {
8375: if (form.newresusetemp[i].value == '1') {
8376: document.getElementById('newrestemplate').style.display = 'inline';
8377: toggleExampleText();
8378: } else {
8379: form.tempcategory.selectedIndex = 0;
8380: select1template_changed();
8381: document.getElementById('newrestemplate').style.display = 'none';
8382: }
8383: }
8384: }
8385: }
8386: }
8387: }
8388:
8389: function toggleExampleText() {
8390: if (document.getElementById('newresexample')) {
8391: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8392: if (url == '') {
8393: document.getElementById('newresexample').style.fontWeight = 'normal';
8394: } else {
8395: document.getElementById('newresexample').style.fontWeight = 'bold';
8396: }
8397: }
8398: }
8399:
8400: function getExample(width,height,scrolling,transparency) {
8401: var url;
8402: if (document.courseresform.newresusetemp.length) {
8403: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
8404: if (document.courseresform.newresusetemp[i].checked) {
8405: if (document.courseresform.newresusetemp[i].value == '1') {
8406: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8407: if (url == '') {
8408: alert('Pick a category and template');
8409: } else {
8410: url = url.replace("$londocroot","");
8411: url += '?inhibitmenu=yes';
8412: }
8413: }
8414: break;
8415: }
8416: }
8417: }
8418: if (url != '') {
8419: openMyModal(url,width,height,scrolling,transparency,'');
8420: }
8421: }
8422:
1.690 raeburn 8423: function toggleImportCrsres(caller) {
1.606 raeburn 8424: var disp = 'none';
8425: if (document.getElementById('importcrsresform')) {
8426: if (caller == 'res') {
8427: var curr = document.getElementById('importcrsresform').style.display;
8428: if (curr == 'none') {
8429: disp='block';
1.698 raeburn 8430: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
8431: if ((document.getElementById('importcrsrescontent')) &&
8432: (document.getElementById('importcrsresempty'))) {
8433: var selelem = document.crsresimportform.elements['coursepath'];
8434: var numdirs = 0;
8435: if (selelem.options.length) {
8436: numdirs = selelem.options.length - 1;
8437: }
8438: if (numdirs) {
8439: document.getElementById('importcrsrescontent').style.display='block';
8440: document.getElementById('importcrsresempty').style.display='none';
8441: } else {
8442: document.getElementById('importcrsrescontent').style.display='none';
8443: document.getElementById('importcrsresempty').style.display='block';
8444: }
8445: }
1.606 raeburn 8446: }
8447: }
8448: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 8449: if (disp == 'block') {
8450: if (document.getElementById('importmapform')) {
8451: if (document.getElementById('importmapform').style.display == 'block') {
8452: document.getElementById('importmapform').style.display = 'none';
8453: }
8454: }
8455: }
1.606 raeburn 8456: resize_scrollbox('contentscroll','1','0');
8457: }
8458: return;
8459: }
8460:
1.690 raeburn 8461: $showfile_js
8462:
1.691 raeburn 8463: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8464: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8465: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8466: var selelem = form.elements[dirsel];
8467: var i, numfiles = selelem.options.length -1;
8468: if (numfiles >=0) {
8469: for (i = numfiles; i >= 0; i--) {
8470: selelem.remove(i);
8471: }
8472: }
8473: if ((location == '') || (location == null) || (location == 'undefined')) {
8474: if (selelem.options.length == 0) {
8475: selelem.options[selelem.options.length] = new Option('','');
8476: selelem.selectedIndex = 0;
8477: }
8478: if (document.getElementById('newstdproblem')) {
8479: document.getElementById('newstdproblem').style.display = 'none';
8480: }
8481: return;
8482: }
8483: var machineIds = new Array($machines_str);
8484: var athome = 0;
8485: var role = location;
8486: if ((location == 'author') || (location == 'course')) {
8487: if (document.getElementById('rolehome_'+location)) {
8488: var currhome = document.getElementById('rolehome_'+location).value;
8489: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8490: if (machineIds.includes(currhome)) {
8491: athome = 1;
8492: }
8493: }
8494: }
8495: } else {
8496: const roleinfo = location.split('___');
8497: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8498: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8499: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8500: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8501: if (machineIds.includes(currhome)) {
8502: athome = 1;
8503: }
8504: }
8505: }
8506: }
1.706 raeburn 8507: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 8508: if (athome) {
8509: if (document.getElementById('stdprobswitch')) {
8510: document.getElementById('stdprobswitch').style.display = 'none';
8511: }
8512: if (document.getElementById('newstdproblem')) {
8513: document.getElementById('newstdproblem').style.display = 'none';
8514: }
1.706 raeburn 8515: var canedit = '$canedit';
8516: if (canedit) {
8517: if (templateradio.length > 1) {
8518: for (var i=0; i<templateradio.length; i++) {
8519: templateradio[i].disabled = false;
8520: }
8521: }
8522: document.courseresform.newresourcename.disabled = false;
8523: document.courseresform.newcrs.disabled = false;
8524: }
1.691 raeburn 8525: var http = new XMLHttpRequest();
8526: var url = "/adm/courseauthor";
1.698 raeburn 8527: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8528: http.open("POST", url, true);
8529: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8530: http.onreadystatechange = function() {
8531: if (http.readyState == 4 && http.status == 200) {
8532: var data = JSON.parse(http.responseText);
8533: if (Array.isArray(data.dirs)) {
8534: var len = data.dirs.length;
8535: if (len) {
8536: if (len > 1) {
8537: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8538: }
8539: }
8540: if (len) {
8541: var j;
8542: for (j = 0; j < len; j++) {
8543: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8544: }
8545: selelem.selectedIndex = 0;
1.697 raeburn 8546: if (len == 1) {
8547: toggleCrsResTitle();
8548: }
1.691 raeburn 8549: }
8550: }
8551: }
8552: }
8553: http.send(params);
8554: } else {
8555: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8556: selelem.selectedIndex = 0;
8557: if (document.getElementById('stdprobswitch')) {
8558: document.getElementById('stdprobswitch').style.display = 'block';
8559: }
8560: if (document.getElementById('newstdproblem')) {
8561: document.getElementById('newstdproblem').style.display = 'none';
8562: }
1.706 raeburn 8563: if (templateradio.length > 1) {
8564: for (var i=0; i<templateradio.length; i++) {
8565: templateradio[i].disabled = true;
8566: }
8567: }
8568: document.courseresform.newresourcename.disabled = true;
8569: document.courseresform.newcrs.disabled = true;
1.691 raeburn 8570: }
8571: }
8572: return;
8573: }
8574:
1.689 raeburn 8575: function switchForProb() {
8576: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8577: var url = '/adm/switchserver?otherserver=';
8578: var newhostid = '';
8579: var role = '';
8580: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8581: if (selloc == 'author') {
8582: newhostid = document.courseresform.rolehome_author.value;
8583: role = "au./&js_escape($env{'user.domain'})/";
8584: } else if (selloc == 'course') {
8585: newhostid = document.courseresform.rolehome_course.value;
8586: role = "&js_escape($env{'request.role'})";
8587: } else {
8588: var items = new Array();
8589: items = selloc.split('___');
8590: var len = document.courseresform.rolehome_coauthor.length;
8591: if (null == len) {
8592: var currval = document.courseresform.rolehome_coauthor.value;
8593: if (null != currval) {
8594: var info = new Array();
8595: info = currval.split('=');
8596: newhostid = info[2];
8597: role = info[0]+'./'+info[1];
8598: }
8599: } else {
8600: for (var i=0; i<len; i++) {
8601: var currval = document.courseresform.rolehome_coauthor[i].value;
8602: if (null != currval) {
8603: var info = new Array();
8604: info = currval.split('=');
8605: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8606: newhostid = info[2];
8607: role = info[0]+'./'+info[1];
8608: break;
8609: }
8610: }
8611: }
8612: }
8613: }
8614: if (newhostid != '') {
8615: url += newhostid;
8616: if (role != '') {
8617: url += '&role='+role;
8618: }
8619: document.location.href = url;
8620: }
8621: }
8622: return;
8623: }
8624:
1.501 raeburn 8625: function makeims(imsform) {
8626: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8627: alert("$js_lt{'imsfile'}");
1.501 raeburn 8628: return;
8629: }
8630: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8631: alert("$js_lt{'imscms'}");
1.501 raeburn 8632: return;
8633: }
8634: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8635: imsform.submit();
8636: }
8637:
1.478 raeburn 8638: function updatePick(targetform,index,caller) {
1.537 raeburn 8639: var pickitem;
8640: var picknumitem;
8641: var picknumtext;
8642: if (index == 'all') {
8643: pickitem = document.getElementById('randompickall');
8644: picknumitem = document.getElementById('rpicknumall');
8645: picknumtext = document.getElementById('rpicktextall');
8646: } else {
8647: pickitem = document.getElementById('randompick_'+index);
8648: picknumitem = document.getElementById('rpicknum_'+index);
8649: picknumtext = document.getElementById('randompicknum_'+index);
8650: }
1.478 raeburn 8651: if (pickitem.checked) {
1.594 damieng 8652: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8653: if (picknum == '' || picknum == null) {
8654: if (caller == 'check') {
8655: pickitem.checked=false;
1.537 raeburn 8656: if (index == 'all') {
8657: picknumtext.innerHTML = '';
8658: if (caller == 'link') {
8659: propagateState(targetform,'rpicknum');
8660: }
8661: } else {
1.538 raeburn 8662: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8663: }
1.478 raeburn 8664: }
8665: } else {
8666: picknum.toString();
8667: var regexdigit=/^\\d+\$/;
8668: if (regexdigit.test(picknum)) {
8669: picknumitem.value = picknum;
1.537 raeburn 8670: if (index == 'all') {
1.538 raeburn 8671: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8672: if (caller == 'link') {
8673: propagateState(targetform,'rpicknum');
8674: }
8675: } else {
8676: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8677: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8678: }
1.478 raeburn 8679: } else {
8680: if (caller == 'check') {
1.537 raeburn 8681: if (index == 'all') {
8682: picknumtext.innerHTML = '';
8683: if (caller == 'link') {
8684: propagateState(targetform,'rpicknum');
8685: }
8686: } else {
8687: pickitem.checked=false;
1.538 raeburn 8688: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8689: }
1.478 raeburn 8690: }
8691: return;
8692: }
8693: }
8694: } else {
1.537 raeburn 8695: picknumitem.value = '';
8696: picknumtext.innerHTML = '';
8697: if (index == 'all') {
8698: if (caller == 'link') {
8699: propagateState(targetform,'rpicknum');
8700: }
8701: } else {
1.538 raeburn 8702: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8703: }
8704: }
8705: }
8706:
8707: function propagateState(form,param) {
8708: if (document.getElementById(param+'all')) {
8709: var setcheck = 0;
8710: var rpick = 0;
8711: if (param == 'rpicknum') {
8712: if (document.getElementById('randompickall')) {
8713: if (document.getElementById('randompickall').checked) {
8714: if (document.getElementById('rpicknumall')) {
8715: rpick = document.getElementById('rpicknumall').value;
8716: }
8717: }
8718: }
8719: } else {
8720: if (document.getElementById(param+'all').checked) {
8721: setcheck = 1;
8722: }
8723: }
1.538 raeburn 8724: var allidxlist;
8725: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8726: if (document.getElementById('all'+param+'idx')) {
8727: allidxlist = document.getElementById('all'+param+'idx').value;
8728: }
8729: var actions = new Array ('remove','cut','copy');
8730: for (var i=0; i<actions.length; i++) {
8731: if (actions[i] != param) {
8732: if (document.getElementById(actions[i]+'all')) {
8733: document.getElementById(actions[i]+'all').checked = false;
8734: }
8735: }
8736: }
8737: }
1.537 raeburn 8738: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8739: allidxlist = form.allidx.value;
8740: }
8741: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8742: allidxlist = form.allmapidx.value;
8743: }
8744: if ((allidxlist != '') && (allidxlist != null)) {
8745: var allidxs = allidxlist.split(',');
8746: if (allidxs.length > 1) {
8747: for (var i=0; i<allidxs.length; i++) {
8748: if (document.getElementById(param+'_'+allidxs[i])) {
8749: if (param == 'rpicknum') {
8750: if (document.getElementById('randompick_'+allidxs[i])) {
8751: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8752: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8753: if (rpick > 0) {
8754: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8755: } else {
8756: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8757: }
8758: }
8759: }
8760: } else {
1.537 raeburn 8761: if (setcheck == 1) {
8762: document.getElementById(param+'_'+allidxs[i]).checked = true;
8763: } else {
8764: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8765: if (param == 'randompick') {
8766: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8767: }
1.537 raeburn 8768: }
8769: }
8770: }
8771: }
1.538 raeburn 8772: if (setcheck == 1) {
8773: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8774: var actions = new Array('copy','cut','remove');
8775: for (var i=0; i<actions.length; i++) {
8776: var otheractions;
8777: var otheridxs;
8778: if (actions[i] === param) {
8779: continue;
8780: } else {
8781: if (document.getElementById('all'+actions[i]+'idx')) {
8782: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8783: otheridxs = otheractions.split(',');
8784: if (otheridxs.length > 1) {
8785: for (var j=0; j<otheridxs.length; j++) {
8786: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8787: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8788: }
1.537 raeburn 8789: }
8790: }
8791: }
1.538 raeburn 8792: }
8793: }
8794: }
8795: }
8796: }
8797: }
8798: }
8799: return;
8800: }
8801:
1.603 raeburn 8802: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8803: var canedit = '$canedit';
8804: if (canedit == '') {
8805: alert("$js_lt{'edri'}");
8806: return;
8807: }
1.539 raeburn 8808: var dosettings;
8809: var doaction;
1.538 raeburn 8810: var control = document.togglemultsettings;
8811: if (context == 'actions') {
8812: control = document.togglemultactions;
1.539 raeburn 8813: doaction = 1;
8814: } else {
8815: dosettings = 1;
1.538 raeburn 8816: }
1.539 raeburn 8817: if (control) {
8818: if (control.showmultpick.length) {
8819: for (var i=0; i<control.showmultpick.length; i++) {
8820: if (control.showmultpick[i].checked) {
8821: if (control.showmultpick[i].value == 1) {
8822: if (context == 'settings') {
8823: dosettings = 0;
8824: } else {
8825: doaction = 0;
1.538 raeburn 8826: }
8827: }
8828: }
1.537 raeburn 8829: }
8830: }
1.539 raeburn 8831: }
8832: if (context == 'settings') {
8833: if (dosettings == 1) {
1.538 raeburn 8834: targetform.changeparms.value=param;
8835: targetform.submit();
8836: }
1.537 raeburn 8837: }
1.539 raeburn 8838: if (context == 'actions') {
8839: if (doaction == 1) {
8840: targetform.cmd.value=param+'_'+index;
8841: targetform.folderpath.value=folderpath;
8842: targetform.markcopy.value=idx+':'+param;
8843: targetform.copyfolder.value=folder+'.'+container;
8844: if (param == 'remove') {
1.603 raeburn 8845: var doremove = 0;
8846: if (skip_confirm) {
8847: if (confirm_removal) {
8848: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8849: doremove = 1;
8850: }
8851: } else {
8852: doremove = 1;
8853: }
8854: } else {
8855: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8856: doremove = 1;
8857: }
8858: }
8859: if (doremove) {
1.539 raeburn 8860: targetform.markcopy.value='';
8861: targetform.copyfolder.value='';
8862: targetform.submit();
8863: }
8864: }
8865: if (param == 'cut') {
1.594 damieng 8866: 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 8867: targetform.submit();
8868: return;
8869: }
8870: }
8871: if (param == 'copy') {
8872: targetform.submit();
8873: return;
8874: }
8875: targetform.markcopy.value='';
8876: targetform.copyfolder.value='';
8877: targetform.cmd.value='';
8878: targetform.folderpath.value='';
8879: return;
8880: } else {
8881: if (document.getElementById(param+'_'+idx)) {
8882: item = document.getElementById(param+'_'+idx);
8883: if (item.type == 'checkbox') {
8884: if (item.checked) {
8885: item.checked = false;
8886: } else {
8887: item.checked = true;
8888: singleCheck(item,idx,param);
8889: }
8890: }
8891: }
8892: }
8893: }
1.537 raeburn 8894: return;
8895: }
8896:
1.538 raeburn 8897: function singleCheck(caller,idx,action) {
8898: actions = new Array('cut','copy','remove');
8899: if (caller.checked) {
8900: for (var i=0; i<actions.length; i++) {
8901: if (actions[i] != action) {
8902: if (document.getElementById(actions[i]+'_'+idx)) {
8903: if (document.getElementById(actions[i]+'_'+idx).checked) {
8904: document.getElementById(actions[i]+'_'+idx).checked = false;
8905: }
1.537 raeburn 8906: }
8907: }
8908: }
1.478 raeburn 8909: }
1.537 raeburn 8910: return;
1.478 raeburn 8911: }
8912:
1.334 muellerd 8913: function unselectInactive(nav) {
1.335 ehlerst 8914: currentNav = document.getElementById(nav);
8915: currentLis = currentNav.getElementsByTagName('LI');
8916: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8917: if (currentLis[i].className == 'goback') {
8918: currentLis[i].className = 'goback';
8919: } else {
8920: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8921: currentLis[i].className = 'right';
1.472 raeburn 8922: } else {
1.374 tempelho 8923: currentLis[i].className = 'i';
1.472 raeburn 8924: }
8925: }
1.335 ehlerst 8926: }
1.332 tempelho 8927: }
8928:
1.334 muellerd 8929: function hideAll(current, nav, data) {
1.335 ehlerst 8930: unselectInactive(nav);
1.570 raeburn 8931: if (current) {
8932: if (current.className == 'right'){
8933: current.className = 'right active'
8934: } else {
8935: current.className = 'active';
8936: }
1.374 tempelho 8937: }
1.335 ehlerst 8938: currentData = document.getElementById(data);
8939: currentDivs = currentData.getElementsByTagName('DIV');
8940: for (i = 0; i < currentDivs.length; i++) {
8941: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8942: currentDivs[i].style.display = 'none';
1.330 tempelho 8943: }
8944: }
1.335 ehlerst 8945: }
1.330 tempelho 8946:
1.374 tempelho 8947: function openTabs(pageId) {
8948: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8949: if(tabnav.length > 2 ){
1.389 tempelho 8950: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8951: currentLis = currentNav.getElementsByTagName('LI');
8952: for(i = 0; i< currentLis.length; i++){
8953: if(currentLis[i].className == 'active') {
1.375 tempelho 8954: funcString = currentLis[i].onclick.toString();
8955: tab = funcString.split('"');
1.420 onken 8956: if(tab.length < 2) {
8957: tab = funcString.split("'");
8958: }
1.375 tempelho 8959: currentData = document.getElementById(tab[1]);
8960: currentData.style.display = 'block';
1.374 tempelho 8961: }
8962: }
8963: }
8964: }
8965:
1.334 muellerd 8966: function showPage(current, pageId, nav, data) {
1.570 raeburn 8967: currstate = current.className;
1.334 muellerd 8968: hideAll(current, nav, data);
1.375 tempelho 8969: openTabs(pageId);
1.334 muellerd 8970: unselectInactive(nav);
1.570 raeburn 8971: if ((currstate == 'active') || (currstate == 'right active')) {
8972: if (currstate == 'active') {
8973: current.className = '';
8974: } else {
8975: current.className = 'right';
8976: }
8977: activeTab = '';
1.656 raeburn 8978: toggleExternal();
1.570 raeburn 8979: toggleUpload();
8980: toggleMap();
1.606 raeburn 8981: toggleCrsRes();
8982: toggleImportCrsres();
1.570 raeburn 8983: resize_scrollbox('contentscroll','1','0');
8984: return;
8985: } else {
8986: current.className = 'active';
8987: }
1.330 tempelho 8988: currentData = document.getElementById(pageId);
8989: currentData.style.display = 'block';
1.458 raeburn 8990: activeTab = pageId;
1.656 raeburn 8991: toggleExternal();
1.501 raeburn 8992: toggleUpload();
1.503 raeburn 8993: toggleMap();
1.606 raeburn 8994: toggleCrsRes();
8995: toggleImportCrsres();
1.433 raeburn 8996: if (nav == 'mainnav') {
8997: var storedpath = "$docs_folderpath";
1.434 raeburn 8998: var storedpage = "$main_container_page";
1.433 raeburn 8999: var reg = new RegExp("^supplemental");
9000: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9001: if (storedpage == 1) {
9002: document.simpleedit.folderpath.value = '';
9003: document.uploaddocument.folderpath.value = '';
9004: } else {
9005: if (reg.test(storedpath)) {
9006: document.simpleedit.folderpath.value = '$toplevelmain';
9007: document.uploaddocument.folderpath.value = '$toplevelmain';
9008: document.newext.folderpath.value = '$toplevelmain';
9009: } else {
9010: document.simpleedit.folderpath.value = storedpath;
9011: document.uploaddocument.folderpath.value = storedpath;
9012: document.newext.folderpath.value = storedpath;
9013: }
1.433 raeburn 9014: }
9015: } else {
1.434 raeburn 9016: if (reg.test(storedpath)) {
9017: document.simpleedit.folderpath.value = storedpath;
9018: document.supuploaddocument.folderpath.value = storedpath;
9019: document.supnewext.folderpath.value = storedpath;
9020: } else {
1.433 raeburn 9021: document.simpleedit.folderpath.value = '$toplevelsupp';
9022: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9023: document.supnewext.folderpath.value = '$toplevelsupp';
9024: }
9025: }
9026: }
1.485 raeburn 9027: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9028: return false;
9029: }
1.329 droeschl 9030:
1.472 raeburn 9031: function toContents(jumpto) {
9032: var newurl = '$backtourl';
1.525 raeburn 9033: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 9034: newurl = newurl+'?postdata='+jumpto;
9035: }
9036: location.href=newurl;
9037: }
9038:
1.538 raeburn 9039: function togglePick(caller,value) {
9040: var disp = 'none';
9041: if (document.getElementById('multi'+caller)) {
9042: var curr = document.getElementById('multi'+caller).style.display;
9043: if (value == 1) {
9044: disp='block';
9045: }
9046: if (curr == disp) {
9047: return;
9048: }
9049: document.getElementById('multi'+caller).style.display=disp;
9050: if (value == 1) {
1.594 damieng 9051: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9052: } else {
9053: document.getElementById('more'+caller).innerHTML = '';
9054: }
9055: if (caller == 'actions') {
9056: setClass(value);
9057: setBoxes(value);
9058: }
9059: }
9060: var showButton = multiSettings();
9061: if (showButton != 1) {
9062: showButton = multiActions();
9063: }
9064: if (document.getElementById('multisave')) {
9065: if (showButton == 1) {
9066: document.getElementById('multisave').style.display='block';
9067: } else {
9068: document.getElementById('multisave').style.display='none';
9069: }
9070: }
9071: resize_scrollbox('contentscroll','1','1');
9072: return;
9073: }
9074:
9075: function toggleCheckUncheck(caller,more) {
9076: if (more == 1) {
1.594 damieng 9077: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 9078: document.getElementById('allfields'+caller).style.display='block';
9079: } else {
1.594 damieng 9080: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9081: document.getElementById('allfields'+caller).style.display='none';
9082: }
9083: resize_scrollbox('contentscroll','1','1');
9084: }
9085:
9086: function multiSettings() {
9087: var inuse = 0;
9088: var settingsform = document.togglemultsettings;
9089: if (settingsform.showmultpick.length > 1) {
9090: for (var i=0; i<settingsform.showmultpick.length; i++) {
9091: if (settingsform.showmultpick[i].checked) {
9092: if (settingsform.showmultpick[i].value == 1) {
9093: inuse = 1;
9094: }
9095: }
9096: }
9097: }
9098: return inuse;
9099: }
9100:
9101: function multiActions() {
9102: var inuse = 0;
9103: var actionsform = document.togglemultactions;
9104: if (actionsform.showmultpick.length > 1) {
9105: for (var i=0; i<actionsform.showmultpick.length; i++) {
9106: if (actionsform.showmultpick[i].checked) {
9107: if (actionsform.showmultpick[i].value == 1) {
9108: inuse = 1;
9109: }
9110: }
9111: }
9112: }
9113: return inuse;
9114: }
9115:
9116: function checkSubmits() {
9117: var numchanges = 0;
9118: var form = document.saveactions;
9119: var doactions = multiActions();
1.542 raeburn 9120: var cutwarnings = 0;
9121: var remwarnings = 0;
1.603 raeburn 9122: var removalinfo = 0;
1.538 raeburn 9123: if (doactions == 1) {
9124: var remidxlist = document.cumulativeactions.allremoveidx.value;
9125: if ((remidxlist != '') && (remidxlist != null)) {
9126: var remidxs = remidxlist.split(',');
9127: for (var i=0; i<remidxs.length; i++) {
9128: if (document.getElementById('remove_'+remidxs[i])) {
9129: if (document.getElementById('remove_'+remidxs[i]).checked) {
9130: form.multiremove.value += remidxs[i]+',';
9131: numchanges ++;
1.542 raeburn 9132: if (document.getElementById('skip_remove_'+remidxs[i])) {
9133: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9134: remwarnings ++;
9135: }
9136: }
1.603 raeburn 9137: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9138: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9139: removalinfo ++;
9140: }
9141: }
1.537 raeburn 9142: }
9143: }
1.538 raeburn 9144: }
9145: }
9146: var cutidxlist = document.cumulativeactions.allcutidx.value;
9147: if ((cutidxlist != '') && (cutidxlist != null)) {
9148: var cutidxs = cutidxlist.split(',');
9149: for (var i=0; i<cutidxs.length; i++) {
9150: if (document.getElementById('cut_'+cutidxs[i])) {
9151: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9152: form.multicut.value += cutidxs[i]+',';
9153: numchanges ++;
1.542 raeburn 9154: if (document.getElementById('skip_cut_'+cutidxs[i])) {
9155: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
9156: cutwarnings ++;
9157: }
9158: }
1.537 raeburn 9159: }
9160: }
9161: }
9162: }
1.538 raeburn 9163: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9164: if ((copyidxlist != '') && (copyidxlist != null)) {
9165: var copyidxs = copyidxlist.split(',');
9166: for (var i=0; i<copyidxs.length; i++) {
9167: if (document.getElementById('copy_'+copyidxs[i])) {
9168: if (document.getElementById('copy_'+copyidxs[i]).checked) {
9169: form.multicopy.value += copyidxs[i]+',';
9170: numchanges ++;
9171: }
9172: }
9173: }
9174: }
9175: if (numchanges > 0) {
9176: form.multichange.value = numchanges;
9177: }
1.537 raeburn 9178: }
1.538 raeburn 9179: var dosettings = multiSettings();
1.543 raeburn 9180: var haschanges = 0;
1.538 raeburn 9181: if (dosettings == 1) {
9182: form.allencrypturl.value = '';
9183: form.allhiddenresource.value = '';
1.543 raeburn 9184: form.changeparms.value = 'all';
9185: var patt=new RegExp(",\$");
1.538 raeburn 9186: var allidxlist = document.cumulativesettings.allidx.value;
9187: if ((allidxlist != '') && (allidxlist != null)) {
9188: var allidxs = allidxlist.split(',');
9189: if (allidxs.length > 1) {
9190: for (var i=0; i<allidxs.length; i++) {
9191: if (document.getElementById('hiddenresource_'+allidxs[i])) {
9192: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
9193: form.allhiddenresource.value += allidxs[i]+',';
9194: }
9195: }
9196: if (document.getElementById('encrypturl_'+allidxs[i])) {
9197: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
9198: form.allencrypturl.value += allidxs[i]+',';
9199: }
9200: }
9201: }
1.543 raeburn 9202: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
9203: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 9204: }
1.538 raeburn 9205: }
9206: form.allrandompick.value = '';
9207: form.allrandomorder.value = '';
9208: var allmapidxlist = document.cumulativesettings.allmapidx.value;
9209: if ((allmapidxlist != '') && (allmapidxlist != null)) {
9210: var allmapidxs = allmapidxlist.split(',');
9211: for (var i=0; i<allmapidxs.length; i++) {
9212: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
9213: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
9214: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
9215: if ((randompick.checked) && (rpicknum.value != '')) {
9216: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
9217: }
9218: if (randorder.checked) {
9219: form.allrandomorder.value += allmapidxs[i]+',';
9220: }
1.537 raeburn 9221: }
1.543 raeburn 9222: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
9223: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
9224: }
9225: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
9226: haschanges = 1;
9227: }
9228: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
9229: haschanges = 1;
9230: }
9231: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
9232: haschanges = 1;
9233: }
9234: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
9235: haschanges = 1;
1.537 raeburn 9236: }
9237: }
1.543 raeburn 9238: if (doactions == 1) {
1.542 raeburn 9239: if (numchanges > 0) {
1.603 raeburn 9240: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 9241: if (remwarnings > 0) {
1.594 damieng 9242: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 9243: return false;
9244: }
9245: }
1.603 raeburn 9246: if (removalinfo > 0) {
9247: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
9248: return false;
9249: }
9250: }
1.542 raeburn 9251: if (cutwarnings > 0) {
1.594 damieng 9252: 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 9253: return false;
9254: }
9255: }
9256: }
9257: form.submit();
9258: return true;
1.543 raeburn 9259: }
9260: }
9261: if (dosettings == 1) {
9262: if (haschanges == 1) {
1.542 raeburn 9263: form.submit();
9264: return true;
9265: }
1.543 raeburn 9266: }
9267: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 9268: alert("$js_lt{'noor'}");
1.543 raeburn 9269: } else {
9270: if (dosettings == 1) {
1.594 damieng 9271: alert("$js_lt{'noch'}");
1.543 raeburn 9272: } else {
1.594 damieng 9273: alert("$js_lt{'noac'}");
1.543 raeburn 9274: }
9275: }
1.538 raeburn 9276: return false;
9277: }
9278:
9279: function setClass(value) {
9280: var cutclass = 'LC_docs_cut';
9281: var copyclass = 'LC_docs_copy';
9282: var removeclass = 'LC_docs_remove';
9283: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
9284: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
9285: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
9286: var links = document.getElementsByTagName('a');
9287: for (var i=0; i<links.length; i++) {
9288: var classes = links[i].className;
9289: if (cutreg.test(classes)) {
9290: links[i].className = cutclass;
9291: if (value == 1) {
9292: links[i].className += " LC_menubuttons_link";
9293: }
9294: } else {
9295: if (copyreg.test(classes)) {
9296: links[i].className = copyclass;
9297: if (value == 1) {
9298: links[i].className += " LC_menubuttons_link";
9299: }
9300: } else {
9301: if (removereg.test(classes)) {
9302: links[i].className = removeclass;
9303: if (value == 1) {
9304: links[i].className += " LC_menubuttons_link";
9305: }
9306: }
9307: }
9308: }
9309: }
9310: return;
1.537 raeburn 9311: }
9312:
1.538 raeburn 9313: function setBoxes(value) {
9314: var remidxlist = document.cumulativeactions.allremoveidx.value;
9315: if ((remidxlist != '') && (remidxlist != null)) {
9316: var remidxs = remidxlist.split(',');
9317: for (var i=0; i<remidxs.length; i++) {
9318: if (document.getElementById('remove_'+remidxs[i])) {
9319: var item = document.getElementById('remove_'+remidxs[i]);
9320: if (value == 1) {
9321: item.className = 'LC_docs_remove';
9322: } else {
9323: item.className = 'LC_hidden';
9324: }
9325: }
9326: }
9327: }
9328: var cutidxlist = document.cumulativeactions.allcutidx.value;
9329: if ((cutidxlist != '') && (cutidxlist != null)) {
9330: var cutidxs = cutidxlist.split(',');
9331: for (var i=0; i<cutidxs.length; i++) {
9332: if (document.getElementById('cut_'+cutidxs[i])) {
9333: var item = document.getElementById('cut_'+cutidxs[i]);
9334: if (value == 1) {
9335: item.className = 'LC_docs_cut';
9336: } else {
9337: item.className = 'LC_hidden';
9338: }
9339: }
1.537 raeburn 9340: }
9341: }
1.538 raeburn 9342: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9343: if ((copyidxlist != '') && (copyidxlist != null)) {
9344: var copyidxs = copyidxlist.split(',');
9345: for (var i=0; i<copyidxs.length; i++) {
9346: if (document.getElementById('copy_'+copyidxs[i])) {
9347: var item = document.getElementById('copy_'+copyidxs[i]);
9348: if (value == 1) {
9349: item.className = 'LC_docs_copy';
9350: } else {
9351: item.className = 'LC_hidden';
9352: }
9353: }
1.537 raeburn 9354: }
9355: }
9356: return;
9357: }
9358:
1.606 raeburn 9359: function validImportCrsRes() {
9360: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
9361: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
9362: if ((fname == '') || (fname == null)) {
9363: alert("$js_lt{'nofi'}");
9364: return false;
9365: }
9366: var url = '/res/$coursedom/$coursenum/';
9367: if (path && path != '/') {
9368: url += path+'/';
9369: }
9370: if (fname != '') {
9371: url += fname;
9372: }
9373: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 9374: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 9375: return true;
9376: }
9377:
9378: function validateNewRes(caller) {
9379: if (caller == 'single') {
9380: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9381: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
9382: var resname = document.courseresform.newresourcename.value;
9383: }
9384: }
9385:
1.611 raeburn 9386: ENDSCRIPT
1.329 droeschl 9387: }
1.457 raeburn 9388:
1.483 raeburn 9389: sub history_tab_js {
9390: return <<"ENDHIST";
9391: function toggleHistoryDisp(choice) {
9392: document.docslogform.docslog.value = choice;
9393: document.docslogform.submit();
9394: return;
9395: }
9396:
9397: ENDHIST
9398: }
9399:
1.484 raeburn 9400: sub inject_data_js {
9401: return <<ENDINJECT;
9402:
9403: function injectData(current, hiddenField, name, value) {
9404: currentElement = document.getElementById(hiddenField);
9405: currentElement.name = name;
9406: currentElement.value = value;
9407: current.submit();
9408: }
9409:
9410: ENDINJECT
9411: }
9412:
9413: sub dump_switchserver_js {
9414: my @hosts = @_;
1.594 damieng 9415: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 9416: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 9417: swit => 'Switch server?',
1.594 damieng 9418: );
9419: my %html_js_lt = &Apache::lonlocal::texthash(
9420: swit => 'Switch server?',
1.709 raeburn 9421: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 9422: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
9423: chos => 'Choose server',
9424: );
1.594 damieng 9425: &js_escape(\%js_lt);
9426: &html_escape(\%html_js_lt);
9427: &js_escape(\%html_js_lt);
1.484 raeburn 9428: my $role = $env{'request.role'};
9429: my $js = <<"ENDSWJS";
9430: <script type="text/javascript">
9431: function write_switchserver() {
9432: var server;
9433: if (document.setserver.posshosts.length > 0) {
9434: for (var i=0; i<document.setserver.posshosts.length; i++) {
9435: if (document.setserver.posshosts[i].checked) {
9436: server = document.setserver.posshosts[i].value;
9437: }
9438: }
9439: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
9440: }
9441: window.close();
9442: }
9443: </script>
9444:
9445: ENDSWJS
9446:
9447: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
9448: {'only_body' => 1,
9449: 'js_ready' => 1,});
9450: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
9451:
9452: my $hostpicker;
9453: my $count = 0;
9454: foreach my $host (sort(@hosts)) {
9455: my $checked;
9456: if ($count == 0) {
9457: $checked = ' checked="checked"';
9458: }
9459: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9460: $host.'"'.$checked.' />'.$host.'</label> ';
9461: $count++;
9462: }
9463:
9464: return <<"ENDSWITCHJS";
9465:
9466: function dump_needs_switchserver(url) {
9467: if (url!='' && url!= null) {
1.594 damieng 9468: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 9469: go(url);
9470: }
9471: }
9472: return;
9473: }
9474:
9475: function choose_switchserver_window() {
9476: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9477: newWindow.document.open();
9478: newWindow.document.writeln('$startpage');
1.594 damieng 9479: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9480: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9481: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9482: '<form name="setserver" method="post" action="" \\/>\\n'+
9483: '$hostpicker\\n'+
9484: '<br \\/><br \\/>\\n'+
1.594 damieng 9485: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9486: 'onclick="write_switchserver();" \\/>\\n'+
9487: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9488: newWindow.document.writeln('$endpage');
9489: newWindow.document.close();
9490: newWindow.focus();
9491: }
9492:
9493: ENDSWITCHJS
9494: }
9495:
9496: sub makedocslogform {
9497: my ($formelems,$docslog) = @_;
9498: return <<"LOGSFORM";
9499: <form action="/adm/coursedocs" method="post" name="docslogform">
9500: <input type="hidden" name="docslog" value="$docslog" />
9501: $formelems
9502: </form>
9503: LOGSFORM
9504: }
9505:
9506: sub makesimpleeditform {
9507: my ($formelems) = @_;
9508: return <<"SIMPFORM";
9509: <form name="simpleedit" method="post" action="/adm/coursedocs">
9510: <input type="hidden" name="importdetail" value="" />
9511: $formelems
9512: </form>
9513: SIMPFORM
9514: }
9515:
1.606 raeburn 9516: sub makenewproblem {
9517: my ($r,$coursedom,$coursenum) = @_;
9518: # Creating a new problem
9519: my ($redirect,$error);
9520: if ($env{'form.authorrole'}) {
9521: my ($newsubdir,$filename);
9522: if ($env{'form.newsubdir'}) {
9523: if ($env{'form.newsubdirname'} ne '') {
9524: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9525: }
1.606 raeburn 9526: }
9527: if ($env{'form.newresourcename'}) {
9528: $filename = $env{'form.newresourcename'};
9529: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9530: $filename =~ s/`//g;
9531: $filename =~ s{/\.\./}{_}g;
9532: $filename =~ s/\.+/./g;
9533: $filename =~ s{/+}{_}g;
9534: if ($filename ne '') {
9535: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9536: if (($ext) && ($ext ne '.problem')) {
9537: $filename = $name.'.problem';
9538: } elsif ($ext eq '') {
9539: $filename .= '.problem';
9540: }
9541: my $docroot = $r->dir_config('lonDocRoot');
9542: my @ids=&Apache::lonnet::current_machine_ids();
9543: if ($env{'form.authorrole'} eq 'author') {
9544: if ($env{'user.author'}) {
9545: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9546: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9547: my $path = $docroot.$url;
9548: my $subdir = $env{'form.authorpath'};
9549: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9550: }
9551: }
9552: } elsif ($env{'form.authorrole'} eq 'course') {
9553: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9554: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9555: my $url = "/priv/$coursedom/$coursenum";
9556: my $path=$docroot.$url;
9557: my $subdir = $env{'form.authorpath'};
9558: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9559: if ($redirect) {
9560: my $rightsfile = 'default.rights';
9561: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 9562: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 9563: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 9564: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9565: if (!-e "$docroot/res/$coursedom") {
9566: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9567: }
1.654 raeburn 9568: if (!-e "$docroot/res/$coursedom/$coursenum") {
9569: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9570: }
9571: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9572: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9573: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9574: }
9575: }
1.654 raeburn 9576: my $source = $docroot.$redirect;
9577: if (!-e "$source.meta") {
9578: my $cid = $coursedom.'_'.$coursenum;
9579: my $now = time;
9580: if (open(my $fh,">$source.meta")) {
9581: my $author=$env{'environment.firstname'}.' '.
9582: $env{'environment.middlename'}.' '.
9583: $env{'environment.lastname'}.' '.
9584: $env{'environment.generation'};
9585: $author =~ s/\s+$//;
9586: my $title = $env{'form.newresourcetitle'};
9587: $title =~ s/^\s+|\s+$//g;
9588: print $fh <<END;
1.606 raeburn 9589:
9590: <abstract></abstract>
9591: <author>$author</author>
9592: <authorspace>$coursenum:$coursedom</authorspace>
9593: <copyright>custom</copyright>
9594: <creationdate>$now</creationdate>
9595: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9596: <dependencies></dependencies>
9597: <domain>$coursedom</domain>
9598: <highestgradelevel>0</highestgradelevel>
9599: <keywords></keywords>
9600: <language>notset </language>
9601: <lastrevisiondate>$now</lastrevisiondate>
9602: <lowestgradelevel>0</lowestgradelevel>
9603: <mime>problem</mime>
9604: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9605: <notes></notes>
9606: <obsolete></obsolete>
9607: <obsoletereplacement></obsoletereplacement>
9608: <owner>$coursenum:$coursedom</owner>
9609: <sourceavail></sourceavail>
9610: <standards></standards>
9611: <subject></subject>
9612: <title>$title</title>
9613: END
1.654 raeburn 9614: close($fh);
1.606 raeburn 9615: }
9616: }
9617: }
9618: }
9619: } else {
9620: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9621: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9622: if (grep(/^\Q$rolehome\E$/,@ids)) {
9623: my $now = time;
9624: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9625: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9626: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9627: my $url = "/priv/$audom/$auname";
9628: my $path = $r->dir_config('lonDocRoot').$url;
9629: my $subdir = $env{'form.authorpath'};
9630: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9631: }
9632: }
9633: }
9634: }
9635: }
9636: }
9637: }
9638: return ($redirect,$error);
9639: }
9640:
9641: sub finishnewprob {
1.654 raeburn 9642: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9643: unless (-d $path) {
9644: unless (mkdir($path,02770)) {
9645: return;
9646: }
9647: }
1.606 raeburn 9648: my $redirect;
9649: if ($subdir ne '/') {
9650: $subdir = &cleandir($subdir);
9651: if (($subdir ne '') && (-d "$path/$subdir")) {
9652: $path .= "/$subdir";
9653: $url .= "/$subdir";
9654: }
9655: }
9656: my $dest;
9657: if ($newsubdir ne '') {
9658: $newsubdir = &cleandir($newsubdir);
9659: }
9660: if ($newsubdir ne '') {
9661: if (-d "$path/$newsubdir") {
9662: $dest = "$path/$newsubdir/$filename";
9663: } else {
9664: my $dirok;
9665: unless (-e "$path/$newsubdir") {
9666: if (mkdir("$path/$newsubdir",02770)) {
9667: if (chmod(02770,"$path/$newsubdir")) {
9668: $dirok = 1;
9669: }
9670: }
9671: }
9672: if ($dirok) {
9673: $dest = "$path/$newsubdir/$filename";
9674: }
9675: }
9676: if (($dest ne '') && (!-e $dest)) {
9677: $redirect = "$url/$newsubdir/$filename";
9678: }
9679: } else {
9680: $dest = "$path/$filename";
9681: if (($dest ne '') && (!-e $dest)) {
9682: $redirect = "$url/$filename";
9683: }
9684: }
1.654 raeburn 9685: if ((!-e $dest) && ($context ne 'upload')) {
9686: my $template = $env{'form.template'};
9687: my $copyfrom;
9688: if ($template ne '') {
9689: my %templates;
9690: my @files = &Apache::lonhomework::get_template_list('problem');
9691: foreach my $poss (@files) {
9692: if (ref($poss) eq 'ARRAY') {
9693: if ($template eq $poss->[0]) {
9694: $templates{$template} = 1;
9695: last;
9696: }
9697: }
9698: }
9699: if ($templates{$template}) {
9700: $copyfrom = $template;
9701: }
9702: }
9703: if ($filename =~ /\.problem$/) {
9704: unless ($copyfrom) {
9705: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9706: }
9707: &File::Copy::copy($copyfrom,$dest);
9708: }
9709: }
1.606 raeburn 9710: return $redirect;
9711: }
9712:
9713: sub cleandir {
9714: my ($dir) = @_;
9715: $dir =~ s/^\s+//;
9716: $dir =~ s/\s+$//;
9717: $dir =~ s/\.+//g;
9718: $dir =~ s/[\#\?&%\":]//g;
9719: return $dir;
9720: }
9721:
1.329 droeschl 9722: 1;
9723: __END__
9724:
9725:
9726: =head1 NAME
9727:
9728: Apache::londocs.pm
9729:
9730: =head1 SYNOPSIS
9731:
9732: This is part of the LearningOnline Network with CAPA project
9733: described at http://www.lon-capa.org.
9734:
9735: =head1 SUBROUTINES
9736:
9737: =over
9738:
9739: =item %help=()
9740:
9741: Available help topics
9742:
9743: =item mapread()
9744:
1.344 bisitz 9745: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9746: @order and @resources, determines status
9747: sets @order - pointer to resources in right order
9748: sets @resources - array with the resources with correct idx
9749:
9750: =item authorhosts()
9751:
9752: Return hash with valid author names
9753:
9754: =item clean()
9755:
9756: =item dumpcourse()
9757:
9758: Actually dump course
9759:
9760: =item group_import()
9761:
9762: Imports the given (name, url) resources into the course
9763: coursenum, coursedom, and folder must precede the list
9764:
9765: =item breadcrumbs()
9766:
9767: =item log_docs()
9768:
9769: =item docs_change_log()
9770:
9771: =item update_paste_buffer()
9772:
9773: =item print_paste_buffer()
9774:
9775: =item do_paste_from_buffer()
9776:
1.538 raeburn 9777: =item do_buffer_empty()
9778:
9779: =item clear_from_buffer()
9780:
1.492 raeburn 9781: =item get_newmap_url()
9782:
9783: =item dbcopy()
9784:
9785: =item uniqueness_check()
9786:
9787: =item contained_map_check()
9788:
9789: =item url_paste_fixups()
9790:
9791: =item apply_fixups()
9792:
9793: =item copy_dependencies()
9794:
1.329 droeschl 9795: =item update_parameter()
9796:
9797: =item handle_edit_cmd()
9798:
9799: =item editor()
9800:
9801: =item process_file_upload()
9802:
9803: =item process_secondary_uploads()
9804:
9805: =item is_supplemental_title()
9806:
9807: =item entryline()
9808:
9809: =item tiehash()
9810:
9811: =item untiehash()
9812:
9813: =item checkonthis()
9814:
9815: check on this
9816:
9817: =item verifycontent()
9818:
9819: Verify Content
9820:
1.636 raeburn 9821: =item devalidateversioncache()
9822:
9823: =item checkversions()
1.329 droeschl 9824:
9825: Check Versions
9826:
9827: =item mark_hash_old()
9828:
9829: =item is_hash_old()
9830:
9831: =item changewarning()
9832:
9833: =item init_breadcrumbs()
9834:
9835: Breadcrumbs for special functions
9836:
1.484 raeburn 9837: =item create_list_elements()
9838:
9839: =item create_form_ul()
9840:
9841: =item startContentScreen()
9842:
9843: =item endContentScreen()
9844:
9845: =item supplemental_base()
9846:
9847: =item embedded_form_elems()
9848:
9849: =item embedded_destination()
9850:
9851: =item return_to_editor()
9852:
9853: =item decompression_info()
9854:
9855: =item decompression_phase_one()
9856:
9857: =item decompression_phase_two()
9858:
9859: =item remove_archive()
9860:
9861: =item generate_admin_menu()
9862:
9863: =item generate_edit_table()
9864:
9865: =item editing_js()
9866:
9867: =item history_tab_js()
9868:
9869: =item inject_data_js()
9870:
9871: =item dump_switchserver_js()
9872:
1.485 raeburn 9873: =item resize_scrollbox_js()
1.484 raeburn 9874:
9875: =item makedocslogform()
9876:
1.485 raeburn 9877: =item makesimpleeditform()
9878:
1.329 droeschl 9879: =back
9880:
9881: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>