Annotation of loncom/interface/londocs.pm, revision 1.699
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.699 ! raeburn 4: # $Id: londocs.pm,v 1.698 2023/03/27 18:41:04 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.645 raeburn 48: use Apache::lonparmset();
1.651 raeburn 49: use Apache::loncourserespicker();
1.329 droeschl 50: use HTML::Entities;
1.488 raeburn 51: use HTML::TokeParser;
1.329 droeschl 52: use GDBM_File;
1.578 raeburn 53: use File::MMagic;
1.606 raeburn 54: use File::Copy;
1.329 droeschl 55: use Apache::lonlocal;
56: use Cwd;
1.643 raeburn 57: use UUID::Tiny ':std';
1.329 droeschl 58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
1.557 raeburn 68: my $suppchanges;
1.329 droeschl 69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
1.492 raeburn 82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
1.329 droeschl 87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 89: $map,1,$report);
1.329 droeschl 90: if ($errtext) { return ($errtext,2); }
1.364 bisitz 91:
1.557 raeburn 92: if ($map =~ /^default/) {
93: $hadchanges=1;
1.682 raeburn 94: } elsif ($contentchg) {
1.557 raeburn 95: $suppchanges=1;
96: }
1.329 droeschl 97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
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);
122: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
1.329 droeschl 129: if ($allowed) {
130: $home++;
1.484 raeburn 131: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 132: } else {
1.484 raeburn 133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 145: return $title;
1.329 droeschl 146: }
147:
1.617 raeburn 148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
1.329 droeschl 185:
1.685 raeburn 186: sub validate_supppath {
187: my ($coursenum,$coursedom) = @_;
188: my $backto;
1.677 raeburn 189: if ($env{'form.supppath'} ne '') {
190: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 191: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 192: for (my $i=0; $i<@items; $i++) {
193: my $odd = $i%2;
194: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
195: $badpath = 1;
1.685 raeburn 196: last;
197: } elsif ($odd) {
198: my $suffix;
199: my $idx = $i-1;
200: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
201: $backto .= '&'.$1;
202: } elsif ($items[$idx] eq 'supplemental') {
203: $backto .= '&'.$items[$i];
204: } else {
205: $backto .= '&'.$items[$i];
206: my $is_hidden;
207: unless ($got_supp) {
1.688 raeburn 208: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 209: if (ref($supplemental) eq 'HASH') {
210: if (ref($supplemental->{'hidden'}) eq 'HASH') {
211: %supphidden = %{$supplemental->{'hidden'}};
212: }
213: if (ref($supplemental->{'ids'}) eq 'HASH') {
214: %suppids = %{$supplemental->{'ids'}};
215: }
216: }
217: $got_supp = 1;
218: }
219: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
220: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
221: if ($supphidden{$mapid}) {
222: $is_hidden = 1;
223: }
224: }
225: $suffix = '::'.$is_hidden.':::';
226: }
227: $supppath .= '&'.$items[$i].$suffix;
228: } else {
229: $supppath .= '&'.$items[$i];
230: $backto .= '&'.$items[$i];
1.677 raeburn 231: }
232: }
233: if ($badpath) {
234: delete($env{'form.supppath'});
1.685 raeburn 235: } else {
236: $supppath =~ s/^\&//;
237: $backto =~ s/^\&//;
238: $env{'form.supppath'} = $supppath;
1.677 raeburn 239: }
240: }
1.685 raeburn 241: return $backto;
1.677 raeburn 242: }
243:
1.329 droeschl 244: sub dumpcourse {
245: my ($r) = @_;
1.408 raeburn 246: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 247: my ($starthash,$js);
248: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
249: $js = <<"ENDJS";
250: <script type="text/javascript">
251: // <![CDATA[
252:
253: function hide_searching() {
254: if (document.getElementById('searching')) {
255: document.getElementById('searching').style.display = 'none';
256: }
257: return;
258: }
259:
260: // ]]>
261: </script>
262: ENDJS
263: $starthash = {
264: add_entries => {'onload' => "hide_searching();"},
265: };
266: }
1.568 raeburn 267: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
268: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 269: $r->print(&startContentScreen('tools'));
1.329 droeschl 270: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 271: unless ($home) {
272: $r->print(&endContentScreen());
273: return '';
274: }
1.329 droeschl 275: my $origcrsid=$env{'request.course.id'};
276: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
277: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
278: # Do the dumping
1.484 raeburn 279: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
280: $r->print(&endContentScreen());
281: return '';
282: }
1.531 raeburn 283: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 284: $r->print('<h3>'.&mt('Copying Files').'</h3>');
285: my $title=$env{'form.authorfolder'};
286: $title=&clean($title);
1.567 raeburn 287: my ($navmap,$errormsg) =
288: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
289: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
290: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
291: my (%maps,%resources,%titles);
292: if (!ref($navmap)) {
293: $r->print($errormsg.
294: &endContentScreen());
295: return '';
296: } else {
297: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
298: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 299: }
1.567 raeburn 300: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
301: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
302: %newcontent,%has_simpleprobs);
303: foreach my $item (sort {$a <=> $b} (@todump)) {
304: my $name = $env{'form.namefor_'.$item};
305: if ($resources{$item}) {
306: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
307: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
308: $tocopy{$1} = $name;
309: $display{$item} = $1;
310: $lookup{$1} = $item;
311: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
312: $simpleproblems{$item} = {
313: symb => $resources{$item},
314: name => $name,
315: };
316: $display{$item} = 'simpleproblem_'.$name;
317: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
318: $has_simpleprobs{$1}{$id} = $item;
319: }
320: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
321: my $marker = $1;
322: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
323: $simplepages{$item} = {
324: res => $res,
325: title => $titles{$item},
326: db => $db_name,
327: marker => $marker,
328: symb => $resources{$item},
329: name => $name,
330: };
331: $display{$item} = '/'.$res;
332: }
333: } elsif ($maps{$item}) {
334: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
335: $tocopy{$1} = $name;
336: $display{$item} = $1;
337: $lookup{$1} = $item;
338: }
339: } else {
340: next;
341: }
342: }
1.329 droeschl 343: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
344: $crs=~s/\_/\//g;
1.567 raeburn 345: my $mm = new File::MMagic;
346: my $prefix = "/uploaded/$cdom/$cnum/";
347: %replacehash = %tocopy;
348: foreach my $item (sort(keys(%simpleproblems))) {
349: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
350: $newcontent{$display{$item}} = $content;
351: }
352: my $gateway = Apache::lonhtmlgateway->new('web');
353: foreach my $item (sort(keys(%simplepages))) {
354: if (ref($simplepages{$item}) eq 'HASH') {
355: my $pagetitle = $simplepages{$item}{'title'};
356: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
357: my %contents;
358: foreach my $field (keys(%fields)) {
359: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
360: my $name = $1;
361: my $msg = $fields{$field};
362: if ($name eq 'webreferences') {
363: if ($msg =~ m{^https?://}) {
364: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
365: }
366: } else {
367: $msg = &Encode::decode('utf8',$msg);
368: $msg = $gateway->process_outgoing_html($msg,1);
369: $contents{$name} = $msg;
370: }
371: } elsif ($field eq 'uploaded.photourl') {
372: my $marker = $simplepages{$item}{marker};
373: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
374: my $filepath = $1;
375: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
376: if ($fname ne '') {
377: $fname=~s/\.(\w+)$//;
378: my $ext=$1;
379: $fname = &clean($fname);
380: $fname.='.'.$ext;
381: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
382: $replacehash{$filepath} = $relpath.$fname;
383: $deps{$item}{$filepath} = 1;
384: }
385: }
386: }
387: }
388: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
389: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
390: my $content = '
391: <html>
392: <head>
393: <title>'.$pagetitle.'</title>
394: </head>
395: <body bgcolor="#ffffff">';
396: if ($contents{title}) {
397: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
398: }
399: if ($contents{image}) {
400: $content .= "\n".$contents{image};
401: }
402: if ($contents{content}) {
403: $content .= '
404: <div class="LC_Box">
1.577 bisitz 405: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 406: $contents{content}.'
407: </div>';
408: }
409: if ($contents{webreferences}) {
410: $content .= '
411: <div class="LC_Box">
1.577 bisitz 412: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 413: $contents{webreferences}.'
414: </div>';
415: }
416: $content .= '
417: </body>
418: </html>
419: ';
420: $newcontent{'/'.$simplepages{$item}{res}} = $content;
421: }
422: }
423: foreach my $item (keys(%tocopy)) {
424: unless ($item=~/\.(sequence|page)$/) {
425: my $currurlpath = $prefix.$item;
426: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
427: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
428: }
429: }
430: foreach my $num (sort {$a <=> $b} (@todump)) {
431: my $src = $display{$num};
432: next if ($src eq '');
433: my @needcopy = ();
434: if ($replacehash{$src}) {
435: push(@needcopy,$src);
436: if (ref($deps{$num}) eq 'HASH') {
437: foreach my $dep (sort(keys(%{$deps{$num}}))) {
438: if ($replacehash{$dep}) {
439: push(@needcopy,$dep);
440: }
441: }
442: }
443: } elsif ($src =~ /^simpleproblem_/) {
444: push(@needcopy,$src);
445: }
446: next if (@needcopy == 0);
447: my ($result,$depresult);
448: for (my $i=0; $i<@needcopy; $i++) {
449: my $item = $needcopy[$i];
450: my $newfilename;
451: if ($simpleproblems{$num}) {
452: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
453: } else {
454: $newfilename=$title.'/'.$replacehash{$item};
455: }
456: $newfilename=~s/\.(\w+)$//;
457: my $ext=$1;
458: $newfilename=&clean($newfilename);
459: $newfilename.='.'.$ext;
460: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
461: if ($newrelpath ne $replacehash{$item}) {
462: $replacehash{$item} = $newrelpath;
463: }
464: my @dirs=split(/\//,$newfilename);
465: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
466: my $makepath=$path;
467: my $fail;
468: my $origin;
469: for (my $i=0;$i<$#dirs;$i++) {
470: $makepath.='/'.$dirs[$i];
471: unless (-e $makepath) {
472: unless(mkdir($makepath,0755)) {
473: $fail = &mt('Directory creation failed.');
474: }
475: }
476: }
477: if ($i == 0) {
478: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
479: } else {
480: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
481: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
482: &mt('(dependency)').'</span>: ';
483: }
484: if (-e $path.'/'.$newfilename) {
485: $fail = &mt('Destination already exists -- not overwriting.');
486: } else {
487: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
488: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
489: ($item =~ /^simpleproblem_/)) {
490: print $fh $newcontent{$item};
491: } else {
492: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
493: if (-e $fileloc) {
494: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
495: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
496: (ref($has_simpleprobs{$item}) eq 'HASH')) {
497: my %changes = %{$has_simpleprobs{$item}};
498: my $content = &Apache::lonclonecourse::rewritefile(
499: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
500: (%replacehash,$crs => '')
501: );
502: my $updatedcontent = '';
503: my $parser = HTML::TokeParser->new(\$content);
504: $parser->attr_encoded(1);
505: while (my $token = $parser->get_token) {
506: if ($token->[0] eq 'S') {
507: if (($token->[1] eq 'resource') &&
508: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
509: ($changes{$token->[2]->{'id'}})) {
510: my $id = $token->[2]->{'id'};
511: $updatedcontent .= '<'.$token->[1];
512: foreach my $attrib (@{$token->[3]}) {
513: next unless ($attrib =~ /^(src|type|title|id)$/);
514: if ($attrib eq 'src') {
515: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
516: if ($file) {
517: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
518: } else {
519: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
520: }
521: } else {
522: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
523: }
524: }
525: $updatedcontent .= ' />'."\n";
526: } else {
527: $updatedcontent .= $token->[4]."\n";
528: }
529: } else {
530: $updatedcontent .= $token->[2];
531: }
532: }
533: print $fh $updatedcontent;
534: } else {
535: print $fh &Apache::lonclonecourse::rewritefile(
536: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
537: (%replacehash,$crs => '')
538: );
539: }
540: } else {
541: print $fh
542: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
543: }
544: } else {
545: $fail = &mt('Source does not exist.');
546: }
547: }
548: $fh->close();
549: } else {
550: $fail = &mt('Could not write to destination.');
551: }
552: }
553: my $text;
554: if ($fail) {
555: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
556: } else {
557: $text = '<span class="LC_success">'.&mt('ok').'</span>';
558: }
559: if ($i == 0) {
560: $result .= $text;
561: } else {
562: $depresult .= $text.'</li>';
563: }
564: }
565: $r->print($result);
566: if ($depresult) {
567: $r->print('<ul>'.$depresult.'</ul>');
568: }
569: }
570: } else {
571: my ($navmap,$errormsg) =
572: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
573: if (!ref($navmap)) {
574: $r->print($errormsg);
575: } else {
576: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
577: $r->rflush();
578: my ($preamble,$formname);
579: $formname = 'dumpdoc';
580: unless ($home==1) {
581: $preamble = '<div class="LC_left_float">'.
582: '<fieldset><legend>'.
583: &mt('Select the Authoring Space').
584: '</legend><select name="authorspace">';
1.329 droeschl 585: }
1.567 raeburn 586: my @orderspaces = ();
587: foreach my $key (sort(keys(%outhash))) {
588: if ($key=~/^home_(.+)$/) {
589: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
590: unshift(@orderspaces,$1);
591: } else {
592: push(@orderspaces,$1);
593: }
594: }
595: }
1.569 raeburn 596: if ($home>1) {
597: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
598: }
1.567 raeburn 599: foreach my $user (@orderspaces) {
1.329 droeschl 600: if ($home==1) {
1.567 raeburn 601: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 602: } else {
1.567 raeburn 603: $preamble .= '<option value="'.$user.'">'.$user.' - '.
604: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
605: }
1.329 droeschl 606: }
1.567 raeburn 607: unless ($home==1) {
608: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 609: }
1.567 raeburn 610: my $title=$origcrsdata{'description'};
611: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 612: $title=&clean($title);
1.567 raeburn 613: $preamble .= '<div class="LC_left_float">'.
614: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
615: '<input type="text" size="50" name="authorfolder" value="'.
616: $title.'" />'.
617: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
618: my %uploadedfiles;
619: &tiehash();
620: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
621: my ($ext)=($file=~/\.(\w+)$/);
622: # FIXME Check supplemental here
623: my $title=$hash{'title_'.$hash{
624: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
625: if (!$title) {
626: $title=$file;
627: } else {
628: $title=~s|/|_|g;
629: }
630: $title=~s/\.(\w+)$//;
631: $title=&clean($title);
632: $title.='.'.$ext;
633: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
634: $uploadedfiles{$file} = $title;
635: }
636: &untiehash();
637: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
638: undef,undef,$preamble,$home,\%uploadedfiles));
639: }
1.329 droeschl 640: }
1.484 raeburn 641: $r->print(&endContentScreen());
1.329 droeschl 642: }
643:
1.567 raeburn 644: sub recurse_html {
645: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
646: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
647: my (%allfiles,%codebase);
648: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
649: if (keys(%allfiles)) {
650: foreach my $dependency (keys(%allfiles)) {
651: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
652: my ($depurl,$relfile,$newcontainer);
653: if ($dependency =~ m{^/}) {
654: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
655: $relfile = $1;
656: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
657: $newcontainer = $1;
658: next if ($replacehash->{$newcontainer});
659: }
660: $depurl = $dependency;
661: } else {
662: next;
663: }
664: } else {
665: $relfile = $dependency;
666: $depurl = $currurlpath;
1.630 raeburn 667: $depurl =~ s{[^/]+$}{};
1.567 raeburn 668: $depurl .= $dependency;
1.630 raeburn 669: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 670: }
671: next if ($relfile eq '');
672: my $newname = $replacehash->{$container};
673: $newname =~ s{[^/]+$}{};
674: $replacehash->{$newcontainer} = $newname.$relfile;
675: $deps->{$item}{$newcontainer} = 1;
676: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
677: my $depfile = &Apache::lonnet::filelocation('',$depurl);
678: my $type = $mm->checktype_filename($depfile);
679: if ($type eq 'text/html') {
680: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
681: }
682: }
683: }
684: }
685: return;
686: }
687:
1.329 droeschl 688: sub group_import {
1.598 raeburn 689: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 690: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
691: %removeparam,$importuploaded,$fixuperrors);
692: $allmaps = {};
1.329 droeschl 693: while (@files) {
694: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 695: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 696: && ($caller eq 'londocs')
697: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 698:
1.329 droeschl 699: my $errtext = '';
700: my $fatal = 0;
701: my $newmapstr = '<map>'."\n".
702: '<resource id="1" src="" type="start"></resource>'."\n".
703: '<link from="1" to="2" index="1"></link>'."\n".
704: '<resource id="2" src="" type="finish"></resource>'."\n".
705: '</map>';
706: $env{'form.output'}=$newmapstr;
707: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',$1.$2);
1.534 raeburn 709: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 710: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
711: $fatal = 2;
712: }
713: if ($fatal) {
714: return ($errtext,$fatal);
715: }
716: }
717: if ($url) {
1.626 raeburn 718: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 719: $url = $1;
720: my $marker = $2;
721: my $info = $3;
1.699 ! raeburn 722: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 723: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 724: my @toolinfo = split(/:/,$info);
725: if ($residx) {
1.604 raeburn 726: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 727: $toolid = $toolsettings{'id'};
728: } else {
1.604 raeburn 729: $toolid = shift(@toolinfo);
1.598 raeburn 730: }
1.699 ! raeburn 731: if ($toolid =~ /^c/) {
! 732: $tooltype = 'crs';
! 733: $toolprefix = 'c';
! 734: } else {
! 735: $tooltype = 'dom';
! 736: }
1.598 raeburn 737: $toolid =~ s/\D//g;
1.604 raeburn 738: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 739: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
740: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 741: foreach my $item (@extras) {
742: $toolhash{$item} = &unescape($toolhash{$item});
743: }
1.645 raeburn 744: if ($folder =~ /^supplemental/) {
1.648 raeburn 745: delete($toolhash{'gradable'});
746: } else {
747: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 748: }
1.598 raeburn 749: if (ref($ltitoolsref) eq 'HASH') {
1.699 ! raeburn 750: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
! 751: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
! 752: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
! 753: my @deleted;
! 754: $toolhash{'id'} = $toolprefix.$toolid;
! 755: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
! 756: ($toolhash{'target'} eq 'window')) {
! 757: if ($toolhash{'target'} eq 'window') {
! 758: foreach my $item ('width','height') {
! 759: $toolhash{$item} =~ s/^\s+//;
! 760: $toolhash{$item} =~ s/\s+$//;
! 761: if ($toolhash{$item} =~ /\D/) {
! 762: delete($toolhash{$item});
! 763: if ($residx) {
! 764: if ($toolsettings{$item}) {
! 765: push(@deleted,$item);
! 766: }
1.624 raeburn 767: }
768: }
769: }
1.604 raeburn 770: }
1.699 ! raeburn 771: } elsif ($residx) {
! 772: $toolhash{'target'} = $toolsettings{'target'};
! 773: if ($toolhash{'target'} eq 'window') {
! 774: foreach my $item ('width','height') {
! 775: $toolhash{$item} = $toolsettings{$item};
! 776: }
! 777: }
! 778: } elsif (ref($tools{'display'}) eq 'HASH') {
! 779: $toolhash{'target'} = $tools{'display'}{'target'};
! 780: if ($toolhash{'target'} eq 'window') {
! 781: $toolhash{'width'} = $tools{'display'}{'width'};
! 782: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 783: }
1.604 raeburn 784: }
1.699 ! raeburn 785: if ($toolhash{'target'} eq 'iframe') {
! 786: foreach my $item ('width','height','linktext','explanation') {
! 787: delete($toolhash{$item});
! 788: if ($residx) {
! 789: if ($toolsettings{$item}) {
! 790: push(@deleted,$item);
! 791: }
1.624 raeburn 792: }
1.604 raeburn 793: }
1.699 ! raeburn 794: } elsif ($toolhash{'target'} eq 'tab') {
! 795: foreach my $item ('width','height') {
! 796: delete($toolhash{$item});
! 797: if ($residx) {
! 798: if ($toolsettings{$item}) {
! 799: push(@deleted,$item);
! 800: }
1.628 raeburn 801: }
802: }
803: }
1.699 ! raeburn 804: if (ref($tools{'crsconf'}) eq 'HASH') {
! 805: foreach my $item ('label','title','linktext','explanation') {
! 806: my $crsitem;
! 807: if (($item eq 'label') || ($item eq 'title')) {
! 808: $crsitem = 'crs'.$item;
! 809: } else {
! 810: $crsitem = $item;
! 811: }
! 812: if ($tools{'crsconf'}{$item}) {
! 813: $toolhash{$crsitem} =~ s/^\s+//;
! 814: $toolhash{$crsitem} =~ s/\s+$//;
! 815: if ($toolhash{$crsitem} eq '') {
! 816: delete($toolhash{$crsitem});
! 817: }
! 818: } else {
1.624 raeburn 819: delete($toolhash{$crsitem});
1.604 raeburn 820: }
1.699 ! raeburn 821: if (($residx) && (exists($toolsettings{$crsitem}))) {
! 822: unless (exists($toolhash{$crsitem})) {
! 823: push(@deleted,$crsitem);
! 824: }
! 825: }
1.604 raeburn 826: }
1.699 ! raeburn 827: }
! 828: if ($toolhash{'passback'}) {
! 829: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
! 830: $toolhash{'gradesecret'} = $gradesecret;
! 831: $toolhash{'gradesecretdate'} = time;
! 832: }
! 833: if ($toolhash{'roster'}) {
! 834: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
! 835: $toolhash{'rostersecret'} = $rostersecret;
! 836: $toolhash{'rostersecretdate'} = time;
! 837: }
! 838: my $changegradable;
! 839: if (($residx) && ($folder =~ /^default/)) {
! 840: if ($toolsettings{'gradable'}) {
! 841: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
! 842: push(@deleted,'gradable');
! 843: $changegradable = 1;
1.604 raeburn 844: }
1.699 ! raeburn 845: } elsif ($toolhash{'gradable'}) {
! 846: $changegradable = 1;
1.604 raeburn 847: }
1.699 ! raeburn 848: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 849: $changegradable = 1;
1.699 ! raeburn 850: if ($toolsettings{'gradable'}) {
! 851: $toolhash{'gradable'} = 1;
! 852: }
1.645 raeburn 853: }
1.648 raeburn 854: }
1.699 ! raeburn 855: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
! 856: if ($putres eq 'ok') {
! 857: if (@deleted) {
! 858: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 859: }
1.699 ! raeburn 860: if (($changegradable) && ($folder =~ /^default/)) {
! 861: my $val;
! 862: if ($toolhash{'gradable'}) {
! 863: $val = 'yes';
! 864: } else {
! 865: $val = 'no';
! 866: }
! 867: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
! 868: 'string_yesno');
! 869: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 870: }
1.699 ! raeburn 871: } else {
! 872: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 873: }
1.604 raeburn 874: }
1.598 raeburn 875: }
876: }
877: }
1.529 raeburn 878: if (($caller eq 'londocs') &&
879: ($folder =~ /^default/)) {
1.534 raeburn 880: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 881: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
882: my $cid = $coursedom.'_'.$coursenum;
883: $allmaps =
884: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
885: $chome,$cid);
886: $donechk = 1;
887: }
888: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 889: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
890: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 891: $importuploaded = 1;
892: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
893: next if ($allmaps->{$url});
894: }
895: }
1.344 bisitz 896: if (!$residx
1.329 droeschl 897: || defined($LONCAPA::map::zombies[$residx])) {
898: $residx = &LONCAPA::map::getresidx($url,$residx);
899: push(@LONCAPA::map::order, $residx);
900: }
901: my $ext = 'false';
902: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 903: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
904: my $filepath = $1;
1.675 raeburn 905: my $fname;
906: if ($name eq '') {
907: $name = &mt('Web Page');
1.534 raeburn 908: $fname = 'web';
909: } else {
1.675 raeburn 910: $fname = $name;
911: $fname=&Apache::lonnet::clean_filename($fname);
912: if ($fname eq '') {
913: $fname = 'web';
914: } elsif (length($fname) > 15) {
915: $fname = substr($fname,0,14);
916: }
1.534 raeburn 917: }
1.675 raeburn 918: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 919: my $initialtext = &mt('Replace with your own content.');
920: my $newhtml = <<END;
1.545 raeburn 921: <html>
1.534 raeburn 922: <head>
1.675 raeburn 923: <title>$title</title>
1.534 raeburn 924: </head>
925: <body bgcolor="#ffffff">
926: $initialtext
927: </body>
928: </html>
929: END
930: $env{'form.output'}=$newhtml;
1.630 raeburn 931: my $result =
1.534 raeburn 932: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
933: 'output',
934: "$filepath/$residx/$fname.html");
935: if ($result =~ m{^/uploaded/}) {
936: $url = $result;
937: if ($filepath =~ /^supplemental/) {
938: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
939: $env{'user.domain'}.'___&&&___'.$name;
940: }
941: } else {
942: return (&mt('Failed to save new web page.'),1);
943: }
944: }
1.675 raeburn 945: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 946: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 947: $LONCAPA::map::resources[$residx] =
1.329 droeschl 948: join(':', ($name, $url, $ext, 'normal', 'res'));
949: }
950: }
1.529 raeburn 951: if ($importuploaded) {
952: my %import_errors;
953: my %updated = (
954: removefrommap => \%removefrommap,
955: removeparam => \%removeparam,
956: );
1.533 raeburn 957: my ($result,$msgsarray,$lockerror) =
958: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 959: if (keys(%import_errors) > 0) {
1.530 raeburn 960: $fixuperrors =
1.529 raeburn 961: '<p span class="LC_warning">'."\n".
962: &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".
963: '<ul>'."\n";
964: foreach my $key (sort(keys(%import_errors))) {
965: $fixuperrors .= '<li>'.$key.'</li>'."\n";
966: }
967: $fixuperrors .= '</ul></p>'."\n";
968: }
1.533 raeburn 969: if (ref($msgsarray) eq 'ARRAY') {
970: if (@{$msgsarray} > 0) {
971: $fixuperrors .= '<p class="LC_info">'.
972: join('<br />',@{$msgsarray}).
973: '</p>';
974: }
975: }
976: if ($lockerror) {
977: $fixuperrors .= '<p class="LC_error">'.
978: $lockerror.
979: '</p>';
980: }
1.529 raeburn 981: }
982: my ($errtext,$fatal) =
983: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 984: unless ($fatal) {
985: if ($folder =~ /^supplemental/) {
1.561 raeburn 986: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
987: $folder.'.'.$container);
1.557 raeburn 988: }
989: }
1.529 raeburn 990: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 991: }
992:
993: sub log_docs {
1.494 raeburn 994: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 995: }
996:
997: {
998: my @oldresources=();
999: my @oldorder=();
1000: my $parmidx;
1001: my %parmaction=();
1002: my %parmvalue=();
1003: my $changedflag;
1004:
1005: sub snapshotbefore {
1006: @oldresources=@LONCAPA::map::resources;
1007: @oldorder=@LONCAPA::map::order;
1008: $parmidx=undef;
1009: %parmaction=();
1010: %parmvalue=();
1011: $changedflag=0;
1012: }
1013:
1014: sub remember_parms {
1015: my ($idx,$parameter,$action,$value)=@_;
1016: $parmidx=$idx;
1017: $parmaction{$parameter}=$action;
1018: $parmvalue{$parameter}=$value;
1019: $changedflag=1;
1020: }
1021:
1022: sub log_differences {
1023: my ($plain)=@_;
1024: my %storehash=('folder' => $plain,
1025: 'currentfolder' => $env{'form.folder'});
1026: if ($parmidx) {
1027: $storehash{'parameter_res'}=$oldresources[$parmidx];
1028: foreach my $parm (keys(%parmaction)) {
1029: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1030: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1031: }
1032: }
1033: my $maxidx=$#oldresources;
1034: if ($#LONCAPA::map::resources>$#oldresources) {
1035: $maxidx=$#LONCAPA::map::resources;
1036: }
1037: for (my $idx=0; $idx<=$maxidx; $idx++) {
1038: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1039: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1040: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1041: $changedflag=1;
1042: }
1043: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1044: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1045: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1046: $changedflag=1;
1047: }
1048: }
1049: $storehash{'maxidx'}=$maxidx;
1050: if ($changedflag) { &log_docs(\%storehash); }
1051: }
1052: }
1053:
1054: sub docs_change_log {
1.611 raeburn 1055: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1056: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1057: my $navmap;
1.483 raeburn 1058: my $js = '<script type="text/javascript">'."\n".
1059: '// <![CDATA['."\n".
1060: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1061: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1062: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1063: &history_tab_js()."\n".
1.484 raeburn 1064: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1065: '// ]]>'."\n".
1066: '</script>'."\n";
1.484 raeburn 1067: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1068: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1069: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1070: my %orderhash;
1071: my $container='sequence';
1072: my $pathitem;
1.519 raeburn 1073: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1074: $container='page';
1075: }
1.519 raeburn 1076: my $folderpath=$env{'form.folderpath'};
1077: if ($folderpath eq '') {
1.617 raeburn 1078: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1079: }
1.617 raeburn 1080: undef($navmap);
1.519 raeburn 1081: $pathitem = '<input type="hidden" name="folderpath" value="'.
1082: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1083: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1084: my $jumpto = $readfile;
1085: $jumpto =~ s{^/}{};
1086: my $tid = 1;
1.489 raeburn 1087: if ($supplementalflag) {
1088: $tid = 2;
1089: }
1.630 raeburn 1090: my ($breadcrumbtrail) =
1.509 raeburn 1091: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1092: $r->print($breadcrumbtrail.
1093: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1094: $readfile));
1.329 droeschl 1095: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1096: $env{'course.'.$env{'request.course.id'}.'.domain'},
1097: $env{'course.'.$env{'request.course.id'}.'.num'});
1098:
1099: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1100:
1101: my %saveable_parameters = ('show' => 'scalar',);
1102: &Apache::loncommon::store_course_settings('docs_log',
1103: \%saveable_parameters);
1104: &Apache::loncommon::restore_course_settings('docs_log',
1105: \%saveable_parameters);
1106: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1107: # FIXME: internationalization seems wrong here
1.329 droeschl 1108: my %lt=('hiddenresource' => 'Resources hidden',
1109: 'encrypturl' => 'URL hidden',
1110: 'randompick' => 'Randomly pick',
1111: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1112: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1113: 'set' => 'set to',
1114: 'del' => 'deleted');
1.484 raeburn 1115: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1116: $pathitem."\n".
1117: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1118: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1119: $r->print('<div class="LC_left_float">'.
1120: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1121: &makedocslogform($filter,1).
1122: '</fieldset></div><br clear="all" />');
1.329 droeschl 1123: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1124: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1125: &mt('After').'</th>'.
1126: &Apache::loncommon::end_data_table_header_row());
1127: my $shown=0;
1128: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1129: if ($env{'form.displayfilter'} eq 'currentfolder') {
1130: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1131: }
1132: my @changes=keys(%{$docslog{$id}{'logentry'}});
1133: if ($env{'form.displayfilter'} eq 'containing') {
1134: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1135: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1136: foreach my $key (@changes) {
1137: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1138: }
1.344 bisitz 1139: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1140: }
1141: my $count = 0;
1142: my $time =
1143: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1144: my $plainname =
1145: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1146: $docslog{$id}{'exe_udom'});
1147: my $about_me_link =
1148: &Apache::loncommon::aboutmewrapper($plainname,
1149: $docslog{$id}{'exe_uname'},
1150: $docslog{$id}{'exe_udom'});
1151: my $send_msg_link='';
1152: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1153: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1154: $send_msg_link ='<br />'.
1155: &Apache::loncommon::messagewrapper(&mt('Send message'),
1156: $docslog{$id}{'exe_uname'},
1157: $docslog{$id}{'exe_udom'});
1158: }
1159: $r->print(&Apache::loncommon::start_data_table_row());
1160: $r->print('<td>'.$time.'</td>
1161: <td>'.$about_me_link.
1162: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1163: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1164: $send_msg_link.'</td><td>'.
1165: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1166: my $is_supp = 0;
1167: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1168: $is_supp = 1;
1169: }
1.329 droeschl 1170: # Before
1171: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1172: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1173: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1174: if ($oldname ne $newname) {
1.488 raeburn 1175: my $shown = &LONCAPA::map::qtescape($oldname);
1176: if ($is_supp) {
1177: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1178: }
1179: $r->print($shown);
1.329 droeschl 1180: }
1181: }
1182: $r->print('<ul>');
1183: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1184: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1185: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1186: if ($is_supp) {
1187: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1188: }
1189: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1190: }
1191: }
1192: $r->print('</ul>');
1193: # After
1194: $r->print('</td><td>');
1195:
1196: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1197: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1198: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1199: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1200: my $shown = &LONCAPA::map::qtescape($newname);
1201: if ($is_supp) {
1202: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1203: }
1204: $r->print($shown);
1.329 droeschl 1205: }
1.364 bisitz 1206: }
1.329 droeschl 1207: $r->print('<ul>');
1208: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1209: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1210: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1211: if ($is_supp) {
1212: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1213: }
1214: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1215: }
1216: }
1217: $r->print('</ul>');
1218: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1219: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1220: if ($title eq '') {
1221: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1222: } elsif ($is_supp) {
1223: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1224: }
1225: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1226: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1227: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1228: # FIXME: internationalization seems wrong here
1.329 droeschl 1229: $r->print('<li>'.
1230: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1231: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1232: .'</li>');
1233: }
1234: }
1235: $r->print('</ul>');
1236: }
1237: # End
1238: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1239: $shown++;
1240: if (!($env{'form.show'} eq &mt('all')
1241: || $shown<=$env{'form.show'})) { last; }
1242: }
1.484 raeburn 1243: $r->print(&Apache::loncommon::end_data_table()."\n".
1244: &makesimpleeditform($pathitem)."\n".
1245: '</div></div>');
1246: $r->print(&endContentScreen());
1.329 droeschl 1247: }
1248:
1249: sub update_paste_buffer {
1.492 raeburn 1250: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1251: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1252: if ($env{'form.multiremove'}) {
1253: $env{'form.multiremove'} =~ s/,$//;
1254: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1255: }
1256: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1257: if ($env{'form.multicut'}) {
1258: $env{'form.multicut'} =~ s/,$//;
1259: foreach my $item (split(/,/,$env{'form.multicut'})) {
1260: unless ($removals{$item}) {
1261: $cuts{$item} = 1;
1262: push(@possibles,$item.':cut');
1263: }
1264: }
1265: }
1266: if ($env{'form.multicopy'}) {
1267: $env{'form.multicopy'} =~ s/,$//;
1268: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1269: unless ($removals{$item} || $cuts{$item}) {
1270: push(@possibles,$item.':copy');
1271: }
1272: }
1273: }
1274: } elsif ($env{'form.markcopy'}) {
1275: @possibles = split(/,/,$env{'form.markcopy'});
1276: }
1.329 droeschl 1277:
1.538 raeburn 1278: return if (@possibles == 0);
1.329 droeschl 1279: return if (!defined($env{'form.copyfolder'}));
1280:
1281: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1282: $env{'form.copyfolder'});
1.538 raeburn 1283: return if ($fatal);
1284:
1285: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1286:
1.538 raeburn 1287: # Retrieve current paste buffer suffixes.
1288: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1289: my (%pasteurls,@newpaste);
1290:
1291: # Construct identifiers for current contents of user's paste buffer
1292: if (@currpaste) {
1293: foreach my $suffix (@currpaste) {
1.667 raeburn 1294: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1295: my $url = $env{'docs.markedcopy_url_'.$suffix};
1296: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1297: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1298: ($url ne '')) {
1299: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1300: $pasteurls{$cid.'_'.$mapidx} = 1;
1301: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1302: $pasteurls{$url} = 1;
1303: } else {
1.669 raeburn 1304: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1305: }
1306: }
1.538 raeburn 1307: }
1308: }
1309:
1310: # Mark items for copying (skip any items already in user's paste buffer)
1311: my %addtoenv;
1.597 raeburn 1312:
1313: my @pathitems = split(/\&/,$env{'form.folderpath'});
1314: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1315: my $ispage = $folderconf[5];
1.597 raeburn 1316:
1.538 raeburn 1317: foreach my $item (@possibles) {
1318: my ($orderidx,$cmd) = split(/:/,$item);
1319: next if ($orderidx =~ /\D/);
1320: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1321: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1322: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1323: my %denied = &action_restrictions($coursenum,$coursedom,
1324: &LONCAPA::map::qtescape($url),
1325: $env{'form.folderpath'},\%curr_groups);
1326: next if ($denied{'copy'});
1327: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1328: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1329: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1330: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1331: next if (exists($pasteurls{$url}));
1332: } else {
1333: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1334: }
1.538 raeburn 1335: my ($suffix,$errortxt,$locknotfreed) =
1336: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1337: if ($suffix ne '') {
1338: push(@newpaste,$suffix);
1339: } else {
1340: if ($locknotfreed) {
1341: return $locknotfreed;
1342: }
1.538 raeburn 1343: }
1344: if (&is_supplemental_title($title)) {
1345: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1346: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1347: }
1.329 droeschl 1348:
1.538 raeburn 1349: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1350: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1351: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1352: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1353: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1354: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1355: my $prefix = $1;
1356: my $subdir =$2;
1357: if ($subdir eq '') {
1358: $subdir = $prefix;
1.492 raeburn 1359: }
1.538 raeburn 1360: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1361: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1362: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1363: if (ref($hierarchy{$url}) eq 'HASH') {
1364: my ($nested,$nestednames);
1365: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1366: $nested =~ s/\&$//;
1367: $nestednames =~ s/\Q___&&&___\E$//;
1368: if ($nested ne '') {
1369: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1370: }
1371: if ($nestednames ne '') {
1372: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1373: }
1.492 raeburn 1374: }
1375: }
1.591 raeburn 1376: if ($locknotfreed) {
1377: $output = $locknotfreed;
1378: last;
1379: }
1.492 raeburn 1380: }
1.538 raeburn 1381: if (@newpaste) {
1382: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1383: }
1.492 raeburn 1384: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1385: delete($env{'form.markcopy'});
1.591 raeburn 1386: return $output;
1.329 droeschl 1387: }
1388:
1.492 raeburn 1389: sub recurse_uploaded_maps {
1390: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1391: if (ref($hierarchy->{$url}) eq 'HASH') {
1392: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1393: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1394: my (@uploaded,@names,%shorter);
1395: for (my $i=0; $i<@maps; $i++) {
1396: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1397: if ($inner ne '') {
1398: push(@uploaded,$inner);
1399: push(@names,&escape($titles[$i]));
1400: $shorter{$maps[$i]} = $inner;
1401: }
1402: }
1403: $$nestref .= "$dir:".join(',',@uploaded).'&';
1404: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1405: foreach my $map (@maps) {
1406: if ($shorter{$map} ne '') {
1407: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1408: }
1409: }
1410: }
1411: return;
1412: }
1413:
1.329 droeschl 1414: sub print_paste_buffer {
1.492 raeburn 1415: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1416: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1417:
1.538 raeburn 1418: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1419: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1420: }
1421:
1.538 raeburn 1422: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1423: my ($pasteitems,@pasteable);
1.575 raeburn 1424: my $clipboardcount = 0;
1.488 raeburn 1425:
1.538 raeburn 1426: # Construct identifiers for current contents of user's paste buffer
1427: foreach my $suffix (@currpaste) {
1428: next if ($suffix =~ /\D/);
1429: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1430: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1431: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1432: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1433: ($url ne '')) {
1.575 raeburn 1434: $clipboardcount ++;
1.538 raeburn 1435: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1436: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
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.626 raeburn 1440: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1441: $is_exttool = 1;
1.538 raeburn 1442: }
1443: if ($folder =~ /^supplemental/) {
1444: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1445: unless ($canpaste) {
1446: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1447: }
1448: } else {
1449: $canpaste = 1;
1450: }
1451: if ($canpaste) {
1452: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1453: my $srcdom = $1;
1454: my $srcnum = $2;
1455: my $rem = $3;
1456: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1457: $othercourse = 1;
1458: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1459: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1460: } else {
1461: $canpaste = 0;
1462: $nopaste = &mt('Paste from another course unavailable.');
1463: }
1464: }
1465: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1466: my $prefix = $1;
1467: $parent = $2;
1468: if ($folder !~ /^\Q$prefix\E/) {
1469: $areachange = 1;
1470: }
1471: $is_uploaded_map = 1;
1.492 raeburn 1472: }
1.597 raeburn 1473: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1474: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1475: if ($cid ne $env{'request.course.id'}) {
1476: my ($srcdom,$srcnum) = split(/_/,$cid);
1477: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1478: if (($is_exttool) && ($srcdom ne $coursedom)) {
1479: $canpaste = 0;
1480: $nopaste = &mt('Paste from another domain unavailable.');
1481: } else {
1482: $othercrs = '<br />'.&mt('(from another course)');
1483: }
1.596 raeburn 1484: } else {
1485: $canpaste = 0;
1486: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1487: }
1.596 raeburn 1488: }
1.492 raeburn 1489: }
1.596 raeburn 1490: if ($canpaste) {
1491: push(@pasteable,$suffix);
1.629 raeburn 1492: }
1.538 raeburn 1493: }
1494: my $buffer;
1.627 raeburn 1495: if ($is_external) {
1.538 raeburn 1496: $buffer = &mt('External Resource').': '.
1497: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1498: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1499: } elsif ($is_exttool) {
1500: $buffer = &mt('External Tool').': '.
1501: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1502: } else {
1503: my $icon = &Apache::loncommon::icon($extension);
1504: if ($extension eq 'sequence' &&
1505: $url =~ m{/default_\d+\.sequence$}x) {
1506: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1507: $icon .= '/navmap.folder.closed.gif';
1508: }
1.589 raeburn 1509: my $title = $env{'docs.markedcopy_title_'.$suffix};
1510: if ($title eq '') {
1511: ($title) = ($url =~ m{/([^/]+)$});
1512: }
1.538 raeburn 1513: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1514: ': '.
1515: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1516: &LONCAPA::map::qtescape($title));
1.538 raeburn 1517: }
1518: $pasteitems .= '<div class="LC_left_float">';
1519: my ($options,$onclick);
1520: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1521: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1522: if (($is_uploaded_map) ||
1523: ($url =~ /(bulletinboard|smppg)$/) ||
1524: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1525: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1526: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1527: }
1528: }
1529: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1530: if ($nopaste) {
1.681 raeburn 1531: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1532: } else {
1533: if ($othercrs) {
1534: $pasteitems .= $othercrs;
1535: }
1536: if ($options) {
1537: $pasteitems .= $options;
1.492 raeburn 1538: }
1539: }
1.538 raeburn 1540: $pasteitems .= '</div>';
1541: }
1542: }
1543: if ($pasteitems eq '') {
1544: &Apache::lonnet::delenv('docs.markedcopies');
1545: }
1546: my ($pasteform,$form_start,$buttons,$form_end);
1547: if ($pasteitems) {
1548: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1549: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1550: if (@pasteable) {
1.575 raeburn 1551: my $value = &mt('Paste to current folder');
1552: if ($container eq 'page') {
1553: $value = &mt('Paste to current page');
1554: }
1555: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1556: }
1557: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1558: if ($clipboardcount > 1) {
1559: $buttons .=
1560: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1561: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1562: (' 'x2).
1563: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1564: (' 'x2);
1.492 raeburn 1565: }
1.575 raeburn 1566: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1567: '</form>';
1.538 raeburn 1568: } else {
1569: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1570: }
1.538 raeburn 1571: $r->print($form_start
1572: .'<fieldset>'
1573: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1574: .$pasteitems
1575: .'</fieldset>'
1576: .$form_end);
1577: }
1578:
1579: sub paste_options {
1580: my ($suffix,$is_uploaded_map,$parent) = @_;
1581: my ($copytext,$movetext);
1582: if ($is_uploaded_map) {
1583: $copytext = &mt('Copy to new folder');
1584: $movetext = &mt('Move old');
1585: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1586: $copytext = &mt('Copy to new board');
1587: $movetext = &mt('Move (not posts)');
1588: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1589: $copytext = &mt('Copy to new page');
1590: $movetext = &mt('Move');
1.533 raeburn 1591: } else {
1.538 raeburn 1592: $copytext = &mt('Copy to new file');
1593: $movetext = &mt('Move');
1594: }
1595: my $output = '<br />'.
1596: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1597: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1598: '<label>'.
1599: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1600: $copytext.'</label></span>'.(' 'x2).' '.
1601: '<span class="LC_nobreak"><label>'.
1602: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1603: $movetext.'</label></span>';
1604: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1605: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1606: '</legend><table border="0">';
1607: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1608: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1609: my $lastdir = $parent;
1610: my %depths = (
1611: $lastdir => 0,
1612: );
1613: my (%display,%deps);
1614: for (my $i=0; $i<@pastemaps; $i++) {
1615: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1616: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1617: my @subfolders = split(/,/,$subfolderstr);
1618: $deps{$lastdir} = \@subfolders;
1619: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1620: my $depth = $depths{$lastdir} + 1;
1621: my $offset = int($depth * 4);
1622: my $indent = (' ' x $offset);
1623: for (my $j=0; $j<@subfolders; $j++) {
1624: $depths{$subfolders[$j]} = $depth;
1625: $display{$subfolders[$j]} =
1626: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1627: '<td><label>'.
1628: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1629: '<label>'.
1630: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1631: &mt('Move old').'</label>'.
1632: '</td></tr>';
1633: }
1.492 raeburn 1634: }
1.538 raeburn 1635: &recurse_print(\$output,$parent,\%deps,\%display);
1636: $output .= '</table></fieldset>';
1.329 droeschl 1637: }
1.538 raeburn 1638: $output .= '</div>';
1639: return $output;
1.488 raeburn 1640: }
1641:
1.492 raeburn 1642: sub recurse_print {
1.538 raeburn 1643: my ($outputref,$dir,$deps,$display) = @_;
1644: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1645: if (ref($deps->{$dir}) eq 'ARRAY') {
1646: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1647: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1648: }
1649: }
1650: }
1651:
1.488 raeburn 1652: sub supp_pasteable {
1653: my ($url) = @_;
1654: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1655: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1656: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1657: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1658: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1659: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1660: return 1;
1661: }
1662: return;
1.329 droeschl 1663: }
1664:
1.492 raeburn 1665: sub paste_popup_js {
1.594 damieng 1666: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1667: show => 'Show Options',
1668: hide => 'Hide Options',
1.594 damieng 1669: );
1670: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1671: none => 'No items selected from clipboard.',
1.492 raeburn 1672: );
1.594 damieng 1673: &html_escape(\%html_js_lt);
1674: &js_escape(\%html_js_lt);
1675: &js_escape(\%js_lt);
1.492 raeburn 1676: return <<"END";
1677:
1.538 raeburn 1678: function showPasteOptions(suffix) {
1679: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1680: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1681: return;
1682: }
1683:
1.538 raeburn 1684: function hidePasteOptions(suffix) {
1685: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1686: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1687: return;
1688: }
1689:
1690: function showOptions(caller,suffix) {
1691: if (document.getElementById('pasteoptionstext_'+suffix)) {
1692: if (caller.checked) {
1.594 damieng 1693: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1694: } else {
1695: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1696: }
1697: if (document.getElementById('pasteoptions_'+suffix)) {
1698: document.getElementById('pasteoptions_'+suffix).style.display='none';
1699: }
1700: }
1.492 raeburn 1701: return;
1702: }
1703:
1.541 raeburn 1704: function validateClipboard() {
1705: var numchk = 0;
1706: if (document.pasteform.pasting.length > 1) {
1707: for (var i=0; i<document.pasteform.pasting.length; i++) {
1708: if (document.pasteform.pasting[i].checked) {
1709: numchk ++;
1710: }
1711: }
1712: } else {
1713: if (document.pasteform.pasting.type == 'checkbox') {
1714: if (document.pasteform.pasting.checked) {
1715: numchk ++;
1716: }
1717: }
1718: }
1719: if (numchk > 0) {
1720: return true;
1721: } else {
1.594 damieng 1722: alert("$js_lt{'none'}");
1.541 raeburn 1723: return false;
1724: }
1725: }
1726:
1.575 raeburn 1727: function checkClipboard() {
1728: if (document.pasteform.pasting.length > 1) {
1729: for (var i=0; i<document.pasteform.pasting.length; i++) {
1730: document.pasteform.pasting[i].checked = true;
1731: }
1732: }
1733: return;
1734: }
1735:
1736: function uncheckClipboard() {
1737: if (document.pasteform.pasting.length >1) {
1738: for (var i=0; i<document.pasteform.pasting.length; i++) {
1739: document.pasteform.pasting[i].checked = false;
1740: }
1741: }
1742: return;
1743: }
1744:
1.492 raeburn 1745: END
1746:
1747: }
1748:
1.329 droeschl 1749: sub do_paste_from_buffer {
1.492 raeburn 1750: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1751:
1.538 raeburn 1752: # Array of items in paste buffer
1753: my (@currpaste,%pastebuffer,%allerrors);
1754: @currpaste = split(/,/,$env{'docs.markedcopies'});
1755:
1.492 raeburn 1756: # Early out if paste buffer is empty
1.538 raeburn 1757: if (@currpaste == 0) {
1.492 raeburn 1758: return ();
1.538 raeburn 1759: }
1760: map { $pastebuffer{$_} = 1; } @currpaste;
1761:
1762: # Array of items selected items to paste
1763: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1764:
1765: # Early out if nothing selected to paste
1766: if (@reqpaste == 0) {
1767: return();
1768: }
1769: my @topaste;
1770: foreach my $suffix (@reqpaste) {
1771: next if ($suffix =~ /\D/);
1772: next unless (exists($pastebuffer{$suffix}));
1773: push(@topaste,$suffix);
1774: }
1775:
1776: # Early out if nothing available to paste
1777: if (@topaste == 0) {
1778: return();
1.329 droeschl 1779: }
1780:
1.627 raeburn 1781: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1782: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1783:
1784: foreach my $suffix (@topaste) {
1785: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1786: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1787: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1788: # Supplemental content may only include certain types of content
1789: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1790: if ($folder =~ /^supplemental/) {
1791: unless (&supp_pasteable($url)) {
1792: $notinsupp{$suffix} = 1;
1793: next;
1794: }
1.492 raeburn 1795: }
1.538 raeburn 1796: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1797: my $srcd = $1;
1798: my $srcn = $2;
1.492 raeburn 1799: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1800: # check for mdc privilege in the course from which the resource was pasted
1801: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1802: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1803: $notincrs{$suffix} = 1;
1804: next;
1805: }
1.491 raeburn 1806: }
1.538 raeburn 1807: $srcdom{$suffix} = $srcd;
1808: $srcnum{$suffix} = $srcn;
1.597 raeburn 1809: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1810: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1811: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1812: my ($srcd,$srcn) = split(/_/,$cid);
1813: # When paste buffer was populated using an active role in a different course
1814: # check for mdc privilege in the course from which the resource was pasted
1815: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1816: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1817: $notincrs{$suffix} = 1;
1818: next;
1819: }
1820: }
1.632 raeburn 1821: # When buffer was populated using an active role in a different course
1822: # disallow pasting of External Tool if course is in a different domain.
1823: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1824: $notindom{$suffix} = 1;
1825: next;
1826: }
1.596 raeburn 1827: $srcdom{$suffix} = $srcd;
1828: $srcnum{$suffix} = $srcn;
1.491 raeburn 1829: }
1.597 raeburn 1830: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1831: push(@dopaste,$suffix);
1832: if ($url=~/\.(page|sequence)$/) {
1833: $is_map{$suffix} = 1;
1834: }
1835: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1836: my $oldprefix = $1;
1.492 raeburn 1837: # When pasting content from Main Content to Supplemental Content and vice versa
1838: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1839: # a folder/page or a document).
1.538 raeburn 1840: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1841: $prefixchg{$suffix} = 'docstosupp';
1842: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1843: $prefixchg{$suffix} = 'supptodocs';
1844: }
1.491 raeburn 1845:
1.492 raeburn 1846: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1847: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1848: my @nested;
1849: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1850: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1851: my @deps = map { /\d+:([\d,]+$)/ } @items;
1852: foreach my $dep (@deps) {
1853: if ($dep =~ /,/) {
1854: push(@nested,split(/,/,$dep));
1855: } else {
1856: push(@nested,$dep);
1857: }
1.492 raeburn 1858: }
1.538 raeburn 1859: foreach my $item (@nested) {
1860: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1861: push(@{$marktomove{$suffix}},$type.'_'.$item);
1862: }
1.492 raeburn 1863: }
1864: }
1.488 raeburn 1865: }
1866: }
1867:
1.538 raeburn 1868: # Early out if nothing available to paste
1869: if (@dopaste == 0) {
1870: return ();
1871: }
1872:
1873: # Populate message hash and hashes used for main content <=> supplemental content
1874: # changes
1875:
1876: %msgs = &Apache::lonlocal::texthash (
1877: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1878: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1879: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1880: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1881: );
1882:
1883: %before = (
1884: docstosupp => {
1885: map => 'default',
1886: doc => 'docs',
1887: },
1888: supptodocs => {
1889: map => 'supplemental',
1890: doc => 'supplemental',
1891: },
1892: );
1893:
1894: %after = (
1895: docstosupp => {
1896: map => 'supplemental',
1897: doc => 'supplemental'
1898: },
1899: supptodocs => {
1900: map => 'default',
1901: doc => 'docs',
1902: },
1903: );
1904:
1905: # Retrieve information about all course maps in main content area
1906:
1907: my $allmaps = {};
1.660 raeburn 1908: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1909:
1910: # Loop over the items to paste
1911: foreach my $suffix (@dopaste) {
1.329 droeschl 1912: # Maps need to be copied first
1.538 raeburn 1913: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1914: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1915: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1916: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1917: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1918: }
1919: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1920: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1921: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1922: my $oldurl = $url;
1923: if ($is_map{$suffix}) {
1.491 raeburn 1924: # If pasting a map, check if map contains other maps
1.538 raeburn 1925: my (%hierarchy,%titles);
1.660 raeburn 1926: if (($folder =~ /^default/) && (!$donechk)) {
1927: $allmaps =
1928: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1929: $env{"course.$env{'request.course.id'}.home"},
1930: $env{'request.course.id'});
1931: $donechk = 1;
1932: }
1.627 raeburn 1933: &contained_map_check($url,$folder,$coursenum,$coursedom,
1934: \%removefrommap,\%removeparam,\%addedmaps,
1935: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1936: if ($url=~ m{^/uploaded/}) {
1937: my $newurl;
1938: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1939: ($newurl,my $error) =
1940: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1941: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1942: \$title,$allmaps,\%newurls);
1943: if ($error) {
1944: $allerrors{$suffix} = $error;
1945: next;
1946: }
1947: if ($newurl ne '') {
1948: if ($newurl ne $url) {
1949: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1950: $newsubdir{$url} = $1;
1951: }
1952: $mapchanges{$url} = 1;
1.492 raeburn 1953: }
1.538 raeburn 1954: }
1955: }
1956: if (($srcdom{$suffix} ne $coursedom) ||
1957: ($srcnum{$suffix} ne $coursenum) ||
1958: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1959: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1960: $coursedom,$coursenum,$srcdom{$suffix},
1961: $srcnum{$suffix},$allmaps,\%rewrites,
1962: \%retitles,\%copies,\%dbcopies,
1963: \%zombies,\%params,\%mapmoves,
1964: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1965: \%newurls,\%resdatacopy)) {
1.538 raeburn 1966: $mapmoves{$url} = 1;
1967: }
1968: $url = $newurl;
1969: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1970: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1971: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1972: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1973: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1974: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1975: }
1976: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1977: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1978: push(@toclear,$suffix);
1979: # if pasting published map (main content area only) check map not already in course
1980: if ($folder =~ /^default/) {
1981: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1982: $duplicate{$suffix} = 1;
1983: next;
1.492 raeburn 1984: }
1.491 raeburn 1985: }
1986: }
1.538 raeburn 1987: }
1.627 raeburn 1988: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1989: my $prefix = $1;
1.648 raeburn 1990: my $fromothercrs;
1.538 raeburn 1991: #need to copy the db contents to a new one, unless this is a move.
1992: my %info = (
1993: src => $url,
1994: cdom => $coursedom,
1995: cnum => $coursenum,
1.596 raeburn 1996: );
1.649 raeburn 1997: if ($prefix eq 'ext.tool') {
1.655 raeburn 1998: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1999: $info{'delgradable'} = 1;
2000: }
2001: }
1.596 raeburn 2002: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2003: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2004: $fromothercrs = 1;
2005: $info{'cdom'} = $srcdom{$suffix};
2006: $info{'cnum'} = $srcnum{$suffix};
2007: }
2008: }
2009: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2010: my (%lockerr,$msg);
1.538 raeburn 2011: my ($newurl,$result,$errtext) =
2012: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2013: if ($result eq 'ok') {
2014: $url = $newurl;
2015: $title=&mt('Copy of').' '.$title;
2016: } else {
2017: if ($prefix eq 'smppg') {
2018: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2019: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2020: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2021: } elsif ($prefix eq 'ext.tool') {
2022: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2023: }
2024: $results{$suffix} = $result;
2025: $msgerrs{$suffix} = $msg;
2026: $lockerrs{$suffix} = $lockerr{$prefix};
2027: next;
2028: }
2029: if ($lockerr{$prefix}) {
2030: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2031: }
1.489 raeburn 2032: }
2033: }
1.538 raeburn 2034: $title = &LONCAPA::map::qtunescape($title);
2035: my $ext='false';
2036: if ($url=~m{^http(|s)://}) { $ext='true'; }
2037: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2038: if ($folder !~ /^supplemental/) {
2039: (undef,undef,$title) =
2040: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2041: }
2042: } else {
2043: if ($folder=~/^supplemental/) {
2044: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2045: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2046: }
1.533 raeburn 2047: }
1.491 raeburn 2048:
2049: # For uploaded files (excluding pages/sequences) path in copied file is changed
2050: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2051: # courses.
2052:
1.538 raeburn 2053: unless ($is_map{$suffix}) {
2054: my $newidx;
1.492 raeburn 2055: # Now insert the URL at the bottom
1.538 raeburn 2056: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2057: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2058: my $relpath = $1;
2059: if ($relpath ne '') {
2060: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2061: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2062: my $newprefix = $newloc;
2063: if ($newloc eq 'default') {
2064: $newprefix = 'docs';
2065: }
2066: if ($newdocsdir eq '') {
2067: $newdocsdir = 'default';
2068: }
1.630 raeburn 2069: if (($prefixchg{$suffix}) ||
2070: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2071: ($srcnum{$suffix} ne $coursenum) ||
2072: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2073: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2074: $url =
2075: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2076: &Apache::lonnet::getfile($oldurl));
2077: if ($url eq '/adm/notfound.html') {
2078: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2079: next;
2080: } else {
2081: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2082: $newsubpath =~ s{/+$}{/};
2083: $docmoves{$oldurl} = $newsubpath;
2084: }
1.491 raeburn 2085: }
2086: }
1.597 raeburn 2087: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2088: my $template = $1;
2089: if ($newidx) {
2090: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2091: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2092: }
1.649 raeburn 2093: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2094: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2095: my $marker = (split(m{/},$url))[4];
2096: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2097: my $val = 'no';
2098: if ($toolsettings{'gradable'}) {
2099: $val = 'yes';
2100: }
2101: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2102: 'string_yesno');
2103: &remember_parms($newidx,'gradable','set',$val);
2104: }
1.491 raeburn 2105: }
1.538 raeburn 2106: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2107: ':'.$ext.':normal:res';
2108: push(@LONCAPA::map::order,$newidx);
2109: # Store the result
2110: my ($errtext,$fatal) =
2111: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2112: if ($fatal) {
2113: $save_err .= $errtext;
2114: $allresult = 'fail';
2115: }
1.488 raeburn 2116: }
1.538 raeburn 2117:
1.597 raeburn 2118: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2119: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2120: unless ($allresult eq 'fail') {
2121: my %updated = (
2122: rewrites => \%rewrites,
2123: zombies => \%zombies,
2124: removefrommap => \%removefrommap,
2125: removeparam => \%removeparam,
2126: dbcopies => \%dbcopies,
1.597 raeburn 2127: resdatacopy => \%resdatacopy,
1.538 raeburn 2128: retitles => \%retitles,
2129: );
2130: my %info = (
2131: newsubdir => \%newsubdir,
2132: params => \%params,
2133: );
2134: if ($prefixchg{$suffix}) {
2135: $info{'before'} = $before{$prefixchg{$suffix}};
2136: $info{'after'} = $after{$prefixchg{$suffix}};
2137: }
2138: my %moves = (
2139: copies => \%copies,
2140: docmoves => \%docmoves,
2141: mapmoves => \%mapmoves,
2142: );
2143: (my $result,$msgs{$suffix},my $lockerror) =
2144: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2145: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2146: $url,'paste');
2147: $lockerrors .= $lockerror;
2148: if ($result eq 'ok') {
2149: if ($is_map{$suffix}) {
2150: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2151: $folder.'.'.$container);
2152: if ($fatal) {
2153: $allresult = 'failread';
2154: } else {
2155: if ($#LONCAPA::map::order<1) {
2156: my $idx=&LONCAPA::map::getresidx();
2157: if ($idx<=0) { $idx=1; }
2158: $LONCAPA::map::order[0]=$idx;
2159: $LONCAPA::map::resources[$idx]='';
2160: }
2161: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2162: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2163: ':'.$ext.':normal:res';
2164: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2165:
2166: # Store the result
1.538 raeburn 2167: my ($errtext,$fatal) =
2168: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2169: if ($fatal) {
2170: $save_err .= $errtext;
2171: $allresult = 'failstore';
2172: }
2173: }
2174: }
2175: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2176: push(@toclear,$suffix);
2177: }
2178: }
1.492 raeburn 2179: }
2180: }
1.538 raeburn 2181: &clear_from_buffer(\@toclear,\@currpaste);
2182: my $msgsarray;
2183: foreach my $suffix (keys(%msgs)) {
2184: if (ref($msgs{$suffix}) eq 'ARRAY') {
2185: $msgsarray .= join(',',@{$msgs{$suffix}});
2186: }
2187: }
2188: return ($allresult,$save_err,$msgsarray,$lockerrors);
2189: }
1.533 raeburn 2190:
1.538 raeburn 2191: sub do_buffer_empty {
2192: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2193: if (@currpaste == 0) {
2194: return &mt('Clipboard is already empty');
2195: }
2196: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2197: if (@toclear == 0) {
2198: return &mt('Nothing selected to clear from clipboard');
2199: }
2200: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2201: if ($numdel) {
2202: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2203: } else {
2204: return &mt('Clipboard unchanged');
1.492 raeburn 2205: }
1.538 raeburn 2206: return;
2207: }
2208:
2209: sub clear_from_buffer {
2210: my ($toclear,$currpaste) = @_;
2211: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2212: my %pastebuffer;
2213: map { $pastebuffer{$_} = 1; } @{$currpaste};
2214: my $numdel = 0;
2215: foreach my $suffix (@{$toclear}) {
2216: next if ($suffix =~ /\D/);
2217: next unless (exists($pastebuffer{$suffix}));
2218: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2219: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2220: delete($pastebuffer{$suffix});
2221: $numdel ++;
2222: }
2223: }
2224: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2225: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2226: return $numdel;
1.492 raeburn 2227: }
2228:
2229: sub get_newmap_url {
2230: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2231: $titleref,$allmaps,$newurls) = @_;
2232: my $newurl;
2233: if ($url=~ m{^/uploaded/}) {
2234: $$titleref=&mt('Copy of').' '.$$titleref;
2235: }
2236: my $now = time;
2237: my $suffix=$$.int(rand(100)).$now;
2238: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2239: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2240: my $path = $1;
2241: my $prefix = $2;
2242: my $ancestor = $3;
2243: if (length($ancestor) > 10) {
2244: $ancestor = substr($ancestor,-10,10);
2245: }
2246: my $newid;
2247: if ($prefixchg) {
2248: if ($folder =~ /^supplemental/) {
2249: $prefix =~ s/^default/supplemental/;
2250: } else {
2251: $prefix =~ s/^supplemental/default/;
2252: }
2253: }
2254: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2255: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2256: } else {
2257: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2258: }
2259: my $counter = 0;
2260: my $is_unique = &uniqueness_check($newurl);
2261: if ($folder =~ /^default/) {
2262: if ($allmaps->{$newurl}) {
2263: $is_unique = 0;
2264: }
2265: }
2266: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2267: $counter ++;
2268: $suffix ++;
2269: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2270: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2271: } else {
2272: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2273: }
2274: $is_unique = &uniqueness_check($newurl);
2275: }
2276: if ($is_unique) {
2277: $newurls->{$newurl} = 1;
2278: } else {
2279: if ($url=~/\.page$/) {
2280: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2281: } else {
2282: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2283: }
2284: }
1.329 droeschl 2285: }
1.492 raeburn 2286: return ($newurl);
1.329 droeschl 2287: }
2288:
1.488 raeburn 2289: sub dbcopy {
1.533 raeburn 2290: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2291: my ($url,$result,$errtext);
2292: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2293: $url = $dbref->{'src'};
1.627 raeburn 2294: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2295: my $prefix = $1;
1.627 raeburn 2296: if ($prefix eq 'ext.tool') {
2297: $prefix = 'exttool';
2298: }
1.533 raeburn 2299: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2300: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2301: my $db_name;
2302: my $marker = (split(m{/},$url))[4];
2303: $marker=~s/\D//g;
2304: if ($dbref->{'src'} =~ m{/smppg$}) {
2305: $db_name =
2306: &Apache::lonsimplepage::get_db_name($url,$marker,
2307: $dbref->{'cdom'},
2308: $dbref->{'cnum'});
1.627 raeburn 2309: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2310: $db_name = 'exttool_'.$marker;
1.533 raeburn 2311: } else {
2312: $db_name = 'bulletinpage_'.$marker;
2313: }
2314: my ($suffix,$freedlock,$error) =
2315: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2316: $coursedom,$coursenum,
2317: 'concat');
2318: if (!$suffix) {
2319: if ($prefix eq 'smppg') {
2320: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2321: } elsif ($prefix eq 'exttool') {
2322: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2323: } else {
1.565 bisitz 2324: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2325: }
2326: if ($error) {
2327: $errtext .= '<br />'.$error;
2328: }
2329: } else {
2330: #need to copy the db contents to a new one.
2331: my %contents=&Apache::lonnet::dump($db_name,
2332: $dbref->{'cdom'},
2333: $dbref->{'cnum'});
2334: if (exists($contents{'uploaded.photourl'})) {
2335: my $photo = $contents{'uploaded.photourl'};
2336: my ($subdir,$fname) =
2337: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2338: my $newphoto;
1.533 raeburn 2339: if ($fname ne '') {
2340: my $content = &Apache::lonnet::getfile($photo);
2341: unless ($content eq '-1') {
2342: $env{'form.'.$suffix.'.photourl'} = $content;
2343: $newphoto =
2344: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2345: delete($env{'form.'.$suffix.'.photourl'});
2346: }
2347: }
2348: if ($newphoto =~ m{^/uploaded/}) {
2349: $contents{'uploaded.photourl'} = $newphoto;
2350: }
2351: }
2352: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2353: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2354: delete($contents{'gradable'});
2355: }
1.533 raeburn 2356: $result=&Apache::lonnet::put($db_name,\%contents,
2357: $coursedom,$coursenum);
2358: if ($result eq 'ok') {
1.627 raeburn 2359: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2360: }
2361: }
2362: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2363: $lockerrorsref->{$prefix} =
1.533 raeburn 2364: '<div class="LC_error">'.
2365: &mt('There was a problem removing a lockfile.');
2366: if ($prefix eq 'smppg') {
1.560 raeburn 2367: $lockerrorsref->{$prefix} .=
1.559 raeburn 2368: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2369: } elsif ($prefix eq 'exttool') {
2370: $lockerrorsref->{$prefix} .=
2371: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2372: } else {
1.565 bisitz 2373: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2374: }
1.560 raeburn 2375: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2376: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2377: '</div>';
1.533 raeburn 2378: }
2379: }
2380: } elsif ($url =~ m{/syllabus$}) {
2381: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2382: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2383: if (($dbref->{'cdom'} ne $coursedom) ||
2384: ($dbref->{'cnum'} ne $coursenum)) {
2385: my %contents=&Apache::lonnet::dump('syllabus',
2386: $dbref->{'cdom'},
2387: $dbref->{'cnum'});
2388: $result=&Apache::lonnet::put('syllabus',\%contents,
2389: $coursedom,$coursenum);
2390: }
2391: }
1.488 raeburn 2392: }
2393: }
1.533 raeburn 2394: return ($url,$result,$errtext);
1.488 raeburn 2395: }
2396:
1.597 raeburn 2397: sub copy_templated_files {
2398: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2399: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2400: my $srccontainer = 'sequence';
2401: if ($srcwaspage) {
2402: $srccontainer = 'page';
2403: }
2404: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2405: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2406: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2407: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2408: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2409: $template.'.problem';
2410: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2411: if ($template eq 'simpleproblem') {
2412: $srcprefix .= '.0.';
2413: my $weightprefix = $newprefix;
2414: $newprefix .= '.0.';
2415: my @simpleprobqtypes = qw(radio option string essay numerical);
2416: my $qtype=$srcparms{$srcprefix.'questiontype'};
2417: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2418: my %newdata = (
2419: $newprefix.'questiontype' => $qtype,
2420: );
1.597 raeburn 2421: foreach my $type (@simpleprobqtypes) {
2422: if ($type eq $qtype) {
2423: $newdata{"$weightprefix.$type.weight"}=1;
2424: } else {
2425: $newdata{"$weightprefix.$type.weight"}=0;
2426: }
2427: }
2428: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2429: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2430: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2431: if ($qtype eq 'numerical') {
2432: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2433: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2434: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2435: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2436: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2437: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2438: unless (defined($maxfoils)) { $maxfoils=10; }
2439: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2440: if ($maxfoils<=0) { $maxfoils=10; }
2441: my $randomize=$srcparms{$srcprefix.'randomize'};
2442: unless (defined($randomize)) { $randomize='yes'; }
2443: unless ($randomize eq 'no') { $randomize='yes'; }
2444: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2445: $newdata{$newprefix.'randomize'} = $randomize;
2446: if ($qtype eq 'option') {
2447: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2448: }
2449: for (my $i=1; $i<=10; $i++) {
2450: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2451: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2452: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2453: }
2454:
2455: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2456: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2457: unless (defined($maxfoils)) { $maxfoils=10; }
2458: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2459: if ($maxfoils<=0) { $maxfoils=10; }
2460: my $randomize=$srcparms{$srcprefix.'randomize'};
2461: unless (defined($randomize)) { $randomize='yes'; }
2462: unless ($randomize eq 'no') { $randomize='yes'; }
2463: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2464: $newdata{$newprefix.'randomize'} = $randomize;
2465: if ($qtype eq 'option') {
2466: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2467: }
2468: for (my $i=1; $i<=10; $i++) {
2469: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2470: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2471: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2472: }
2473: } elsif ($qtype eq 'string') {
2474: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2475: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2476: }
2477: if (keys(%newdata)) {
2478: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2479: $coursenum);
2480: if ($putres eq 'ok') {
2481: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2482: }
2483: }
2484: }
2485: }
2486: }
2487:
1.329 droeschl 2488: sub uniqueness_check {
2489: my ($newurl) = @_;
2490: my $unique = 1;
2491: foreach my $res (@LONCAPA::map::order) {
2492: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2493: $url=&LONCAPA::map::qtescape($url);
2494: if ($newurl eq $url) {
2495: $unique = 0;
1.344 bisitz 2496: last;
1.329 droeschl 2497: }
2498: }
2499: return $unique;
2500: }
2501:
1.488 raeburn 2502: sub contained_map_check {
1.627 raeburn 2503: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2504: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2505: my $content = &Apache::lonnet::getfile($url);
2506: unless ($content eq '-1') {
2507: my $parser = HTML::TokeParser->new(\$content);
2508: $parser->attr_encoded(1);
2509: while (my $token = $parser->get_token) {
2510: next if ($token->[0] ne 'S');
2511: if ($token->[1] eq 'resource') {
2512: next if ($token->[2]->{'type'} eq 'zombie');
2513: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2514: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2515: my $srcdom = $1;
2516: unless ($srcdom eq $coursedom) {
2517: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2518: next;
2519: }
2520: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2521: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2522: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2523: next;
2524: }
2525: }
1.492 raeburn 2526: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2527: if ($1 eq 'uploaded') {
2528: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2529: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2530: } else {
1.492 raeburn 2531: if ($allmaps->{$ressrc}) {
1.529 raeburn 2532: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2533: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2534: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2535: } else {
2536: $addedmaps->{$ressrc} = [$url];
2537: }
1.488 raeburn 2538: }
1.627 raeburn 2539: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2540: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2541: }
1.492 raeburn 2542: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2543: if ($folder =~ /^supplemental/) {
1.492 raeburn 2544: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2545: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2546: } else {
2547: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2548: }
1.488 raeburn 2549: }
2550: }
2551: }
2552: }
2553: return;
2554: }
2555:
2556: sub url_paste_fixups {
1.533 raeburn 2557: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2558: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2559: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2560: my $checktitle;
2561: if (($prefixchg) &&
1.492 raeburn 2562: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2563: $checktitle = 1;
2564: }
1.492 raeburn 2565: my $skip;
2566: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2567: my $mapid = $1.$2;
2568: if ($tomove->{$mapid}) {
2569: $skip = 1;
2570: }
2571: }
1.491 raeburn 2572: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2573: return if ($file eq '-1');
2574: my $parser = HTML::TokeParser->new(\$file);
2575: $parser->attr_encoded(1);
1.491 raeburn 2576: my $changed = 0;
1.488 raeburn 2577: while (my $token = $parser->get_token) {
2578: next if ($token->[0] ne 'S');
2579: if ($token->[1] eq 'resource') {
2580: my $ressrc = $token->[2]->{'src'};
2581: next if ($ressrc eq '');
1.491 raeburn 2582: my $id = $token->[2]->{'id'};
1.492 raeburn 2583: my $title = $token->[2]->{'title'};
1.491 raeburn 2584: if ($checktitle) {
2585: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2586: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2587: }
2588: }
1.488 raeburn 2589: next if ($token->[2]->{'type'} eq 'external');
2590: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2591: next if ($skip);
1.532 raeburn 2592: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2593: $changed = 1;
2594: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2595: my $srcdom = $1;
2596: my $srcnum = $2;
1.488 raeburn 2597: my $rem = $3;
1.492 raeburn 2598: my $newurl;
2599: my $mapname;
2600: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2601: my $prefix = $1;
2602: $mapname = $prefix.$2;
2603: if ($tomove->{$mapname}) {
1.533 raeburn 2604: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2605: $srcdom,$srcnum,$allmaps,$rewrites,
2606: $retitles,$copies,$dbcopies,$zombies,
2607: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2608: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2609: next;
2610: } else {
2611: ($newurl,my $error) =
2612: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2613: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2614: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2615: $newsubdir->{$ressrc} = $1;
2616: }
2617: if ($error) {
2618: next;
2619: }
2620: }
2621: }
2622: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2623: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2624:
1.488 raeburn 2625: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2626: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2627: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2628: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2629: $cnum,$srcdom,$srcnum,$allmaps,
2630: $rewrites,$retitles,$copies,$dbcopies,
2631: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2632: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2633: $mapmoves->{$ressrc} = 1;
2634: }
2635: $changed = 1;
1.488 raeburn 2636: } else {
1.532 raeburn 2637: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2638: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2639: $changed = 1;
1.488 raeburn 2640: }
2641: }
1.649 raeburn 2642: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2643: next if ($skip);
1.492 raeburn 2644: my $srcdom = $1;
2645: my $srcnum = $2;
1.649 raeburn 2646: my $rem = $3;
2647: my ($is_exttool,$exttoolchg);
2648: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2649: $is_exttool = 1;
1.649 raeburn 2650: }
1.492 raeburn 2651: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2652: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2653: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2654: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2655: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2656: $changed = 1;
1.649 raeburn 2657: if ($is_exttool) {
2658: $exttoolchg = 1;
2659: }
2660: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2661: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2662: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2663: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2664: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2665: $changed = 1;
2666: $exttoolchg = 1;
2667: }
2668: if (($is_exttool) && ($prefixchg)) {
2669: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2670: if ($exttoolchg) {
2671: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2672: }
2673: }
1.533 raeburn 2674: }
2675: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2676: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2677: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2678: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2679: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2680: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2681: $changed = 1;
1.488 raeburn 2682: }
1.597 raeburn 2683: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2684: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2685: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2686: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2687: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2688: }
1.488 raeburn 2689: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2690: next if ($skip);
2691: my $srcdom = $1;
2692: my $srcnum = $2;
2693: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2694: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2695: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2696: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2697: $changed = 1;
1.488 raeburn 2698: }
2699: }
2700: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2701: next if ($skip);
1.488 raeburn 2702: my $to = $token->[2]->{'to'};
2703: if ($to ne '') {
2704: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2705: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2706: } else {
2707: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2708: }
2709: }
2710: }
2711: }
1.491 raeburn 2712: return $changed;
1.488 raeburn 2713: }
2714:
2715: sub apply_fixups {
1.529 raeburn 2716: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2717: $oldurl,$url,$caller) = @_;
2718: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2719: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2720: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2721: if (ref($updated) eq 'HASH') {
2722: if (ref($updated->{'rewrites'}) eq 'HASH') {
2723: %rewrites = %{$updated->{'rewrites'}};
2724: }
2725: if (ref($updated->{'zombies'}) eq 'HASH') {
2726: %zombies = %{$updated->{'zombies'}};
2727: }
2728: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2729: %removefrommap = %{$updated->{'removefrommap'}};
2730: }
2731: if (ref($updated->{'removeparam'}) eq 'HASH') {
2732: %removeparam = %{$updated->{'removeparam'}};
2733: }
2734: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2735: %dbcopies = %{$updated->{'dbcopies'}};
2736: }
2737: if (ref($updated->{'retitles'}) eq 'HASH') {
2738: %retitles = %{$updated->{'retitles'}};
2739: }
1.597 raeburn 2740: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2741: %resdatacopy = %{$updated->{'resdatacopy'}};
2742: }
1.529 raeburn 2743: }
2744: if (ref($info) eq 'HASH') {
2745: if (ref($info->{'newsubdir'}) eq 'HASH') {
2746: %newsubdir = %{$info->{'newsubdir'}};
2747: }
2748: if (ref($info->{'params'}) eq 'HASH') {
2749: %params = %{$info->{'params'}};
2750: }
2751: if (ref($info->{'before'}) eq 'HASH') {
2752: %before = %{$info->{'before'}};
2753: }
2754: if (ref($info->{'after'}) eq 'HASH') {
2755: %after = %{$info->{'after'}};
2756: }
2757: }
2758: if (ref($moves) eq 'HASH') {
2759: if (ref($moves->{'copies'}) eq 'HASH') {
2760: %copies = %{$moves->{'copies'}};
2761: }
2762: if (ref($moves->{'docmoves'}) eq 'HASH') {
2763: %docmoves = %{$moves->{'docmoves'}};
2764: }
2765: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2766: %mapmoves = %{$moves->{'mapmoves'}};
2767: }
2768: }
2769: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2770: my @allcopies;
1.529 raeburn 2771: if (exists($copies{$key})) {
2772: if (ref($copies{$key}) eq 'HASH') {
2773: my %added;
2774: foreach my $innerkey (keys(%{$copies{$key}})) {
2775: if (($innerkey ne '') && (!$added{$innerkey})) {
2776: push(@allcopies,$innerkey);
2777: $added{$innerkey} = 1;
2778: }
1.491 raeburn 2779: }
1.529 raeburn 2780: undef(%added);
1.491 raeburn 2781: }
2782: }
2783: if ($key eq $oldurl) {
1.529 raeburn 2784: if ((exists($docmoves{$key}))) {
1.532 raeburn 2785: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2786: push(@allcopies,$oldurl);
2787: }
2788: }
2789: }
2790: if (@allcopies > 0) {
2791: foreach my $item (@allcopies) {
1.492 raeburn 2792: my ($relpath,$oldsubdir,$fname) =
2793: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2794: if ($fname ne '') {
2795: my $content = &Apache::lonnet::getfile($item);
2796: unless ($content eq '-1') {
2797: my $storefn;
1.529 raeburn 2798: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2799: $storefn = $docmoves{$key};
1.491 raeburn 2800: } else {
2801: $storefn = $relpath;
2802: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2803: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2804: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2805: }
1.529 raeburn 2806: if ($newsubdir{$key}) {
1.532 raeburn 2807: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2808: }
2809: }
2810: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2811: my $copyurl =
2812: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2813: $storefn.$fname,$content);
2814: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2815: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2816: return &mt('Paste failed: an error occurred copying the file.');
2817: } elsif (ref($errors) eq 'HASH') {
2818: $errors->{$item} = 1;
1.489 raeburn 2819: }
2820: }
1.488 raeburn 2821: }
2822: }
1.491 raeburn 2823: }
2824: }
2825: }
1.529 raeburn 2826: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2827: my $storefn=$key;
2828: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2829: if ($prefixchg && $before{'map'} && $after{'map'}) {
2830: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2831: }
1.529 raeburn 2832: if ($newsubdir{$key}) {
2833: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2834: }
1.491 raeburn 2835: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2836: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2837: ($after{'map'} eq 'default') &&
2838: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2839: $mapcontent = '<map>'."\n".
2840: '<resource id="1" src="" type="start" />'."\n".
2841: '<link from="1" to="2" index="1" />'."\n".
2842: '<resource id="2" src="" type="finish" />'."\n".
2843: '</map>';
2844: }
1.491 raeburn 2845: if ($mapcontent eq '-1') {
2846: if (ref($errors) eq 'HASH') {
2847: $errors->{$key} = 1;
2848: }
2849: } else {
2850: my $newmap =
2851: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2852: $mapcontent);
2853: if ($newmap eq '/adm/notfound.html') {
2854: if (ref($errors) eq 'HASH') {
2855: $errors->{$key} = 1;
1.489 raeburn 2856: }
1.488 raeburn 2857: }
2858: }
2859: }
1.491 raeburn 2860: my %updates;
2861: if ($is_map) {
1.529 raeburn 2862: if (ref($updated) eq 'HASH') {
2863: foreach my $type (keys(%{$updated})) {
2864: if (ref($updated->{$type}) eq 'HASH') {
2865: foreach my $key (keys(%{$updated->{$type}})) {
2866: $updates{$key} = 1;
2867: }
2868: }
2869: }
1.491 raeburn 2870: }
2871: foreach my $key (keys(%updates)) {
1.492 raeburn 2872: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2873: if (ref($rewrites{$key}) eq 'HASH') {
2874: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2875: }
1.529 raeburn 2876: if (ref($retitles{$key}) eq 'HASH') {
2877: %toretitle = %{$retitles{$key}};
1.491 raeburn 2878: }
1.529 raeburn 2879: if (ref($removefrommap{$key}) eq 'HASH') {
2880: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2881: }
1.529 raeburn 2882: if (ref($removeparam{$key}) eq 'HASH') {
2883: %remparam = %{$removeparam{$key}};
1.492 raeburn 2884: }
1.529 raeburn 2885: if (ref($zombies{$key}) eq 'HASH') {
2886: %zombie = %{$zombies{$key}};
1.491 raeburn 2887: }
1.529 raeburn 2888: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2889: foreach my $idx (keys(%{$dbcopies{$key}})) {
2890: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2891: my ($newurl,$result,$errtext) =
2892: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2893: if ($result eq 'ok') {
2894: $newdb{$idx} = $newurl;
2895: } elsif (ref($errors) eq 'HASH') {
2896: $errors->{$key} = 1;
2897: }
2898: push(@msgs,$errtext);
2899: }
1.491 raeburn 2900: }
2901: }
1.597 raeburn 2902: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2903: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2904: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2905: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2906: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2907: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2908: my $template = $1;
2909: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2910: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2911: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2912: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2913: unless ($gotnewmapname) {
2914: ($newmapname) = ($key =~ m{/([^/]+)$});
2915: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2916: if ($newsubdir{$key}) {
2917: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2918: }
2919: $gotnewmapname = 1;
2920: }
1.597 raeburn 2921: my $srcmapinfo = $srcfolder.':'.$idx;
2922: if ($srccontainer eq 'page') {
2923: $srcmapinfo .= ':1';
2924: }
2925: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2926: $cnum,$template,$idx,$newmapname);
2927: }
2928: }
2929: }
2930: }
2931: }
1.529 raeburn 2932: if (ref($params{$key}) eq 'HASH') {
2933: %currparam = %{$params{$key}};
1.492 raeburn 2934: }
2935: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2936: if ($fatal) {
1.533 raeburn 2937: return ($errtext);
1.492 raeburn 2938: }
2939: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2940: if (defined($LONCAPA::map::zombies[$i])) {
2941: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2942: if ($zombie{$i} eq $src) {
1.492 raeburn 2943: undef($LONCAPA::map::zombies[$i]);
2944: }
2945: }
2946: }
1.646 raeburn 2947: my $total = scalar(@LONCAPA::map::order) - 1;
2948: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2949: my $idx = $LONCAPA::map::order[$i];
2950: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2951: my $changed;
1.529 raeburn 2952: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2953: if ((exists($toremove{$idx})) &&
2954: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2955: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2956: if (ref($currparam{$idx}) eq 'ARRAY') {
2957: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2958: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2959: }
2960: }
2961: next;
2962: }
2963: my $origsrc = $src;
1.532 raeburn 2964: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2965: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2966: $changed = 1;
1.491 raeburn 2967: }
1.492 raeburn 2968: }
1.532 raeburn 2969: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2970: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2971: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2972: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2973: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2974: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2975: } else {
1.529 raeburn 2976: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2977: }
1.491 raeburn 2978: }
1.532 raeburn 2979: if ($origsrc =~ /\.(page|sequence)$/) {
2980: if ($newsubdir{$origsrc}) {
1.529 raeburn 2981: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2982: }
1.532 raeburn 2983: } elsif ($newsubdir{$key}) {
2984: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2985: }
2986: }
1.492 raeburn 2987: $changed = 1;
1.533 raeburn 2988: } elsif ($newdb{$idx} ne '') {
2989: $src = $newdb{$idx};
1.492 raeburn 2990: $changed = 1;
2991: }
2992: if ($changed) {
1.538 raeburn 2993: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2994: }
2995: }
2996: }
2997: foreach my $idx (keys(%remparam)) {
2998: if (ref($remparam{$idx}) eq 'ARRAY') {
2999: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3000: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3001: }
3002: }
3003: }
1.533 raeburn 3004: if (values(%lockerrors) > 0) {
3005: $lockmsg = join('<br />',values(%lockerrors));
3006: }
1.491 raeburn 3007: my $storefn;
3008: if ($key eq $oldurl) {
3009: $storefn = $url;
3010: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3011: } else {
3012: $storefn = $key;
3013: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3014: if ($prefixchg && $before{'map'} && $after{'map'}) {
3015: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3016: }
1.529 raeburn 3017: if ($newsubdir{$key}) {
3018: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3019: }
1.491 raeburn 3020: }
1.492 raeburn 3021: my $report;
3022: if ($folder !~ /^supplemental/) {
3023: $report = 1;
3024: }
1.527 raeburn 3025: (my $outtext,$errtext) =
1.492 raeburn 3026: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3027: if ($errtext) {
1.529 raeburn 3028: if ($caller eq 'paste') {
1.533 raeburn 3029: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3030: }
1.491 raeburn 3031: }
3032: }
3033: }
1.533 raeburn 3034: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3035: }
3036:
3037: sub copy_dependencies {
3038: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3039: my $content;
3040: if (ref($contentref)) {
3041: $content = $$contentref;
3042: } else {
3043: $content = &Apache::lonnet::getfile($item);
3044: }
3045: unless ($content eq '-1') {
3046: my $mm = new File::MMagic;
3047: my $mimetype = $mm->checktype_contents($content);
3048: if ($mimetype eq 'text/html') {
3049: my (%allfiles,%codebase,$state);
3050: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3051: if ($res eq 'ok') {
3052: my ($numexisting,$numpathchanges,$existing);
3053: (undef,$numexisting,$numpathchanges,$existing) =
3054: &Apache::loncommon::ask_for_embedded_content(
3055: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3056: {'error_on_invalid_names' => 1,
3057: 'ignore_remote_references' => 1,
3058: 'docs_url' => $item,
3059: 'context' => 'paste'});
3060: if ($numexisting > 0) {
3061: if (ref($existing) eq 'HASH') {
3062: foreach my $dep (keys(%{$existing})) {
3063: my $depfile = $dep;
3064: unless ($depfile =~ m{^\Q$relpath\E}) {
3065: $depfile = $relpath.$dep;
3066: }
3067: my $depcontent = &Apache::lonnet::getfile($depfile);
3068: unless ($depcontent eq '-1') {
3069: my $storedep = $dep;
3070: $storedep =~ s{^\Q$relpath\E}{};
3071: my $dep_url =
3072: &Apache::lonclonecourse::writefile(
3073: $env{'request.course.id'},
3074: $storefn.$storedep,$depcontent);
3075: if ($dep_url eq '/adm/notfound.html') {
3076: if (ref($errors) eq 'HASH') {
3077: $errors->{$depfile} = 1;
3078: }
3079: } else {
3080: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3081: }
3082: }
3083: }
1.488 raeburn 3084: }
3085: }
3086: }
3087: }
3088: }
3089: return;
3090: }
3091:
1.329 droeschl 3092: my %parameter_type = ( 'randompick' => 'int_pos',
3093: 'hiddenresource' => 'string_yesno',
3094: 'encrypturl' => 'string_yesno',
3095: 'randomorder' => 'string_yesno',);
3096: my $valid_parameters_re = join('|',keys(%parameter_type));
3097: # set parameters
3098: sub update_parameter {
1.537 raeburn 3099: if ($env{'form.changeparms'} eq 'all') {
3100: my (@allidx,@allmapidx,%allchecked,%currchecked);
3101: %allchecked = (
3102: 'hiddenresource' => {},
3103: 'encrypturl' => {},
3104: 'randompick' => {},
3105: 'randomorder' => {},
3106: );
3107: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3108: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3109: if ($which eq 'randompick') {
3110: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3111: my ($res,$value) = split(/:/,$item);
3112: if ($value =~ /^\d+$/) {
3113: $allchecked{$which}{$res} = $value;
3114: }
3115: }
3116: } else {
1.539 raeburn 3117: if ($env{'form.all'.$which}) {
3118: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3119: }
1.537 raeburn 3120: }
3121: }
3122: my $haschanges = 0;
3123: foreach my $res (@LONCAPA::map::order) {
3124: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3125: $name=&LONCAPA::map::qtescape($name);
3126: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3127: next unless $url;
1.537 raeburn 3128: my $is_map;
3129: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3130: $is_map = 1;
3131: }
3132: foreach my $which (keys(%allchecked)) {
3133: if (($which eq 'randompick' || $which eq 'randomorder')) {
3134: next if (!$is_map);
3135: }
3136: my $oldvalue = 0;
3137: my $newvalue = 0;
3138: if ($allchecked{$which}{$res}) {
3139: $newvalue = $allchecked{$which}{$res};
3140: }
3141: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3142: if ($which eq 'randompick') {
3143: if ($current =~ /^(\d+)$/) {
3144: $oldvalue = $1;
3145: }
3146: } else {
3147: if ($current =~ /^yes$/i) {
3148: $oldvalue = 1;
3149: }
3150: }
3151: if ($oldvalue ne $newvalue) {
3152: $haschanges = 1;
3153: if ($newvalue) {
3154: my $storeval = 'yes';
3155: if ($which eq 'randompick') {
3156: $storeval = $newvalue;
3157: }
3158: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3159: $storeval,
3160: $parameter_type{$which});
3161: &remember_parms($res,$which,'set',$storeval);
3162: } elsif ($oldvalue) {
3163: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3164: &remember_parms($res,$which,'del');
3165: }
3166: }
3167: }
3168: }
3169: return $haschanges;
3170: } else {
1.588 raeburn 3171: my $haschanges = 0;
3172: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3173:
1.537 raeburn 3174: my $which = $env{'form.changeparms'};
3175: my $idx = $env{'form.setparms'};
1.588 raeburn 3176: my $oldvalue = 0;
3177: my $newvalue = 0;
3178: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3179: if ($which eq 'randompick') {
3180: if ($current =~ /^(\d+)$/) {
3181: $oldvalue = $1;
3182: }
3183: } elsif ($current =~ /^yes$/i) {
3184: $oldvalue = 1;
3185: }
1.537 raeburn 3186: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3187: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3188: : 1;
3189: }
3190: if ($oldvalue ne $newvalue) {
3191: $haschanges = 1;
3192: if ($newvalue) {
3193: my $storeval = 'yes';
3194: if ($which eq 'randompick') {
3195: $storeval = $newvalue;
3196: }
3197: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3198: $parameter_type{$which});
3199: &remember_parms($idx,$which,'set',$storeval);
3200: } else {
3201: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3202: &remember_parms($idx,$which,'del');
3203: }
1.537 raeburn 3204: }
1.588 raeburn 3205: return $haschanges;
1.329 droeschl 3206: }
3207: }
3208:
3209: sub handle_edit_cmd {
3210: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3211: my $haschanges = 0;
1.543 raeburn 3212: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3213: return $haschanges;
1.543 raeburn 3214: }
1.329 droeschl 3215: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3216:
3217: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3218: my ($title, $url, @rrest) = split(':', $ratstr);
3219:
1.538 raeburn 3220: if ($cmd eq 'remove') {
1.329 droeschl 3221: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3222: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3223: &Apache::lonnet::removeuploadedurl($url);
3224: } else {
3225: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3226: }
3227: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3228: $haschanges = 1;
1.329 droeschl 3229: } elsif ($cmd eq 'cut') {
3230: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3231: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3232: $haschanges = 1;
1.344 bisitz 3233: } elsif ($cmd eq 'up'
1.329 droeschl 3234: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3235: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3236: $haschanges = 1;
1.329 droeschl 3237: } elsif ($cmd eq 'down'
3238: && defined($LONCAPA::map::order[$idx+1])) {
3239: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3240: $haschanges = 1;
1.329 droeschl 3241: } elsif ($cmd eq 'rename') {
3242: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3243: if ($comment=~/\S/) {
3244: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3245: $comment.':'.join(':', $url, @rrest);
3246: }
3247: # Devalidate title cache
3248: my $renamed_url=&LONCAPA::map::qtescape($url);
3249: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3250: $haschanges = 1;
3251: } elsif ($cmd eq 'setalias') {
3252: my $newvalue = $env{'form.alias'};
3253: if ($newvalue ne '') {
3254: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3255: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3256: 'string');
3257: &remember_parms($idx,'mapalias','set',$newvalue);
3258: $haschanges = 1;
3259: }
3260: }
3261: } elsif ($cmd eq 'delalias') {
3262: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3263: if ($current ne '') {
3264: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3265: &remember_parms($idx,'mapalias','del');
3266: $haschanges = 1;
3267: }
1.329 droeschl 3268: }
1.633 raeburn 3269: return $haschanges;
1.329 droeschl 3270: }
3271:
3272: sub editor {
1.458 raeburn 3273: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3274: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3275: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3276: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3277: if ($allowed) {
1.519 raeburn 3278: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3279: $is_random_order,$container) =
1.510 raeburn 3280: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3281: $r->print($breadcrumbtrail);
1.519 raeburn 3282: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3283: $container = 'page';
3284: } else {
3285: $container = 'sequence';
1.510 raeburn 3286: }
1.484 raeburn 3287:
1.525 raeburn 3288: my $jumpto;
3289:
3290: unless ($supplementalflag) {
1.546 raeburn 3291: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3292: }
1.484 raeburn 3293:
3294: unless ($allowed) {
3295: $randompick = -1;
3296: }
3297:
1.615 raeburn 3298: my ($errtext,$fatal);
3299: if (($folder eq '') && (!$supplementalflag)) {
3300: if (@LONCAPA::map::order) {
3301: undef(@LONCAPA::map::order);
3302: undef(@LONCAPA::map::resources);
3303: undef(@LONCAPA::map::resparms);
3304: undef(@LONCAPA::map::zombies);
3305: }
3306: $folder = 'default';
3307: $container = 'sequence';
3308: } else {
3309: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3310: $folder.'.'.$container);
3311: return $errtext if ($fatal);
3312: }
1.329 droeschl 3313:
3314: if ($#LONCAPA::map::order<1) {
3315: my $idx=&LONCAPA::map::getresidx();
3316: if ($idx<=0) { $idx=1; }
3317: $LONCAPA::map::order[0]=$idx;
3318: $LONCAPA::map::resources[$idx]='';
3319: }
1.364 bisitz 3320:
1.329 droeschl 3321: # ------------------------------------------------------------ Process commands
3322:
3323: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3324: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3325: # set parameters and change order
3326: &snapshotbefore();
3327:
3328: if (&update_parameter()) {
1.588 raeburn 3329: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3330: return $errtext if ($fatal);
3331: }
3332:
3333: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3334: # change order
3335: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3336: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3337:
3338: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3339: return $errtext if ($fatal);
3340: }
1.364 bisitz 3341:
1.329 droeschl 3342: if ($env{'form.pastemarked'}) {
1.491 raeburn 3343: my %paste_errors;
1.533 raeburn 3344: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3345: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3346: \%paste_errors);
1.541 raeburn 3347: if (ref($pastemsgarray) eq 'ARRAY') {
3348: if (@{$pastemsgarray} > 0) {
3349: $r->print('<p class="LC_info">'.
3350: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3351: '</p>');
3352: }
1.541 raeburn 3353: }
3354: if ($lockerror) {
3355: $r->print('<p class="LC_error">'.
3356: $lockerror.
3357: '</p>');
3358: }
3359: if ($save_error ne '') {
3360: return $save_error;
3361: }
3362: if ($paste_res) {
3363: my %errortext = &Apache::lonlocal::texthash (
3364: fail => 'Storage of folder contents failed',
3365: failread => 'Reading folder contents failed',
3366: failstore => 'Storage of folder contents failed',
3367: );
3368: if ($errortext{$paste_res}) {
3369: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3370: }
1.329 droeschl 3371: }
1.491 raeburn 3372: if (keys(%paste_errors) > 0) {
1.538 raeburn 3373: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3374: &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".
3375: '<ul>'."\n");
3376: foreach my $key (sort(keys(%paste_errors))) {
3377: $r->print('<li>'.$key.'</li>'."\n");
3378: }
3379: $r->print('</ul></p>'."\n");
3380: }
1.538 raeburn 3381: } elsif ($env{'form.clearmarked'}) {
3382: my $output = &do_buffer_empty();
3383: if ($output) {
3384: $r->print('<p class="LC_info">'.$output.'</p>');
3385: }
3386: }
1.329 droeschl 3387:
3388: $r->print($upload_output);
3389:
1.538 raeburn 3390: # Rename, cut, copy or remove a single resource
1.602 raeburn 3391: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3392: my $contentchg;
1.633 raeburn 3393: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3394: $contentchg = 1;
3395: }
3396: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3397: return $errtext if ($fatal);
3398: }
1.538 raeburn 3399:
3400: # Cut, copy and/or remove multiple resources
3401: if ($env{'form.multichange'}) {
3402: my %allchecked = (
3403: cut => {},
3404: remove => {},
3405: );
3406: my $needsupdate;
3407: foreach my $which (keys(%allchecked)) {
3408: $env{'form.multi'.$which} =~ s/,$//;
3409: if ($env{'form.multi'.$which}) {
3410: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3411: if (ref($allchecked{$which}) eq 'HASH') {
3412: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3413: }
3414: }
3415: }
3416: if ($needsupdate) {
3417: my $haschanges = 0;
3418: my %curr_groups = &Apache::longroup::coursegroups();
3419: my $total = scalar(@LONCAPA::map::order) - 1;
3420: for (my $i=$total; $i>=0; $i--) {
3421: my $res = $LONCAPA::map::order[$i];
3422: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3423: $name=&LONCAPA::map::qtescape($name);
3424: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3425: next unless $url;
1.538 raeburn 3426: my %denied =
3427: &action_restrictions($coursenum,$coursedom,$url,
3428: $env{'form.folderpath'},\%curr_groups);
3429: foreach my $which (keys(%allchecked)) {
3430: next if ($denied{$which});
3431: next unless ($allchecked{$which}{$res});
3432: if ($which eq 'remove') {
3433: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3434: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3435: &Apache::lonnet::removeuploadedurl($url);
3436: } else {
3437: &LONCAPA::map::makezombie($res);
3438: }
3439: splice(@LONCAPA::map::order,$i,1);
3440: $haschanges ++;
3441: } elsif ($which eq 'cut') {
3442: &LONCAPA::map::makezombie($res);
3443: splice(@LONCAPA::map::order,$i,1);
3444: $haschanges ++;
3445: }
3446: }
3447: }
3448: if ($haschanges) {
3449: ($errtext,$fatal) =
3450: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3451: return $errtext if ($fatal);
3452: }
3453: }
3454: }
3455:
1.329 droeschl 3456: # Group import/search
3457: if ($env{'form.importdetail'}) {
3458: my @imports;
3459: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3460: if (defined($item)) {
3461: my ($name,$url,$residx)=
1.533 raeburn 3462: map { &unescape($_); } split(/\=/,$item);
3463: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3464: my ($suffix,$errortxt,$locknotfreed) =
3465: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3466: if ($locknotfreed) {
3467: $r->print($locknotfreed);
3468: }
3469: if ($suffix) {
3470: $url =~ s/_new\./_$suffix./;
3471: } else {
3472: return $errortxt;
3473: }
1.533 raeburn 3474: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3475: my $type = $1;
3476: my ($suffix,$errortxt,$locknotfreed) =
3477: &new_timebased_suffix($coursedom,$coursenum,$type);
3478: if ($locknotfreed) {
3479: $r->print($locknotfreed);
3480: }
3481: if ($suffix) {
3482: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3483: } else {
3484: return $errortxt;
3485: }
1.626 raeburn 3486: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3487: my ($suffix,$errortxt,$locknotfreed) =
3488: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3489: if ($locknotfreed) {
3490: $r->print($locknotfreed);
3491: }
3492: if ($suffix) {
3493: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3494: } else {
3495: return $errortxt;
3496: }
1.534 raeburn 3497: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3498: if ($supplementalflag) {
3499: next unless ($1 eq 'supplemental');
3500: if ($folder eq 'supplemental') {
3501: next unless ($2 eq 'default');
3502: } else {
3503: next unless ($folder eq 'supplemental_'.$2);
3504: }
3505: } else {
3506: next unless ($1 eq 'docs');
3507: if ($folder eq 'default') {
3508: next unless ($2 eq 'default');
3509: } else {
3510: next unless ($folder eq 'default_'.$2);
3511: }
3512: }
1.504 raeburn 3513: }
1.329 droeschl 3514: push(@imports, [$name, $url, $residx]);
3515: }
3516: }
1.530 raeburn 3517: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3518: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3519: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3520: return $errtext if ($fatal);
1.529 raeburn 3521: if ($fixuperrors) {
3522: $r->print($fixuperrors);
3523: }
1.329 droeschl 3524: }
3525: # Loading a complete map
3526: if ($env{'form.loadmap'}) {
3527: if ($env{'form.importmap'}=~/\w/) {
3528: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3529: my ($title,$url,$ext,$type)=split(/\:/,$res);
3530: my $idx=&LONCAPA::map::getresidx($url);
3531: $LONCAPA::map::resources[$idx]=$res;
3532: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3533: }
3534: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3535: $folder.'.'.$container,1);
1.329 droeschl 3536: return $errtext if ($fatal);
3537: } else {
3538: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3539:
1.329 droeschl 3540: }
3541: }
3542: &log_differences($plain);
3543: }
3544: # ---------------------------------------------------------------- End commands
3545: # ---------------------------------------------------------------- Print screen
3546: my $idx=0;
3547: my $shown=0;
3548: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3549: $r->print('<div class="LC_Box">'.
1.432 raeburn 3550: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3551: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3552: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3553: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3554: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3555: '</ol>');
1.381 bisitz 3556: if ($randompick>=0) {
3557: $r->print('<p class="LC_warning">'
3558: .&mt('Caution: this folder is set to randomly pick a subset'
3559: .' of resources. Adding or removing resources from this'
3560: .' folder will change the set of resources that the'
3561: .' students see, resulting in spurious or missing credit'
3562: .' for completed problems, not limited to ones you'
3563: .' modify. Do not modify the contents of this folder if'
3564: .' it is in active student use.')
3565: .'</p>'
3566: );
3567: }
3568: if ($is_random_order) {
3569: $r->print('<p class="LC_warning">'
3570: .&mt('Caution: this folder is set to randomly order its'
3571: .' contents. Adding or removing resources from this folder'
3572: .' will change the order of resources shown.')
3573: .'</p>'
3574: );
3575: }
3576: $r->print('</div>');
1.364 bisitz 3577: }
1.381 bisitz 3578:
1.685 raeburn 3579: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3580: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3581: if (ref($supplemental) eq 'HASH') {
3582: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3583: (ref($supplemental->{'ids'}) eq 'HASH')) {
3584: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3585: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3586: if ($supplemental->{'hidden'}->{$mapnum}) {
3587: $ishidden = 1;
3588: }
3589: }
3590: }
3591: }
3592: }
3593:
1.538 raeburn 3594: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3595: %filters = (
1.543 raeburn 3596: canremove => [],
3597: cancut => [],
3598: cancopy => [],
3599: hiddenresource => [],
3600: encrypturl => [],
3601: randomorder => [],
3602: randompick => [],
1.538 raeburn 3603: );
3604: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3605: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3606: foreach my $res (@LONCAPA::map::order) {
3607: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3608: $name=&LONCAPA::map::qtescape($name);
3609: $url=&LONCAPA::map::qtescape($url);
3610: unless ($name) { $name=(split(/\//,$url))[-1]; }
3611: unless ($name) { $idx++; next; }
1.537 raeburn 3612: push(@allidx,$res);
3613: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3614: push(@allmapidx,$res);
3615: }
1.617 raeburn 3616:
1.682 raeburn 3617: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3618: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3619: $idx++;
3620: next;
3621: }
1.682 raeburn 3622: }
1.381 bisitz 3623: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3624: $coursenum,$coursedom,$crstype,
1.538 raeburn 3625: $pathitem,$supplementalflag,$container,
1.620 raeburn 3626: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3627: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3628: $idx++;
3629: $shown++;
1.329 droeschl 3630: }
1.424 onken 3631: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3632:
1.538 raeburn 3633: my $need_save;
1.611 raeburn 3634: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3635: my $toolslink;
1.682 raeburn 3636: if ($allowed || $canedit) {
3637: my $helpitem = 'Navigation_Screen';
3638: if (!$allowed) {
3639: $helpitem = 'Supplemental_Navigation';
3640: }
1.544 raeburn 3641: $toolslink = '<table><tr><td>'
1.520 raeburn 3642: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3643: $helpitem,undef,'RAT')
1.520 raeburn 3644: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3645: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3646: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3647: .'id="LC_content_toolbar_edittoplevel" '
3648: .'class="LC_toolbarItem" '
3649: .'title="'.&mt('Supplemental Content Editor').'">'
3650: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3651: }
1.510 raeburn 3652: if ($shown) {
3653: if ($allowed) {
3654: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3655: .&Apache::loncommon::start_data_table(undef,'contentlist')
3656: .&Apache::loncommon::start_data_table_header_row()
3657: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3658: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3659: .'<th>'.&mt('Document').'</th>'
3660: .'<th colspan="2">'.&mt('Settings').'</th>'
3661: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3662: if ($folder !~ /^supplemental/) {
1.538 raeburn 3663: $lists{'canhide'} = join(',',@allidx);
3664: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3665: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3666: 'randomorder','randompick');
3667: foreach my $item (@possfilters) {
1.538 raeburn 3668: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3669: if (@{$filters{$item}} > 0) {
3670: $lists{$item} = join(',',@{$filters{$item}});
3671: }
1.538 raeburn 3672: }
3673: }
1.537 raeburn 3674: if (@allidx > 0) {
3675: my $path;
3676: if ($env{'form.folderpath'}) {
1.630 raeburn 3677: $path =
1.537 raeburn 3678: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3679: }
1.538 raeburn 3680: if (@allidx > 1) {
1.630 raeburn 3681: $to_show .=
1.538 raeburn 3682: &Apache::loncommon::continue_data_table_row().
3683: '<td colspan="2"> </td>'.
3684: '<td>'.
1.611 raeburn 3685: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3686: '</td>'.
1.633 raeburn 3687: '<td colspan="3"> </td>'.
3688: '<td colspan="2">'.
1.611 raeburn 3689: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3690: '</td>'.
3691: &Apache::loncommon::end_data_table_row();
3692: $need_save = 1;
3693: }
1.537 raeburn 3694: }
3695: }
3696: $to_show .= $output.' '
1.510 raeburn 3697: .&Apache::loncommon::end_data_table()
3698: .'<br style="line-height:2px;" />'
3699: .&Apache::loncommon::end_scrollbox();
3700: } else {
1.520 raeburn 3701: $to_show .= $toolslink
1.510 raeburn 3702: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3703: .$output.' '
3704: .&Apache::loncommon::end_data_table();
1.393 raeburn 3705: }
1.510 raeburn 3706: } else {
1.520 raeburn 3707: if (!$allowed) {
3708: $to_show .= $toolslink;
3709: }
1.615 raeburn 3710: my $noresmsg;
3711: if ($allowed && $hiddentop && !$supplementalflag) {
3712: $noresmsg = &mt('Main Content Hidden');
3713: } else {
3714: $noresmsg = &mt('Currently empty');
3715: }
1.510 raeburn 3716: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3717: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3718: .$noresmsg
1.510 raeburn 3719: .'</div>'
3720: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3721: }
3722: } else {
1.510 raeburn 3723: if ($shown) {
3724: $to_show = '<div>'
3725: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3726: .$output
3727: .&Apache::loncommon::end_data_table()
3728: .'</div>';
3729: } else {
3730: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3731: .&mt('Currently empty')
1.510 raeburn 3732: .'</div>'
3733: }
1.458 raeburn 3734: }
3735: my $tid = 1;
3736: if ($supplementalflag) {
3737: $tid = 2;
1.329 droeschl 3738: }
3739: if ($allowed) {
1.484 raeburn 3740: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3741: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3742: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3743: if ($canedit) {
3744: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3745: }
1.460 raeburn 3746: } else {
3747: $r->print($to_show);
1.329 droeschl 3748: }
3749: return;
3750: }
3751:
1.538 raeburn 3752: sub multiple_check_form {
1.611 raeburn 3753: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3754: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3755: my $disabled;
3756: unless ($canedit) {
3757: $disabled = 'disabled="disabled"';
3758: }
1.538 raeburn 3759: my $output =
3760: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3761: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3762: '<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>'.
3763: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3764: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3765: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3766: if ($caller eq 'settings') {
3767: $output .=
3768: '<table><tr>'.
3769: '<td class="LC_docs_entry_parameter">'.
3770: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3771: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3772: '</label></span></td>'.
3773: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3774: '<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 3775: '</span></td>'.
3776: '</tr>'."\n".
3777: '<tr>'.
3778: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3779: '<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 3780: '</label></span>'.
3781: '</td></tr></table>'."\n";
3782: } else {
3783: $output .=
3784: '<table><tr>'.
3785: '<td class="LC_docs_entry_parameter">'.
3786: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3787: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3788: '</label></span></td>'.
3789: '<td class="LC_docs_entry_parameter">'.
3790: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3791: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3792: '</label></span></td>'."\n".
3793: '<td class="LC_docs_entry_parameter">'.
3794: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3795: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3796: '</label></span></td>'.
3797: '</tr></table>'."\n";
3798: }
3799: $output .=
3800: '</fieldset>'.
3801: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3802: if ($caller eq 'settings') {
3803: $output .=
1.543 raeburn 3804: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3805: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3806: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3807: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3808: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3809: } elsif ($caller eq 'actions') {
3810: $output .=
3811: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3812: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3813: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3814: }
3815: $output .=
3816: '</form>'.
3817: '</div>';
3818: return $output;
3819: }
3820:
1.329 droeschl 3821: sub process_file_upload {
1.552 raeburn 3822: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3823: # upload a file, if present
1.552 raeburn 3824: my $filesize = length($env{'form.uploaddoc'});
3825: if (!$filesize) {
3826: $$upload_output = '<div class="LC_error">'.
3827: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3828: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3829: $filesize).'<br />'.
3830: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3831: '</div>';
3832: return;
3833: }
3834: my $quotatype = 'unofficial';
3835: if ($crstype eq 'Community') {
1.601 raeburn 3836: $quotatype = 'community';
3837: } elsif ($crstype eq 'Placement') {
3838: $quotatype = 'placement';
1.580 raeburn 3839: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3840: $quotatype = 'official';
1.573 raeburn 3841: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3842: $quotatype = 'textbook';
1.552 raeburn 3843: }
3844: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3845: $filesize = int($filesize/1000); #expressed in kb
3846: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3847: $env{'form.uploaddoc.filename'},$filesize,
3848: 'upload',$quotatype);
1.552 raeburn 3849: return if ($$upload_output);
3850: }
1.440 raeburn 3851: my ($parseaction,$showupload,$nextphase,$mimetype);
3852: if ($env{'form.parserflag'}) {
1.329 droeschl 3853: $parseaction = 'parse';
3854: }
3855: my $folder=$env{'form.folder'};
3856: if ($folder eq '') {
3857: $folder='default';
3858: }
3859: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3860: my $errtext='';
3861: my $fatal=0;
3862: my $container='sequence';
1.519 raeburn 3863: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3864: $container='page';
3865: }
3866: ($errtext,$fatal)=
1.534 raeburn 3867: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3868: if ($#LONCAPA::map::order<1) {
3869: $LONCAPA::map::order[0]=1;
3870: $LONCAPA::map::resources[1]='';
3871: }
3872: my $destination = 'docs/';
3873: if ($folder =~ /^supplemental/) {
3874: $destination = 'supplemental/';
3875: }
3876: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3877: $destination .= 'default/';
3878: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3879: $destination .= $2.'/';
3880: }
1.534 raeburn 3881: if ($fatal) {
3882: $$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>';
3883: return;
3884: }
1.440 raeburn 3885: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3886: my $newidx=&LONCAPA::map::getresidx();
3887: $destination .= $newidx;
1.439 raeburn 3888: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3889: $parseaction,$allfiles,
1.440 raeburn 3890: $codebase,undef,undef,undef,undef,
3891: undef,undef,\$mimetype);
3892: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3893: my $stored = $1;
3894: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3895: $stored.'</span>').'</p>';
3896: } else {
3897: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3898:
1.457 raeburn 3899: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3900: return;
3901: }
1.329 droeschl 3902: my $ext='false';
3903: if ($url=~m{^http://}) { $ext='true'; }
3904: $url = &LONCAPA::map::qtunescape($url);
3905: my $comment=$env{'form.comment'};
3906: $comment = &LONCAPA::map::qtunescape($comment);
3907: if ($folder=~/^supplemental/) {
3908: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3909: $env{'user.domain'}.'___&&&___'.$comment;
3910: }
3911:
3912: $LONCAPA::map::resources[$newidx]=
3913: $comment.':'.$url.':'.$ext.':normal:res';
3914: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3915: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3916: $folder.'.'.$container,1);
1.329 droeschl 3917: if ($fatal) {
1.457 raeburn 3918: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3919: return;
1.329 droeschl 3920: } else {
1.440 raeburn 3921: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3922: $$upload_output = $showupload;
1.384 raeburn 3923: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3924: if ($total_embedded > 0) {
1.440 raeburn 3925: my $uploadphase = 'upload_embedded';
3926: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3927: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3928: my ($embedded,$num) =
1.440 raeburn 3929: &Apache::loncommon::ask_for_embedded_content(
3930: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3931: if ($embedded) {
3932: if ($num) {
3933: $$upload_output .=
3934: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3935: $nextphase = $uploadphase;
3936: } else {
3937: $$upload_output .= $embedded;
3938: }
3939: } else {
3940: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3941: }
1.329 droeschl 3942: } else {
1.440 raeburn 3943: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3944: }
1.457 raeburn 3945: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3946: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3947: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3948: $nextphase = 'decompress_uploaded';
3949: my $position = scalar(@LONCAPA::map::order)-1;
3950: my $noextract = &return_to_editor();
3951: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3952: my %archiveitems = (
3953: folderpath => $env{'form.folderpath'},
3954: cmd => $nextphase,
3955: newidx => $newidx,
3956: position => $position,
3957: phase => $nextphase,
1.477 raeburn 3958: comment => $comment,
1.480 raeburn 3959: );
3960: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3961: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3962: $$upload_output = $showupload.
3963: &Apache::loncommon::decompress_form($mimetype,
3964: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3965: \%archiveitems,\@current);
1.329 droeschl 3966: }
3967: }
3968: }
1.440 raeburn 3969: return $nextphase;
1.329 droeschl 3970: }
3971:
1.480 raeburn 3972: sub get_dir_list {
3973: my ($url,$coursenum,$coursedom,$newidx) = @_;
3974: my ($destination,$dir_root) = &embedded_destination();
3975: my ($dirlistref,$listerror) =
3976: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3977: my @dir_lines;
3978: my $dirptr=16384;
3979: if (ref($dirlistref) eq 'ARRAY') {
3980: foreach my $dir_line (sort
3981: {
3982: my ($afile)=split('&',$a,2);
3983: my ($bfile)=split('&',$b,2);
3984: return (lc($afile) cmp lc($bfile));
3985: } (@{$dirlistref})) {
3986: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3987: $filename =~ s/\s+$//;
3988: next if ($filename =~ /^\.\.?$/);
3989: my $isdir = 0;
3990: if ($dirptr&$testdir) {
3991: $isdir = 1;
3992: }
3993: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3994: }
3995: }
3996: return @dir_lines;
3997: }
3998:
1.329 droeschl 3999: sub is_supplemental_title {
4000: my ($title) = @_;
4001: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4002: }
4003:
4004: # --------------------------------------------------------------- An entry line
4005:
4006: sub entryline {
1.501 raeburn 4007: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4008: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4009: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4010: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4011: if (&is_supplemental_title($title)) {
1.488 raeburn 4012: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4013: $encodedtitle=$title;
1.329 droeschl 4014: } else {
4015: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4016: $encodedtitle=$title;
1.329 droeschl 4017: $renametitle=$title;
4018: $foldertitle=$title;
4019: }
4020:
1.611 raeburn 4021: my ($disabled,$readonly,$js_lt);
4022: unless ($canedit) {
4023: $disabled = 'disabled="disabled"';
4024: $readonly = 1;
4025: }
4026:
1.329 droeschl 4027: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4028:
1.329 droeschl 4029: $renametitle=~s/\\/\\\\/g;
4030: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4031: $renametitle=~s/"/%22/g;
1.581 raeburn 4032: $renametitle=~s/ /%20/g;
4033: $oldtitle = $renametitle;
1.576 raeburn 4034: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4035: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4036: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4037: # Edit commands
1.679 raeburn 4038: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4039: if ($env{'form.folderpath'}) {
4040: $esc_path=&escape($env{'form.folderpath'});
4041: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4042: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4043: }
1.505 raeburn 4044: my $isexternal;
1.510 raeburn 4045: if ($residx) {
1.501 raeburn 4046: my $currurl = $url;
4047: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4048: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4049: $isexternal = 1;
4050: }
1.510 raeburn 4051: if (!$supplementalflag) {
4052: my $path = 'uploaded/'.
4053: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4054: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4055: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4056: $residx,
4057: &Apache::lonnet::declutter($currurl));
4058: }
1.501 raeburn 4059: }
1.538 raeburn 4060: my ($renamelink,%lt,$ishash);
4061: if (ref($filtersref) eq 'HASH') {
4062: $ishash = 1;
4063: }
4064:
1.329 droeschl 4065: if ($allowed) {
1.538 raeburn 4066: $form_start = '
4067: <form action="/adm/coursedocs" method="post">
4068: ';
4069: $form_common=(<<END);
4070: <input type="hidden" name="folderpath" value="$path" />
4071: <input type="hidden" name="symb" value="$symb" />
4072: END
4073: $form_param=(<<END);
4074: <input type="hidden" name="setparms" value="$orderidx" />
4075: <input type="hidden" name="changeparms" value="0" />
4076: END
4077: $form_end = '</form>';
4078:
1.329 droeschl 4079: my $incindex=$index+1;
4080: my $selectbox='';
1.471 raeburn 4081: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4082: ((split(/\:/,
1.344 bisitz 4083: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4084: ne '') &&
1.329 droeschl 4085: ((split(/\:/,
1.344 bisitz 4086: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4087: ne '')) {
4088: $selectbox=
4089: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4090: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4091: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4092: if ($i==$incindex) {
1.358 bisitz 4093: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4094: } else {
4095: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4096: }
4097: }
4098: $selectbox.='</select>';
4099: }
1.501 raeburn 4100: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4101: 'up' => 'Move Up',
4102: 'dw' => 'Move Down',
4103: 'rm' => 'Remove',
4104: 'ct' => 'Cut',
4105: 'rn' => 'Rename',
1.501 raeburn 4106: 'cp' => 'Copy',
1.633 raeburn 4107: 'da' => 'Unset alias',
4108: 'sa' => 'Set alias',
1.501 raeburn 4109: 'ex' => 'External Resource',
1.598 raeburn 4110: 'et' => 'External Tool',
1.501 raeburn 4111: 'ed' => 'Edit',
4112: 'pr' => 'Preview',
4113: 'sv' => 'Save',
4114: 'ul' => 'URL',
1.611 raeburn 4115: 'ti' => 'Title',
1.618 raeburn 4116: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4117: );
1.538 raeburn 4118: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4119: $env{'form.folderpath'},
4120: $currgroups);
1.517 raeburn 4121: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4122: my $skip_confirm = 0;
1.603 raeburn 4123: my $confirm_removal = 0;
1.329 droeschl 4124: if ( $folder =~ /^supplemental/
4125: || ($url =~ m{( /smppg$
4126: |/syllabus$
4127: |/aboutme$
4128: |/navmaps$
4129: |/bulletinboard$
1.626 raeburn 4130: |/ext\.tool$
1.505 raeburn 4131: |\.html$)}x)
4132: || $isexternal) {
1.329 droeschl 4133: $skip_confirm = 1;
4134: }
1.603 raeburn 4135: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4136: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4137: $confirm_removal = 1;
4138: }
1.633 raeburn 4139: if ($url =~ /$LONCAPA::assess_re/) {
4140: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4141: }
1.329 droeschl 4142:
1.538 raeburn 4143: if ($denied{'copy'}) {
1.543 raeburn 4144: $copylink=(<<ENDCOPY)
1.507 raeburn 4145: <span style="visibility: hidden;">$lt{'cp'}</span>
4146: ENDCOPY
4147: } else {
1.538 raeburn 4148: my $formname = 'edit_copy_'.$orderidx;
4149: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4150: $copylink=(<<ENDCOPY);
1.538 raeburn 4151: <form name="$formname" method="post" action="/adm/coursedocs">
4152: $form_common
1.611 raeburn 4153: <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 4154: $form_end
1.329 droeschl 4155: ENDCOPY
1.538 raeburn 4156: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4157: push(@{$filtersref->{'cancopy'}},$orderidx);
4158: }
1.329 droeschl 4159: }
1.538 raeburn 4160: if ($denied{'cut'}) {
1.507 raeburn 4161: $cutlink=(<<ENDCUT);
4162: <span style="visibility: hidden;">$lt{'ct'}</span>
4163: ENDCUT
4164: } else {
1.538 raeburn 4165: my $formname = 'edit_cut_'.$orderidx;
4166: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4167: $cutlink=(<<ENDCUT);
1.538 raeburn 4168: <form name="$formname" method="post" action="/adm/coursedocs">
4169: $form_common
1.542 raeburn 4170: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4171: <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 4172: $form_end
1.329 droeschl 4173: ENDCUT
1.538 raeburn 4174: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4175: push(@{$filtersref->{'cancut'}},$orderidx);
4176: }
1.329 droeschl 4177: }
1.538 raeburn 4178: if ($denied{'remove'}) {
1.507 raeburn 4179: $removelink=(<<ENDREM);
4180: <span style="visibility: hidden;">$lt{'rm'}</a>
4181: ENDREM
4182: } else {
1.538 raeburn 4183: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4184: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4185: $removelink=(<<ENDREM);
1.538 raeburn 4186: <form name="$formname" method="post" action="/adm/coursedocs">
4187: $form_common
1.542 raeburn 4188: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4189: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4190: <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 4191: $form_end
1.497 raeburn 4192: ENDREM
1.538 raeburn 4193: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4194: push(@{$filtersref->{'canremove'}},$orderidx);
4195: }
1.497 raeburn 4196: }
1.551 raeburn 4197: $renamelink=(<<ENDREN);
1.581 raeburn 4198: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4199: ENDREN
1.611 raeburn 4200: my ($uplink,$downlink);
4201: if ($canedit) {
4202: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4203: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4204: } else {
4205: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4206: $downlink = $uplink;
4207: }
1.329 droeschl 4208: $line.=(<<END);
4209: <td>
1.379 bisitz 4210: <div class="LC_docs_entry_move">
1.611 raeburn 4211: <a href="$uplink">
1.501 raeburn 4212: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4213: </a>
4214: </div>
4215: <div class="LC_docs_entry_move">
1.611 raeburn 4216: <a href="$downlink">
1.501 raeburn 4217: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4218: </a>
4219: </div>
1.329 droeschl 4220: </td>
4221: <td>
4222: $form_start
1.538 raeburn 4223: $form_param
1.478 raeburn 4224: $form_common
1.329 droeschl 4225: $selectbox
4226: $form_end
4227: </td>
1.540 raeburn 4228: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4229: $removelink
1.329 droeschl 4230: $cutlink
4231: $copylink
4232: </td>
4233: END
4234: }
4235: # Figure out what kind of a resource this is
4236: my ($extension)=($url=~/\.(\w+)$/);
4237: my $uploaded=($url=~/^\/*uploaded\//);
4238: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4239: my $isfolder;
4240: my $ispage;
4241: my $containerarg;
1.615 raeburn 4242: my $folderurl;
1.685 raeburn 4243: my $plainurl;
1.329 droeschl 4244: if ($uploaded) {
1.472 raeburn 4245: if (($extension eq 'sequence') || ($extension eq 'page')) {
4246: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4247: $containerarg = $1;
1.472 raeburn 4248: if ($extension eq 'sequence') {
4249: $icon=$iconpath.'navmap.folder.closed.gif';
4250: $isfolder=1;
4251: } else {
4252: $icon=$iconpath.'page.gif';
4253: $ispage=1;
4254: }
1.615 raeburn 4255: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4256: if ($allowed) {
4257: $url='/adm/coursedocs?';
4258: } else {
4259: $url='/adm/supplemental?';
4260: }
1.329 droeschl 4261: } else {
1.685 raeburn 4262: $plainurl = $url;
1.329 droeschl 4263: }
4264: }
1.364 bisitz 4265:
1.621 raeburn 4266: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4267: my $orig_url = $url;
1.340 raeburn 4268: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4269: if ($container eq 'page') {
4270: $url=~s{^http(|s)(:|:)//}{/ext/};
4271: } else {
4272: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4273: }
1.501 raeburn 4274: if (!$supplementalflag && $residx && $symb) {
4275: if ((!$isfolder) && (!$ispage)) {
4276: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4277: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4278: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4279: } else {
4280: $url=&Apache::lonnet::clutter($url);
4281: }
1.501 raeburn 4282: if ($url=~/^\/*uploaded\//) {
4283: $url=~/\.(\w+)$/;
4284: my $embstyle=&Apache::loncommon::fileembstyle($1);
4285: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4286: $url='/adm/wrapper'.$url;
4287: } elsif ($embstyle eq 'ssi') {
4288: #do nothing with these
4289: } elsif ($url!~/\.(sequence|page)$/) {
4290: $url='/adm/coursedocs/showdoc'.$url;
4291: }
1.623 raeburn 4292: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4293: my $wrapped = $1;
4294: my $exturl = $2;
1.668 raeburn 4295: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4296: $url='/adm/wrapper'.$url;
4297: }
4298: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4299: $nomodal = 1;
4300: }
1.626 raeburn 4301: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4302: $url='/adm/wrapper'.$url;
1.621 raeburn 4303: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4304: if (($ENV{'SERVER_PORT'} == 443) &&
4305: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4306: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4307: $url .= '?usehttp=1';
4308: }
1.621 raeburn 4309: $nomodal = 1;
4310: }
1.598 raeburn 4311: }
1.696 raeburn 4312: my $checkencrypt;
1.680 raeburn 4313: if (!$env{'request.role.adv'}) {
1.615 raeburn 4314: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4315: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4316: $checkencrypt = 1;
1.620 raeburn 4317: } elsif (ref($navmapref)) {
1.615 raeburn 4318: unless (ref($$navmapref)) {
4319: $$navmapref = Apache::lonnavmaps::navmap->new();
4320: }
4321: if (ref($$navmapref)) {
4322: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4323: $checkencrypt = 1;
1.615 raeburn 4324: }
4325: }
4326: }
1.680 raeburn 4327: }
4328: if ($checkencrypt) {
4329: my $currenc = $env{'request.enc'};
4330: $env{'request.enc'} = 1;
4331: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 4332: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 4333: if (&Apache::lonnet::symbverify($symb,$url)) {
4334: $url = $shownurl;
4335: } else {
4336: $url = '';
4337: }
4338: $env{'request.enc'} = $currenc;
4339: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4340: $shownsymb = $symb;
4341: if ($isexternal) {
4342: $url =~ s/\#[^#]+$//;
4343: if ($container eq 'page') {
4344: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4345: }
1.612 raeburn 4346: }
1.696 raeburn 4347: } else {
4348: $url = '';
1.680 raeburn 4349: }
4350: unless ($env{'request.role.adv'}) {
4351: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4352: $url = '';
4353: }
4354: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4355: $url = '';
4356: $hiddenres = 1;
4357: }
4358: }
1.696 raeburn 4359: if (($url ne '') && ($shownsymb ne '')) {
4360: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4361: }
1.329 droeschl 4362: }
1.621 raeburn 4363: } elsif ($supplementalflag) {
1.610 raeburn 4364: if ($isexternal) {
4365: if ($url =~ /^([^#]+)#([^#]+)$/) {
4366: $url = $1;
4367: $anchor = $2;
1.623 raeburn 4368: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4369: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4370: if ($hostname ne '') {
4371: $url = 'http://'.$hostname.$url;
4372: }
4373: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4374: }
4375: $nomodal = 1;
4376: }
1.610 raeburn 4377: }
1.621 raeburn 4378: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4379: if (($ENV{'SERVER_PORT'} == 443) &&
4380: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4381: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4382: if ($hostname ne '') {
4383: $url = 'http://'.$hostname.$url;
4384: }
4385: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4386: }
1.621 raeburn 4387: $nomodal = 1;
4388: }
1.686 raeburn 4389: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4390: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4391: unless ($embstyle eq 'ssi') {
4392: if (($embstyle eq 'img')
4393: || ($embstyle eq 'emb')
4394: || ($embstyle eq 'wrp')) {
4395: $url='/adm/wrapper'.$url;
4396: } elsif ($url !~ /\.(sequence|page)$/) {
4397: $url='/adm/coursedocs/showdoc'.$url;
4398: }
4399: }
1.610 raeburn 4400: }
1.685 raeburn 4401: unless ($allowed && $env{'request.role.adv'}) {
4402: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4403: $hiddenres = 1;
4404: }
4405: }
1.329 droeschl 4406: }
1.615 raeburn 4407: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4408: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4409: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4410: my $foldername=&escape($foldertitle);
4411: my $folderpath=$env{'form.folderpath'};
4412: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4413: if (!$allowed && $supplementalflag) {
1.519 raeburn 4414: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4415: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4416: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4417: $hiddenfolder = 1;
1.682 raeburn 4418: }
1.510 raeburn 4419: } else {
1.617 raeburn 4420: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4421: 'parameter_randompick'))[0];
4422: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4423: 'parameter_randomorder'))[0]=~/^yes$/i);
4424: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4425: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4426: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4427: 'parameter_encrypturl'))[0]=~/^yes$/i);
4428: unless ($hiddenmap) {
1.620 raeburn 4429: if (ref($navmapref)) {
4430: unless (ref($$navmapref)) {
4431: $$navmapref = Apache::lonnavmaps::navmap->new();
4432: }
4433: if (ref($$navmapref)) {
4434: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4435: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4436: unless (@resources) {
4437: $hiddenmap = 1;
4438: unless ($env{'request.role.adv'}) {
4439: $url = '';
4440: $hiddenfolder = 1;
4441: }
1.617 raeburn 4442: }
1.615 raeburn 4443: }
4444: }
4445: }
4446: }
1.617 raeburn 4447: unless ($encryptmap) {
1.620 raeburn 4448: if ((ref($navmapref)) && (ref($$navmapref))) {
4449: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4450: $encryptmap = 1;
4451: }
1.617 raeburn 4452: }
4453: }
1.630 raeburn 4454:
1.617 raeburn 4455: # Append randompick number, hidden, and encrypted with ":" to foldername,
4456: # so it gets transferred between levels
4457: $folderpath.=$containerarg.'&'.$foldername.
4458: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4459: unless ($url eq '') {
1.612 raeburn 4460: $url.='folderpath='.&escape($folderpath);
4461: }
1.510 raeburn 4462: my $rpckchk;
4463: if ($rpicknum) {
4464: $rpckchk = ' checked="checked"';
1.543 raeburn 4465: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4466: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4467: }
1.510 raeburn 4468: }
1.537 raeburn 4469: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4470: $rand_pick_text =
1.478 raeburn 4471: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4472: $form_param."\n".
1.478 raeburn 4473: $form_common."\n".
1.611 raeburn 4474: '<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 4475: if ($rpicknum ne '') {
4476: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4477: }
1.537 raeburn 4478: $rand_pick_text .= '</span></span>'.
4479: $form_end;
1.543 raeburn 4480: my $ro_set;
1.617 raeburn 4481: if ($randorder) {
1.543 raeburn 4482: $ro_set = 'checked="checked"';
4483: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4484: push(@{$filtersref->{'randomorder'}},$orderidx);
4485: }
4486: }
1.564 raeburn 4487: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4488: $rand_order_text =
1.537 raeburn 4489: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4490: $form_param."\n".
1.537 raeburn 4491: $form_common."\n".
1.611 raeburn 4492: '<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 4493: $form_end;
1.510 raeburn 4494: }
1.509 raeburn 4495: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4496: my $isexttool;
1.626 raeburn 4497: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4498: $url='/adm/wrapper'.$url;
4499: $isexttool = 1;
4500: }
1.510 raeburn 4501: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4502: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4503: if ($title) {
1.687 raeburn 4504: $url .= '&title='.$encodedtitle;
1.510 raeburn 4505: }
1.598 raeburn 4506: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4507: $url .= '&idx='.$orderidx;
4508: }
1.610 raeburn 4509: if ($anchor ne '') {
4510: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4511: }
1.329 droeschl 4512: }
1.519 raeburn 4513: my ($tdalign,$tdwidth);
1.501 raeburn 4514: if ($allowed) {
1.630 raeburn 4515: my $fileloc =
1.501 raeburn 4516: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4517: if ($isexternal) {
1.630 raeburn 4518: ($editlink,$extresform) =
1.611 raeburn 4519: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4520: undef,undef,undef,undef,undef,undef,
4521: undef,$disabled);
1.626 raeburn 4522: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4523: ($editlink,$extresform) =
4524: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4525: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4526: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4527: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4528: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4529: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4530: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4531: my $suppanchor;
4532: if ($supplementalflag) {
4533: $suppanchor = $anchor;
4534: }
1.630 raeburn 4535: my $jscall =
1.501 raeburn 4536: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4537: $switchserver,
1.503 raeburn 4538: $forceedit,
1.679 raeburn 4539: undef,$symb,$shownsymb,
1.511 raeburn 4540: &escape($env{'form.folderpath'}),
1.622 raeburn 4541: $renametitle,$hostname,
4542: '','',1,$suppanchor);
1.501 raeburn 4543: if ($jscall) {
1.518 raeburn 4544: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4545: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4546: }
4547: }
4548: }
1.519 raeburn 4549: $tdalign = ' align="right" valign="top"';
4550: $tdwidth = ' width="80%"';
1.329 droeschl 4551: }
1.408 raeburn 4552: my $reinit;
4553: if ($crstype eq 'Community') {
4554: $reinit = &mt('(re-initialize community to access)');
4555: } else {
4556: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4557: }
4558: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4559: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4560: $line.= '<br />';
4561: if ($curralias ne '') {
4562: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4563: $lt{'da'}.'</a></span>';
4564: } else {
4565: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4566: $lt{'sa'}.'</a></span>';
4567: }
4568: }
4569: $line.='</td><td>';
1.685 raeburn 4570: my ($link,$nolink);
1.472 raeburn 4571: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4572: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4573: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4574: $nolink = 1;
4575: }
4576: }
4577: if ($nolink) {
4578: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4579: } else {
4580: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4581: }
1.469 www 4582: } elsif ($url) {
1.610 raeburn 4583: if ($anchor ne '') {
4584: if ($supplementalflag) {
4585: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4586: } else {
4587: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4588: }
4589: }
1.622 raeburn 4590: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4591: $link = 'http://'.$hostname.$url;
4592: } else {
4593: $link = $url;
4594: }
1.659 raeburn 4595: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4596: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4597: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4598: $nolink = 1;
4599: }
4600: }
4601: if ($nolink) {
4602: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4603: } elsif ($nomodal) {
1.621 raeburn 4604: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4605: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4606: } else {
4607: $line.=&Apache::loncommon::modal_link($link,
4608: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4609: }
1.469 www 4610: } else {
4611: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4612: }
1.519 raeburn 4613: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4614: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4615: if ($nolink) {
4616: $line.=$title;
4617: } else {
4618: $line.='<a href="'.$url.'">'.$title.'</a>';
4619: }
1.682 raeburn 4620: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4621: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4622: my $editurl = $url;
4623: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4624: $line .= ' '.'<a href="'.$editurl.'">'.
4625: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4626: '</a>';
4627: }
4628: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4629: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4630: }
1.469 www 4631: } elsif ($url) {
1.685 raeburn 4632: if ($nolink) {
4633: $line.=$title;
4634: } elsif ($nomodal) {
1.621 raeburn 4635: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4636: $title.'</a>';
4637: } else {
4638: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4639: }
1.617 raeburn 4640: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4641: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4642: } else {
4643: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4644: }
1.633 raeburn 4645: if (($allowed) && ($curralias ne '')) {
4646: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4647: } else {
4648: $line .= $extresform;
4649: }
4650: $line .= '</td>';
1.478 raeburn 4651: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4652: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4653: if ($uploaded && $url && !$isfolder && !$ispage) {
4654: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4655: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4656: }
4657: }
1.682 raeburn 4658: if ($allowed) {
4659: my %lt=&Apache::lonlocal::texthash(
4660: 'hd' => 'Hidden',
4661: 'ec' => 'URL hidden');
4662: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4663: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4664: $hidtext = ' checked="checked"';
1.694 raeburn 4665: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 4666: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4667: }
4668: }
1.682 raeburn 4669: $formhidden = 'edit_hiddenresource_'.$orderidx;
4670: $line.=(<<ENDPARMS);
1.329 droeschl 4671: <td class="LC_docs_entry_parameter">
1.537 raeburn 4672: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4673: $form_param
1.478 raeburn 4674: $form_common
1.611 raeburn 4675: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4676: $form_end
1.682 raeburn 4677: ENDPARMS
4678: if ($folder =~/^supplemental/) {
4679: $line.= "\n <td>";
4680: } else {
4681: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4682: $enctext = ' checked="checked"';
4683: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4684: push(@{$filtersref->{'encrypturl'}},$orderidx);
4685: }
4686: }
4687: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4688: $line.=(<<ENDPARMS);
1.458 raeburn 4689: <br />
1.537 raeburn 4690: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4691: $form_param
1.478 raeburn 4692: $form_common
1.611 raeburn 4693: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4694: $form_end
4695: </td>
1.478 raeburn 4696: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4697: $rand_order_text</td>
1.329 droeschl 4698: ENDPARMS
1.682 raeburn 4699: }
1.329 droeschl 4700: }
1.379 bisitz 4701: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4702: return $line;
4703: }
4704:
1.538 raeburn 4705: sub action_restrictions {
4706: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4707: my %denied = (
4708: cut => 0,
4709: copy => 0,
4710: remove => 0,
4711: );
4712: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4713: # no copy for published maps
4714: $denied{'copy'} = 1;
1.597 raeburn 4715: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4716: unless ($1 eq 'simpleproblem') {
4717: $denied{'copy'} = 1;
4718: }
4719: $denied{'cut'} = 1;
1.538 raeburn 4720: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4721: if ($folderpath =~ /^default&[^\&]+$/) {
4722: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4723: $denied{'remove'} = 1;
4724: }
4725: $denied{'cut'} = 1;
4726: $denied{'copy'} = 1;
4727: }
4728: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4729: my $group = $1;
4730: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4731: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4732: $denied{'remove'} = 1;
4733: }
4734: }
4735: $denied{'cut'} = 1;
4736: $denied{'copy'} = 1;
4737: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4738: my $group = $1;
4739: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4740: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4741: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4742: if (keys(%groupsettings) > 0) {
4743: $denied{'remove'} = 1;
4744: }
4745: $denied{'cut'} = 1;
4746: $denied{'copy'} = 1;
4747: }
4748: }
4749: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4750: my $group = $1;
4751: if ($url =~ /group_boards_\Q$group\E/) {
4752: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4753: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4754: if (keys(%groupsettings) > 0) {
4755: if (ref($groupsettings{'functions'}) eq 'HASH') {
4756: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4757: $denied{'remove'} = 1;
4758: }
4759: }
4760: }
4761: $denied{'cut'} = 1;
4762: $denied{'copy'} = 1;
4763: }
4764: }
4765: }
4766: return %denied;
4767: }
4768:
1.533 raeburn 4769: sub new_timebased_suffix {
1.538 raeburn 4770: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4771: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4772: if ($type eq 'paste') {
4773: $prefix = $type;
4774: $namespace = 'courseeditor';
1.587 raeburn 4775: $idtype = 'addcode';
1.538 raeburn 4776: } elsif ($type eq 'map') {
1.533 raeburn 4777: $prefix = 'docs';
4778: if ($area eq 'supplemental') {
4779: $prefix = 'supp';
4780: }
4781: $prefix .= $container;
4782: $namespace = 'uploadedmaps';
4783: } else {
4784: $prefix = $type;
4785: $namespace = 'templated';
1.504 raeburn 4786: }
4787: my ($suffix,$freedlock,$error) =
1.587 raeburn 4788: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4789: if (!$suffix) {
1.538 raeburn 4790: if ($type eq 'paste') {
4791: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4792: } elsif ($type eq 'map') {
1.533 raeburn 4793: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4794: } elsif ($type eq 'smppg') {
4795: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4796: } elsif ($type eq 'exttool') {
4797: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4798: } else {
1.565 bisitz 4799: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4800: }
1.504 raeburn 4801: if ($error) {
4802: $errtext .= '<br />'.$error;
4803: }
4804: }
4805: if ($freedlock ne 'ok') {
1.630 raeburn 4806: $locknotfreed =
1.533 raeburn 4807: '<div class="LC_error">'.
4808: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4809: if ($type eq 'paste') {
1.591 raeburn 4810: if ($freedlock eq 'nolock') {
4811: $locknotfreed =
4812: '<div class="LC_error">'.
4813: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4814:
1.593 droeschl 4815: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4816: } else {
4817: $locknotfreed .=
4818: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4819: }
1.538 raeburn 4820: } elsif ($type eq 'map') {
1.591 raeburn 4821: $locknotfreed .=
4822: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4823: } elsif ($type eq 'smppg') {
4824: $locknotfreed .=
4825: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4826: } elsif ($type eq 'exttool') {
4827: $locknotfreed .=
4828: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4829: } else {
4830: $locknotfreed .=
1.565 bisitz 4831: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4832: }
1.538 raeburn 4833: unless ($type eq 'paste') {
4834: $locknotfreed .=
1.560 raeburn 4835: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4836: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4837: }
4838: $locknotfreed .= '</div>';
1.504 raeburn 4839: }
4840: return ($suffix,$errtext,$locknotfreed);
4841: }
4842:
1.329 droeschl 4843: =pod
4844:
4845: =item tiehash()
4846:
4847: tie the hash
4848:
4849: =cut
4850:
4851: sub tiehash {
4852: my ($mode)=@_;
4853: $hashtied=0;
4854: if ($env{'request.course.fn'}) {
4855: if ($mode eq 'write') {
4856: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4857: &GDBM_WRCREAT(),0640)) {
4858: $hashtied=2;
4859: }
4860: } else {
4861: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4862: &GDBM_READER(),0640)) {
4863: $hashtied=1;
4864: }
4865: }
1.364 bisitz 4866: }
1.329 droeschl 4867: }
4868:
4869: sub untiehash {
4870: if ($hashtied) { untie %hash; }
4871: $hashtied=0;
4872: return OK;
4873: }
4874:
4875:
4876:
4877:
4878: sub checkonthis {
1.637 raeburn 4879: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4880: $url=&unescape($url);
4881: $alreadyseen{$url}=1;
4882: $r->rflush();
4883: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4884: $r->print("\n<br />");
4885: if ($level==0) {
4886: $r->print("<br />");
4887: }
4888: for (my $i=0;$i<=$level*5;$i++) {
4889: $r->print(' ');
4890: }
4891: $r->print('<a href="'.$url.'" target="cat">'.
4892: ($title?$title:$url).'</a> ');
4893: if ($url=~/^\/res\//) {
1.637 raeburn 4894: my $updated;
4895: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4896: ($url !~ /\.\d+\.\w+$/)) {
4897: $updated = &Apache::lonnet::remove_stale_resfile($url);
4898: }
1.329 droeschl 4899: my $result=&Apache::lonnet::repcopy(
4900: &Apache::lonnet::filelocation('',$url));
4901: if ($result eq 'ok') {
4902: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4903: if ($updated) {
4904: $r->print('<br />');
4905: for (my $i=0;$i<=$level*5;$i++) {
4906: $r->print(' ');
4907: }
4908: $r->print('- '.&mt('Outdated copy removed'));
4909: }
1.329 droeschl 4910: $r->rflush();
4911: &Apache::lonnet::countacc($url);
4912: $url=~/\.(\w+)$/;
4913: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4914: $r->print('<br />');
4915: $r->rflush();
4916: for (my $i=0;$i<=$level*5;$i++) {
4917: $r->print(' ');
4918: }
4919: $r->print('- '.&mt('Rendering:').' ');
4920: my ($errorcount,$warningcount)=split(/:/,
4921: &Apache::lonnet::ssi_body($url,
4922: ('grade_target'=>'web',
4923: 'return_only_error_and_warning_counts' => 1)));
4924: if (($errorcount) ||
4925: ($warningcount)) {
4926: if ($errorcount) {
1.369 bisitz 4927: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4928: &mt('[quant,_1,error]',$errorcount).'</span>');
4929: }
4930: if ($warningcount) {
4931: $r->print('<span class="LC_warning">'.
4932: &mt('[quant,_1,warning]',$warningcount).'</span>');
4933: }
4934: } else {
4935: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4936: }
4937: $r->rflush();
4938: }
4939: my $dependencies=
4940: &Apache::lonnet::metadata($url,'dependencies');
4941: foreach my $dep (split(/\,/,$dependencies)) {
4942: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4943: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4944: }
4945: }
4946: } elsif ($result eq 'unavailable') {
4947: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4948: } elsif ($result eq 'not_found') {
4949: unless ($url=~/\$/) {
1.521 bisitz 4950: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4951: } else {
1.366 bisitz 4952: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4953: }
4954: } else {
4955: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4956: }
1.637 raeburn 4957: if (($updated) && ($result ne 'ok')) {
4958: $r->print('<br />'.&mt('Outdated copy removed'));
4959: }
1.329 droeschl 4960: }
4961: }
4962: }
4963:
4964:
4965:
4966: =pod
4967:
4968: =item list_symbs()
4969:
1.485 raeburn 4970: List Content Identifiers
1.329 droeschl 4971:
4972: =cut
4973:
4974: sub list_symbs {
4975: my ($r) = @_;
4976:
1.408 raeburn 4977: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4978: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4979: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4980: $r->print(&startContentScreen('tools'));
1.329 droeschl 4981: my $navmap = Apache::lonnavmaps::navmap->new();
4982: if (!defined($navmap)) {
4983: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4984: '<div class="LC_error">'.
4985: &mt('Unable to retrieve information about course contents').
4986: '</div>');
1.408 raeburn 4987: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4988: } else {
1.484 raeburn 4989: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4990: &Apache::loncommon::start_data_table().
4991: &Apache::loncommon::start_data_table_header_row().
4992: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4993: &Apache::loncommon::end_data_table_header_row()."\n");
4994: my $count;
1.329 droeschl 4995: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4996: $r->print(&Apache::loncommon::start_data_table_row().
4997: '<td>'.$res->compTitle().'</td>'.
4998: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4999: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5000: $count ++;
5001: }
5002: if (!$count) {
5003: $r->print(&Apache::loncommon::start_data_table_row().
5004: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5005: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5006: }
1.484 raeburn 5007: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5008: }
1.521 bisitz 5009: $r->print(&endContentScreen());
1.329 droeschl 5010: }
5011:
1.651 raeburn 5012: sub short_urls {
5013: my ($r,$canedit) = @_;
5014: my $crstype = &Apache::loncommon::course_type();
5015: my $formname = 'shortenurl';
5016: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5017: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5018: $r->print(&startContentScreen('tools'));
5019: my ($navmap,$errormsg) =
5020: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5021: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5022: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5023: my (%maps,%resources,%titles);
5024: if (!ref($navmap)) {
5025: $r->print($errormsg.
5026: &endContentScreen());
5027: return '';
5028: } else {
1.652 raeburn 5029: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5030: $r->rflush();
5031: my $readonly;
5032: if ($canedit) {
1.671 raeburn 5033: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5034: if ($numnew) {
5035: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5036: }
5037: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5038: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5039: foreach my $error (@{$errors}) {
5040: $r->print('<li>'.$error.'</li>');
5041: }
5042: $r->print('</ul><br />');
5043: }
5044: } else {
5045: $readonly = 1;
5046: }
5047: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5048: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5049: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5050: }
5051: $r->print(&endContentScreen());
5052: }
5053:
1.637 raeburn 5054: sub contentverifyform {
5055: my ($r) = @_;
5056: my $crstype = &Apache::loncommon::course_type();
5057: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5058: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5059: $r->print(&startContentScreen('tools'));
5060: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5061: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5062: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5063: ' <span class="LC_nobreak">'.
5064: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5065: &mt('No').'</label>'.(' 'x2).
5066: '<label><input type="radio" name="checkstale" value="1" />'.
5067: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5068: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5069: '<input type="hidden" value="1" name="tools" />'.
5070: '<input type="hidden" value="1" name="verify" /></p></form>');
5071: $r->print(&endContentScreen());
5072: return;
5073: }
1.329 droeschl 5074:
5075: sub verifycontent {
1.637 raeburn 5076: my ($r,$checkstale) = @_;
1.408 raeburn 5077: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5078: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5079: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5080: $r->print(&startContentScreen('tools'));
5081: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5082: $hashtied=0;
5083: undef %alreadyseen;
5084: %alreadyseen=();
5085: &tiehash();
1.484 raeburn 5086:
1.329 droeschl 5087: foreach my $key (keys(%hash)) {
5088: if ($hash{$key}=~/\.(page|sequence)$/) {
5089: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5090: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5091: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5092: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5093: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5094: }
5095: }
5096: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5097: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5098: }
5099: }
5100: &untiehash();
1.442 www 5101: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5102: $r->print(&endContentScreen());
1.329 droeschl 5103: }
5104:
5105: sub devalidateversioncache {
5106: my $src=shift;
5107: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5108: &Apache::lonnet::clutter($src));
5109: }
5110:
5111: sub checkversions {
1.611 raeburn 5112: my ($r,$canedit) = @_;
1.408 raeburn 5113: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5114: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5115: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5116: $r->print(&startContentScreen('tools'));
1.442 www 5117:
1.329 droeschl 5118: my $header='';
5119: my $startsel='';
5120: my $monthsel='';
5121: my $weeksel='';
5122: my $daysel='';
5123: my $allsel='';
5124: my %changes=();
5125: my $starttime=0;
5126: my $haschanged=0;
5127: my %setversions=&Apache::lonnet::dump('resourceversions',
5128: $env{'course.'.$env{'request.course.id'}.'.domain'},
5129: $env{'course.'.$env{'request.course.id'}.'.num'});
5130:
5131: $hashtied=0;
5132: &tiehash();
1.611 raeburn 5133: if ($canedit) {
5134: my %newsetversions=();
5135: if ($env{'form.setmostrecent'}) {
5136: $haschanged=1;
5137: foreach my $key (keys(%hash)) {
5138: if ($key=~/^ids\_(\/res\/.+)$/) {
5139: $newsetversions{$1}='mostrecent';
5140: &devalidateversioncache($1);
5141: }
5142: }
5143: } elsif ($env{'form.setcurrent'}) {
5144: $haschanged=1;
5145: foreach my $key (keys(%hash)) {
5146: if ($key=~/^ids\_(\/res\/.+)$/) {
5147: my $getvers=&Apache::lonnet::getversion($1);
5148: if ($getvers>0) {
5149: $newsetversions{$1}=$getvers;
5150: &devalidateversioncache($1);
5151: }
5152: }
1.329 droeschl 5153: }
1.611 raeburn 5154: } elsif ($env{'form.setversions'}) {
5155: $haschanged=1;
5156: foreach my $key (keys(%env)) {
5157: if ($key=~/^form\.set_version_(.+)$/) {
5158: my $src=$1;
5159: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5160: $newsetversions{$src}=$env{$key};
5161: &devalidateversioncache($src);
5162: }
5163: }
1.329 droeschl 5164: }
1.611 raeburn 5165: }
5166: if ($haschanged) {
5167: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5168: $env{'course.'.$env{'request.course.id'}.'.domain'},
5169: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5170: $r->print(&Apache::loncommon::confirmwrapper(
5171: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5172: } else {
5173: $r->print(&Apache::loncommon::confirmwrapper(
5174: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5175: }
1.611 raeburn 5176: &mark_hash_old();
5177: }
5178: &changewarning($r,'');
1.329 droeschl 5179: }
5180: if ($env{'form.timerange'} eq 'all') {
5181: # show all documents
1.549 raeburn 5182: $header=&mt('All content in '.$crstype);
1.521 bisitz 5183: $allsel=' selected="selected"';
1.329 droeschl 5184: foreach my $key (keys(%hash)) {
5185: if ($key=~/^ids\_(\/res\/.+)$/) {
5186: my $src=$1;
5187: $changes{$src}=1;
5188: }
5189: }
5190: } else {
5191: # show documents which changed
5192: %changes=&Apache::lonnet::dump
5193: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5194: $env{'course.'.$env{'request.course.id'}.'.num'});
5195: my $firstkey=(keys(%changes))[0];
5196: unless ($firstkey=~/^error\:/) {
5197: unless ($env{'form.timerange'}) {
5198: $env{'form.timerange'}=604800;
5199: }
5200: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5201: .&mt('seconds');
5202: if ($env{'form.timerange'}==-1) {
5203: $seltext='since start of course';
1.521 bisitz 5204: $startsel=' selected="selected"';
1.329 droeschl 5205: $env{'form.timerange'}=time;
5206: }
5207: $starttime=time-$env{'form.timerange'};
5208: if ($env{'form.timerange'}==2592000) {
5209: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5210: $monthsel=' selected="selected"';
1.329 droeschl 5211: } elsif ($env{'form.timerange'}==604800) {
5212: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5213: $weeksel=' selected="selected"';
1.329 droeschl 5214: } elsif ($env{'form.timerange'}==86400) {
5215: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5216: $daysel=' selected="selected"';
1.329 droeschl 5217: }
5218: $header=&mt('Content changed').' '.$seltext;
5219: } else {
5220: $header=&mt('No content modifications yet.');
5221: }
5222: }
5223: %setversions=&Apache::lonnet::dump('resourceversions',
5224: $env{'course.'.$env{'request.course.id'}.'.domain'},
5225: $env{'course.'.$env{'request.course.id'}.'.num'});
5226: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5227: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5228: 'lm' => 'Version changes since last Month',
5229: 'lw' => 'Version changes since last Week',
5230: 'sy' => 'Version changes since Yesterday',
5231: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5232: 'cd' => 'Change display',
1.329 droeschl 5233: 'sd' => 'Display',
5234: 'fi' => 'File',
5235: 'md' => 'Modification Date',
5236: 'mr' => 'Most recently published Version',
1.408 raeburn 5237: 've' => 'Version used in '.$crstype,
5238: 'vu' => 'Set Version to be used in '.$crstype,
5239: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5240: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5241: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5242: 'di' => 'Differences',
1.484 raeburn 5243: 'save' => 'Save changes',
5244: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5245: 'act' => 'Actions');
1.611 raeburn 5246: my ($disabled,$readonly);
5247: unless ($canedit) {
5248: $disabled = 'disabled="disabled"';
5249: $readonly = 1;
5250: }
1.329 droeschl 5251: $r->print(<<ENDHEADERS);
1.484 raeburn 5252: <h4 class="LC_info">$header</h4>
1.329 droeschl 5253: <form action="/adm/coursedocs" method="post">
5254: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5255: <div class="LC_left_float">
1.479 golterma 5256: <fieldset>
1.484 raeburn 5257: <legend>$lt{'cd'}</legend>
1.329 droeschl 5258: <select name="timerange">
1.521 bisitz 5259: <option value='all'$allsel>$lt{'al'}</option>
5260: <option value="-1"$startsel>$lt{'st'}</option>
5261: <option value="2592000"$monthsel>$lt{'lm'}</option>
5262: <option value="604800"$weeksel>$lt{'lw'}</option>
5263: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5264: </select>
5265: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5266: </fieldset>
5267: </div>
5268: <div class="LC_left_float">
5269: <fieldset>
5270: <legend>$lt{'act'}</legend>
1.611 raeburn 5271: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5272: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5273: </fieldset>
5274: </div>
5275: <br clear="all" />
5276: <hr />
5277: <h4>$lt{'vers'}</h4>
1.329 droeschl 5278: ENDHEADERS
1.479 golterma 5279: #number of columns for version history
1.571 raeburn 5280: my %changedbytime;
5281: foreach my $key (keys(%changes)) {
5282: #excludes not versionable problems from resource version history:
5283: next if ($key =~ /^\/res\/lib\/templates/);
5284: my $chg;
5285: if ($env{'form.timerange'} eq 'all') {
5286: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5287: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5288: } else {
5289: $chg = $changes{$key};
5290: next if ($chg < $starttime);
5291: }
5292: push(@{$changedbytime{$chg}},$key);
5293: }
5294: if (keys(%changedbytime) == 0) {
5295: &untiehash();
5296: $r->print(&mt('No content changes in imported content in specified time frame').
5297: &endContentScreen());
5298: return;
5299: }
1.479 golterma 5300: $r->print(
1.611 raeburn 5301: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5302: &Apache::loncommon::start_data_table().
5303: &Apache::loncommon::start_data_table_header_row().
5304: '<th>'.&mt('Resources').'</th>'.
5305: "<th>$lt{'mr'}</th>".
5306: "<th>$lt{'ve'}</th>".
5307: "<th>$lt{'vu'}</th>".
5308: '<th>'.&mt('History').'</th>'.
5309: &Apache::loncommon::end_data_table_header_row()
5310: );
1.571 raeburn 5311: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5312: foreach my $key (sort(@{$changedbytime{$chg}})) {
5313: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5314: my $currentversion=&Apache::lonnet::getversion($key);
5315: if ($currentversion<0) {
5316: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5317: }
5318: my $linkurl=&Apache::lonnet::clutter($key);
5319: $r->print(
5320: &Apache::loncommon::start_data_table_row().
5321: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5322: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5323: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5324: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5325: '<td align="right">'
5326: );
5327: # Used in course
5328: my $usedversion=$hash{'version_'.$linkurl};
5329: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5330: if ($usedversion != $currentversion) {
1.479 golterma 5331: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5332: } else {
1.479 golterma 5333: $r->print($usedversion);
5334: }
1.329 droeschl 5335: } else {
1.521 bisitz 5336: $r->print($currentversion);
1.329 droeschl 5337: }
1.571 raeburn 5338: $r->print('</td><td title="'.$lt{'vu'}.'">');
5339: # Set version
5340: $r->print(&Apache::loncommon::select_form(
5341: $setversions{$linkurl},
5342: 'set_version_'.$linkurl,
5343: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5344: '' => '',
5345: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5346: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5347: my $lastold=1;
5348: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5349: my $url=$root.'.'.$prevvers.'.'.$extension;
5350: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5351: $lastold=$prevvers;
5352: }
5353: }
5354: $r->print('</td>');
5355: # List all available versions
5356: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5357: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5358: my $url=$root.'.'.$prevvers.'.'.$extension;
5359: $r->print(
5360: '<span class="LC_nobreak">'
5361: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5362: .&mt('Version [_1]',$prevvers).'</a>'
5363: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5364: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5365: .')');
5366: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5367: $r->print(
5368: ' <a href="/adm/diff?filename='.
5369: &Apache::lonnet::clutter($root.'.'.$extension).
5370: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5371: '" target="diffs">'.&mt('Diffs').'</a>');
5372: }
5373: $r->print('</span><br />');
1.329 droeschl 5374: }
1.571 raeburn 5375: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5376: }
1.329 droeschl 5377: }
1.521 bisitz 5378: $r->print(
5379: &Apache::loncommon::end_data_table().
1.611 raeburn 5380: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5381: '</form>'
5382: );
1.329 droeschl 5383:
5384: &untiehash();
1.521 bisitz 5385: $r->print(&endContentScreen());
1.571 raeburn 5386: return;
1.329 droeschl 5387: }
5388:
5389: sub mark_hash_old {
5390: my $retie_hash=0;
5391: if ($hashtied) {
5392: $retie_hash=1;
5393: &untiehash();
5394: }
5395: &tiehash('write');
5396: $hash{'old'}=1;
5397: &untiehash();
5398: if ($retie_hash) { &tiehash(); }
5399: }
5400:
5401: sub is_hash_old {
5402: my $untie_hash=0;
5403: if (!$hashtied) {
5404: $untie_hash=1;
5405: &tiehash();
5406: }
5407: my $return=$hash{'old'};
5408: if ($untie_hash) { &untiehash(); }
5409: return $return;
5410: }
5411:
5412: sub changewarning {
5413: my ($r,$postexec,$message,$url)=@_;
5414: if (!&is_hash_old()) { return; }
5415: my $pathvar='folderpath';
5416: my $path=&escape($env{'form.folderpath'});
5417: if (!defined($url)) {
5418: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5419: }
5420: my $course_type = &Apache::loncommon::course_type();
5421: if (!defined($message)) {
5422: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5423: }
1.653 raeburn 5424: my $windowname = 'loncapaclient';
5425: if ($env{'request.lti.login'}) {
5426: $windowname .= 'lti';
5427: }
1.329 droeschl 5428: $r->print("\n\n".
1.372 bisitz 5429: '<script type="text/javascript">'."\n".
5430: '// <![CDATA['."\n".
5431: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5432: '// ]]>'."\n".
1.369 bisitz 5433: '</script>'."\n".
1.653 raeburn 5434: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5435: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5436: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5437: &mt($message,' <input type="hidden" name="'.
5438: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5439: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5440: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5441: }
5442:
5443:
5444: sub init_breadcrumbs {
1.571 raeburn 5445: my ($form,$text,$help)=@_;
1.329 droeschl 5446: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5447: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5448: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5449: faq=>273,
5450: bug=>'Instructor Interface',
1.571 raeburn 5451: help => $help});
1.329 droeschl 5452: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5453: text=>$text,
5454: faq=>273,
5455: bug=>'Instructor Interface'});
5456: }
5457:
1.441 www 5458: # subroutine to list form elements
5459: sub create_list_elements {
5460: my @formarr = @_;
5461: my $list = '';
1.501 raeburn 5462: foreach my $button (@formarr){
5463: foreach my $picture (keys(%{$button})) {
5464: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5465: }
5466: }
5467: return $list;
5468: }
1.329 droeschl 5469:
1.441 www 5470: # subroutine to create ul from list elements
5471: sub create_form_ul {
5472: my $list = shift;
5473: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5474: return $ul;
5475: }
1.329 droeschl 5476:
1.442 www 5477: #
5478: # Start tabs
5479: #
5480:
5481: sub startContentScreen {
1.484 raeburn 5482: my ($mode) = @_;
5483: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5484: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5485: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5486: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5487: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5488: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5489: } else {
1.549 raeburn 5490: $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 5491: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5492: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5493: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5494: }
5495: $output .= "\n".'</ul>'."\n";
5496: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5497: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5498: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5499: return $output;
1.442 www 5500: }
5501:
5502: #
5503: # End tabs
5504: #
5505:
5506: sub endContentScreen {
1.484 raeburn 5507: return '</div></div></div>';
1.442 www 5508: }
1.329 droeschl 5509:
1.446 www 5510: sub supplemental_base {
1.548 raeburn 5511: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5512: }
5513:
1.329 droeschl 5514: sub handler {
5515: my $r = shift;
5516: &Apache::loncommon::content_type($r,'text/html');
5517: $r->send_http_header;
5518: return OK if $r->header_only;
1.484 raeburn 5519:
5520: # get course data
1.408 raeburn 5521: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5522: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5523: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5524:
1.606 raeburn 5525: # get docroot
5526: my $londocroot = $r->dir_config('lonDocRoot');
5527:
1.484 raeburn 5528: # graphics settings
5529: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5530:
1.443 www 5531: #
1.329 droeschl 5532: # --------------------------------------------- Initialize help topics for this
5533: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5534: 'Adding_External_Resource','Adding_External_Tool',
5535: 'Navigate_Content','Adding_Folders','Docs_Overview',
5536: 'Load_Map','Supplemental','Score_Upload_Form',
5537: 'Adding_Pages','Importing_LON-CAPA_Resource',
5538: 'Importing_IMS_Course','Uploading_From_Harddrive',
5539: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5540: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5541: }
5542: # Composite help files
5543: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5544: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5545: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5546: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5547: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5548: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5549: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5550: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5551: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5552: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5553:
1.611 raeburn 5554: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5555: # does this user have privileges to modify content.
5556: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5557: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5558: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5559: $allowed = 1;
1.682 raeburn 5560: }
5561: $canedit = 1;
5562: $canview = 1;
5563: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5564: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5565: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5566: $allowed = 1;
5567: }
1.682 raeburn 5568: $canview = 1;
1.611 raeburn 5569: }
5570: unless ($canedit) {
5571: $disabled = ' disabled="disabled"';
1.472 raeburn 5572: }
1.582 raeburn 5573: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5574: if ($env{'form.inhibitmenu'}) {
5575: unless ($env{'form.inhibitmenu'} eq 'yes') {
5576: delete($env{'form.inhibitmenu'});
5577: }
5578: }
5579:
1.582 raeburn 5580: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5581: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5582: if (!$canedit) {
5583: &verifycontent($r);
5584: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5585: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5586: text=>'Results',
5587: faq=>273,
5588: bug=>'Instructor Interface'});
5589: &verifycontent($r,$env{'form.checkstale'});
5590: } else {
5591: &contentverifyform($r);
5592: }
1.329 droeschl 5593: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5594: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5595: &list_symbs($r);
1.651 raeburn 5596: } elsif ($allowed && $env{'form.shorturls'}) {
5597: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5598: &short_urls($r,$canedit);
1.329 droeschl 5599: } elsif ($allowed && $env{'form.docslog'}) {
5600: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5601: my $folder = $env{'form.folder'};
5602: if ($folder eq '') {
5603: $folder='default';
5604: }
1.611 raeburn 5605: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5606: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5607: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5608: &checkversions($r,$canedit);
5609: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5610: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5611: &dumpcourse($r);
1.611 raeburn 5612: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5613: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5614: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5615: } else {
1.611 raeburn 5616: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5617: $noendpage = 1;
5618: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5619: if ($redirect) {
5620: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5621: my $container = 'sequence';
5622: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5623: $is_random_order,$container) =
5624: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5625: my (@folders)=split('&',$env{'form.folderpath'});
5626: $env{'form.foldername'}=&unescape(pop(@folders));
5627: my $folder=pop(@folders);
5628: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5629: $folder.'.'.$container);
5630: my $warning;
5631: if ($fatal) {
5632: if ($container eq 'page') {
5633: $warning = &mt('An error occurred retrieving the contents of the current page.');
5634: } else {
5635: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5636: }
5637: } else {
5638: my $url = $redirect;
5639: my $srcfile = $londocroot.$url;
5640: $url =~ s{^/priv/}{/res/};
5641: my $targetfile = $londocroot.$url;
5642: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5643: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5644: $env{'form.folder'} = $folder;
5645: &snapshotbefore();
5646: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5647: my $ext = 'false';
5648: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5649: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5650: ':'.$ext.':normal:res';
5651: push(@LONCAPA::map::order,$newidx);
5652: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5653: 'string_yesno');
5654: &remember_parms($newidx,'hiddenresource','set','yes');
5655: ($errtext,$fatal) =
5656: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5657: &log_differences($plain);
5658: &mark_hash_old();
5659: $r->internal_redirect($redirect);
5660: return OK;
5661: }
1.654 raeburn 5662: } else {
5663: $r->internal_redirect($redirect);
1.606 raeburn 5664: }
5665: }
5666: }
1.445 www 5667: #
5668: # Done catching special calls
1.484 raeburn 5669: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5670: # Get the parameters that may be needed
5671: #
5672: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5673: ['folderpath','title',
1.519 raeburn 5674: 'forcesupplement','forcestandard',
1.510 raeburn 5675: 'tools','symb','command','supppath']);
1.445 www 5676:
1.635 raeburn 5677: foreach my $item ('forcesupplement','forcestandard','tools') {
5678: next if ($env{'form.'.$item} eq '');
5679: unless ($env{'form.'.$item} eq '1') {
5680: delete($env{'form.'.$item});
5681: }
5682: }
5683:
5684: if ($env{'form.command'}) {
5685: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5686: delete($env{'form.command'});
5687: }
5688: }
5689:
5690: if ($env{'form.symb'}) {
5691: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5692: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5693: delete($env{'form.symb'});
5694: }
5695: }
5696:
1.445 www 5697: # standard=1: this is a "new-style" course with an uploaded map as top level
5698: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5699:
5700: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5701:
1.484 raeburn 5702: # Decide whether this should display supplemental or main content or utilities
1.445 www 5703: # supplementalflag=1: show supplemental documents
5704: # supplementalflag=0: show standard documents
1.484 raeburn 5705: # toolsflag=1: show utilities
1.445 www 5706:
1.561 raeburn 5707: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5708: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5709: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5710: $supplementalflag=0;
5711: }
5712: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5713: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5714: unless ($allowed) { $supplementalflag=1; }
5715: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5716: my $toolsflag=0;
5717: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5718:
1.635 raeburn 5719: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5720: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5721: }
5722:
1.685 raeburn 5723: my $backto_supppath;
1.635 raeburn 5724: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5725: if ($supplementalflag && $allowed) {
5726: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5727: }
1.635 raeburn 5728: }
5729:
1.329 droeschl 5730: my $script='';
5731: my $showdoc=0;
1.457 raeburn 5732: my $addentries = {};
1.475 raeburn 5733: my $container;
1.329 droeschl 5734: my $containertag;
1.508 raeburn 5735: my $pathitem;
1.598 raeburn 5736: my %ltitools;
1.699 ! raeburn 5737: my $posslti;
1.617 raeburn 5738: my $hiddentop;
1.615 raeburn 5739: my $navmap;
1.617 raeburn 5740: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5741:
1.464 www 5742: # Do we directly jump somewhere?
1.525 raeburn 5743: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5744: if ($env{'form.symb'} ne '') {
1.522 raeburn 5745: $env{'form.folderpath'}=
1.617 raeburn 5746: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5747: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5748: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5749: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5750: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5751: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5752: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5753: }
1.472 raeburn 5754: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5755: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5756: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5757: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5758: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5759: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5760: } elsif ($env{'form.command'} eq 'contents') {
5761: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5762: } elsif ($env{'form.command'} eq 'home') {
5763: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5764: }
5765:
1.525 raeburn 5766:
1.445 www 5767: # Where do we store these for when we come back?
5768: my $stored_folderpath='docs_folderpath';
5769: if ($supplementalflag) {
5770: $stored_folderpath='docs_sup_folderpath';
5771: }
1.464 www 5772:
1.519 raeburn 5773: # No folderpath, and in edit mode, see if we have something stored
5774: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5775: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5776: {'folderpath' => 'scalar'});
1.615 raeburn 5777:
5778: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5779: if ($supplementalflag) {
5780: undef($env{'form.folderpath'}) if ($1 eq 'default');
5781: } else {
5782: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5783: }
5784: } else {
1.523 raeburn 5785: undef($env{'form.folderpath'});
5786: }
1.677 raeburn 5787: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5788: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5789: }
1.329 droeschl 5790: }
1.446 www 5791:
5792: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5793: if (!$allowed) {
1.446 www 5794: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5795: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5796: }
5797: }
1.446 www 5798: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5799: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5800: $env{'form.folderpath'} = &supplemental_base()
5801: .'&'.
1.329 droeschl 5802: $env{'form.folderpath'};
5803: }
1.685 raeburn 5804: # If allowed and user's role is not advanced check folderpath is not hidden
5805: my $hidden_and_empty;
1.687 raeburn 5806: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5807: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5808: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5809: my $folder = $pathitems[-2];
5810: if ($folder eq '') {
5811: undef($env{'form.folderpath'});
5812: } else {
5813: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5814: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5815: $folderurl .= '.page';
5816: } else {
5817: $folderurl .= '.sequence';
5818: }
1.685 raeburn 5819: if ($supplementalflag) {
5820: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5821: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5822: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5823: if (ref($supplemental) eq 'HASH') {
5824: my ($suppmap,$suppmapnum);
5825: if ($folder eq 'supplemental') {
5826: $suppmap = 'default';
5827: $suppmapnum = 0;
5828: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5829: $suppmap = $1;
5830: $suppmapnum = $suppmap;
5831: }
5832: if ($hiddenfolder) {
5833: my $hascontent;
5834: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5835: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5836: $hascontent = 1;
5837: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5838: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5839: if ($id =~ /^$suppmapnum\:/) {
5840: $hascontent = 1;
5841: last;
5842: }
5843: }
5844: }
5845: last if ($hascontent);
5846: }
5847: unless ($hascontent) {
5848: if ($foldername ne '') {
5849: $hidden_and_empty = $foldername;
5850: } else {
5851: $hidden_and_empty = $folder;
5852: }
5853: }
5854: }
5855: }
5856: } else {
5857: unless (ref($navmap)) {
5858: $navmap = Apache::lonnavmaps::navmap->new();
5859: }
5860: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5861: $foldername = &HTML::Entities::decode(&unescape($foldername));
5862: if (ref($navmap)) {
5863: if ($hiddenfolder ||
5864: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5865: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5866: unless (@resources) {
5867: if ($foldername ne '') {
5868: $hidden_and_empty = $foldername;
5869: } else {
5870: $hidden_and_empty = $folder;
5871: }
5872: }
5873: }
5874: }
1.617 raeburn 5875: }
1.685 raeburn 5876: if ($hidden_and_empty ne '') {
5877: splice(@pathitems,-2);
5878: if (@pathitems) {
5879: $env{'form.folderpath'} = join('&',@pathitems);
5880: } else {
5881: undef($env{'form.folderpath'});
1.615 raeburn 5882: }
5883: }
5884: }
5885: }
5886:
1.446 www 5887: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5888: unless ($env{'form.folderpath'}) {
1.446 www 5889: if ($supplementalflag) {
5890: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5891: } elsif ($allowed) {
5892: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5893: }
1.472 raeburn 5894: }
1.446 www 5895:
1.445 www 5896: # Store this
1.484 raeburn 5897: unless ($toolsflag) {
1.615 raeburn 5898: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5899: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5900: {'folderpath' => 'scalar'});
1.510 raeburn 5901: }
1.519 raeburn 5902: my $folderpath;
1.484 raeburn 5903: if ($env{'form.folderpath'}) {
1.519 raeburn 5904: $folderpath = $env{'form.folderpath'};
5905: my (@folders)=split('&',$env{'form.folderpath'});
5906: $env{'form.foldername'}=&unescape(pop(@folders));
5907: if ($env{'form.foldername'} =~ /\:1$/) {
5908: $container = 'page';
5909: } else {
5910: $container = 'sequence';
5911: }
5912: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5913: } else {
1.519 raeburn 5914: if ($env{'form.folder'} eq '' ||
5915: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5916: if ($env{'form.folder'} eq 'supplemental') {
5917: $folderpath=&supplemental_base();
5918: } elsif (!$hiddentop) {
5919: $folderpath='default&'.
5920: &escape(&mt('Main Content').':::::');
5921: }
1.484 raeburn 5922: }
5923: }
1.519 raeburn 5924: $containertag = '<input type="hidden" name="folderpath" value="" />';
5925: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5926: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5927: $showdoc='/'.$1;
5928: }
5929: if ($showdoc) { # got called in sequence from course
5930: $allowed=0;
5931: } else {
1.611 raeburn 5932: if ($canedit) {
1.484 raeburn 5933: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5934: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5935: }
5936: }
1.329 droeschl 5937: }
5938:
1.344 bisitz 5939: # get personal data
1.329 droeschl 5940: my $uname=$env{'user.name'};
5941: my $udom=$env{'user.domain'};
5942: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5943:
5944: if ($allowed) {
1.484 raeburn 5945: if ($toolsflag) {
5946: $script .= &inject_data_js();
5947: my ($home,$other,%outhash)=&authorhosts();
5948: if (!$home && $other) {
5949: my @hosts;
5950: foreach my $aurole (keys(%outhash)) {
5951: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5952: push(@hosts,$outhash{$aurole});
5953: }
5954: }
5955: $script .= &dump_switchserver_js(@hosts);
5956: }
1.458 raeburn 5957: } else {
1.570 raeburn 5958: my $tid = 1;
1.484 raeburn 5959: my @tabids;
5960: if ($supplementalflag) {
1.655 raeburn 5961: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5962: $tid = 2;
1.484 raeburn 5963: } else {
5964: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5965: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5966: unshift(@tabids,'001');
5967: push(@tabids,('dd1','ee1'));
5968: }
1.458 raeburn 5969: }
1.484 raeburn 5970: my $tabidstr = join("','",@tabids);
1.699 ! raeburn 5971: my (%domtools,%crstools);
! 5972: my %tooltypes = &Apache::loncommon::usable_exttools();
! 5973: if ($tooltypes{'dom'}) {
! 5974: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
! 5975: }
! 5976: if ($tooltypes{'crs'}) {
! 5977: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
! 5978: }
! 5979: %ltitools = (
! 5980: dom => \%domtools,
! 5981: crs => \%crstools,
! 5982: );
! 5983: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 5984: my $hostname = $r->hostname();
1.606 raeburn 5985: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5986: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5987: &history_tab_js().
5988: &inject_data_js().
1.570 raeburn 5989: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5990: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 5991: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5992: if ($hidden_and_empty ne '') {
5993: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5994: $hidden_and_empty);
5995: $onload .= "javascript:alert('".&js_escape($alert)."');";
5996: }
1.484 raeburn 5997: $addentries = {
1.685 raeburn 5998: onload => $onload,
1.484 raeburn 5999: };
1.458 raeburn 6000: }
1.538 raeburn 6001: $script .= &paste_popup_js();
1.501 raeburn 6002: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6003: &mt('Switch server?');
6004:
6005:
1.329 droeschl 6006: }
6007: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6008: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6009: .'// <![CDATA['."\n"
6010: .$script."\n"
6011: .'// ]]>'."\n"
1.595 musolffc 6012: .'</script>'."\n"
6013: .'<script type="text/javascript"
6014: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6015:
6016: # Breadcrumbs
6017: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 6018:
6019: if ($showdoc) {
1.682 raeburn 6020: my $args;
6021: if ($supplementalflag) {
1.687 raeburn 6022: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6023: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 6024: $args = {'bread_crumbs' => $brcrum};
6025: } else {
6026: $args = {'force_register' => $showdoc};
6027: }
6028: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6029: } elsif ($toolsflag) {
1.611 raeburn 6030: my ($breadtext,$breadtitle);
1.617 raeburn 6031: $breadtext = "$crstype Editor";
1.611 raeburn 6032: if ($canedit) {
6033: $breadtitle = 'Editing '.$crstype.' Contents';
6034: } else {
6035: $breadtext .= ' (View-only mode)';
6036: $breadtitle = 'Viewing '.$crstype.' Contents';
6037: }
1.571 raeburn 6038: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6039: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6040: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6041: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6042: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6043: $breadtitle)
1.571 raeburn 6044: );
1.510 raeburn 6045: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6046: unless ($env{'request.role.adv'}) {
6047: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6048: $r->internal_redirect('/adm/navmaps');
6049: return OK;
6050: }
6051: }
1.510 raeburn 6052: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6053: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6054: {'bread_crumbs' => $brcrum,}));
6055: } else {
1.611 raeburn 6056: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6057: $breadtext = "$crstype Editor";
1.611 raeburn 6058: if ($canedit) {
6059: $breadtitle = 'Editing '.$crstype.' Contents';
6060: $helpitem = 'Docs_Adding_Course_Doc';
6061: } else {
6062: $breadtext .= ' (View-only mode)';
6063: $breadtitle = 'Viewing '.$crstype.' Contents';
6064: $helpitem = 'Docs_Viewing_Course_Doc';
6065: }
1.392 raeburn 6066: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6067: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6068: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6069: {'add_entries' => $addentries}
6070: )
1.392 raeburn 6071: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6072: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6073: $breadtitle,
6074: $helpitem)
1.392 raeburn 6075: );
6076: }
1.364 bisitz 6077:
1.329 droeschl 6078: my %allfiles = ();
6079: my %codebase = ();
1.440 raeburn 6080: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6081: if ($canedit) {
1.684 raeburn 6082: undef($suppchanges);
1.329 droeschl 6083: if (($env{'form.uploaddoc.filename'}) &&
6084: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6085: my $context = $1;
6086: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6087: undef($hadchanges);
1.440 raeburn 6088: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6089: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6090: undef($navmap);
1.329 droeschl 6091: if ($hadchanges) {
6092: &mark_hash_old();
6093: }
1.684 raeburn 6094: if ($suppchanges) {
6095: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6096: undef($suppchanges);
6097: }
1.440 raeburn 6098: $r->print($upload_output);
6099: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6100: # Process file upload - phase two - upload embedded objects
6101: $uploadphase = 'check_embedded';
6102: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6103: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6104: $env{'form.newidx'});
6105: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6106: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6107: my ($destination,$dir_root) = &embedded_destination();
6108: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6109: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6110: my ($result,$flag) =
1.440 raeburn 6111: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6112: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6113: $actionurl);
6114: $r->print($result.&return_to_editor());
6115: } elsif ($env{'form.phase'} eq 'check_embedded') {
6116: # Process file upload - phase three - modify references in HTML file
6117: $uploadphase = 'modified_orightml';
6118: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6119: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6120: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6121: my $result =
1.482 raeburn 6122: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6123: $docuname,$docudom,undef,
6124: $dir_root);
1.630 raeburn 6125: $r->print($result.&return_to_editor());
1.476 raeburn 6126: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6127: $uploadphase = 'decompress_phase_one';
6128: $r->print(&decompression_phase_one().
6129: &return_to_editor());
6130: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6131: $uploadphase = 'decompress_phase_two';
6132: $r->print(&decompression_phase_two().
6133: &return_to_editor());
1.329 droeschl 6134: }
6135: }
6136:
1.484 raeburn 6137: if ($allowed && $toolsflag) {
6138: $r->print(&startContentScreen('tools'));
1.611 raeburn 6139: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6140: $r->print(&endContentScreen());
6141: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6142: # -----------------------------------------------------------------------------
6143: my %lt=&Apache::lonlocal::texthash(
6144: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6145: 'upfi' => 'Upload File',
1.553 raeburn 6146: 'upld' => 'Upload Content',
1.329 droeschl 6147: 'srch' => 'Search',
6148: 'impo' => 'Import',
1.487 raeburn 6149: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6150: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6151: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6152: 'extr' => 'External Resource',
6153: 'extt' => 'External Tool',
1.329 droeschl 6154: 'selm' => 'Select Map',
6155: 'load' => 'Load Map',
6156: 'newf' => 'New Folder',
6157: 'newp' => 'New Composite Page',
6158: 'syll' => 'Syllabus',
1.425 raeburn 6159: 'navc' => 'Table of Contents',
1.343 biermanm 6160: 'sipa' => 'Simple Course Page',
1.329 droeschl 6161: 'sipr' => 'Simple Problem',
1.630 raeburn 6162: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6163: 'stpr' => 'Standard Problem',
6164: 'news' => 'New sub-directory',
6165: 'crpr' => 'Create Problem',
1.689 raeburn 6166: 'swit' => 'Switch Server',
1.329 droeschl 6167: 'drbx' => 'Drop Box',
1.451 www 6168: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6169: 'bull' => 'Discussion Board',
1.347 weissno 6170: 'mypi' => 'My Personal Information Page',
1.353 weissno 6171: 'grpo' => 'Group Portfolio',
1.329 droeschl 6172: 'rost' => 'Course Roster',
1.528 raeburn 6173: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6174: 'imsf' => 'IMS Upload',
6175: 'imsl' => 'Upload IMS package',
1.501 raeburn 6176: 'cms' => 'Origin of IMS package',
6177: 'se' => 'Select',
1.329 droeschl 6178: 'file' => 'File',
6179: 'title' => 'Title',
1.606 raeburn 6180: 'addp' => 'Add Placeholder to course?',
6181: 'uste' => 'Use Template?',
6182: 'fnam' => 'File Name:',
6183: 'loca' => 'Location:',
6184: 'dire' => 'Directory:',
6185: 'cate' => 'Category:',
6186: 'tmpl' => 'Template:',
1.698 raeburn 6187: 'empd' => 'No resources found',
1.329 droeschl 6188: 'comment' => 'Comment',
1.403 raeburn 6189: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6190: 'bb5' => 'Blackboard 5',
6191: 'bb6' => 'Blackboard 6',
6192: 'angel5' => 'ANGEL 5.5',
6193: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6194: 'yes' => 'Yes',
6195: 'no' => 'No',
1.618 raeburn 6196: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6197: );
1.329 droeschl 6198: # -----------------------------------------------------------------------------
1.595 musolffc 6199:
6200: # Calculate free quota space for a user or course. A javascript function checks
6201: # file size to determine if upload should be allowed.
6202: my $quotatype = 'unofficial';
6203: if ($crstype eq 'Community') {
1.601 raeburn 6204: $quotatype = 'community';
6205: } elsif ($crstype eq 'Placement') {
6206: $quotatype = 'placement';
1.595 musolffc 6207: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6208: $quotatype = 'official';
6209: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6210: $quotatype = 'textbook';
6211: }
6212: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6213: 'course',$quotatype); # expressed in MB
6214: my $current_disk_usage = 0;
6215: foreach my $subdir ('docs','supplemental') {
6216: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6217: "userfiles/$subdir",1); # expressed in kB
6218: }
6219: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6220: my $usage = $current_disk_usage/1024; # in MB
6221: my $quota = $disk_quota;
6222: my $percent;
6223: if ($disk_quota == 0) {
6224: $percent = 100.0;
6225: } else {
1.619 raeburn 6226: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6227: }
6228: $usage = sprintf("%.2f",$usage);
6229: $quota = sprintf("%.2f",$quota);
6230: $percent = sprintf("%.0f",$percent);
6231: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6232: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6233:
1.329 droeschl 6234: my $fileupload=(<<FIUP);
1.605 raeburn 6235: $quotainfo
1.329 droeschl 6236: $lt{'file'}:<br />
1.662 raeburn 6237: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6238: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6239: FIUP
6240:
6241: my $checkbox=(<<CHBO);
6242: <!-- <label>$lt{'parse'}?
6243: <input type="checkbox" name="parserflag" />
6244: </label> -->
6245: <label>
1.611 raeburn 6246: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6247: </label>
6248: CHBO
1.501 raeburn 6249: my $imsfolder = $env{'form.folder'};
6250: if ($imsfolder eq '') {
6251: $imsfolder = 'default';
6252: }
6253: my $imspform=(<<IMSFORM);
6254: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6255: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6256: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6257: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6258: <legend>$lt{'imsf'}</legend>
6259: $fileupload
6260: <br />
6261: <p>
6262: $lt{'cms'}:
1.611 raeburn 6263: <select name="source" $disabled>
1.501 raeburn 6264: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6265: <option value="bb5">$lt{'bb5'}</option>
6266: <option value="bb6">$lt{'bb6'}</option>
6267: <option value="angel5">$lt{'angel5'}</option>
6268: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6269: </select>
6270: <input type="hidden" name="folder" value="$imsfolder" />
6271: </p>
6272: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6273: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6274: </fieldset>
6275: </form>
6276: IMSFORM
1.329 droeschl 6277:
6278: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6279: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6280: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6281: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6282: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6283: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6284: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6285: $fileupload
1.329 droeschl 6286: <br />
6287: $lt{'title'}:<br />
1.611 raeburn 6288: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6289: $pathitem
1.329 droeschl 6290: <input type="hidden" name="cmd" value="upload_default" />
6291: <br />
1.458 raeburn 6292: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6293: $checkbox
6294: </span>
1.501 raeburn 6295: <br clear="all" />
1.611 raeburn 6296: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6297: </fieldset>
6298: </form>
1.383 tempelho 6299: FUFORM
1.329 droeschl 6300:
1.611 raeburn 6301: my $mapimportjs;
6302: if ($canedit) {
6303: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6304: } else {
6305: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6306: }
1.502 raeburn 6307: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6308: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6309: $lt{'impm'}</a>$help{'Load_Map'}
6310: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6311: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6312: <legend>$lt{'impm'}</legend>
1.371 tempelho 6313: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6314: $lt{'copm'}<br />
6315: <span class="LC_nobreak">
6316: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6317: onfocus="this.blur();$mapimportjs" $disabled />
6318: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6319: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6320: </fieldset>
6321: </form>
6322:
1.383 tempelho 6323: SEDFFORM
1.606 raeburn 6324: my $importcrsresform;
1.608 raeburn 6325: my ($numdirs,$pickfile) =
1.690 raeburn 6326: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6327: "resize_scrollbox('contentscroll','1','0');",
6328: undef,'res');
1.606 raeburn 6329: if ($pickfile) {
6330: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6331: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6332: $lt{'imcr'}</a>$help{'Course_Resources'}
6333: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6334: <fieldset id="importcrsresform" style="display: none;">
6335: <legend>$lt{'imcr'}</legend>
1.698 raeburn 6336: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 6337: <input type="hidden" name="active" value="bb" />
6338: $pickfile
6339: <p>
1.699 ! raeburn 6340: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 6341: </p>
6342: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6343: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 6344: </div>
6345: <div id="importcrsresempty" style="display: none;">
6346: <p>
6347: $lt{'empd'}
6348: </p>
6349: </div>
1.606 raeburn 6350: </fieldset>
6351: </form>
6352: CRSFORM
6353: }
6354:
1.611 raeburn 6355: my $fromstoredjs;
6356: if ($canedit) {
6357: $fromstoredjs = 'open_StoredLinks_Import()';
6358: } else {
6359: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6360: }
6361:
1.502 raeburn 6362: my @importpubforma = (
1.508 raeburn 6363: { '<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>" },
1.423 onken 6364: { '<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.611 raeburn 6365: { '<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>' },
1.606 raeburn 6366: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6367: );
6368: if ($pickfile) {
1.690 raeburn 6369: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606 raeburn 6370: }
1.502 raeburn 6371: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6372: my $extresourcesform =
6373: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6374: $help{'Adding_External_Resource'},
6375: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6376: my $exttoolform =
6377: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6378: $help{'Adding_External_Tool'},undef,
6379: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6380: \%ltitools,$disabled);
1.329 droeschl 6381: if ($allowed) {
1.492 raeburn 6382: my $folder = $env{'form.folder'};
6383: if ($folder eq '') {
6384: $folder='default';
6385: }
1.615 raeburn 6386: if ($canedit) {
6387: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6388: if ($output) {
6389: $r->print($output);
6390: }
1.538 raeburn 6391: }
1.337 ehlerst 6392: $r->print(<<HIDDENFORM);
6393: <form name="renameform" method="post" action="/adm/coursedocs">
6394: <input type="hidden" name="title" />
6395: <input type="hidden" name="cmd" />
6396: <input type="hidden" name="markcopy" />
6397: <input type="hidden" name="copyfolder" />
6398: $containertag
6399: </form>
1.633 raeburn 6400: <form name="aliasform" method="post" action="/adm/coursedocs">
6401: <input type="hidden" name="alias" />
6402: <input type="hidden" name="cmd" />
6403: $containertag
6404: </form>
1.484 raeburn 6405:
1.337 ehlerst 6406: HIDDENFORM
1.508 raeburn 6407: $r->print(&makesimpleeditform($pathitem)."\n".
6408: &makedocslogform($pathitem."\n".
1.484 raeburn 6409: '<input type="hidden" name="folder" value="'.
6410: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6411: }
1.442 www 6412:
6413: # Generate the tabs
1.510 raeburn 6414: my ($mode,$needs_end);
1.472 raeburn 6415: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6416: my @folders = split('&',$env{'form.folderpath'});
6417: unless (@folders > 2) {
6418: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6419: $needs_end = 1;
6420: }
1.472 raeburn 6421: } else {
1.484 raeburn 6422: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6423: $needs_end = 1;
1.472 raeburn 6424: }
1.443 www 6425:
1.442 www 6426: #
1.622 raeburn 6427: my $hostname = $r->hostname();
1.442 www 6428: my $savefolderpath;
6429:
1.395 raeburn 6430: if ($allowed) {
1.329 droeschl 6431: my $folder=$env{'form.folder'};
1.615 raeburn 6432: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6433: $folder='default';
1.356 tempelho 6434: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6435: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6436: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6437: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6438: }
6439: my $postexec='';
6440: if ($folder eq 'default') {
1.653 raeburn 6441: my $windowname = 'loncapaclient';
6442: if ($env{'request.lti.login'}) {
6443: $windowname .= 'lti';
6444: }
1.372 bisitz 6445: $r->print('<script type="text/javascript">'."\n"
6446: .'// <![CDATA['."\n"
1.653 raeburn 6447: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6448: .'// ]]>'."\n"
6449: .'</script>'."\n"
1.369 bisitz 6450: );
1.329 droeschl 6451: } else {
6452: #$postexec='self.close();';
6453: }
1.504 raeburn 6454: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6455: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6456: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6457:
6458: my $newnavform=(<<NNFORM);
6459: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6460: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6461: $pathitem
1.329 droeschl 6462: <input type="hidden" name="importdetail"
6463: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6464: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6465: $help{'Navigate_Content'}
6466: </form>
6467: NNFORM
6468: my $newsmppageform=(<<NSPFORM);
6469: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6470: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6471: $pathitem
1.329 droeschl 6472: <input type="hidden" name="importdetail" value="" />
1.423 onken 6473: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6474: $help{'Simple Page'}
1.329 droeschl 6475: </form>
6476: NSPFORM
6477:
6478: my $newsmpproblemform=(<<NSPROBFORM);
6479: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6480: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6481: $pathitem
1.329 droeschl 6482: <input type="hidden" name="importdetail" value="" />
1.423 onken 6483: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6484: $help{'Simple_Problem'}
1.329 droeschl 6485: </form>
6486:
6487: NSPROBFORM
6488:
6489: my $newdropboxform=(<<NDBFORM);
6490: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6491: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6492: $pathitem
1.329 droeschl 6493: <input type="hidden" name="importdetail" value="" />
1.423 onken 6494: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6495: $help{'Dropbox'}
1.344 bisitz 6496: </form>
1.329 droeschl 6497: NDBFORM
6498:
6499: my $newexuploadform=(<<NEXUFORM);
6500: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6501: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6502: $pathitem
1.329 droeschl 6503: <input type="hidden" name="importdetail" value="" />
1.423 onken 6504: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6505: $help{'Score_Upload_Form'}
6506: </form>
6507: NEXUFORM
6508:
6509: my $newbulform=(<<NBFORM);
6510: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6511: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6512: $pathitem
1.329 droeschl 6513: <input type="hidden" name="importdetail" value="" />
1.423 onken 6514: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6515: $help{'Bulletin Board'}
6516: </form>
6517: NBFORM
6518:
6519: my $newaboutmeform=(<<NAMFORM);
6520: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6521: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6522: $pathitem
1.329 droeschl 6523: <input type="hidden" name="importdetail"
6524: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6525: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6526: $help{'My Personal Information Page'}
1.329 droeschl 6527: </form>
6528: NAMFORM
6529:
6530: my $newaboutsomeoneform=(<<NASOFORM);
6531: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6532: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6533: $pathitem
1.329 droeschl 6534: <input type="hidden" name="importdetail" value="" />
1.423 onken 6535: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6536: </form>
6537: NASOFORM
6538:
6539: my $newrosterform=(<<NROSTFORM);
6540: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6541: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6542: $pathitem
1.329 droeschl 6543: <input type="hidden" name="importdetail"
6544: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6545: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6546: $help{'Course_Roster'}
1.329 droeschl 6547: </form>
6548: NROSTFORM
6549:
1.534 raeburn 6550: my $newwebpage;
6551: if ($folder =~ /^default_?(\d*)$/) {
6552: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6553: if ($1) {
6554: $newwebpage .= $1;
6555: } else {
6556: $newwebpage .= 'default';
6557: }
6558: $newwebpage .= '/new.html';
6559: }
6560: my $newwebpageform =(<<NWEBFORM);
6561: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6562: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6563: $pathitem
6564: <input type="hidden" name="importdetail" value="$newwebpage" />
6565: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6566: $help{'Web_Page'}
1.534 raeburn 6567: </form>
6568: NWEBFORM
1.604 raeburn 6569:
1.606 raeburn 6570: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6571: my $machines_str = "'".join("','",@ids)."'";
6572: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6573: if ($env{'user.author'}) {
6574: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6575: $is_home{'author'} = 1;
1.606 raeburn 6576: }
1.691 raeburn 6577: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6578: }
6579: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6580: ['active'],['ca','aa']);
1.691 raeburn 6581: my %by_roletype;
1.606 raeburn 6582: if (keys(%roleshash)) {
6583: foreach my $entry (keys(%roleshash)) {
6584: my ($auname,$audom,$roletype) = split(/:/,$entry);
6585: my $key = $entry;
6586: $key =~ s/:/___/g;
1.691 raeburn 6587: my $author = $auname.'___'.$audom;
6588: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6589: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6590: $toppath{$author} = "/priv/$audom/$auname";
6591: if (grep(/^\Q$rolehome\E$/,@ids)) {
6592: $is_home{$author} = 1;
1.606 raeburn 6593: }
1.691 raeburn 6594: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6595: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6596: }
1.691 raeburn 6597: }
6598: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6599: if (grep(/^\Q$crshome\E$/,@ids)) {
6600: $is_home{'course'} = 1;
6601: }
6602: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6603: my $pickdir = $lt{'loca'}.
6604: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6605: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6606: if ($env{'user.author'}) {
6607: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6608: }
6609: if (keys(%by_roletype)) {
6610: foreach my $possrole ('ca','aa') {
6611: if (ref($by_roletype{$possrole}) eq 'HASH') {
6612: my $roletitle = &Apache::lonnet::plaintext($possrole);
6613: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6614: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6615: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6616: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6617: }
6618: }
6619: }
6620: }
1.691 raeburn 6621: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6622: '</select><br />'."\n".
6623: $lt{'dire'}.
6624: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6625: '<option value=""></option>'.
6626: '</select><br />'."\n";
1.606 raeburn 6627:
6628: my %seltemplate_menus;
6629: my @files = &Apache::lonhomework::get_template_list('problem');
6630: my @noexamplelink = ('blank.problem','blank.library','script.library');
6631: my $currentcategory = '';
6632: my @ordered = ('');
6633: my %templatehelp;
6634: my $defcategory = '';
6635: my @catorder = ($defcategory);
6636: $seltemplate_menus{$defcategory}->{'order'} = [''];
6637: $seltemplate_menus{$defcategory}->{'text'} = '';
6638: foreach my $file (@files) {
6639: if (ref($file) eq 'ARRAY') {
6640: my ($path,$title,$category,$help) = @{$file};
6641: next if ($title !~ /\S/);
6642: if (&js_escape($category) ne $currentcategory) {
6643: $currentcategory = &js_escape($category);
6644: push(@catorder,&js_escape($currentcategory));
6645: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6646: $seltemplate_menus{$currentcategory}->{'default'} = '';
6647: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6648: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6649: }
6650: if ($path) {
6651: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6652: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6653: if ($help) {
6654: $templatehelp{$path} = $help;
6655: }
6656: }
6657: }
6658: }
6659:
6660: my $templates = $lt{'cate'}.' '.
6661: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6662: $defcategory,'tempcategory','template',
6663: \%seltemplate_menus,\@catorder,
6664: "resize_scrollbox('contentscroll','1','0');",
6665: "toggleExampleText();",'template').'<br />';
6666: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6667: '<span id="newresexample">'.&mt('Example').'<span></a>';
6668: my $crsresform=(<<RESFORM);
1.691 raeburn 6669: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 6670: $lt{'stpr'}</a>$help{'Course_Resource'}
6671: <form action="/adm/coursedocs" method="post" name="courseresform">
6672: <fieldset id="crsresform" style="display:none;">
6673: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6674: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6675: <p>
6676: $pickdir
1.691 raeburn 6677: <div id="newstdproblem" style="display:none;">
1.606 raeburn 6678: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6679: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6680:
1.611 raeburn 6681: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6682: </span><span id="newsubdir"></span>
6683: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.699 ! raeburn 6684: </div>
1.606 raeburn 6685: </p>
6686: $lt{'fnam'}
1.611 raeburn 6687: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6688: <p>
1.691 raeburn 6689: <div id="newresource" style="display:none">
1.606 raeburn 6690: $lt{'addp'}
1.611 raeburn 6691: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6692: $lt{'no'}</label>
1.611 raeburn 6693: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6694: $lt{'yes'}</label>
6695: <span id="newrestitle"></span>
1.611 raeburn 6696: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6697: </div>
6698: </p>
6699: <p>
6700: $lt{'uste'}
1.611 raeburn 6701: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6702: $lt{'no'}</label>
1.611 raeburn 6703: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6704: $lt{'yes'}</label>
6705: <div id="newrestemplate" style="display:none">
6706: $templates
6707: $templatepreview
6708: </div>
6709: </p>
6710: <span class="LC_nobreak">
6711: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6712: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6713: </span>
1.689 raeburn 6714: </div>
1.691 raeburn 6715: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 6716: $rolehomes
6717: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6718: </div>
1.606 raeburn 6719: </fieldset>
6720: </form>
6721:
6722: RESFORM
1.534 raeburn 6723:
1.342 ehlerst 6724: my $specialdocumentsform;
1.383 tempelho 6725: my @specialdocumentsforma;
1.451 www 6726: my $gradingform;
6727: my @gradingforma;
6728: my $communityform;
6729: my @communityforma;
1.351 ehlerst 6730: my $newfolderform;
1.390 tempelho 6731: my $newfolderb;
1.342 ehlerst 6732:
1.451 www 6733: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6734:
1.329 droeschl 6735: my $newpageform=(<<NPFORM);
6736: <form action="/adm/coursedocs" method="post" name="newpage">
6737: <input type="hidden" name="folderpath" value="$path" />
6738: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6739: <input type="hidden" name="active" value="ee" />
1.423 onken 6740: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6741: $help{'Adding_Pages'}
1.329 droeschl 6742: </form>
6743: NPFORM
1.390 tempelho 6744:
6745:
1.351 ehlerst 6746: $newfolderform=(<<NFFORM);
1.329 droeschl 6747: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6748: $pathitem
1.329 droeschl 6749: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6750: <input type="hidden" name="active" value="" />
1.422 onken 6751: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6752: </form>
6753: NFFORM
6754:
6755: my $newsylform=(<<NSYLFORM);
6756: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6757: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6758: $pathitem
1.329 droeschl 6759: <input type="hidden" name="importdetail"
6760: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6761: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6762: $help{'Syllabus'}
1.383 tempelho 6763:
1.329 droeschl 6764: </form>
6765: NSYLFORM
1.364 bisitz 6766:
1.329 droeschl 6767: my $newgroupfileform=(<<NGFFORM);
6768: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6769: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6770: $pathitem
1.329 droeschl 6771: <input type="hidden" name="importdetail"
6772: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6773: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6774: $help{'Group Portfolio'}
1.329 droeschl 6775: </form>
6776: NGFFORM
1.672 raeburn 6777: if ($container eq 'page') {
6778: @specialdocumentsforma=(
6779: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6780: );
6781: } else {
6782: @specialdocumentsforma=(
1.421 onken 6783: {'<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 6784: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6785: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6786: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6787: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6788: );
6789: }
1.451 www 6790: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6791:
1.655 raeburn 6792: my @external = (
6793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6794: );
1.699 ! raeburn 6795: if ($posslti) {
1.655 raeburn 6796: push(@external,
6797: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6798: );
1.598 raeburn 6799: }
1.655 raeburn 6800: my $externalform = &create_form_ul(&create_list_elements(@external));
6801:
6802: my @importdoc = ();
1.519 raeburn 6803: unless ($container eq 'page') {
6804: push(@importdoc,
6805: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6806: );
6807: }
6808: push(@importdoc,
1.558 raeburn 6809: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6810: );
1.501 raeburn 6811: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6812:
1.451 www 6813: @gradingforma=(
6814: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6815: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6816: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 6817: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 6818: );
6819: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6820:
6821: @communityforma=(
6822: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6823: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6824: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6825: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6826: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6827: );
6828: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6829:
1.330 tempelho 6830: my %orderhash = (
1.553 raeburn 6831: 'aa' => ['Upload',$fileuploadform],
6832: 'bb' => ['Import',$importpubform],
1.655 raeburn 6833: 'cc' => ['External',$externalform],
6834: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6835: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6836: );
1.519 raeburn 6837: unless ($container eq 'page') {
1.434 raeburn 6838: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6839: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6840: }
6841:
1.341 ehlerst 6842: $hadchanges=0;
1.484 raeburn 6843: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6844: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6845: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6846: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6847: undef($navmap);
1.443 www 6848: if ($error) {
6849: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6850: }
1.639 raeburn 6851: if ($hadchanges) {
6852: unless (&is_hash_old()) {
1.638 raeburn 6853: &mark_hash_old();
6854: }
6855: }
1.341 ehlerst 6856:
1.443 www 6857: &changewarning($r,'');
6858: }
1.458 raeburn 6859: }
1.442 www 6860:
1.443 www 6861: # Supplemental documents start here
6862:
1.329 droeschl 6863: my $folder=$env{'form.folder'};
1.443 www 6864: unless ($supplementalflag) {
1.329 droeschl 6865: $folder='supplemental';
6866: }
1.685 raeburn 6867: if (($folder eq 'supplemental') &&
1.329 droeschl 6868: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6869: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6870: } elsif ($allowed) {
1.356 tempelho 6871: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6872: }
1.508 raeburn 6873: $pathitem = '<input type="hidden" name="folderpath" value="'.
6874: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6875: if ($allowed) {
6876: my $folderseq=
1.504 raeburn 6877: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6878:
6879: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6880: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6881: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6882: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6883: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6884: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6885: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6886: $fileupload
6887: <br />
6888: <br />
6889: <span class="LC_nobreak">
6890: $checkbox
6891: </span>
6892: <br /><br />
6893: $lt{'comment'}:<br />
1.383 tempelho 6894: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6895: <br />
1.508 raeburn 6896: $pathitem
1.329 droeschl 6897: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6898: <input type='submit' value="$lt{'upld'}" />
6899: </form>
1.329 droeschl 6900: SUPDOCFORM
6901:
6902: my $supnewfolderform=(<<SNFFORM);
6903: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6904: <input type="hidden" name="active" value="" />
1.508 raeburn 6905: $pathitem
1.329 droeschl 6906: <input type="hidden" name="importdetail" value="" />
1.423 onken 6907: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6908: $help{'Adding_Folders'}
1.329 droeschl 6909: </form>
6910: SNFFORM
1.383 tempelho 6911:
1.510 raeburn 6912: my $supextform =
6913: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6914: $help{'Adding_External_Resource'},
6915: undef,undef,undef,undef,undef,undef,
6916: $disabled);
1.329 droeschl 6917:
1.598 raeburn 6918: my $supexttoolform =
6919: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6920: $help{'Adding_External_Tool'},
6921: undef,undef,'tool',$coursedom,
1.611 raeburn 6922: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6923:
1.329 droeschl 6924: my $supnewsylform=(<<SNSFORM);
6925: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6926: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6927: $pathitem
1.329 droeschl 6928: <input type="hidden" name="importdetail"
6929: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6930: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6931: $help{'Syllabus'}
6932: </form>
6933: SNSFORM
6934:
6935: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6936: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6937: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6938: $pathitem
1.329 droeschl 6939: <input type="hidden" name="importdetail"
6940: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6941: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6942: $help{'My Personal Information Page'}
1.329 droeschl 6943: </form>
6944: SNAMFORM
6945:
1.534 raeburn 6946: my $supwebpage;
6947: if ($folder =~ /^supplemental_?(\d*)$/) {
6948: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6949: if ($1) {
6950: $supwebpage .= $1;
6951: } else {
6952: $supwebpage .= 'default';
6953: }
6954: $supwebpage .= '/new.html';
6955: }
6956: my $supwebpageform =(<<SWEBFORM);
6957: <form action="/adm/coursedocs" method="post" name="supwebpage">
6958: <input type="hidden" name="active" value="cc" />
6959: $pathitem
6960: <input type="hidden" name="importdetail" value="$supwebpage" />
6961: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6962: $help{'Web_Page'}
1.534 raeburn 6963: </form>
6964: SWEBFORM
6965:
1.333 muellerd 6966:
1.383 tempelho 6967: my @specialdocs = (
1.618 raeburn 6968: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6969: =>$supnewsylform},
1.611 raeburn 6970: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6971: =>$supnewaboutmeform},
1.534 raeburn 6972: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6973:
1.383 tempelho 6974: );
1.655 raeburn 6975: my @supexternal = (
6976: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6977: =>$supextform});
1.699 ! raeburn 6978: if ($posslti) {
1.655 raeburn 6979: push(@supexternal,
6980: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6981: =>$supexttoolform});
6982: }
1.655 raeburn 6983: my @supimportdoc = (
1.598 raeburn 6984: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6985: =>$supupdocform},
1.598 raeburn 6986: );
1.501 raeburn 6987:
6988: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6989: my %suporderhash = (
1.390 tempelho 6990: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6991: 'dd' => ['Upload',$supupdocform],
6992: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6993: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6994: );
1.443 www 6995: if ($supplementalflag) {
1.682 raeburn 6996: $suppchanges = 0;
6997: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6998: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6999: \%ltitools,$canedit,$hostname);
7000: if ($error) {
7001: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7002: }
7003: if ($suppchanges) {
1.684 raeburn 7004: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7005: undef($suppchanges);
7006: }
1.393 raeburn 7007: }
1.443 www 7008: } elsif ($supplementalflag) {
1.458 raeburn 7009: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7010: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7011: $hostname);
1.393 raeburn 7012: if ($error) {
7013: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7014: }
1.393 raeburn 7015: }
1.389 tempelho 7016:
1.510 raeburn 7017: if ($needs_end) {
7018: $r->print(&endContentScreen());
7019: }
1.383 tempelho 7020:
1.329 droeschl 7021: if ($allowed) {
7022: $r->print('
7023: <form method="post" name="extimport" action="/adm/coursedocs">
7024: <input type="hidden" name="title" />
7025: <input type="hidden" name="url" />
7026: <input type="hidden" name="useform" />
7027: <input type="hidden" name="residx" />
7028: </form>');
7029: }
1.484 raeburn 7030: } elsif ($showdoc) {
1.329 droeschl 7031: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7032: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7033: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7034: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7035: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7036: }
7037: }
1.630 raeburn 7038: unless ($noendpage) {
1.606 raeburn 7039: $r->print(&Apache::loncommon::end_page());
7040: }
1.329 droeschl 7041: return OK;
1.364 bisitz 7042: }
1.329 droeschl 7043:
1.440 raeburn 7044: sub embedded_form_elems {
7045: my ($phase,$primaryurl,$newidx) = @_;
7046: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7047: $newidx =~s /\D+//g;
1.440 raeburn 7048: return <<STATE;
7049: <input type="hidden" name="folderpath" value="$folderpath" />
7050: <input type="hidden" name="cmd" value="upload_embedded" />
7051: <input type="hidden" name="newidx" value="$newidx" />
7052: <input type="hidden" name="phase" value="$phase" />
7053: <input type="hidden" name="primaryurl" value="$primaryurl" />
7054: STATE
7055: }
7056:
7057: sub embedded_destination {
7058: my $folder=$env{'form.folder'};
7059: my $destination = 'docs/';
7060: if ($folder =~ /^supplemental/) {
7061: $destination = 'supplemental/';
7062: }
7063: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7064: $destination .= 'default/';
7065: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7066: $destination .= $2.'/';
7067: }
1.634 raeburn 7068: my $newidx = $env{'form.newidx'};
7069: $newidx =~s /\D+//g;
7070: if ($newidx) {
7071: $destination .= $newidx;
7072: }
1.440 raeburn 7073: my $dir_root = '/userfiles';
7074: return ($destination,$dir_root);
7075: }
7076:
7077: sub return_to_editor {
7078: my $actionurl = '/adm/coursedocs';
7079: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7080: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7081: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7082: '</a></p>';
7083: }
7084:
1.476 raeburn 7085: sub decompression_info {
7086: my ($destination,$dir_root) = &embedded_destination();
7087: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7088: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7089: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7090: my $container='sequence';
1.480 raeburn 7091: my ($pathitem,$hiddenelem);
1.583 raeburn 7092: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7093: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7094: $container='page';
7095: }
1.480 raeburn 7096: unshift(@hiddens,$pathitem);
7097: foreach my $item (@hiddens) {
1.634 raeburn 7098: if ($item eq 'newidx') {
7099: next if ($env{'form.'.$item} =~ /\D/);
7100: }
1.480 raeburn 7101: if ($env{'form.'.$item}) {
7102: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7103: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7104: }
1.477 raeburn 7105: }
1.476 raeburn 7106: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7107: $hiddenelem);
7108: }
7109:
7110: sub decompression_phase_one {
7111: my ($dir,$file,$warning,$error,$output);
7112: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7113: &decompression_info();
1.490 raeburn 7114: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7115: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7116: } else {
7117: my $file = $1;
1.630 raeburn 7118: $output =
1.481 raeburn 7119: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7120: $destination,$dir_root,
7121: $hiddenelem);
7122: if ($env{'form.autoextract_camtasia'}) {
7123: $output .= &remove_archive($docudom,$docuname,$container);
7124: }
1.476 raeburn 7125: }
7126: if ($error) {
7127: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7128: $error.'</p>'."\n";
7129: }
7130: if ($warning) {
7131: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7132: }
7133: return $output;
7134: }
7135:
7136: sub decompression_phase_two {
7137: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7138: &decompression_info();
1.481 raeburn 7139: my $output;
1.480 raeburn 7140: if ($env{'form.archivedelete'}) {
1.481 raeburn 7141: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7142: }
7143: $output .=
1.481 raeburn 7144: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7145: $destination,$dir_root,$hiddenelem);
7146: return $output;
7147: }
7148:
1.480 raeburn 7149: sub remove_archive {
7150: my ($docudom,$docuname,$container) = @_;
7151: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7152: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7153: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7154: if ($fatal) {
7155: if ($container eq 'page') {
7156: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7157: } else {
7158: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7159: }
1.583 raeburn 7160: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7161: } else {
7162: my $currcmd = $env{'form.cmd'};
7163: my $position = $env{'form.position'};
1.583 raeburn 7164: my $archiveidx = $position;
1.563 raeburn 7165: if ($position > 0) {
1.583 raeburn 7166: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7167: $archiveidx = $position-1;
7168: }
7169: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7170: my ($title,$url,@rrest) =
1.583 raeburn 7171: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7172: if ($url eq $env{'form.archiveurl'}) {
7173: if (&handle_edit_cmd($docuname,$docudom)) {
7174: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7175: if ($suppchanges) {
7176: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7177: undef($suppchanges);
7178: }
1.583 raeburn 7179: if ($fatal) {
7180: if ($container eq 'page') {
7181: $delwarning = &mt('An error occurred updating the contents of the current page.');
7182: } else {
7183: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7184: }
1.480 raeburn 7185: } else {
1.583 raeburn 7186: $delresult = &mt('Archive file removed.');
1.480 raeburn 7187: }
7188: }
1.583 raeburn 7189: } else {
7190: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7191: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7192: }
7193: }
7194: $env{'form.cmd'} = $currcmd;
7195: }
7196: if ($delwarning) {
7197: $output = '<p class="LC_warning">'.
7198: $delwarning.
7199: '</p>';
7200: }
7201: if ($delresult) {
7202: $output .= '<p class="LC_info">'.
7203: $delresult.
7204: '</p>';
7205: }
1.481 raeburn 7206: return $output;
1.480 raeburn 7207: }
7208:
1.484 raeburn 7209: sub generate_admin_menu {
1.611 raeburn 7210: my ($crstype,$canedit) = @_;
1.484 raeburn 7211: my $lc_crstype = lc($crstype);
7212: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7213: my %lt= ( # do not translate here
1.484 raeburn 7214: 'vc' => 'Verify Content',
7215: 'cv' => 'Check/Set Resource Versions',
7216: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7217: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7218: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7219: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7220: );
1.484 raeburn 7221: my ($candump,$dumpurl);
7222: if ($home + $other > 0) {
7223: $candump = 'F';
7224: if ($home) {
7225: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7226: } else {
7227: my @hosts;
7228: foreach my $aurole (keys(%outhash)) {
7229: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7230: push(@hosts,$outhash{$aurole});
1.538 raeburn 7231: }
1.484 raeburn 7232: }
7233: if (@hosts == 1) {
7234: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7235: '&role='.
7236: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7237: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7238: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7239: } else {
7240: $dumpurl = "javascript:choose_switchserver_window()";
7241: }
7242: }
7243: }
7244: my @menu=
7245: ({ categorytitle=>'Administration',
7246: items =>[
7247: { linktext => $lt{'vc'},
7248: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7249: permission => 'F',
1.571 raeburn 7250: help => 'Docs_Verify_Content',
1.484 raeburn 7251: icon => 'verify.png',
7252: linktitle => 'Verify contents can be retrieved/rendered',
7253: },
7254: { linktext => $lt{'cv'},
7255: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7256: permission => 'F',
1.571 raeburn 7257: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7258: icon => 'resversion.png',
7259: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7260: },
7261: { linktext => $lt{'ls'},
7262: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7263: permission => 'F',
7264: #help => '',
7265: icon => 'symbs.png',
7266: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7267: },
1.651 raeburn 7268: { linktext => $lt{'ct'},
7269: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7270: permission => 'F',
7271: help => 'Docs_Short_URLs',
7272: icon => 'shorturls.png',
7273: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7274: },
1.484 raeburn 7275: ]
1.611 raeburn 7276: });
7277: if ($canedit) {
7278: push(@menu,
1.484 raeburn 7279: { categorytitle=>'Export',
7280: items =>[
7281: { linktext => $lt{'imse'},
7282: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7283: permission => 'F',
7284: help => 'Docs_Export_Course_Docs',
7285: icon => 'imsexport.png',
7286: linktitle => $lt{'imse'},
7287: },
7288: { linktext => $lt{'dcd'},
7289: url => $dumpurl,
7290: permission => $candump,
1.571 raeburn 7291: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7292: icon => 'dump.png',
7293: linktitle => $lt{'dcd'},
7294: },
7295: ]
7296: });
1.611 raeburn 7297: }
1.484 raeburn 7298: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7299: '<input type="hidden" id="dummy" />'."\n".
7300: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7301: '</form>';
1.329 droeschl 7302: }
7303:
7304: sub generate_edit_table {
1.538 raeburn 7305: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7306: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7307: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7308: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7309: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7310: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7311: $activetab = $env{'form.active'};
7312: }
1.611 raeburn 7313: unless ($canedit) {
7314: $disabled = ' disabled="disabled"';
7315: }
1.472 raeburn 7316: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7317: my $backtext = &mt('Exit Editor');
1.458 raeburn 7318: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7319: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7320: '<li class="goback">'.
1.546 raeburn 7321: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7322: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7323: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7324: '<li>'.
7325: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7326: &mt('Undo Delete').'</a></li>'."\n";
7327: if ($env{'form.docslog'}) {
7328: $form .= '<li class="active">';
7329: } else {
7330: $form .= '<li>';
7331: }
7332: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7333: &mt('History').'</a></li>'."\n";
7334: if ($env{'form.docslog'}) {
7335: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7336: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7337: }
1.458 raeburn 7338: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7339: if($name ne '00'){
1.371 tempelho 7340: if($activetab eq '' || $activetab ne $name){
7341: $active = '';
7342: }elsif($activetab eq $name){
7343: $active = 'class="active"';
7344: }
1.458 raeburn 7345: $form .= '<li style="float:right" '.$active
1.484 raeburn 7346: .' 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 7347: } else {
1.570 raeburn 7348: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7349:
7350: }
1.329 droeschl 7351: }
1.484 raeburn 7352: $form .= '</ul>'."\n";
7353: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7354:
7355: if ($to_show ne '') {
1.538 raeburn 7356: my $saveform;
7357: if ($need_save) {
7358: my $button = &mt('Make changes');
7359: my $path;
7360: if ($env{'form.folderpath'}) {
7361: $path =
7362: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7363: }
7364: $saveform = <<"END";
7365: <div id="multisave" style="display:none; clear:both;" >
7366: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7367: <input type="hidden" name="folderpath" value="$path" />
7368: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7369: <input type="hidden" name="allhiddenresource" value="" />
7370: <input type="hidden" name="allencrypturl" value="" />
7371: <input type="hidden" name="allrandompick" value="" />
7372: <input type="hidden" name="allrandomorder" value="" />
7373: <input type="hidden" name="changeparms" value="" />
7374: <input type="hidden" name="multiremove" value="" />
7375: <input type="hidden" name="multicut" value="" />
7376: <input type="hidden" name="multicopy" value="" />
7377: <input type="hidden" name="multichange" value="" />
7378: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7379: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7380: </form>
7381: </div>
7382: END
7383: }
7384: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7385: }
1.363 ehlerst 7386: foreach my $field (keys(%orderhash)){
1.390 tempelho 7387: if($field ne '00'){
1.422 onken 7388: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7389: $active = 'style="display: none;float:left"';
1.422 onken 7390: }elsif($activetab eq $field){
1.458 raeburn 7391: $active = 'style="display:block;float:left"';
1.422 onken 7392: }
7393: $form .= '<div id="'.$field.$tid.'"'
7394: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7395: .'</div>'."\n";
1.363 ehlerst 7396: }
7397: }
1.484 raeburn 7398: unless ($env{'form.docslog'}) {
7399: $form .= '</div></div>'."\n";
7400: }
1.329 droeschl 7401: return $form;
7402: }
7403:
7404: sub editing_js {
1.622 raeburn 7405: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7406: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7407: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7408: p_mnf => 'Name of New Folder',
7409: t_mnf => 'New Folder',
7410: p_mnp => 'Name of New Page',
7411: t_mnp => 'New Page',
1.451 www 7412: p_mxu => 'Title for the External Score',
1.349 biermanm 7413: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7414: p_msb => 'Title for the Problem',
7415: p_mdb => 'Title for the Drop Box',
1.336 schafran 7416: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7417: p_mwp => 'Title for Web Page',
1.606 raeburn 7418: p_mnr => 'Title for the Resource',
1.348 weissno 7419: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7420: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7421: p_mab_alrt1 => 'Not a valid user:domain',
7422: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7423: p_chn => 'New Title',
7424: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7425: p_rmr2a => 'Remove',
7426: p_rmr2b => '?',
7427: p_rmr3a => 'Remove those',
7428: p_rmr3b => 'items?',
7429: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7430: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7431: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7432: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7433: p_ctr2a => 'Cut',
7434: p_ctr2b => '?',
7435: p_ctr3a => 'Cut those',
7436: p_ctr3b => 'items?',
1.633 raeburn 7437: setal => 'Enter a (unique) alias',
7438: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7439: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7440: imsfile => 'You must choose an IMS package for import',
7441: imscms => 'You must select which Course Management System was the source of the IMS package',
7442: invurl => 'Invalid URL',
7443: titbl => 'Title is blank',
1.538 raeburn 7444: more => '(More ...)',
7445: less => '(Less ...)',
1.543 raeburn 7446: noor => 'No actions selected or changes to settings specified.',
7447: noch => 'No changes to settings specified.',
7448: noac => 'No actions selected.',
1.606 raeburn 7449: nofi => 'No file selected',
7450: tinc => 'Title in course',
7451: sunm => 'Sub-directory name',
1.618 raeburn 7452: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7453: sele => 'Select',
7454: swit => 'Switch server required',
1.329 droeschl 7455: );
1.594 damieng 7456: &js_escape(\%js_lt);
1.433 raeburn 7457: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7458: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7459: my $main_container_page;
1.519 raeburn 7460: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7461: $main_container_page = 1;
1.434 raeburn 7462: }
1.617 raeburn 7463: my $backtourl;
7464: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7465: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7466: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7467: my @ids=&Apache::lonnet::current_machine_ids();
7468: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7469: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7470: my $caller = $1;
1.525 raeburn 7471: if ($caller =~ /^supplemental/) {
7472: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7473: } else {
7474: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7475: $res = &Apache::lonnet::clutter($res);
7476: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7477: my ($url,$anchor);
7478: if ($res =~ /^([^#]+)#([^#]+)$/) {
7479: $url = $1;
7480: $anchor = $2;
7481: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7482: $caller = $1.&escape('#').$anchor;
7483: }
1.614 raeburn 7484: } else {
7485: $url = $res;
1.609 raeburn 7486: }
1.640 raeburn 7487: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7488: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7489: $backtourl .= '?navmap=1';
7490: } else {
7491: $backtourl .= '?symb='.
7492: &HTML::Entities::encode($caller,'<>&"');
7493: }
1.622 raeburn 7494: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7495: if (($ENV{'SERVER_PORT'} == 443) &&
7496: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7497: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7498: if ($hostname ne '') {
7499: $backtourl = 'http://'.$hostname.$backtourl;
7500: }
7501: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7502: }
7503: }
1.623 raeburn 7504: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7505: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7506: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7507: if ($hostname ne '') {
7508: $backtourl = 'http://'.$hostname.$backtourl;
7509: }
7510: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7511: }
1.623 raeburn 7512: }
1.622 raeburn 7513: }
1.609 raeburn 7514: if ($anchor ne '') {
7515: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7516: }
1.590 raeburn 7517: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7518: } else {
7519: $backtourl = '/adm/navmaps';
1.525 raeburn 7520: }
7521: }
7522: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7523: $backtourl = '/adm/menu';
7524: } elsif ($supplementalflag) {
1.682 raeburn 7525: if (($env{'request.role.adv'}) ||
7526: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7527: $backtourl = '/adm/supplemental';
7528: } else {
7529: $backtourl = '/adm/navmaps';
7530: }
1.525 raeburn 7531: } else {
7532: $backtourl = '/adm/navmaps';
1.472 raeburn 7533: }
7534:
1.655 raeburn 7535: my $fieldsets = "'doc'";
1.519 raeburn 7536: unless ($main_container_page) {
7537: $fieldsets .=",'ims'";
7538: }
1.655 raeburn 7539: my $extfieldsets = "'ext'";
7540: if ($posslti) {
7541: $extfieldsets .= ",'tool'";
7542: }
1.501 raeburn 7543: if ($supplementalflag) {
1.655 raeburn 7544: $fieldsets = "'suppdoc'";
7545: $extfieldsets = "'suppext'";
1.600 raeburn 7546: if ($posslti) {
1.655 raeburn 7547: $extfieldsets .= ",'supptool'";
1.600 raeburn 7548: }
1.501 raeburn 7549: }
1.655 raeburn 7550:
1.611 raeburn 7551: my $jsmakefunctions;
7552: if ($canedit) {
7553: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7554: function makenewfolder(targetform,folderseq) {
1.594 damieng 7555: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7556: if (foldername) {
1.676 raeburn 7557: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7558: targetform.submit();
7559: }
7560: }
7561:
7562: function makenewpage(targetform,folderseq) {
1.594 damieng 7563: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7564: if (pagename) {
1.676 raeburn 7565: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7566: targetform.submit();
7567: }
7568: }
7569:
7570: function makeexamupload() {
1.594 damieng 7571: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7572: if (title) {
1.329 droeschl 7573: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7574: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7575: this.document.forms.newexamupload.submit();
7576: }
7577: }
7578:
7579: function makesmppage() {
1.594 damieng 7580: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7581: if (title) {
1.329 droeschl 7582: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7583: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7584: this.document.forms.newsmppg.submit();
7585: }
7586: }
7587:
1.534 raeburn 7588: function makewebpage(type) {
1.594 damieng 7589: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7590: var formname;
7591: if (type == 'supp') {
7592: formname = this.document.forms.supwebpage;
7593: } else {
7594: formname = this.document.forms.newwebpage;
7595: }
7596: if (title) {
7597: var webpage = formname.importdetail.value;
1.675 raeburn 7598: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7599: formname.submit();
7600: }
7601: }
7602:
1.329 droeschl 7603: function makesmpproblem() {
1.594 damieng 7604: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7605: if (title) {
1.329 droeschl 7606: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7607: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7608: this.document.forms.newsmpproblem.submit();
7609: }
7610: }
7611:
7612: function makedropbox() {
1.594 damieng 7613: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7614: if (title) {
1.329 droeschl 7615: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7616: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7617: this.document.forms.newdropbox.submit();
7618: }
7619: }
7620:
7621: function makebulboard() {
1.594 damieng 7622: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7623: if (title) {
7624: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7625: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7626: this.document.forms.newbul.submit();
7627: }
7628: }
7629:
7630: function makeabout() {
1.594 damieng 7631: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7632: if (user) {
7633: var comp=new Array();
7634: comp=user.split(':');
7635: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7636: if ((comp[0]) && (comp[1])) {
7637: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7638: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7639: this.document.forms.newaboutsomeone.submit();
7640: } else {
7641: alert("$js_lt{'p_mab_alrt1'}");
7642: }
7643: } else {
7644: alert("$js_lt{'p_mab_alrt2'}");
7645: }
7646: }
7647: }
7648:
7649: function makenew(targetform) {
7650: targetform.submit();
7651: }
7652:
7653: function changename(folderpath,index,oldtitle) {
7654: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7655: if (title) {
7656: this.document.forms.renameform.markcopy.value='';
7657: this.document.forms.renameform.title.value=title;
7658: this.document.forms.renameform.cmd.value='rename_'+index;
7659: this.document.forms.renameform.folderpath.value=folderpath;
7660: this.document.forms.renameform.submit();
7661: }
7662: }
7663:
1.633 raeburn 7664: function setalias(folderpath,index) {
7665: var alias = prompt('$js_lt{"setal"}');
7666: if ((alias != null) && (alias != '')) {
7667: this.document.forms.aliasform.alias.value=alias;
7668: this.document.forms.aliasform.cmd.value='setalias_'+index;
7669: this.document.forms.aliasform.folderpath.value=folderpath;
7670: this.document.forms.aliasform.submit();
7671: }
7672: }
7673:
7674: function delalias(folderpath,index) {
7675: if (confirm('$js_lt{"delal"}')) {
7676: this.document.forms.aliasform.cmd.value='delalias_'+index;
7677: this.document.forms.aliasform.folderpath.value=folderpath;
7678: this.document.forms.aliasform.submit();
7679: }
7680: }
7681:
1.611 raeburn 7682: ENDNEWSCRIPT
7683: } else {
7684: $jsmakefunctions = <<ENDNEWSCRIPT;
7685:
7686: function makenewfolder() {
7687: alert("$js_lt{'edri'}");
7688: }
7689:
7690: function makenewpage() {
7691: alert("$js_lt{'edri'}");
7692: }
7693:
7694: function makeexamupload() {
7695: alert("$js_lt{'edri'}");
7696: }
7697:
7698: function makesmppage() {
7699: alert("$js_lt{'edri'}");
7700: }
7701:
7702: function makewebpage(type) {
7703: alert("$js_lt{'edri'}");
7704: }
7705:
7706: function makesmpproblem() {
7707: alert("$js_lt{'edri'}");
7708: }
7709:
7710: function makedropbox() {
7711: alert("$js_lt{'edri'}");
7712: }
7713:
7714: function makebulboard() {
7715: alert("$js_lt{'edri'}");
7716: }
7717:
7718: function makeabout() {
7719: alert("$js_lt{'edri'}");
7720: }
7721:
7722: function changename() {
7723: alert("$js_lt{'edri'}");
7724: }
7725:
1.633 raeburn 7726: function setalias() {
7727: alert("$js_lt{'edri'}");
7728: }
7729:
7730: function delalias() {
7731: alert("$js_lt{'edri'}");
7732: }
7733:
1.611 raeburn 7734: function makenew() {
7735: alert("$js_lt{'edri'}");
7736: }
7737:
7738: function groupimport() {
7739: alert("$js_lt{'edri'}");
1.335 ehlerst 7740: }
1.611 raeburn 7741:
7742: function groupsearch() {
7743: alert("$js_lt{'edri'}");
1.335 ehlerst 7744: }
1.611 raeburn 7745:
7746: function groupopen(url,recover) {
7747: var options="scrollbars=1,resizable=1,menubar=0";
7748: idxflag=1;
7749: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7750: idx.focus();
1.329 droeschl 7751: }
7752:
1.611 raeburn 7753: ENDNEWSCRIPT
7754:
7755: }
7756: return <<ENDSCRIPT;
7757:
7758: $jsmakefunctions
7759:
1.501 raeburn 7760: function toggleUpload(caller) {
7761: var blocks = Array($fieldsets);
7762: for (var i=0; i<blocks.length; i++) {
7763: var disp = 'none';
7764: if (caller == blocks[i]) {
7765: var curr = document.getElementById('upload'+caller+'form').style.display;
7766: if (curr == 'none') {
7767: disp='block';
7768: }
7769: }
7770: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7771: }
7772: resize_scrollbox('contentscroll','1','1');
7773: return;
7774: }
7775:
7776: function toggleExternal(caller) {
7777: var blocks = Array($extfieldsets);
7778: for (var i=0; i<blocks.length; i++) {
7779: var disp = 'none';
7780: if (caller == blocks[i]) {
7781: var curr = document.getElementById('external'+caller+'form').style.display;
7782: if (curr == 'none') {
7783: disp='block';
7784: }
7785: }
7786: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7787: if ((caller == 'tool') || (caller == 'supptool')) {
7788: if (disp == 'block') {
1.655 raeburn 7789: if (document.getElementById('LC_exttoolid')) {
7790: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7791: var suppflag = 0;
7792: if (caller == 'supptool') {
7793: suppflag = 1;
7794: }
7795: currForm = document.getElementById('new'+caller);
1.655 raeburn 7796: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7797: }
7798: }
7799: }
1.501 raeburn 7800: }
1.502 raeburn 7801: resize_scrollbox('contentscroll','1','1');
7802: return;
7803: }
7804:
1.514 raeburn 7805: function toggleMap(caller) {
1.502 raeburn 7806: var disp = 'none';
1.510 raeburn 7807: if (document.getElementById('importmapform')) {
1.514 raeburn 7808: if (caller == 'map') {
7809: var curr = document.getElementById('importmapform').style.display;
7810: if (curr == 'none') {
7811: disp='block';
7812: }
1.510 raeburn 7813: }
7814: document.getElementById('importmapform').style.display=disp;
7815: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7816: }
1.501 raeburn 7817: return;
1.329 droeschl 7818: }
7819:
1.691 raeburn 7820: function toggleCrsRes(caller) {
1.606 raeburn 7821: var disp = 'none';
7822: if (document.getElementById('crsresform')) {
7823: if (caller == 'res') {
1.691 raeburn 7824: var form = document.getElementById('crsresform');
7825: var curr = form.style.display;
1.606 raeburn 7826: if (curr == 'none') {
7827: disp='block';
1.691 raeburn 7828: document.courseresform.authorrole.selectedIndex = 0;
7829: document.courseresform.authorpath.selectedIndex = 0;
7830: document.courseresform.newresourceadd.selectedIndex = 0;
7831: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7832: toggleNewInCourse(document.courseresform);
7833: if (document.getElementById('newresource')) {
7834: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 7835: }
7836: if (document.courseresform.newresusetemp.length) {
7837: document.courseresform.newresusetemp[0].checked = true;
7838: toggleWithTemplate(document.courseresform);
7839: }
7840: document.courseresform.newresourcename.value = '';
7841: }
7842: }
7843: if (document.courseresform.newsubdir.length) {
7844: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7845: if (document.courseresform.newsubdir[j].value == 0) {
7846: document.courseresform.newsubdir[j].checked = true;
7847: }
7848: break;
7849: }
7850: if (document.getElementById('newsubdirname')) {
7851: document.getElementById('newsubdirname').type = "hidden";
7852: document.getElementById('newsubdirname').value = "";
7853: }
7854: if (document.getElementById('newsubdir')) {
7855: document.getElementById('newsubdir').innerHTML = "";
7856: }
7857: }
7858: document.getElementById('crsresform').style.display=disp;
7859: resize_scrollbox('contentscroll','1','0');
7860: }
7861: return;
7862: }
7863:
7864: function toggleNewsubdir(form) {
7865: if (form.newsubdir.length) {
7866: for (var j=0; j<form.newsubdir.length; j++) {
7867: if (form.newsubdir[j].checked) {
7868: if (document.getElementById('newsubdirname')) {
7869: if (form.newsubdir[j].value == '1') {
7870: document.getElementById('newsubdirname').type = "text";
7871: if (document.getElementById('newsubdir')) {
7872: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7873: }
7874: } else {
7875: document.getElementById('newsubdirname').type = "hidden";
7876: document.getElementById('newsubdirname').value = "";
7877: document.getElementById('newsubdir').innerHTML = "";
7878: }
7879: }
7880: break;
7881: }
7882: }
7883: }
7884: }
7885:
7886: function toggleCrsResTitle() {
7887: if (document.getElementById('newresource')) {
1.691 raeburn 7888: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7889: if (selloc == 'course') {
1.606 raeburn 7890: document.getElementById('newresource').style.display = 'inline';
7891: document.courseresform.newresourceadd[0].checked = true;
7892: toggleNewInCourse(document.courseresform);
7893: } else {
7894: document.getElementById('newresource').style.display = 'none';
7895: }
1.689 raeburn 7896: }
7897: if (document.getElementById('newstdproblem')) {
7898: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7899: document.getElementById('newstdproblem').style.display = 'none';
7900: if (document.getElementById('stdprobswitch')) {
7901: document.getElementById('stdprobswitch').style.display = 'block';
7902: }
7903: } else {
7904: document.getElementById('newstdproblem').style.display = 'block';
7905: if (document.getElementById('stdprobswitch')) {
7906: document.getElementById('stdprobswitch').style.display = 'none';
7907: }
7908: }
7909: }
1.606 raeburn 7910: }
7911:
7912: function toggleNewInCourse(form) {
7913: if (form.newresourceadd.length) {
7914: for (var i=0; i<form.newresourceadd.length; i++) {
7915: if (form.newresourceadd[i].checked) {
7916: if (document.getElementById('newresourcetitle')) {
7917: if (form.newresourceadd[i].value == '1') {
7918: document.getElementById('newresourcetitle').type = 'text';
7919: if (document.getElementById('newrestitle')) {
7920: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7921: }
7922: } else {
7923: document.getElementById('newresourcetitle').type = 'hidden';
7924: document.getElementById('newresourcetitle').value = '';
7925: if (document.getElementById('newrestitle')) {
7926: document.getElementById('newrestitle').innerHTML = '';
7927: }
7928: }
7929: }
7930: break;
7931: }
7932: }
7933: }
7934: }
7935:
7936: function toggleWithTemplate(form) {
7937: if (form.newresusetemp.length) {
7938: for (var i=0; i<form.newresusetemp.length; i++) {
7939: if (form.newresusetemp[i].checked) {
7940: if (document.getElementById('newrestemplate')) {
7941: if (form.newresusetemp[i].value == '1') {
7942: document.getElementById('newrestemplate').style.display = 'inline';
7943: toggleExampleText();
7944: } else {
7945: form.tempcategory.selectedIndex = 0;
7946: select1template_changed();
7947: document.getElementById('newrestemplate').style.display = 'none';
7948: }
7949: }
7950: }
7951: }
7952: }
7953: }
7954:
7955: function toggleExampleText() {
7956: if (document.getElementById('newresexample')) {
7957: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7958: if (url == '') {
7959: document.getElementById('newresexample').style.fontWeight = 'normal';
7960: } else {
7961: document.getElementById('newresexample').style.fontWeight = 'bold';
7962: }
7963: }
7964: }
7965:
7966: function getExample(width,height,scrolling,transparency) {
7967: var url;
7968: if (document.courseresform.newresusetemp.length) {
7969: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7970: if (document.courseresform.newresusetemp[i].checked) {
7971: if (document.courseresform.newresusetemp[i].value == '1') {
7972: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7973: if (url == '') {
7974: alert('Pick a category and template');
7975: } else {
7976: url = url.replace("$londocroot","");
7977: url += '?inhibitmenu=yes';
7978: }
7979: }
7980: break;
7981: }
7982: }
7983: }
7984: if (url != '') {
7985: openMyModal(url,width,height,scrolling,transparency,'');
7986: }
7987: }
7988:
1.690 raeburn 7989: function toggleImportCrsres(caller) {
1.606 raeburn 7990: var disp = 'none';
7991: if (document.getElementById('importcrsresform')) {
7992: if (caller == 'res') {
7993: var curr = document.getElementById('importcrsresform').style.display;
7994: if (curr == 'none') {
7995: disp='block';
1.698 raeburn 7996: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
7997: if ((document.getElementById('importcrsrescontent')) &&
7998: (document.getElementById('importcrsresempty'))) {
7999: var selelem = document.crsresimportform.elements['coursepath'];
8000: var numdirs = 0;
8001: if (selelem.options.length) {
8002: numdirs = selelem.options.length - 1;
8003: }
8004: if (numdirs) {
8005: document.getElementById('importcrsrescontent').style.display='block';
8006: document.getElementById('importcrsresempty').style.display='none';
8007: } else {
8008: document.getElementById('importcrsrescontent').style.display='none';
8009: document.getElementById('importcrsresempty').style.display='block';
8010: }
8011: }
1.606 raeburn 8012: }
8013: }
8014: document.getElementById('importcrsresform').style.display=disp;
8015: resize_scrollbox('contentscroll','1','0');
8016: }
8017: return;
8018: }
8019:
1.690 raeburn 8020: $showfile_js
8021:
1.691 raeburn 8022: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8023: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8024: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8025: var selelem = form.elements[dirsel];
8026: var i, numfiles = selelem.options.length -1;
8027: if (numfiles >=0) {
8028: for (i = numfiles; i >= 0; i--) {
8029: selelem.remove(i);
8030: }
8031: }
8032: if ((location == '') || (location == null) || (location == 'undefined')) {
8033: if (selelem.options.length == 0) {
8034: selelem.options[selelem.options.length] = new Option('','');
8035: selelem.selectedIndex = 0;
8036: }
8037: if (document.getElementById('newstdproblem')) {
8038: document.getElementById('newstdproblem').style.display = 'none';
8039: }
8040: return;
8041: }
8042: var machineIds = new Array($machines_str);
8043: var athome = 0;
8044: var role = location;
8045: if ((location == 'author') || (location == 'course')) {
8046: if (document.getElementById('rolehome_'+location)) {
8047: var currhome = document.getElementById('rolehome_'+location).value;
8048: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8049: if (machineIds.includes(currhome)) {
8050: athome = 1;
8051: }
8052: }
8053: }
8054: } else {
8055: const roleinfo = location.split('___');
8056: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8057: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8058: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8059: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8060: if (machineIds.includes(currhome)) {
8061: athome = 1;
8062: }
8063: }
8064: }
8065: }
8066: if (athome) {
8067: if (document.getElementById('stdprobswitch')) {
8068: document.getElementById('stdprobswitch').style.display = 'none';
8069: }
8070: if (document.getElementById('newstdproblem')) {
8071: document.getElementById('newstdproblem').style.display = 'none';
8072: }
8073: var http = new XMLHttpRequest();
8074: var url = "/adm/courseauthor";
1.698 raeburn 8075: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8076: http.open("POST", url, true);
8077: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8078: http.onreadystatechange = function() {
8079: if (http.readyState == 4 && http.status == 200) {
8080: var data = JSON.parse(http.responseText);
8081: if (Array.isArray(data.dirs)) {
8082: var len = data.dirs.length;
8083: if (len) {
8084: if (len > 1) {
8085: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8086: }
8087: }
8088: if (len) {
8089: var j;
8090: for (j = 0; j < len; j++) {
8091: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8092: }
8093: selelem.selectedIndex = 0;
1.697 raeburn 8094: if (len == 1) {
8095: toggleCrsResTitle();
8096: }
1.691 raeburn 8097: }
8098: }
8099: }
8100: }
8101: http.send(params);
8102: } else {
8103: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8104: selelem.selectedIndex = 0;
8105: if (document.getElementById('stdprobswitch')) {
8106: document.getElementById('stdprobswitch').style.display = 'block';
8107: }
8108: if (document.getElementById('newstdproblem')) {
8109: document.getElementById('newstdproblem').style.display = 'none';
8110: }
8111: }
8112: }
8113: return;
8114: }
8115:
1.689 raeburn 8116: function switchForProb() {
8117: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8118: var url = '/adm/switchserver?otherserver=';
8119: var newhostid = '';
8120: var role = '';
8121: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8122: if (selloc == 'author') {
8123: newhostid = document.courseresform.rolehome_author.value;
8124: role = "au./&js_escape($env{'user.domain'})/";
8125: } else if (selloc == 'course') {
8126: newhostid = document.courseresform.rolehome_course.value;
8127: role = "&js_escape($env{'request.role'})";
8128: } else {
8129: var items = new Array();
8130: items = selloc.split('___');
8131: var len = document.courseresform.rolehome_coauthor.length;
8132: if (null == len) {
8133: var currval = document.courseresform.rolehome_coauthor.value;
8134: if (null != currval) {
8135: var info = new Array();
8136: info = currval.split('=');
8137: newhostid = info[2];
8138: role = info[0]+'./'+info[1];
8139: }
8140: } else {
8141: for (var i=0; i<len; i++) {
8142: var currval = document.courseresform.rolehome_coauthor[i].value;
8143: if (null != currval) {
8144: var info = new Array();
8145: info = currval.split('=');
8146: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8147: newhostid = info[2];
8148: role = info[0]+'./'+info[1];
8149: break;
8150: }
8151: }
8152: }
8153: }
8154: }
8155: if (newhostid != '') {
8156: url += newhostid;
8157: if (role != '') {
8158: url += '&role='+role;
8159: }
8160: document.location.href = url;
8161: }
8162: }
8163: return;
8164: }
8165:
1.501 raeburn 8166: function makeims(imsform) {
8167: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8168: alert("$js_lt{'imsfile'}");
1.501 raeburn 8169: return;
8170: }
8171: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8172: alert("$js_lt{'imscms'}");
1.501 raeburn 8173: return;
8174: }
8175: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8176: imsform.submit();
8177: }
8178:
1.478 raeburn 8179: function updatePick(targetform,index,caller) {
1.537 raeburn 8180: var pickitem;
8181: var picknumitem;
8182: var picknumtext;
8183: if (index == 'all') {
8184: pickitem = document.getElementById('randompickall');
8185: picknumitem = document.getElementById('rpicknumall');
8186: picknumtext = document.getElementById('rpicktextall');
8187: } else {
8188: pickitem = document.getElementById('randompick_'+index);
8189: picknumitem = document.getElementById('rpicknum_'+index);
8190: picknumtext = document.getElementById('randompicknum_'+index);
8191: }
1.478 raeburn 8192: if (pickitem.checked) {
1.594 damieng 8193: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8194: if (picknum == '' || picknum == null) {
8195: if (caller == 'check') {
8196: pickitem.checked=false;
1.537 raeburn 8197: if (index == 'all') {
8198: picknumtext.innerHTML = '';
8199: if (caller == 'link') {
8200: propagateState(targetform,'rpicknum');
8201: }
8202: } else {
1.538 raeburn 8203: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8204: }
1.478 raeburn 8205: }
8206: } else {
8207: picknum.toString();
8208: var regexdigit=/^\\d+\$/;
8209: if (regexdigit.test(picknum)) {
8210: picknumitem.value = picknum;
1.537 raeburn 8211: if (index == 'all') {
1.538 raeburn 8212: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8213: if (caller == 'link') {
8214: propagateState(targetform,'rpicknum');
8215: }
8216: } else {
8217: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8218: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8219: }
1.478 raeburn 8220: } else {
8221: if (caller == 'check') {
1.537 raeburn 8222: if (index == 'all') {
8223: picknumtext.innerHTML = '';
8224: if (caller == 'link') {
8225: propagateState(targetform,'rpicknum');
8226: }
8227: } else {
8228: pickitem.checked=false;
1.538 raeburn 8229: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8230: }
1.478 raeburn 8231: }
8232: return;
8233: }
8234: }
8235: } else {
1.537 raeburn 8236: picknumitem.value = '';
8237: picknumtext.innerHTML = '';
8238: if (index == 'all') {
8239: if (caller == 'link') {
8240: propagateState(targetform,'rpicknum');
8241: }
8242: } else {
1.538 raeburn 8243: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8244: }
8245: }
8246: }
8247:
8248: function propagateState(form,param) {
8249: if (document.getElementById(param+'all')) {
8250: var setcheck = 0;
8251: var rpick = 0;
8252: if (param == 'rpicknum') {
8253: if (document.getElementById('randompickall')) {
8254: if (document.getElementById('randompickall').checked) {
8255: if (document.getElementById('rpicknumall')) {
8256: rpick = document.getElementById('rpicknumall').value;
8257: }
8258: }
8259: }
8260: } else {
8261: if (document.getElementById(param+'all').checked) {
8262: setcheck = 1;
8263: }
8264: }
1.538 raeburn 8265: var allidxlist;
8266: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8267: if (document.getElementById('all'+param+'idx')) {
8268: allidxlist = document.getElementById('all'+param+'idx').value;
8269: }
8270: var actions = new Array ('remove','cut','copy');
8271: for (var i=0; i<actions.length; i++) {
8272: if (actions[i] != param) {
8273: if (document.getElementById(actions[i]+'all')) {
8274: document.getElementById(actions[i]+'all').checked = false;
8275: }
8276: }
8277: }
8278: }
1.537 raeburn 8279: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8280: allidxlist = form.allidx.value;
8281: }
8282: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8283: allidxlist = form.allmapidx.value;
8284: }
8285: if ((allidxlist != '') && (allidxlist != null)) {
8286: var allidxs = allidxlist.split(',');
8287: if (allidxs.length > 1) {
8288: for (var i=0; i<allidxs.length; i++) {
8289: if (document.getElementById(param+'_'+allidxs[i])) {
8290: if (param == 'rpicknum') {
8291: if (document.getElementById('randompick_'+allidxs[i])) {
8292: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8293: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8294: if (rpick > 0) {
8295: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8296: } else {
8297: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8298: }
8299: }
8300: }
8301: } else {
1.537 raeburn 8302: if (setcheck == 1) {
8303: document.getElementById(param+'_'+allidxs[i]).checked = true;
8304: } else {
8305: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8306: if (param == 'randompick') {
8307: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8308: }
1.537 raeburn 8309: }
8310: }
8311: }
8312: }
1.538 raeburn 8313: if (setcheck == 1) {
8314: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8315: var actions = new Array('copy','cut','remove');
8316: for (var i=0; i<actions.length; i++) {
8317: var otheractions;
8318: var otheridxs;
8319: if (actions[i] === param) {
8320: continue;
8321: } else {
8322: if (document.getElementById('all'+actions[i]+'idx')) {
8323: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8324: otheridxs = otheractions.split(',');
8325: if (otheridxs.length > 1) {
8326: for (var j=0; j<otheridxs.length; j++) {
8327: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8328: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8329: }
1.537 raeburn 8330: }
8331: }
8332: }
1.538 raeburn 8333: }
8334: }
8335: }
8336: }
8337: }
8338: }
8339: }
8340: return;
8341: }
8342:
1.603 raeburn 8343: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8344: var canedit = '$canedit';
8345: if (canedit == '') {
8346: alert("$js_lt{'edri'}");
8347: return;
8348: }
1.539 raeburn 8349: var dosettings;
8350: var doaction;
1.538 raeburn 8351: var control = document.togglemultsettings;
8352: if (context == 'actions') {
8353: control = document.togglemultactions;
1.539 raeburn 8354: doaction = 1;
8355: } else {
8356: dosettings = 1;
1.538 raeburn 8357: }
1.539 raeburn 8358: if (control) {
8359: if (control.showmultpick.length) {
8360: for (var i=0; i<control.showmultpick.length; i++) {
8361: if (control.showmultpick[i].checked) {
8362: if (control.showmultpick[i].value == 1) {
8363: if (context == 'settings') {
8364: dosettings = 0;
8365: } else {
8366: doaction = 0;
1.538 raeburn 8367: }
8368: }
8369: }
1.537 raeburn 8370: }
8371: }
1.539 raeburn 8372: }
8373: if (context == 'settings') {
8374: if (dosettings == 1) {
1.538 raeburn 8375: targetform.changeparms.value=param;
8376: targetform.submit();
8377: }
1.537 raeburn 8378: }
1.539 raeburn 8379: if (context == 'actions') {
8380: if (doaction == 1) {
8381: targetform.cmd.value=param+'_'+index;
8382: targetform.folderpath.value=folderpath;
8383: targetform.markcopy.value=idx+':'+param;
8384: targetform.copyfolder.value=folder+'.'+container;
8385: if (param == 'remove') {
1.603 raeburn 8386: var doremove = 0;
8387: if (skip_confirm) {
8388: if (confirm_removal) {
8389: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8390: doremove = 1;
8391: }
8392: } else {
8393: doremove = 1;
8394: }
8395: } else {
8396: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8397: doremove = 1;
8398: }
8399: }
8400: if (doremove) {
1.539 raeburn 8401: targetform.markcopy.value='';
8402: targetform.copyfolder.value='';
8403: targetform.submit();
8404: }
8405: }
8406: if (param == 'cut') {
1.594 damieng 8407: 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 8408: targetform.submit();
8409: return;
8410: }
8411: }
8412: if (param == 'copy') {
8413: targetform.submit();
8414: return;
8415: }
8416: targetform.markcopy.value='';
8417: targetform.copyfolder.value='';
8418: targetform.cmd.value='';
8419: targetform.folderpath.value='';
8420: return;
8421: } else {
8422: if (document.getElementById(param+'_'+idx)) {
8423: item = document.getElementById(param+'_'+idx);
8424: if (item.type == 'checkbox') {
8425: if (item.checked) {
8426: item.checked = false;
8427: } else {
8428: item.checked = true;
8429: singleCheck(item,idx,param);
8430: }
8431: }
8432: }
8433: }
8434: }
1.537 raeburn 8435: return;
8436: }
8437:
1.538 raeburn 8438: function singleCheck(caller,idx,action) {
8439: actions = new Array('cut','copy','remove');
8440: if (caller.checked) {
8441: for (var i=0; i<actions.length; i++) {
8442: if (actions[i] != action) {
8443: if (document.getElementById(actions[i]+'_'+idx)) {
8444: if (document.getElementById(actions[i]+'_'+idx).checked) {
8445: document.getElementById(actions[i]+'_'+idx).checked = false;
8446: }
1.537 raeburn 8447: }
8448: }
8449: }
1.478 raeburn 8450: }
1.537 raeburn 8451: return;
1.478 raeburn 8452: }
8453:
1.334 muellerd 8454: function unselectInactive(nav) {
1.335 ehlerst 8455: currentNav = document.getElementById(nav);
8456: currentLis = currentNav.getElementsByTagName('LI');
8457: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8458: if (currentLis[i].className == 'goback') {
8459: currentLis[i].className = 'goback';
8460: } else {
8461: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8462: currentLis[i].className = 'right';
1.472 raeburn 8463: } else {
1.374 tempelho 8464: currentLis[i].className = 'i';
1.472 raeburn 8465: }
8466: }
1.335 ehlerst 8467: }
1.332 tempelho 8468: }
8469:
1.334 muellerd 8470: function hideAll(current, nav, data) {
1.335 ehlerst 8471: unselectInactive(nav);
1.570 raeburn 8472: if (current) {
8473: if (current.className == 'right'){
8474: current.className = 'right active'
8475: } else {
8476: current.className = 'active';
8477: }
1.374 tempelho 8478: }
1.335 ehlerst 8479: currentData = document.getElementById(data);
8480: currentDivs = currentData.getElementsByTagName('DIV');
8481: for (i = 0; i < currentDivs.length; i++) {
8482: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8483: currentDivs[i].style.display = 'none';
1.330 tempelho 8484: }
8485: }
1.335 ehlerst 8486: }
1.330 tempelho 8487:
1.374 tempelho 8488: function openTabs(pageId) {
8489: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8490: if(tabnav.length > 2 ){
1.389 tempelho 8491: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8492: currentLis = currentNav.getElementsByTagName('LI');
8493: for(i = 0; i< currentLis.length; i++){
8494: if(currentLis[i].className == 'active') {
1.375 tempelho 8495: funcString = currentLis[i].onclick.toString();
8496: tab = funcString.split('"');
1.420 onken 8497: if(tab.length < 2) {
8498: tab = funcString.split("'");
8499: }
1.375 tempelho 8500: currentData = document.getElementById(tab[1]);
8501: currentData.style.display = 'block';
1.374 tempelho 8502: }
8503: }
8504: }
8505: }
8506:
1.334 muellerd 8507: function showPage(current, pageId, nav, data) {
1.570 raeburn 8508: currstate = current.className;
1.334 muellerd 8509: hideAll(current, nav, data);
1.375 tempelho 8510: openTabs(pageId);
1.334 muellerd 8511: unselectInactive(nav);
1.570 raeburn 8512: if ((currstate == 'active') || (currstate == 'right active')) {
8513: if (currstate == 'active') {
8514: current.className = '';
8515: } else {
8516: current.className = 'right';
8517: }
8518: activeTab = '';
1.656 raeburn 8519: toggleExternal();
1.570 raeburn 8520: toggleUpload();
8521: toggleMap();
1.606 raeburn 8522: toggleCrsRes();
8523: toggleImportCrsres();
1.570 raeburn 8524: resize_scrollbox('contentscroll','1','0');
8525: return;
8526: } else {
8527: current.className = 'active';
8528: }
1.330 tempelho 8529: currentData = document.getElementById(pageId);
8530: currentData.style.display = 'block';
1.458 raeburn 8531: activeTab = pageId;
1.656 raeburn 8532: toggleExternal();
1.501 raeburn 8533: toggleUpload();
1.503 raeburn 8534: toggleMap();
1.606 raeburn 8535: toggleCrsRes();
8536: toggleImportCrsres();
1.433 raeburn 8537: if (nav == 'mainnav') {
8538: var storedpath = "$docs_folderpath";
1.434 raeburn 8539: var storedpage = "$main_container_page";
1.433 raeburn 8540: var reg = new RegExp("^supplemental");
8541: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8542: if (storedpage == 1) {
8543: document.simpleedit.folderpath.value = '';
8544: document.uploaddocument.folderpath.value = '';
8545: } else {
8546: if (reg.test(storedpath)) {
8547: document.simpleedit.folderpath.value = '$toplevelmain';
8548: document.uploaddocument.folderpath.value = '$toplevelmain';
8549: document.newext.folderpath.value = '$toplevelmain';
8550: } else {
8551: document.simpleedit.folderpath.value = storedpath;
8552: document.uploaddocument.folderpath.value = storedpath;
8553: document.newext.folderpath.value = storedpath;
8554: }
1.433 raeburn 8555: }
8556: } else {
1.434 raeburn 8557: if (reg.test(storedpath)) {
8558: document.simpleedit.folderpath.value = storedpath;
8559: document.supuploaddocument.folderpath.value = storedpath;
8560: document.supnewext.folderpath.value = storedpath;
8561: } else {
1.433 raeburn 8562: document.simpleedit.folderpath.value = '$toplevelsupp';
8563: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8564: document.supnewext.folderpath.value = '$toplevelsupp';
8565: }
8566: }
8567: }
1.485 raeburn 8568: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8569: return false;
8570: }
1.329 droeschl 8571:
1.472 raeburn 8572: function toContents(jumpto) {
8573: var newurl = '$backtourl';
1.525 raeburn 8574: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8575: newurl = newurl+'?postdata='+jumpto;
8576: }
8577: location.href=newurl;
8578: }
8579:
1.538 raeburn 8580: function togglePick(caller,value) {
8581: var disp = 'none';
8582: if (document.getElementById('multi'+caller)) {
8583: var curr = document.getElementById('multi'+caller).style.display;
8584: if (value == 1) {
8585: disp='block';
8586: }
8587: if (curr == disp) {
8588: return;
8589: }
8590: document.getElementById('multi'+caller).style.display=disp;
8591: if (value == 1) {
1.594 damieng 8592: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8593: } else {
8594: document.getElementById('more'+caller).innerHTML = '';
8595: }
8596: if (caller == 'actions') {
8597: setClass(value);
8598: setBoxes(value);
8599: }
8600: }
8601: var showButton = multiSettings();
8602: if (showButton != 1) {
8603: showButton = multiActions();
8604: }
8605: if (document.getElementById('multisave')) {
8606: if (showButton == 1) {
8607: document.getElementById('multisave').style.display='block';
8608: } else {
8609: document.getElementById('multisave').style.display='none';
8610: }
8611: }
8612: resize_scrollbox('contentscroll','1','1');
8613: return;
8614: }
8615:
8616: function toggleCheckUncheck(caller,more) {
8617: if (more == 1) {
1.594 damieng 8618: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8619: document.getElementById('allfields'+caller).style.display='block';
8620: } else {
1.594 damieng 8621: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8622: document.getElementById('allfields'+caller).style.display='none';
8623: }
8624: resize_scrollbox('contentscroll','1','1');
8625: }
8626:
8627: function multiSettings() {
8628: var inuse = 0;
8629: var settingsform = document.togglemultsettings;
8630: if (settingsform.showmultpick.length > 1) {
8631: for (var i=0; i<settingsform.showmultpick.length; i++) {
8632: if (settingsform.showmultpick[i].checked) {
8633: if (settingsform.showmultpick[i].value == 1) {
8634: inuse = 1;
8635: }
8636: }
8637: }
8638: }
8639: return inuse;
8640: }
8641:
8642: function multiActions() {
8643: var inuse = 0;
8644: var actionsform = document.togglemultactions;
8645: if (actionsform.showmultpick.length > 1) {
8646: for (var i=0; i<actionsform.showmultpick.length; i++) {
8647: if (actionsform.showmultpick[i].checked) {
8648: if (actionsform.showmultpick[i].value == 1) {
8649: inuse = 1;
8650: }
8651: }
8652: }
8653: }
8654: return inuse;
8655: }
8656:
8657: function checkSubmits() {
8658: var numchanges = 0;
8659: var form = document.saveactions;
8660: var doactions = multiActions();
1.542 raeburn 8661: var cutwarnings = 0;
8662: var remwarnings = 0;
1.603 raeburn 8663: var removalinfo = 0;
1.538 raeburn 8664: if (doactions == 1) {
8665: var remidxlist = document.cumulativeactions.allremoveidx.value;
8666: if ((remidxlist != '') && (remidxlist != null)) {
8667: var remidxs = remidxlist.split(',');
8668: for (var i=0; i<remidxs.length; i++) {
8669: if (document.getElementById('remove_'+remidxs[i])) {
8670: if (document.getElementById('remove_'+remidxs[i]).checked) {
8671: form.multiremove.value += remidxs[i]+',';
8672: numchanges ++;
1.542 raeburn 8673: if (document.getElementById('skip_remove_'+remidxs[i])) {
8674: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8675: remwarnings ++;
8676: }
8677: }
1.603 raeburn 8678: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8679: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8680: removalinfo ++;
8681: }
8682: }
1.537 raeburn 8683: }
8684: }
1.538 raeburn 8685: }
8686: }
8687: var cutidxlist = document.cumulativeactions.allcutidx.value;
8688: if ((cutidxlist != '') && (cutidxlist != null)) {
8689: var cutidxs = cutidxlist.split(',');
8690: for (var i=0; i<cutidxs.length; i++) {
8691: if (document.getElementById('cut_'+cutidxs[i])) {
8692: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8693: form.multicut.value += cutidxs[i]+',';
8694: numchanges ++;
1.542 raeburn 8695: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8696: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8697: cutwarnings ++;
8698: }
8699: }
1.537 raeburn 8700: }
8701: }
8702: }
8703: }
1.538 raeburn 8704: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8705: if ((copyidxlist != '') && (copyidxlist != null)) {
8706: var copyidxs = copyidxlist.split(',');
8707: for (var i=0; i<copyidxs.length; i++) {
8708: if (document.getElementById('copy_'+copyidxs[i])) {
8709: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8710: form.multicopy.value += copyidxs[i]+',';
8711: numchanges ++;
8712: }
8713: }
8714: }
8715: }
8716: if (numchanges > 0) {
8717: form.multichange.value = numchanges;
8718: }
1.537 raeburn 8719: }
1.538 raeburn 8720: var dosettings = multiSettings();
1.543 raeburn 8721: var haschanges = 0;
1.538 raeburn 8722: if (dosettings == 1) {
8723: form.allencrypturl.value = '';
8724: form.allhiddenresource.value = '';
1.543 raeburn 8725: form.changeparms.value = 'all';
8726: var patt=new RegExp(",\$");
1.538 raeburn 8727: var allidxlist = document.cumulativesettings.allidx.value;
8728: if ((allidxlist != '') && (allidxlist != null)) {
8729: var allidxs = allidxlist.split(',');
8730: if (allidxs.length > 1) {
8731: for (var i=0; i<allidxs.length; i++) {
8732: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8733: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8734: form.allhiddenresource.value += allidxs[i]+',';
8735: }
8736: }
8737: if (document.getElementById('encrypturl_'+allidxs[i])) {
8738: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8739: form.allencrypturl.value += allidxs[i]+',';
8740: }
8741: }
8742: }
1.543 raeburn 8743: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8744: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8745: }
1.538 raeburn 8746: }
8747: form.allrandompick.value = '';
8748: form.allrandomorder.value = '';
8749: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8750: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8751: var allmapidxs = allmapidxlist.split(',');
8752: for (var i=0; i<allmapidxs.length; i++) {
8753: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8754: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8755: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8756: if ((randompick.checked) && (rpicknum.value != '')) {
8757: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8758: }
8759: if (randorder.checked) {
8760: form.allrandomorder.value += allmapidxs[i]+',';
8761: }
1.537 raeburn 8762: }
1.543 raeburn 8763: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8764: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8765: }
8766: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8767: haschanges = 1;
8768: }
8769: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8770: haschanges = 1;
8771: }
8772: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8773: haschanges = 1;
8774: }
8775: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8776: haschanges = 1;
1.537 raeburn 8777: }
8778: }
1.543 raeburn 8779: if (doactions == 1) {
1.542 raeburn 8780: if (numchanges > 0) {
1.603 raeburn 8781: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8782: if (remwarnings > 0) {
1.594 damieng 8783: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8784: return false;
8785: }
8786: }
1.603 raeburn 8787: if (removalinfo > 0) {
8788: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8789: return false;
8790: }
8791: }
1.542 raeburn 8792: if (cutwarnings > 0) {
1.594 damieng 8793: 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 8794: return false;
8795: }
8796: }
8797: }
8798: form.submit();
8799: return true;
1.543 raeburn 8800: }
8801: }
8802: if (dosettings == 1) {
8803: if (haschanges == 1) {
1.542 raeburn 8804: form.submit();
8805: return true;
8806: }
1.543 raeburn 8807: }
8808: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8809: alert("$js_lt{'noor'}");
1.543 raeburn 8810: } else {
8811: if (dosettings == 1) {
1.594 damieng 8812: alert("$js_lt{'noch'}");
1.543 raeburn 8813: } else {
1.594 damieng 8814: alert("$js_lt{'noac'}");
1.543 raeburn 8815: }
8816: }
1.538 raeburn 8817: return false;
8818: }
8819:
8820: function setClass(value) {
8821: var cutclass = 'LC_docs_cut';
8822: var copyclass = 'LC_docs_copy';
8823: var removeclass = 'LC_docs_remove';
8824: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8825: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8826: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8827: var links = document.getElementsByTagName('a');
8828: for (var i=0; i<links.length; i++) {
8829: var classes = links[i].className;
8830: if (cutreg.test(classes)) {
8831: links[i].className = cutclass;
8832: if (value == 1) {
8833: links[i].className += " LC_menubuttons_link";
8834: }
8835: } else {
8836: if (copyreg.test(classes)) {
8837: links[i].className = copyclass;
8838: if (value == 1) {
8839: links[i].className += " LC_menubuttons_link";
8840: }
8841: } else {
8842: if (removereg.test(classes)) {
8843: links[i].className = removeclass;
8844: if (value == 1) {
8845: links[i].className += " LC_menubuttons_link";
8846: }
8847: }
8848: }
8849: }
8850: }
8851: return;
1.537 raeburn 8852: }
8853:
1.538 raeburn 8854: function setBoxes(value) {
8855: var remidxlist = document.cumulativeactions.allremoveidx.value;
8856: if ((remidxlist != '') && (remidxlist != null)) {
8857: var remidxs = remidxlist.split(',');
8858: for (var i=0; i<remidxs.length; i++) {
8859: if (document.getElementById('remove_'+remidxs[i])) {
8860: var item = document.getElementById('remove_'+remidxs[i]);
8861: if (value == 1) {
8862: item.className = 'LC_docs_remove';
8863: } else {
8864: item.className = 'LC_hidden';
8865: }
8866: }
8867: }
8868: }
8869: var cutidxlist = document.cumulativeactions.allcutidx.value;
8870: if ((cutidxlist != '') && (cutidxlist != null)) {
8871: var cutidxs = cutidxlist.split(',');
8872: for (var i=0; i<cutidxs.length; i++) {
8873: if (document.getElementById('cut_'+cutidxs[i])) {
8874: var item = document.getElementById('cut_'+cutidxs[i]);
8875: if (value == 1) {
8876: item.className = 'LC_docs_cut';
8877: } else {
8878: item.className = 'LC_hidden';
8879: }
8880: }
1.537 raeburn 8881: }
8882: }
1.538 raeburn 8883: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8884: if ((copyidxlist != '') && (copyidxlist != null)) {
8885: var copyidxs = copyidxlist.split(',');
8886: for (var i=0; i<copyidxs.length; i++) {
8887: if (document.getElementById('copy_'+copyidxs[i])) {
8888: var item = document.getElementById('copy_'+copyidxs[i]);
8889: if (value == 1) {
8890: item.className = 'LC_docs_copy';
8891: } else {
8892: item.className = 'LC_hidden';
8893: }
8894: }
1.537 raeburn 8895: }
8896: }
8897: return;
8898: }
8899:
1.606 raeburn 8900: function validImportCrsRes() {
8901: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8902: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8903: if ((fname == '') || (fname == null)) {
8904: alert("$js_lt{'nofi'}");
8905: return false;
8906: }
8907: var url = '/res/$coursedom/$coursenum/';
8908: if (path && path != '/') {
8909: url += path+'/';
8910: }
8911: if (fname != '') {
8912: url += fname;
8913: }
8914: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8915: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8916: return true;
8917: }
8918:
8919: function validateNewRes(caller) {
8920: if (caller == 'single') {
8921: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8922: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8923: var resname = document.courseresform.newresourcename.value;
8924: }
8925: }
8926:
1.611 raeburn 8927: ENDSCRIPT
1.329 droeschl 8928: }
1.457 raeburn 8929:
1.483 raeburn 8930: sub history_tab_js {
8931: return <<"ENDHIST";
8932: function toggleHistoryDisp(choice) {
8933: document.docslogform.docslog.value = choice;
8934: document.docslogform.submit();
8935: return;
8936: }
8937:
8938: ENDHIST
8939: }
8940:
1.484 raeburn 8941: sub inject_data_js {
8942: return <<ENDINJECT;
8943:
8944: function injectData(current, hiddenField, name, value) {
8945: currentElement = document.getElementById(hiddenField);
8946: currentElement.name = name;
8947: currentElement.value = value;
8948: current.submit();
8949: }
8950:
8951: ENDINJECT
8952: }
8953:
8954: sub dump_switchserver_js {
8955: my @hosts = @_;
1.594 damieng 8956: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8957: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8958: swit => 'Switch server?',
1.594 damieng 8959: );
8960: my %html_js_lt = &Apache::lonlocal::texthash(
8961: swit => 'Switch server?',
1.568 raeburn 8962: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8963: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8964: chos => 'Choose server',
8965: );
1.594 damieng 8966: &js_escape(\%js_lt);
8967: &html_escape(\%html_js_lt);
8968: &js_escape(\%html_js_lt);
1.484 raeburn 8969: my $role = $env{'request.role'};
8970: my $js = <<"ENDSWJS";
8971: <script type="text/javascript">
8972: function write_switchserver() {
8973: var server;
8974: if (document.setserver.posshosts.length > 0) {
8975: for (var i=0; i<document.setserver.posshosts.length; i++) {
8976: if (document.setserver.posshosts[i].checked) {
8977: server = document.setserver.posshosts[i].value;
8978: }
8979: }
8980: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8981: }
8982: window.close();
8983: }
8984: </script>
8985:
8986: ENDSWJS
8987:
8988: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8989: {'only_body' => 1,
8990: 'js_ready' => 1,});
8991: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8992:
8993: my $hostpicker;
8994: my $count = 0;
8995: foreach my $host (sort(@hosts)) {
8996: my $checked;
8997: if ($count == 0) {
8998: $checked = ' checked="checked"';
8999: }
9000: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9001: $host.'"'.$checked.' />'.$host.'</label> ';
9002: $count++;
9003: }
9004:
9005: return <<"ENDSWITCHJS";
9006:
9007: function dump_needs_switchserver(url) {
9008: if (url!='' && url!= null) {
1.594 damieng 9009: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 9010: go(url);
9011: }
9012: }
9013: return;
9014: }
9015:
9016: function choose_switchserver_window() {
9017: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9018: newWindow.document.open();
9019: newWindow.document.writeln('$startpage');
1.594 damieng 9020: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9021: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9022: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9023: '<form name="setserver" method="post" action="" \\/>\\n'+
9024: '$hostpicker\\n'+
9025: '<br \\/><br \\/>\\n'+
1.594 damieng 9026: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9027: 'onclick="write_switchserver();" \\/>\\n'+
9028: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9029: newWindow.document.writeln('$endpage');
9030: newWindow.document.close();
9031: newWindow.focus();
9032: }
9033:
9034: ENDSWITCHJS
9035: }
9036:
9037: sub makedocslogform {
9038: my ($formelems,$docslog) = @_;
9039: return <<"LOGSFORM";
9040: <form action="/adm/coursedocs" method="post" name="docslogform">
9041: <input type="hidden" name="docslog" value="$docslog" />
9042: $formelems
9043: </form>
9044: LOGSFORM
9045: }
9046:
9047: sub makesimpleeditform {
9048: my ($formelems) = @_;
9049: return <<"SIMPFORM";
9050: <form name="simpleedit" method="post" action="/adm/coursedocs">
9051: <input type="hidden" name="importdetail" value="" />
9052: $formelems
9053: </form>
9054: SIMPFORM
9055: }
9056:
1.606 raeburn 9057: sub makenewproblem {
9058: my ($r,$coursedom,$coursenum) = @_;
9059: # Creating a new problem
9060: my ($redirect,$error);
9061: if ($env{'form.authorrole'}) {
9062: my ($newsubdir,$filename);
9063: if ($env{'form.newsubdir'}) {
9064: if ($env{'form.newsubdirname'} ne '') {
9065: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9066: }
1.606 raeburn 9067: }
9068: if ($env{'form.newresourcename'}) {
9069: $filename = $env{'form.newresourcename'};
9070: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9071: $filename =~ s/`//g;
9072: $filename =~ s{/\.\./}{_}g;
9073: $filename =~ s/\.+/./g;
9074: $filename =~ s{/+}{_}g;
9075: if ($filename ne '') {
9076: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9077: if (($ext) && ($ext ne '.problem')) {
9078: $filename = $name.'.problem';
9079: } elsif ($ext eq '') {
9080: $filename .= '.problem';
9081: }
9082: my $docroot = $r->dir_config('lonDocRoot');
9083: my @ids=&Apache::lonnet::current_machine_ids();
9084: if ($env{'form.authorrole'} eq 'author') {
9085: if ($env{'user.author'}) {
9086: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9087: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9088: my $path = $docroot.$url;
9089: my $subdir = $env{'form.authorpath'};
9090: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9091: }
9092: }
9093: } elsif ($env{'form.authorrole'} eq 'course') {
9094: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9095: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9096: my $url = "/priv/$coursedom/$coursenum";
9097: my $path=$docroot.$url;
9098: my $subdir = $env{'form.authorpath'};
9099: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9100: if ($redirect) {
9101: my $rightsfile = 'default.rights';
9102: my $sourcerights = "$path/$rightsfile";
9103: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9104: my $now = time;
9105: if (!-e $sourcerights) {
9106: my $cid = $coursedom.'_'.$coursenum;
9107: if (open(my $fh,">$sourcerights")) {
9108: print $fh <<END;
9109: <accessrule effect="deny" realm="" type="course" role="" />
9110: <accessrule effect="allow" realm="$cid" type="course" role="" />
9111: END
9112: close($fh);
9113: }
9114: }
9115: if (!-e "$sourcerights.meta") {
9116: if (open(my $fh,">$sourcerights.meta")) {
9117: my $author=$env{'environment.firstname'}.' '.
9118: $env{'environment.middlename'}.' '.
9119: $env{'environment.lastname'}.' '.
9120: $env{'environment.generation'};
9121: $author =~ s/\s+$//;
9122: print $fh <<"END";
9123:
9124: <abstract></abstract>
9125: <author>$author</author>
9126: <authorspace>$coursenum:$coursedom</authorspace>
9127: <copyright>private</copyright>
9128: <creationdate>$now</creationdate>
9129: <customdistributionfile></customdistributionfile>
9130: <dependencies></dependencies>
9131: <domain>$coursedom</domain>
9132: <highestgradelevel>0</highestgradelevel>
9133: <keywords></keywords>
9134: <language>notset </language>
9135: <lastrevisiondate>$now</lastrevisiondate>
9136: <lowestgradelevel>0</lowestgradelevel>
9137: <mime>rights</mime>
9138: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9139: <notes></notes>
9140: <obsolete></obsolete>
9141: <obsoletereplacement></obsoletereplacement>
9142: <owner>$coursenum:$coursedom</owner>
9143: <rule>deny:::course,allow:$cid::course</rule>
9144: <sourceavail></sourceavail>
9145: <standards></standards>
9146: <subject></subject>
9147: <title></title>
9148: END
1.654 raeburn 9149: close($fh);
9150: }
9151: }
9152: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9153: if (!-e "$docroot/res/$coursedom") {
9154: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9155: }
1.654 raeburn 9156: if (!-e "$docroot/res/$coursedom/$coursenum") {
9157: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9158: }
9159: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9160: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9161: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9162: }
9163: }
1.654 raeburn 9164: my $source = $docroot.$redirect;
9165: if (!-e "$source.meta") {
9166: my $cid = $coursedom.'_'.$coursenum;
9167: my $now = time;
9168: if (open(my $fh,">$source.meta")) {
9169: my $author=$env{'environment.firstname'}.' '.
9170: $env{'environment.middlename'}.' '.
9171: $env{'environment.lastname'}.' '.
9172: $env{'environment.generation'};
9173: $author =~ s/\s+$//;
9174: my $title = $env{'form.newresourcetitle'};
9175: $title =~ s/^\s+|\s+$//g;
9176: print $fh <<END;
1.606 raeburn 9177:
9178: <abstract></abstract>
9179: <author>$author</author>
9180: <authorspace>$coursenum:$coursedom</authorspace>
9181: <copyright>custom</copyright>
9182: <creationdate>$now</creationdate>
9183: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9184: <dependencies></dependencies>
9185: <domain>$coursedom</domain>
9186: <highestgradelevel>0</highestgradelevel>
9187: <keywords></keywords>
9188: <language>notset </language>
9189: <lastrevisiondate>$now</lastrevisiondate>
9190: <lowestgradelevel>0</lowestgradelevel>
9191: <mime>problem</mime>
9192: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9193: <notes></notes>
9194: <obsolete></obsolete>
9195: <obsoletereplacement></obsoletereplacement>
9196: <owner>$coursenum:$coursedom</owner>
9197: <sourceavail></sourceavail>
9198: <standards></standards>
9199: <subject></subject>
9200: <title>$title</title>
9201: END
1.654 raeburn 9202: close($fh);
1.606 raeburn 9203: }
9204: }
9205: }
9206: }
9207: } else {
9208: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9209: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9210: if (grep(/^\Q$rolehome\E$/,@ids)) {
9211: my $now = time;
9212: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9213: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9214: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9215: my $url = "/priv/$audom/$auname";
9216: my $path = $r->dir_config('lonDocRoot').$url;
9217: my $subdir = $env{'form.authorpath'};
9218: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9219: }
9220: }
9221: }
9222: }
9223: }
9224: }
9225: }
9226: return ($redirect,$error);
9227: }
9228:
9229: sub finishnewprob {
1.654 raeburn 9230: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9231: unless (-d $path) {
9232: unless (mkdir($path,02770)) {
9233: return;
9234: }
9235: }
1.606 raeburn 9236: my $redirect;
9237: if ($subdir ne '/') {
9238: $subdir = &cleandir($subdir);
9239: if (($subdir ne '') && (-d "$path/$subdir")) {
9240: $path .= "/$subdir";
9241: $url .= "/$subdir";
9242: }
9243: }
9244: my $dest;
9245: if ($newsubdir ne '') {
9246: $newsubdir = &cleandir($newsubdir);
9247: }
9248: if ($newsubdir ne '') {
9249: if (-d "$path/$newsubdir") {
9250: $dest = "$path/$newsubdir/$filename";
9251: } else {
9252: my $dirok;
9253: unless (-e "$path/$newsubdir") {
9254: if (mkdir("$path/$newsubdir",02770)) {
9255: if (chmod(02770,"$path/$newsubdir")) {
9256: $dirok = 1;
9257: }
9258: }
9259: }
9260: if ($dirok) {
9261: $dest = "$path/$newsubdir/$filename";
9262: }
9263: }
9264: if (($dest ne '') && (!-e $dest)) {
9265: $redirect = "$url/$newsubdir/$filename";
9266: }
9267: } else {
9268: $dest = "$path/$filename";
9269: if (($dest ne '') && (!-e $dest)) {
9270: $redirect = "$url/$filename";
9271: }
9272: }
1.654 raeburn 9273: if ((!-e $dest) && ($context ne 'upload')) {
9274: my $template = $env{'form.template'};
9275: my $copyfrom;
9276: if ($template ne '') {
9277: my %templates;
9278: my @files = &Apache::lonhomework::get_template_list('problem');
9279: foreach my $poss (@files) {
9280: if (ref($poss) eq 'ARRAY') {
9281: if ($template eq $poss->[0]) {
9282: $templates{$template} = 1;
9283: last;
9284: }
9285: }
9286: }
9287: if ($templates{$template}) {
9288: $copyfrom = $template;
9289: }
9290: }
9291: if ($filename =~ /\.problem$/) {
9292: unless ($copyfrom) {
9293: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9294: }
9295: &File::Copy::copy($copyfrom,$dest);
9296: }
9297: }
1.606 raeburn 9298: return $redirect;
9299: }
9300:
9301: sub cleandir {
9302: my ($dir) = @_;
9303: $dir =~ s/^\s+//;
9304: $dir =~ s/\s+$//;
9305: $dir =~ s/\.+//g;
9306: $dir =~ s/[\#\?&%\":]//g;
9307: return $dir;
9308: }
9309:
1.329 droeschl 9310: 1;
9311: __END__
9312:
9313:
9314: =head1 NAME
9315:
9316: Apache::londocs.pm
9317:
9318: =head1 SYNOPSIS
9319:
9320: This is part of the LearningOnline Network with CAPA project
9321: described at http://www.lon-capa.org.
9322:
9323: =head1 SUBROUTINES
9324:
9325: =over
9326:
9327: =item %help=()
9328:
9329: Available help topics
9330:
9331: =item mapread()
9332:
1.344 bisitz 9333: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9334: @order and @resources, determines status
9335: sets @order - pointer to resources in right order
9336: sets @resources - array with the resources with correct idx
9337:
9338: =item authorhosts()
9339:
9340: Return hash with valid author names
9341:
9342: =item clean()
9343:
9344: =item dumpcourse()
9345:
9346: Actually dump course
9347:
9348: =item group_import()
9349:
9350: Imports the given (name, url) resources into the course
9351: coursenum, coursedom, and folder must precede the list
9352:
9353: =item breadcrumbs()
9354:
9355: =item log_docs()
9356:
9357: =item docs_change_log()
9358:
9359: =item update_paste_buffer()
9360:
9361: =item print_paste_buffer()
9362:
9363: =item do_paste_from_buffer()
9364:
1.538 raeburn 9365: =item do_buffer_empty()
9366:
9367: =item clear_from_buffer()
9368:
1.492 raeburn 9369: =item get_newmap_url()
9370:
9371: =item dbcopy()
9372:
9373: =item uniqueness_check()
9374:
9375: =item contained_map_check()
9376:
9377: =item url_paste_fixups()
9378:
9379: =item apply_fixups()
9380:
9381: =item copy_dependencies()
9382:
1.329 droeschl 9383: =item update_parameter()
9384:
9385: =item handle_edit_cmd()
9386:
9387: =item editor()
9388:
9389: =item process_file_upload()
9390:
9391: =item process_secondary_uploads()
9392:
9393: =item is_supplemental_title()
9394:
9395: =item entryline()
9396:
9397: =item tiehash()
9398:
9399: =item untiehash()
9400:
9401: =item checkonthis()
9402:
9403: check on this
9404:
9405: =item verifycontent()
9406:
9407: Verify Content
9408:
1.636 raeburn 9409: =item devalidateversioncache()
9410:
9411: =item checkversions()
1.329 droeschl 9412:
9413: Check Versions
9414:
9415: =item mark_hash_old()
9416:
9417: =item is_hash_old()
9418:
9419: =item changewarning()
9420:
9421: =item init_breadcrumbs()
9422:
9423: Breadcrumbs for special functions
9424:
1.484 raeburn 9425: =item create_list_elements()
9426:
9427: =item create_form_ul()
9428:
9429: =item startContentScreen()
9430:
9431: =item endContentScreen()
9432:
9433: =item supplemental_base()
9434:
9435: =item embedded_form_elems()
9436:
9437: =item embedded_destination()
9438:
9439: =item return_to_editor()
9440:
9441: =item decompression_info()
9442:
9443: =item decompression_phase_one()
9444:
9445: =item decompression_phase_two()
9446:
9447: =item remove_archive()
9448:
9449: =item generate_admin_menu()
9450:
9451: =item generate_edit_table()
9452:
9453: =item editing_js()
9454:
9455: =item history_tab_js()
9456:
9457: =item inject_data_js()
9458:
9459: =item dump_switchserver_js()
9460:
1.485 raeburn 9461: =item resize_scrollbox_js()
1.484 raeburn 9462:
9463: =item makedocslogform()
9464:
1.485 raeburn 9465: =item makesimpleeditform()
9466:
1.329 droeschl 9467: =back
9468:
9469: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>