Annotation of loncom/interface/londocs.pm, revision 1.698
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.698 ! raeburn 4: # $Id: londocs.pm,v 1.697 2023/03/23 22:54:38 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.604 raeburn 722: my ($toolid,%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: }
731: $toolid =~ s/\D//g;
1.604 raeburn 732: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 733: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
734: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 735: foreach my $item (@extras) {
736: $toolhash{$item} = &unescape($toolhash{$item});
737: }
1.645 raeburn 738: if ($folder =~ /^supplemental/) {
1.648 raeburn 739: delete($toolhash{'gradable'});
740: } else {
741: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 742: }
1.598 raeburn 743: if (ref($ltitoolsref) eq 'HASH') {
744: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 raeburn 745: my @deleted;
1.598 raeburn 746: $toolhash{'id'} = $toolid;
1.628 raeburn 747: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
748: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 749: if ($toolhash{'target'} eq 'window') {
750: foreach my $item ('width','height') {
751: $toolhash{$item} =~ s/^\s+//;
752: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 753: if ($toolhash{$item} =~ /\D/) {
754: delete($toolhash{$item});
755: if ($residx) {
756: if ($toolsettings{$item}) {
757: push(@deleted,$item);
758: }
759: }
760: }
1.604 raeburn 761: }
762: }
763: } elsif ($residx) {
764: $toolhash{'target'} = $toolsettings{'target'};
765: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 766: foreach my $item ('width','height') {
1.624 raeburn 767: $toolhash{$item} = $toolsettings{$item};
768: }
1.604 raeburn 769: }
770: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
771: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
774: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
775: }
776: }
1.598 raeburn 777: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 778: foreach my $item ('width','height','linktext','explanation') {
779: delete($toolhash{$item});
780: if ($residx) {
781: if ($toolsettings{$item}) {
782: push(@deleted,$item);
783: }
1.604 raeburn 784: }
785: }
1.628 raeburn 786: } elsif ($toolhash{'target'} eq 'tab') {
787: foreach my $item ('width','height') {
788: delete($toolhash{$item});
789: if ($residx) {
790: if ($toolsettings{$item}) {
791: push(@deleted,$item);
792: }
793: }
794: }
1.604 raeburn 795: }
796: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 797: foreach my $item ('label','title','linktext','explanation') {
798: my $crsitem;
799: if (($item eq 'label') || ($item eq 'title')) {
800: $crsitem = 'crs'.$item;
801: } else {
802: $crsitem = $item;
803: }
1.604 raeburn 804: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 805: $toolhash{$crsitem} =~ s/^\s+//;
806: $toolhash{$crsitem} =~ s/\s+$//;
807: if ($toolhash{$crsitem} eq '') {
808: delete($toolhash{$crsitem});
1.604 raeburn 809: }
810: } else {
1.624 raeburn 811: delete($toolhash{$crsitem});
1.604 raeburn 812: }
1.624 raeburn 813: if (($residx) && (exists($toolsettings{$crsitem}))) {
814: unless (exists($toolhash{$crsitem})) {
815: push(@deleted,$crsitem);
1.604 raeburn 816: }
817: }
1.598 raeburn 818: }
819: }
1.643 raeburn 820: if ($toolhash{'passback'}) {
821: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
822: $toolhash{'gradesecret'} = $gradesecret;
823: $toolhash{'gradesecretdate'} = time;
824: }
825: if ($toolhash{'roster'}) {
826: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
827: $toolhash{'rostersecret'} = $rostersecret;
828: $toolhash{'rostersecretdate'} = time;
829: }
1.645 raeburn 830: my $changegradable;
831: if (($residx) && ($folder =~ /^default/)) {
1.648 raeburn 832: if ($toolsettings{'gradable'}) {
833: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 834: push(@deleted,'gradable');
835: $changegradable = 1;
836: }
1.648 raeburn 837: } elsif ($toolhash{'gradable'}) {
838: $changegradable = 1;
839: }
840: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 841: $changegradable = 1;
1.648 raeburn 842: if ($toolsettings{'gradable'}) {
843: $toolhash{'gradable'} = 1;
844: }
1.645 raeburn 845: }
846: }
1.598 raeburn 847: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 848: if ($putres eq 'ok') {
849: if (@deleted) {
850: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645 raeburn 851: }
852: if (($changegradable) && ($folder =~ /^default/)) {
853: my $val;
854: if ($toolhash{'gradable'}) {
855: $val = 'yes';
856: } else {
857: $val = 'no';
858: }
859: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
860: 'string_yesno');
861: &remember_parms($residx,'gradable','set',$val);
862: }
863: } else {
864: return (&mt('Failed to save update to external tool.'),1);
1.604 raeburn 865: }
1.598 raeburn 866: }
867: }
868: }
1.529 raeburn 869: if (($caller eq 'londocs') &&
870: ($folder =~ /^default/)) {
1.534 raeburn 871: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 872: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
873: my $cid = $coursedom.'_'.$coursenum;
874: $allmaps =
875: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
876: $chome,$cid);
877: $donechk = 1;
878: }
879: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 880: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
881: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 882: $importuploaded = 1;
883: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
884: next if ($allmaps->{$url});
885: }
886: }
1.344 bisitz 887: if (!$residx
1.329 droeschl 888: || defined($LONCAPA::map::zombies[$residx])) {
889: $residx = &LONCAPA::map::getresidx($url,$residx);
890: push(@LONCAPA::map::order, $residx);
891: }
892: my $ext = 'false';
893: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 894: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
895: my $filepath = $1;
1.675 raeburn 896: my $fname;
897: if ($name eq '') {
898: $name = &mt('Web Page');
1.534 raeburn 899: $fname = 'web';
900: } else {
1.675 raeburn 901: $fname = $name;
902: $fname=&Apache::lonnet::clean_filename($fname);
903: if ($fname eq '') {
904: $fname = 'web';
905: } elsif (length($fname) > 15) {
906: $fname = substr($fname,0,14);
907: }
1.534 raeburn 908: }
1.675 raeburn 909: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 910: my $initialtext = &mt('Replace with your own content.');
911: my $newhtml = <<END;
1.545 raeburn 912: <html>
1.534 raeburn 913: <head>
1.675 raeburn 914: <title>$title</title>
1.534 raeburn 915: </head>
916: <body bgcolor="#ffffff">
917: $initialtext
918: </body>
919: </html>
920: END
921: $env{'form.output'}=$newhtml;
1.630 raeburn 922: my $result =
1.534 raeburn 923: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
924: 'output',
925: "$filepath/$residx/$fname.html");
926: if ($result =~ m{^/uploaded/}) {
927: $url = $result;
928: if ($filepath =~ /^supplemental/) {
929: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
930: $env{'user.domain'}.'___&&&___'.$name;
931: }
932: } else {
933: return (&mt('Failed to save new web page.'),1);
934: }
935: }
1.675 raeburn 936: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 937: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 938: $LONCAPA::map::resources[$residx] =
1.329 droeschl 939: join(':', ($name, $url, $ext, 'normal', 'res'));
940: }
941: }
1.529 raeburn 942: if ($importuploaded) {
943: my %import_errors;
944: my %updated = (
945: removefrommap => \%removefrommap,
946: removeparam => \%removeparam,
947: );
1.533 raeburn 948: my ($result,$msgsarray,$lockerror) =
949: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 950: if (keys(%import_errors) > 0) {
1.530 raeburn 951: $fixuperrors =
1.529 raeburn 952: '<p span class="LC_warning">'."\n".
953: &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".
954: '<ul>'."\n";
955: foreach my $key (sort(keys(%import_errors))) {
956: $fixuperrors .= '<li>'.$key.'</li>'."\n";
957: }
958: $fixuperrors .= '</ul></p>'."\n";
959: }
1.533 raeburn 960: if (ref($msgsarray) eq 'ARRAY') {
961: if (@{$msgsarray} > 0) {
962: $fixuperrors .= '<p class="LC_info">'.
963: join('<br />',@{$msgsarray}).
964: '</p>';
965: }
966: }
967: if ($lockerror) {
968: $fixuperrors .= '<p class="LC_error">'.
969: $lockerror.
970: '</p>';
971: }
1.529 raeburn 972: }
973: my ($errtext,$fatal) =
974: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 975: unless ($fatal) {
976: if ($folder =~ /^supplemental/) {
1.561 raeburn 977: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
978: $folder.'.'.$container);
1.557 raeburn 979: }
980: }
1.529 raeburn 981: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 982: }
983:
984: sub log_docs {
1.494 raeburn 985: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 986: }
987:
988: {
989: my @oldresources=();
990: my @oldorder=();
991: my $parmidx;
992: my %parmaction=();
993: my %parmvalue=();
994: my $changedflag;
995:
996: sub snapshotbefore {
997: @oldresources=@LONCAPA::map::resources;
998: @oldorder=@LONCAPA::map::order;
999: $parmidx=undef;
1000: %parmaction=();
1001: %parmvalue=();
1002: $changedflag=0;
1003: }
1004:
1005: sub remember_parms {
1006: my ($idx,$parameter,$action,$value)=@_;
1007: $parmidx=$idx;
1008: $parmaction{$parameter}=$action;
1009: $parmvalue{$parameter}=$value;
1010: $changedflag=1;
1011: }
1012:
1013: sub log_differences {
1014: my ($plain)=@_;
1015: my %storehash=('folder' => $plain,
1016: 'currentfolder' => $env{'form.folder'});
1017: if ($parmidx) {
1018: $storehash{'parameter_res'}=$oldresources[$parmidx];
1019: foreach my $parm (keys(%parmaction)) {
1020: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1021: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1022: }
1023: }
1024: my $maxidx=$#oldresources;
1025: if ($#LONCAPA::map::resources>$#oldresources) {
1026: $maxidx=$#LONCAPA::map::resources;
1027: }
1028: for (my $idx=0; $idx<=$maxidx; $idx++) {
1029: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1030: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1031: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1032: $changedflag=1;
1033: }
1034: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1035: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1036: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1037: $changedflag=1;
1038: }
1039: }
1040: $storehash{'maxidx'}=$maxidx;
1041: if ($changedflag) { &log_docs(\%storehash); }
1042: }
1043: }
1044:
1045: sub docs_change_log {
1.611 raeburn 1046: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1047: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1048: my $navmap;
1.483 raeburn 1049: my $js = '<script type="text/javascript">'."\n".
1050: '// <![CDATA['."\n".
1051: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1052: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1053: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1054: &history_tab_js()."\n".
1.484 raeburn 1055: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1056: '// ]]>'."\n".
1057: '</script>'."\n";
1.484 raeburn 1058: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1059: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1060: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1061: my %orderhash;
1062: my $container='sequence';
1063: my $pathitem;
1.519 raeburn 1064: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1065: $container='page';
1066: }
1.519 raeburn 1067: my $folderpath=$env{'form.folderpath'};
1068: if ($folderpath eq '') {
1.617 raeburn 1069: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1070: }
1.617 raeburn 1071: undef($navmap);
1.519 raeburn 1072: $pathitem = '<input type="hidden" name="folderpath" value="'.
1073: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1074: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1075: my $jumpto = $readfile;
1076: $jumpto =~ s{^/}{};
1077: my $tid = 1;
1.489 raeburn 1078: if ($supplementalflag) {
1079: $tid = 2;
1080: }
1.630 raeburn 1081: my ($breadcrumbtrail) =
1.509 raeburn 1082: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1083: $r->print($breadcrumbtrail.
1084: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1085: $readfile));
1.329 droeschl 1086: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1087: $env{'course.'.$env{'request.course.id'}.'.domain'},
1088: $env{'course.'.$env{'request.course.id'}.'.num'});
1089:
1090: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1091:
1092: my %saveable_parameters = ('show' => 'scalar',);
1093: &Apache::loncommon::store_course_settings('docs_log',
1094: \%saveable_parameters);
1095: &Apache::loncommon::restore_course_settings('docs_log',
1096: \%saveable_parameters);
1097: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1098: # FIXME: internationalization seems wrong here
1.329 droeschl 1099: my %lt=('hiddenresource' => 'Resources hidden',
1100: 'encrypturl' => 'URL hidden',
1101: 'randompick' => 'Randomly pick',
1102: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1103: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1104: 'set' => 'set to',
1105: 'del' => 'deleted');
1.484 raeburn 1106: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1107: $pathitem."\n".
1108: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1109: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1110: $r->print('<div class="LC_left_float">'.
1111: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1112: &makedocslogform($filter,1).
1113: '</fieldset></div><br clear="all" />');
1.329 droeschl 1114: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1115: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1116: &mt('After').'</th>'.
1117: &Apache::loncommon::end_data_table_header_row());
1118: my $shown=0;
1119: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1120: if ($env{'form.displayfilter'} eq 'currentfolder') {
1121: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1122: }
1123: my @changes=keys(%{$docslog{$id}{'logentry'}});
1124: if ($env{'form.displayfilter'} eq 'containing') {
1125: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1126: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1127: foreach my $key (@changes) {
1128: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1129: }
1.344 bisitz 1130: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1131: }
1132: my $count = 0;
1133: my $time =
1134: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1135: my $plainname =
1136: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1137: $docslog{$id}{'exe_udom'});
1138: my $about_me_link =
1139: &Apache::loncommon::aboutmewrapper($plainname,
1140: $docslog{$id}{'exe_uname'},
1141: $docslog{$id}{'exe_udom'});
1142: my $send_msg_link='';
1143: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1144: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1145: $send_msg_link ='<br />'.
1146: &Apache::loncommon::messagewrapper(&mt('Send message'),
1147: $docslog{$id}{'exe_uname'},
1148: $docslog{$id}{'exe_udom'});
1149: }
1150: $r->print(&Apache::loncommon::start_data_table_row());
1151: $r->print('<td>'.$time.'</td>
1152: <td>'.$about_me_link.
1153: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1154: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1155: $send_msg_link.'</td><td>'.
1156: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1157: my $is_supp = 0;
1158: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1159: $is_supp = 1;
1160: }
1.329 droeschl 1161: # Before
1162: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1163: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1164: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1165: if ($oldname ne $newname) {
1.488 raeburn 1166: my $shown = &LONCAPA::map::qtescape($oldname);
1167: if ($is_supp) {
1168: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1169: }
1170: $r->print($shown);
1.329 droeschl 1171: }
1172: }
1173: $r->print('<ul>');
1174: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1175: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1176: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1177: if ($is_supp) {
1178: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1179: }
1180: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1181: }
1182: }
1183: $r->print('</ul>');
1184: # After
1185: $r->print('</td><td>');
1186:
1187: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1188: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1189: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1190: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1191: my $shown = &LONCAPA::map::qtescape($newname);
1192: if ($is_supp) {
1193: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1194: }
1195: $r->print($shown);
1.329 droeschl 1196: }
1.364 bisitz 1197: }
1.329 droeschl 1198: $r->print('<ul>');
1199: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1200: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1201: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1202: if ($is_supp) {
1203: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1204: }
1205: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1206: }
1207: }
1208: $r->print('</ul>');
1209: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1210: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1211: if ($title eq '') {
1212: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1213: } elsif ($is_supp) {
1214: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1215: }
1216: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1217: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1218: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1219: # FIXME: internationalization seems wrong here
1.329 droeschl 1220: $r->print('<li>'.
1221: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1222: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1223: .'</li>');
1224: }
1225: }
1226: $r->print('</ul>');
1227: }
1228: # End
1229: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1230: $shown++;
1231: if (!($env{'form.show'} eq &mt('all')
1232: || $shown<=$env{'form.show'})) { last; }
1233: }
1.484 raeburn 1234: $r->print(&Apache::loncommon::end_data_table()."\n".
1235: &makesimpleeditform($pathitem)."\n".
1236: '</div></div>');
1237: $r->print(&endContentScreen());
1.329 droeschl 1238: }
1239:
1240: sub update_paste_buffer {
1.492 raeburn 1241: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1242: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1243: if ($env{'form.multiremove'}) {
1244: $env{'form.multiremove'} =~ s/,$//;
1245: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1246: }
1247: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1248: if ($env{'form.multicut'}) {
1249: $env{'form.multicut'} =~ s/,$//;
1250: foreach my $item (split(/,/,$env{'form.multicut'})) {
1251: unless ($removals{$item}) {
1252: $cuts{$item} = 1;
1253: push(@possibles,$item.':cut');
1254: }
1255: }
1256: }
1257: if ($env{'form.multicopy'}) {
1258: $env{'form.multicopy'} =~ s/,$//;
1259: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1260: unless ($removals{$item} || $cuts{$item}) {
1261: push(@possibles,$item.':copy');
1262: }
1263: }
1264: }
1265: } elsif ($env{'form.markcopy'}) {
1266: @possibles = split(/,/,$env{'form.markcopy'});
1267: }
1.329 droeschl 1268:
1.538 raeburn 1269: return if (@possibles == 0);
1.329 droeschl 1270: return if (!defined($env{'form.copyfolder'}));
1271:
1272: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1273: $env{'form.copyfolder'});
1.538 raeburn 1274: return if ($fatal);
1275:
1276: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1277:
1.538 raeburn 1278: # Retrieve current paste buffer suffixes.
1279: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1280: my (%pasteurls,@newpaste);
1281:
1282: # Construct identifiers for current contents of user's paste buffer
1283: if (@currpaste) {
1284: foreach my $suffix (@currpaste) {
1.667 raeburn 1285: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1286: my $url = $env{'docs.markedcopy_url_'.$suffix};
1287: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1288: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1289: ($url ne '')) {
1290: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1291: $pasteurls{$cid.'_'.$mapidx} = 1;
1292: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1293: $pasteurls{$url} = 1;
1294: } else {
1.669 raeburn 1295: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1296: }
1297: }
1.538 raeburn 1298: }
1299: }
1300:
1301: # Mark items for copying (skip any items already in user's paste buffer)
1302: my %addtoenv;
1.597 raeburn 1303:
1304: my @pathitems = split(/\&/,$env{'form.folderpath'});
1305: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1306: my $ispage = $folderconf[5];
1.597 raeburn 1307:
1.538 raeburn 1308: foreach my $item (@possibles) {
1309: my ($orderidx,$cmd) = split(/:/,$item);
1310: next if ($orderidx =~ /\D/);
1311: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1312: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1313: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1314: my %denied = &action_restrictions($coursenum,$coursedom,
1315: &LONCAPA::map::qtescape($url),
1316: $env{'form.folderpath'},\%curr_groups);
1317: next if ($denied{'copy'});
1318: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1319: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1320: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1321: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1322: next if (exists($pasteurls{$url}));
1323: } else {
1324: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1325: }
1.538 raeburn 1326: my ($suffix,$errortxt,$locknotfreed) =
1327: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1328: if ($suffix ne '') {
1329: push(@newpaste,$suffix);
1330: } else {
1331: if ($locknotfreed) {
1332: return $locknotfreed;
1333: }
1.538 raeburn 1334: }
1335: if (&is_supplemental_title($title)) {
1336: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1337: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1338: }
1.329 droeschl 1339:
1.538 raeburn 1340: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1341: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1342: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1343: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1344: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1345: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1346: my $prefix = $1;
1347: my $subdir =$2;
1348: if ($subdir eq '') {
1349: $subdir = $prefix;
1.492 raeburn 1350: }
1.538 raeburn 1351: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1352: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1353: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1354: if (ref($hierarchy{$url}) eq 'HASH') {
1355: my ($nested,$nestednames);
1356: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1357: $nested =~ s/\&$//;
1358: $nestednames =~ s/\Q___&&&___\E$//;
1359: if ($nested ne '') {
1360: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1361: }
1362: if ($nestednames ne '') {
1363: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1364: }
1.492 raeburn 1365: }
1366: }
1.591 raeburn 1367: if ($locknotfreed) {
1368: $output = $locknotfreed;
1369: last;
1370: }
1.492 raeburn 1371: }
1.538 raeburn 1372: if (@newpaste) {
1373: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1374: }
1.492 raeburn 1375: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1376: delete($env{'form.markcopy'});
1.591 raeburn 1377: return $output;
1.329 droeschl 1378: }
1379:
1.492 raeburn 1380: sub recurse_uploaded_maps {
1381: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1382: if (ref($hierarchy->{$url}) eq 'HASH') {
1383: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1384: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1385: my (@uploaded,@names,%shorter);
1386: for (my $i=0; $i<@maps; $i++) {
1387: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1388: if ($inner ne '') {
1389: push(@uploaded,$inner);
1390: push(@names,&escape($titles[$i]));
1391: $shorter{$maps[$i]} = $inner;
1392: }
1393: }
1394: $$nestref .= "$dir:".join(',',@uploaded).'&';
1395: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1396: foreach my $map (@maps) {
1397: if ($shorter{$map} ne '') {
1398: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1399: }
1400: }
1401: }
1402: return;
1403: }
1404:
1.329 droeschl 1405: sub print_paste_buffer {
1.492 raeburn 1406: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1407: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1408:
1.538 raeburn 1409: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1410: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1411: }
1412:
1.538 raeburn 1413: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1414: my ($pasteitems,@pasteable);
1.575 raeburn 1415: my $clipboardcount = 0;
1.488 raeburn 1416:
1.538 raeburn 1417: # Construct identifiers for current contents of user's paste buffer
1418: foreach my $suffix (@currpaste) {
1419: next if ($suffix =~ /\D/);
1420: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1421: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1422: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1423: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1424: ($url ne '')) {
1.575 raeburn 1425: $clipboardcount ++;
1.538 raeburn 1426: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1427: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1428: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1429: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1430: $is_external = 1;
1.626 raeburn 1431: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1432: $is_exttool = 1;
1.538 raeburn 1433: }
1434: if ($folder =~ /^supplemental/) {
1435: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1436: unless ($canpaste) {
1437: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1438: }
1439: } else {
1440: $canpaste = 1;
1441: }
1442: if ($canpaste) {
1443: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1444: my $srcdom = $1;
1445: my $srcnum = $2;
1446: my $rem = $3;
1447: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1448: $othercourse = 1;
1449: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1450: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1451: } else {
1452: $canpaste = 0;
1453: $nopaste = &mt('Paste from another course unavailable.');
1454: }
1455: }
1456: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1457: my $prefix = $1;
1458: $parent = $2;
1459: if ($folder !~ /^\Q$prefix\E/) {
1460: $areachange = 1;
1461: }
1462: $is_uploaded_map = 1;
1.492 raeburn 1463: }
1.597 raeburn 1464: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1465: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1466: if ($cid ne $env{'request.course.id'}) {
1467: my ($srcdom,$srcnum) = split(/_/,$cid);
1468: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1469: if (($is_exttool) && ($srcdom ne $coursedom)) {
1470: $canpaste = 0;
1471: $nopaste = &mt('Paste from another domain unavailable.');
1472: } else {
1473: $othercrs = '<br />'.&mt('(from another course)');
1474: }
1.596 raeburn 1475: } else {
1476: $canpaste = 0;
1477: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1478: }
1.596 raeburn 1479: }
1.492 raeburn 1480: }
1.596 raeburn 1481: if ($canpaste) {
1482: push(@pasteable,$suffix);
1.629 raeburn 1483: }
1.538 raeburn 1484: }
1485: my $buffer;
1.627 raeburn 1486: if ($is_external) {
1.538 raeburn 1487: $buffer = &mt('External Resource').': '.
1488: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1489: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1490: } elsif ($is_exttool) {
1491: $buffer = &mt('External Tool').': '.
1492: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1493: } else {
1494: my $icon = &Apache::loncommon::icon($extension);
1495: if ($extension eq 'sequence' &&
1496: $url =~ m{/default_\d+\.sequence$}x) {
1497: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1498: $icon .= '/navmap.folder.closed.gif';
1499: }
1.589 raeburn 1500: my $title = $env{'docs.markedcopy_title_'.$suffix};
1501: if ($title eq '') {
1502: ($title) = ($url =~ m{/([^/]+)$});
1503: }
1.538 raeburn 1504: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1505: ': '.
1506: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1507: &LONCAPA::map::qtescape($title));
1.538 raeburn 1508: }
1509: $pasteitems .= '<div class="LC_left_float">';
1510: my ($options,$onclick);
1511: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1512: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1513: if (($is_uploaded_map) ||
1514: ($url =~ /(bulletinboard|smppg)$/) ||
1515: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1516: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1517: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1518: }
1519: }
1520: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1521: if ($nopaste) {
1.681 raeburn 1522: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1523: } else {
1524: if ($othercrs) {
1525: $pasteitems .= $othercrs;
1526: }
1527: if ($options) {
1528: $pasteitems .= $options;
1.492 raeburn 1529: }
1530: }
1.538 raeburn 1531: $pasteitems .= '</div>';
1532: }
1533: }
1534: if ($pasteitems eq '') {
1535: &Apache::lonnet::delenv('docs.markedcopies');
1536: }
1537: my ($pasteform,$form_start,$buttons,$form_end);
1538: if ($pasteitems) {
1539: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1540: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1541: if (@pasteable) {
1.575 raeburn 1542: my $value = &mt('Paste to current folder');
1543: if ($container eq 'page') {
1544: $value = &mt('Paste to current page');
1545: }
1546: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1547: }
1548: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1549: if ($clipboardcount > 1) {
1550: $buttons .=
1551: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1552: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1553: (' 'x2).
1554: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1555: (' 'x2);
1.492 raeburn 1556: }
1.575 raeburn 1557: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1558: '</form>';
1.538 raeburn 1559: } else {
1560: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1561: }
1.538 raeburn 1562: $r->print($form_start
1563: .'<fieldset>'
1564: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1565: .$pasteitems
1566: .'</fieldset>'
1567: .$form_end);
1568: }
1569:
1570: sub paste_options {
1571: my ($suffix,$is_uploaded_map,$parent) = @_;
1572: my ($copytext,$movetext);
1573: if ($is_uploaded_map) {
1574: $copytext = &mt('Copy to new folder');
1575: $movetext = &mt('Move old');
1576: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1577: $copytext = &mt('Copy to new board');
1578: $movetext = &mt('Move (not posts)');
1579: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1580: $copytext = &mt('Copy to new page');
1581: $movetext = &mt('Move');
1.533 raeburn 1582: } else {
1.538 raeburn 1583: $copytext = &mt('Copy to new file');
1584: $movetext = &mt('Move');
1585: }
1586: my $output = '<br />'.
1587: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1588: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1589: '<label>'.
1590: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1591: $copytext.'</label></span>'.(' 'x2).' '.
1592: '<span class="LC_nobreak"><label>'.
1593: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1594: $movetext.'</label></span>';
1595: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1596: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1597: '</legend><table border="0">';
1598: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1599: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1600: my $lastdir = $parent;
1601: my %depths = (
1602: $lastdir => 0,
1603: );
1604: my (%display,%deps);
1605: for (my $i=0; $i<@pastemaps; $i++) {
1606: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1607: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1608: my @subfolders = split(/,/,$subfolderstr);
1609: $deps{$lastdir} = \@subfolders;
1610: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1611: my $depth = $depths{$lastdir} + 1;
1612: my $offset = int($depth * 4);
1613: my $indent = (' ' x $offset);
1614: for (my $j=0; $j<@subfolders; $j++) {
1615: $depths{$subfolders[$j]} = $depth;
1616: $display{$subfolders[$j]} =
1617: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1618: '<td><label>'.
1619: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1620: '<label>'.
1621: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1622: &mt('Move old').'</label>'.
1623: '</td></tr>';
1624: }
1.492 raeburn 1625: }
1.538 raeburn 1626: &recurse_print(\$output,$parent,\%deps,\%display);
1627: $output .= '</table></fieldset>';
1.329 droeschl 1628: }
1.538 raeburn 1629: $output .= '</div>';
1630: return $output;
1.488 raeburn 1631: }
1632:
1.492 raeburn 1633: sub recurse_print {
1.538 raeburn 1634: my ($outputref,$dir,$deps,$display) = @_;
1635: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1636: if (ref($deps->{$dir}) eq 'ARRAY') {
1637: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1638: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1639: }
1640: }
1641: }
1642:
1.488 raeburn 1643: sub supp_pasteable {
1644: my ($url) = @_;
1645: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1646: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1647: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1648: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1649: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1650: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1651: return 1;
1652: }
1653: return;
1.329 droeschl 1654: }
1655:
1.492 raeburn 1656: sub paste_popup_js {
1.594 damieng 1657: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1658: show => 'Show Options',
1659: hide => 'Hide Options',
1.594 damieng 1660: );
1661: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1662: none => 'No items selected from clipboard.',
1.492 raeburn 1663: );
1.594 damieng 1664: &html_escape(\%html_js_lt);
1665: &js_escape(\%html_js_lt);
1666: &js_escape(\%js_lt);
1.492 raeburn 1667: return <<"END";
1668:
1.538 raeburn 1669: function showPasteOptions(suffix) {
1670: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1671: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1672: return;
1673: }
1674:
1.538 raeburn 1675: function hidePasteOptions(suffix) {
1676: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1677: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1678: return;
1679: }
1680:
1681: function showOptions(caller,suffix) {
1682: if (document.getElementById('pasteoptionstext_'+suffix)) {
1683: if (caller.checked) {
1.594 damieng 1684: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1685: } else {
1686: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1687: }
1688: if (document.getElementById('pasteoptions_'+suffix)) {
1689: document.getElementById('pasteoptions_'+suffix).style.display='none';
1690: }
1691: }
1.492 raeburn 1692: return;
1693: }
1694:
1.541 raeburn 1695: function validateClipboard() {
1696: var numchk = 0;
1697: if (document.pasteform.pasting.length > 1) {
1698: for (var i=0; i<document.pasteform.pasting.length; i++) {
1699: if (document.pasteform.pasting[i].checked) {
1700: numchk ++;
1701: }
1702: }
1703: } else {
1704: if (document.pasteform.pasting.type == 'checkbox') {
1705: if (document.pasteform.pasting.checked) {
1706: numchk ++;
1707: }
1708: }
1709: }
1710: if (numchk > 0) {
1711: return true;
1712: } else {
1.594 damieng 1713: alert("$js_lt{'none'}");
1.541 raeburn 1714: return false;
1715: }
1716: }
1717:
1.575 raeburn 1718: function checkClipboard() {
1719: if (document.pasteform.pasting.length > 1) {
1720: for (var i=0; i<document.pasteform.pasting.length; i++) {
1721: document.pasteform.pasting[i].checked = true;
1722: }
1723: }
1724: return;
1725: }
1726:
1727: function uncheckClipboard() {
1728: if (document.pasteform.pasting.length >1) {
1729: for (var i=0; i<document.pasteform.pasting.length; i++) {
1730: document.pasteform.pasting[i].checked = false;
1731: }
1732: }
1733: return;
1734: }
1735:
1.492 raeburn 1736: END
1737:
1738: }
1739:
1.329 droeschl 1740: sub do_paste_from_buffer {
1.492 raeburn 1741: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1742:
1.538 raeburn 1743: # Array of items in paste buffer
1744: my (@currpaste,%pastebuffer,%allerrors);
1745: @currpaste = split(/,/,$env{'docs.markedcopies'});
1746:
1.492 raeburn 1747: # Early out if paste buffer is empty
1.538 raeburn 1748: if (@currpaste == 0) {
1.492 raeburn 1749: return ();
1.538 raeburn 1750: }
1751: map { $pastebuffer{$_} = 1; } @currpaste;
1752:
1753: # Array of items selected items to paste
1754: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1755:
1756: # Early out if nothing selected to paste
1757: if (@reqpaste == 0) {
1758: return();
1759: }
1760: my @topaste;
1761: foreach my $suffix (@reqpaste) {
1762: next if ($suffix =~ /\D/);
1763: next unless (exists($pastebuffer{$suffix}));
1764: push(@topaste,$suffix);
1765: }
1766:
1767: # Early out if nothing available to paste
1768: if (@topaste == 0) {
1769: return();
1.329 droeschl 1770: }
1771:
1.627 raeburn 1772: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1773: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1774:
1775: foreach my $suffix (@topaste) {
1776: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1777: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1778: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1779: # Supplemental content may only include certain types of content
1780: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1781: if ($folder =~ /^supplemental/) {
1782: unless (&supp_pasteable($url)) {
1783: $notinsupp{$suffix} = 1;
1784: next;
1785: }
1.492 raeburn 1786: }
1.538 raeburn 1787: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1788: my $srcd = $1;
1789: my $srcn = $2;
1.492 raeburn 1790: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1791: # check for mdc privilege in the course from which the resource was pasted
1792: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1793: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1794: $notincrs{$suffix} = 1;
1795: next;
1796: }
1.491 raeburn 1797: }
1.538 raeburn 1798: $srcdom{$suffix} = $srcd;
1799: $srcnum{$suffix} = $srcn;
1.597 raeburn 1800: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1801: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1802: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1803: my ($srcd,$srcn) = split(/_/,$cid);
1804: # When paste buffer was populated using an active role in a different course
1805: # check for mdc privilege in the course from which the resource was pasted
1806: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1807: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1808: $notincrs{$suffix} = 1;
1809: next;
1810: }
1811: }
1.632 raeburn 1812: # When buffer was populated using an active role in a different course
1813: # disallow pasting of External Tool if course is in a different domain.
1814: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1815: $notindom{$suffix} = 1;
1816: next;
1817: }
1.596 raeburn 1818: $srcdom{$suffix} = $srcd;
1819: $srcnum{$suffix} = $srcn;
1.491 raeburn 1820: }
1.597 raeburn 1821: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1822: push(@dopaste,$suffix);
1823: if ($url=~/\.(page|sequence)$/) {
1824: $is_map{$suffix} = 1;
1825: }
1826: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1827: my $oldprefix = $1;
1.492 raeburn 1828: # When pasting content from Main Content to Supplemental Content and vice versa
1829: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1830: # a folder/page or a document).
1.538 raeburn 1831: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1832: $prefixchg{$suffix} = 'docstosupp';
1833: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1834: $prefixchg{$suffix} = 'supptodocs';
1835: }
1.491 raeburn 1836:
1.492 raeburn 1837: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1838: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1839: my @nested;
1840: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1841: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1842: my @deps = map { /\d+:([\d,]+$)/ } @items;
1843: foreach my $dep (@deps) {
1844: if ($dep =~ /,/) {
1845: push(@nested,split(/,/,$dep));
1846: } else {
1847: push(@nested,$dep);
1848: }
1.492 raeburn 1849: }
1.538 raeburn 1850: foreach my $item (@nested) {
1851: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1852: push(@{$marktomove{$suffix}},$type.'_'.$item);
1853: }
1.492 raeburn 1854: }
1855: }
1.488 raeburn 1856: }
1857: }
1858:
1.538 raeburn 1859: # Early out if nothing available to paste
1860: if (@dopaste == 0) {
1861: return ();
1862: }
1863:
1864: # Populate message hash and hashes used for main content <=> supplemental content
1865: # changes
1866:
1867: %msgs = &Apache::lonlocal::texthash (
1868: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1869: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1870: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1871: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1872: );
1873:
1874: %before = (
1875: docstosupp => {
1876: map => 'default',
1877: doc => 'docs',
1878: },
1879: supptodocs => {
1880: map => 'supplemental',
1881: doc => 'supplemental',
1882: },
1883: );
1884:
1885: %after = (
1886: docstosupp => {
1887: map => 'supplemental',
1888: doc => 'supplemental'
1889: },
1890: supptodocs => {
1891: map => 'default',
1892: doc => 'docs',
1893: },
1894: );
1895:
1896: # Retrieve information about all course maps in main content area
1897:
1898: my $allmaps = {};
1.660 raeburn 1899: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1900:
1901: # Loop over the items to paste
1902: foreach my $suffix (@dopaste) {
1.329 droeschl 1903: # Maps need to be copied first
1.538 raeburn 1904: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1905: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1906: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1907: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1908: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1909: }
1910: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1911: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1912: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1913: my $oldurl = $url;
1914: if ($is_map{$suffix}) {
1.491 raeburn 1915: # If pasting a map, check if map contains other maps
1.538 raeburn 1916: my (%hierarchy,%titles);
1.660 raeburn 1917: if (($folder =~ /^default/) && (!$donechk)) {
1918: $allmaps =
1919: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1920: $env{"course.$env{'request.course.id'}.home"},
1921: $env{'request.course.id'});
1922: $donechk = 1;
1923: }
1.627 raeburn 1924: &contained_map_check($url,$folder,$coursenum,$coursedom,
1925: \%removefrommap,\%removeparam,\%addedmaps,
1926: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1927: if ($url=~ m{^/uploaded/}) {
1928: my $newurl;
1929: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1930: ($newurl,my $error) =
1931: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1932: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1933: \$title,$allmaps,\%newurls);
1934: if ($error) {
1935: $allerrors{$suffix} = $error;
1936: next;
1937: }
1938: if ($newurl ne '') {
1939: if ($newurl ne $url) {
1940: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1941: $newsubdir{$url} = $1;
1942: }
1943: $mapchanges{$url} = 1;
1.492 raeburn 1944: }
1.538 raeburn 1945: }
1946: }
1947: if (($srcdom{$suffix} ne $coursedom) ||
1948: ($srcnum{$suffix} ne $coursenum) ||
1949: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1950: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1951: $coursedom,$coursenum,$srcdom{$suffix},
1952: $srcnum{$suffix},$allmaps,\%rewrites,
1953: \%retitles,\%copies,\%dbcopies,
1954: \%zombies,\%params,\%mapmoves,
1955: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1956: \%newurls,\%resdatacopy)) {
1.538 raeburn 1957: $mapmoves{$url} = 1;
1958: }
1959: $url = $newurl;
1960: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1961: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1962: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1963: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1964: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1965: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1966: }
1967: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1968: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1969: push(@toclear,$suffix);
1970: # if pasting published map (main content area only) check map not already in course
1971: if ($folder =~ /^default/) {
1972: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1973: $duplicate{$suffix} = 1;
1974: next;
1.492 raeburn 1975: }
1.491 raeburn 1976: }
1977: }
1.538 raeburn 1978: }
1.627 raeburn 1979: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1980: my $prefix = $1;
1.648 raeburn 1981: my $fromothercrs;
1.538 raeburn 1982: #need to copy the db contents to a new one, unless this is a move.
1983: my %info = (
1984: src => $url,
1985: cdom => $coursedom,
1986: cnum => $coursenum,
1.596 raeburn 1987: );
1.649 raeburn 1988: if ($prefix eq 'ext.tool') {
1.655 raeburn 1989: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1990: $info{'delgradable'} = 1;
1991: }
1992: }
1.596 raeburn 1993: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1994: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1995: $fromothercrs = 1;
1996: $info{'cdom'} = $srcdom{$suffix};
1997: $info{'cnum'} = $srcnum{$suffix};
1998: }
1999: }
2000: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2001: my (%lockerr,$msg);
1.538 raeburn 2002: my ($newurl,$result,$errtext) =
2003: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2004: if ($result eq 'ok') {
2005: $url = $newurl;
2006: $title=&mt('Copy of').' '.$title;
2007: } else {
2008: if ($prefix eq 'smppg') {
2009: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2010: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2011: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2012: } elsif ($prefix eq 'ext.tool') {
2013: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2014: }
2015: $results{$suffix} = $result;
2016: $msgerrs{$suffix} = $msg;
2017: $lockerrs{$suffix} = $lockerr{$prefix};
2018: next;
2019: }
2020: if ($lockerr{$prefix}) {
2021: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2022: }
1.489 raeburn 2023: }
2024: }
1.538 raeburn 2025: $title = &LONCAPA::map::qtunescape($title);
2026: my $ext='false';
2027: if ($url=~m{^http(|s)://}) { $ext='true'; }
2028: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2029: if ($folder !~ /^supplemental/) {
2030: (undef,undef,$title) =
2031: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2032: }
2033: } else {
2034: if ($folder=~/^supplemental/) {
2035: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2036: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2037: }
1.533 raeburn 2038: }
1.491 raeburn 2039:
2040: # For uploaded files (excluding pages/sequences) path in copied file is changed
2041: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2042: # courses.
2043:
1.538 raeburn 2044: unless ($is_map{$suffix}) {
2045: my $newidx;
1.492 raeburn 2046: # Now insert the URL at the bottom
1.538 raeburn 2047: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2048: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2049: my $relpath = $1;
2050: if ($relpath ne '') {
2051: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2052: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2053: my $newprefix = $newloc;
2054: if ($newloc eq 'default') {
2055: $newprefix = 'docs';
2056: }
2057: if ($newdocsdir eq '') {
2058: $newdocsdir = 'default';
2059: }
1.630 raeburn 2060: if (($prefixchg{$suffix}) ||
2061: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2062: ($srcnum{$suffix} ne $coursenum) ||
2063: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2064: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2065: $url =
2066: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2067: &Apache::lonnet::getfile($oldurl));
2068: if ($url eq '/adm/notfound.html') {
2069: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2070: next;
2071: } else {
2072: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2073: $newsubpath =~ s{/+$}{/};
2074: $docmoves{$oldurl} = $newsubpath;
2075: }
1.491 raeburn 2076: }
2077: }
1.597 raeburn 2078: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2079: my $template = $1;
2080: if ($newidx) {
2081: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2082: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2083: }
1.649 raeburn 2084: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2085: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2086: my $marker = (split(m{/},$url))[4];
2087: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2088: my $val = 'no';
2089: if ($toolsettings{'gradable'}) {
2090: $val = 'yes';
2091: }
2092: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2093: 'string_yesno');
2094: &remember_parms($newidx,'gradable','set',$val);
2095: }
1.491 raeburn 2096: }
1.538 raeburn 2097: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2098: ':'.$ext.':normal:res';
2099: push(@LONCAPA::map::order,$newidx);
2100: # Store the result
2101: my ($errtext,$fatal) =
2102: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2103: if ($fatal) {
2104: $save_err .= $errtext;
2105: $allresult = 'fail';
2106: }
1.488 raeburn 2107: }
1.538 raeburn 2108:
1.597 raeburn 2109: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2110: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2111: unless ($allresult eq 'fail') {
2112: my %updated = (
2113: rewrites => \%rewrites,
2114: zombies => \%zombies,
2115: removefrommap => \%removefrommap,
2116: removeparam => \%removeparam,
2117: dbcopies => \%dbcopies,
1.597 raeburn 2118: resdatacopy => \%resdatacopy,
1.538 raeburn 2119: retitles => \%retitles,
2120: );
2121: my %info = (
2122: newsubdir => \%newsubdir,
2123: params => \%params,
2124: );
2125: if ($prefixchg{$suffix}) {
2126: $info{'before'} = $before{$prefixchg{$suffix}};
2127: $info{'after'} = $after{$prefixchg{$suffix}};
2128: }
2129: my %moves = (
2130: copies => \%copies,
2131: docmoves => \%docmoves,
2132: mapmoves => \%mapmoves,
2133: );
2134: (my $result,$msgs{$suffix},my $lockerror) =
2135: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2136: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2137: $url,'paste');
2138: $lockerrors .= $lockerror;
2139: if ($result eq 'ok') {
2140: if ($is_map{$suffix}) {
2141: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2142: $folder.'.'.$container);
2143: if ($fatal) {
2144: $allresult = 'failread';
2145: } else {
2146: if ($#LONCAPA::map::order<1) {
2147: my $idx=&LONCAPA::map::getresidx();
2148: if ($idx<=0) { $idx=1; }
2149: $LONCAPA::map::order[0]=$idx;
2150: $LONCAPA::map::resources[$idx]='';
2151: }
2152: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2153: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2154: ':'.$ext.':normal:res';
2155: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2156:
2157: # Store the result
1.538 raeburn 2158: my ($errtext,$fatal) =
2159: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2160: if ($fatal) {
2161: $save_err .= $errtext;
2162: $allresult = 'failstore';
2163: }
2164: }
2165: }
2166: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2167: push(@toclear,$suffix);
2168: }
2169: }
1.492 raeburn 2170: }
2171: }
1.538 raeburn 2172: &clear_from_buffer(\@toclear,\@currpaste);
2173: my $msgsarray;
2174: foreach my $suffix (keys(%msgs)) {
2175: if (ref($msgs{$suffix}) eq 'ARRAY') {
2176: $msgsarray .= join(',',@{$msgs{$suffix}});
2177: }
2178: }
2179: return ($allresult,$save_err,$msgsarray,$lockerrors);
2180: }
1.533 raeburn 2181:
1.538 raeburn 2182: sub do_buffer_empty {
2183: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2184: if (@currpaste == 0) {
2185: return &mt('Clipboard is already empty');
2186: }
2187: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2188: if (@toclear == 0) {
2189: return &mt('Nothing selected to clear from clipboard');
2190: }
2191: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2192: if ($numdel) {
2193: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2194: } else {
2195: return &mt('Clipboard unchanged');
1.492 raeburn 2196: }
1.538 raeburn 2197: return;
2198: }
2199:
2200: sub clear_from_buffer {
2201: my ($toclear,$currpaste) = @_;
2202: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2203: my %pastebuffer;
2204: map { $pastebuffer{$_} = 1; } @{$currpaste};
2205: my $numdel = 0;
2206: foreach my $suffix (@{$toclear}) {
2207: next if ($suffix =~ /\D/);
2208: next unless (exists($pastebuffer{$suffix}));
2209: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2210: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2211: delete($pastebuffer{$suffix});
2212: $numdel ++;
2213: }
2214: }
2215: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2216: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2217: return $numdel;
1.492 raeburn 2218: }
2219:
2220: sub get_newmap_url {
2221: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2222: $titleref,$allmaps,$newurls) = @_;
2223: my $newurl;
2224: if ($url=~ m{^/uploaded/}) {
2225: $$titleref=&mt('Copy of').' '.$$titleref;
2226: }
2227: my $now = time;
2228: my $suffix=$$.int(rand(100)).$now;
2229: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2230: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2231: my $path = $1;
2232: my $prefix = $2;
2233: my $ancestor = $3;
2234: if (length($ancestor) > 10) {
2235: $ancestor = substr($ancestor,-10,10);
2236: }
2237: my $newid;
2238: if ($prefixchg) {
2239: if ($folder =~ /^supplemental/) {
2240: $prefix =~ s/^default/supplemental/;
2241: } else {
2242: $prefix =~ s/^supplemental/default/;
2243: }
2244: }
2245: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2246: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2247: } else {
2248: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2249: }
2250: my $counter = 0;
2251: my $is_unique = &uniqueness_check($newurl);
2252: if ($folder =~ /^default/) {
2253: if ($allmaps->{$newurl}) {
2254: $is_unique = 0;
2255: }
2256: }
2257: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2258: $counter ++;
2259: $suffix ++;
2260: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2261: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2262: } else {
2263: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2264: }
2265: $is_unique = &uniqueness_check($newurl);
2266: }
2267: if ($is_unique) {
2268: $newurls->{$newurl} = 1;
2269: } else {
2270: if ($url=~/\.page$/) {
2271: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2272: } else {
2273: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2274: }
2275: }
1.329 droeschl 2276: }
1.492 raeburn 2277: return ($newurl);
1.329 droeschl 2278: }
2279:
1.488 raeburn 2280: sub dbcopy {
1.533 raeburn 2281: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2282: my ($url,$result,$errtext);
2283: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2284: $url = $dbref->{'src'};
1.627 raeburn 2285: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2286: my $prefix = $1;
1.627 raeburn 2287: if ($prefix eq 'ext.tool') {
2288: $prefix = 'exttool';
2289: }
1.533 raeburn 2290: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2291: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2292: my $db_name;
2293: my $marker = (split(m{/},$url))[4];
2294: $marker=~s/\D//g;
2295: if ($dbref->{'src'} =~ m{/smppg$}) {
2296: $db_name =
2297: &Apache::lonsimplepage::get_db_name($url,$marker,
2298: $dbref->{'cdom'},
2299: $dbref->{'cnum'});
1.627 raeburn 2300: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2301: $db_name = 'exttool_'.$marker;
1.533 raeburn 2302: } else {
2303: $db_name = 'bulletinpage_'.$marker;
2304: }
2305: my ($suffix,$freedlock,$error) =
2306: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2307: $coursedom,$coursenum,
2308: 'concat');
2309: if (!$suffix) {
2310: if ($prefix eq 'smppg') {
2311: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2312: } elsif ($prefix eq 'exttool') {
2313: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2314: } else {
1.565 bisitz 2315: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2316: }
2317: if ($error) {
2318: $errtext .= '<br />'.$error;
2319: }
2320: } else {
2321: #need to copy the db contents to a new one.
2322: my %contents=&Apache::lonnet::dump($db_name,
2323: $dbref->{'cdom'},
2324: $dbref->{'cnum'});
2325: if (exists($contents{'uploaded.photourl'})) {
2326: my $photo = $contents{'uploaded.photourl'};
2327: my ($subdir,$fname) =
2328: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2329: my $newphoto;
1.533 raeburn 2330: if ($fname ne '') {
2331: my $content = &Apache::lonnet::getfile($photo);
2332: unless ($content eq '-1') {
2333: $env{'form.'.$suffix.'.photourl'} = $content;
2334: $newphoto =
2335: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2336: delete($env{'form.'.$suffix.'.photourl'});
2337: }
2338: }
2339: if ($newphoto =~ m{^/uploaded/}) {
2340: $contents{'uploaded.photourl'} = $newphoto;
2341: }
2342: }
2343: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2344: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2345: delete($contents{'gradable'});
2346: }
1.533 raeburn 2347: $result=&Apache::lonnet::put($db_name,\%contents,
2348: $coursedom,$coursenum);
2349: if ($result eq 'ok') {
1.627 raeburn 2350: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2351: }
2352: }
2353: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2354: $lockerrorsref->{$prefix} =
1.533 raeburn 2355: '<div class="LC_error">'.
2356: &mt('There was a problem removing a lockfile.');
2357: if ($prefix eq 'smppg') {
1.560 raeburn 2358: $lockerrorsref->{$prefix} .=
1.559 raeburn 2359: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2360: } elsif ($prefix eq 'exttool') {
2361: $lockerrorsref->{$prefix} .=
2362: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2363: } else {
1.565 bisitz 2364: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2365: }
1.560 raeburn 2366: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2367: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2368: '</div>';
1.533 raeburn 2369: }
2370: }
2371: } elsif ($url =~ m{/syllabus$}) {
2372: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2373: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2374: if (($dbref->{'cdom'} ne $coursedom) ||
2375: ($dbref->{'cnum'} ne $coursenum)) {
2376: my %contents=&Apache::lonnet::dump('syllabus',
2377: $dbref->{'cdom'},
2378: $dbref->{'cnum'});
2379: $result=&Apache::lonnet::put('syllabus',\%contents,
2380: $coursedom,$coursenum);
2381: }
2382: }
1.488 raeburn 2383: }
2384: }
1.533 raeburn 2385: return ($url,$result,$errtext);
1.488 raeburn 2386: }
2387:
1.597 raeburn 2388: sub copy_templated_files {
2389: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2390: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2391: my $srccontainer = 'sequence';
2392: if ($srcwaspage) {
2393: $srccontainer = 'page';
2394: }
2395: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2396: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2397: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2398: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2399: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2400: $template.'.problem';
2401: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2402: if ($template eq 'simpleproblem') {
2403: $srcprefix .= '.0.';
2404: my $weightprefix = $newprefix;
2405: $newprefix .= '.0.';
2406: my @simpleprobqtypes = qw(radio option string essay numerical);
2407: my $qtype=$srcparms{$srcprefix.'questiontype'};
2408: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2409: my %newdata = (
2410: $newprefix.'questiontype' => $qtype,
2411: );
1.597 raeburn 2412: foreach my $type (@simpleprobqtypes) {
2413: if ($type eq $qtype) {
2414: $newdata{"$weightprefix.$type.weight"}=1;
2415: } else {
2416: $newdata{"$weightprefix.$type.weight"}=0;
2417: }
2418: }
2419: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2420: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2421: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2422: if ($qtype eq 'numerical') {
2423: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2424: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2425: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2426: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2427: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2428: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2429: unless (defined($maxfoils)) { $maxfoils=10; }
2430: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2431: if ($maxfoils<=0) { $maxfoils=10; }
2432: my $randomize=$srcparms{$srcprefix.'randomize'};
2433: unless (defined($randomize)) { $randomize='yes'; }
2434: unless ($randomize eq 'no') { $randomize='yes'; }
2435: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2436: $newdata{$newprefix.'randomize'} = $randomize;
2437: if ($qtype eq 'option') {
2438: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2439: }
2440: for (my $i=1; $i<=10; $i++) {
2441: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2442: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2443: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2444: }
2445:
2446: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2447: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2448: unless (defined($maxfoils)) { $maxfoils=10; }
2449: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2450: if ($maxfoils<=0) { $maxfoils=10; }
2451: my $randomize=$srcparms{$srcprefix.'randomize'};
2452: unless (defined($randomize)) { $randomize='yes'; }
2453: unless ($randomize eq 'no') { $randomize='yes'; }
2454: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2455: $newdata{$newprefix.'randomize'} = $randomize;
2456: if ($qtype eq 'option') {
2457: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2458: }
2459: for (my $i=1; $i<=10; $i++) {
2460: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2461: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2462: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2463: }
2464: } elsif ($qtype eq 'string') {
2465: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2466: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2467: }
2468: if (keys(%newdata)) {
2469: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2470: $coursenum);
2471: if ($putres eq 'ok') {
2472: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2473: }
2474: }
2475: }
2476: }
2477: }
2478:
1.329 droeschl 2479: sub uniqueness_check {
2480: my ($newurl) = @_;
2481: my $unique = 1;
2482: foreach my $res (@LONCAPA::map::order) {
2483: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2484: $url=&LONCAPA::map::qtescape($url);
2485: if ($newurl eq $url) {
2486: $unique = 0;
1.344 bisitz 2487: last;
1.329 droeschl 2488: }
2489: }
2490: return $unique;
2491: }
2492:
1.488 raeburn 2493: sub contained_map_check {
1.627 raeburn 2494: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2495: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2496: my $content = &Apache::lonnet::getfile($url);
2497: unless ($content eq '-1') {
2498: my $parser = HTML::TokeParser->new(\$content);
2499: $parser->attr_encoded(1);
2500: while (my $token = $parser->get_token) {
2501: next if ($token->[0] ne 'S');
2502: if ($token->[1] eq 'resource') {
2503: next if ($token->[2]->{'type'} eq 'zombie');
2504: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2505: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2506: my $srcdom = $1;
2507: unless ($srcdom eq $coursedom) {
2508: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2509: next;
2510: }
2511: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2512: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2513: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2514: next;
2515: }
2516: }
1.492 raeburn 2517: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2518: if ($1 eq 'uploaded') {
2519: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2520: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2521: } else {
1.492 raeburn 2522: if ($allmaps->{$ressrc}) {
1.529 raeburn 2523: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2524: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2525: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2526: } else {
2527: $addedmaps->{$ressrc} = [$url];
2528: }
1.488 raeburn 2529: }
1.627 raeburn 2530: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2531: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2532: }
1.492 raeburn 2533: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2534: if ($folder =~ /^supplemental/) {
1.492 raeburn 2535: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2536: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2537: } else {
2538: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2539: }
1.488 raeburn 2540: }
2541: }
2542: }
2543: }
2544: return;
2545: }
2546:
2547: sub url_paste_fixups {
1.533 raeburn 2548: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2549: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2550: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2551: my $checktitle;
2552: if (($prefixchg) &&
1.492 raeburn 2553: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2554: $checktitle = 1;
2555: }
1.492 raeburn 2556: my $skip;
2557: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2558: my $mapid = $1.$2;
2559: if ($tomove->{$mapid}) {
2560: $skip = 1;
2561: }
2562: }
1.491 raeburn 2563: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2564: return if ($file eq '-1');
2565: my $parser = HTML::TokeParser->new(\$file);
2566: $parser->attr_encoded(1);
1.491 raeburn 2567: my $changed = 0;
1.488 raeburn 2568: while (my $token = $parser->get_token) {
2569: next if ($token->[0] ne 'S');
2570: if ($token->[1] eq 'resource') {
2571: my $ressrc = $token->[2]->{'src'};
2572: next if ($ressrc eq '');
1.491 raeburn 2573: my $id = $token->[2]->{'id'};
1.492 raeburn 2574: my $title = $token->[2]->{'title'};
1.491 raeburn 2575: if ($checktitle) {
2576: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2577: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2578: }
2579: }
1.488 raeburn 2580: next if ($token->[2]->{'type'} eq 'external');
2581: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2582: next if ($skip);
1.532 raeburn 2583: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2584: $changed = 1;
2585: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2586: my $srcdom = $1;
2587: my $srcnum = $2;
1.488 raeburn 2588: my $rem = $3;
1.492 raeburn 2589: my $newurl;
2590: my $mapname;
2591: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2592: my $prefix = $1;
2593: $mapname = $prefix.$2;
2594: if ($tomove->{$mapname}) {
1.533 raeburn 2595: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2596: $srcdom,$srcnum,$allmaps,$rewrites,
2597: $retitles,$copies,$dbcopies,$zombies,
2598: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2599: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2600: next;
2601: } else {
2602: ($newurl,my $error) =
2603: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2604: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2605: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2606: $newsubdir->{$ressrc} = $1;
2607: }
2608: if ($error) {
2609: next;
2610: }
2611: }
2612: }
2613: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2614: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2615:
1.488 raeburn 2616: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2617: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2618: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2619: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2620: $cnum,$srcdom,$srcnum,$allmaps,
2621: $rewrites,$retitles,$copies,$dbcopies,
2622: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2623: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2624: $mapmoves->{$ressrc} = 1;
2625: }
2626: $changed = 1;
1.488 raeburn 2627: } else {
1.532 raeburn 2628: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2629: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2630: $changed = 1;
1.488 raeburn 2631: }
2632: }
1.649 raeburn 2633: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2634: next if ($skip);
1.492 raeburn 2635: my $srcdom = $1;
2636: my $srcnum = $2;
1.649 raeburn 2637: my $rem = $3;
2638: my ($is_exttool,$exttoolchg);
2639: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2640: $is_exttool = 1;
1.649 raeburn 2641: }
1.492 raeburn 2642: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2643: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2644: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2645: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2646: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2647: $changed = 1;
1.649 raeburn 2648: if ($is_exttool) {
2649: $exttoolchg = 1;
2650: }
2651: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2652: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2653: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2654: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2655: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2656: $changed = 1;
2657: $exttoolchg = 1;
2658: }
2659: if (($is_exttool) && ($prefixchg)) {
2660: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2661: if ($exttoolchg) {
2662: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2663: }
2664: }
1.533 raeburn 2665: }
2666: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2667: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2668: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2669: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2670: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2671: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2672: $changed = 1;
1.488 raeburn 2673: }
1.597 raeburn 2674: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2675: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2676: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2677: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2678: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2679: }
1.488 raeburn 2680: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2681: next if ($skip);
2682: my $srcdom = $1;
2683: my $srcnum = $2;
2684: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2685: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2686: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2687: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2688: $changed = 1;
1.488 raeburn 2689: }
2690: }
2691: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2692: next if ($skip);
1.488 raeburn 2693: my $to = $token->[2]->{'to'};
2694: if ($to ne '') {
2695: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2696: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2697: } else {
2698: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2699: }
2700: }
2701: }
2702: }
1.491 raeburn 2703: return $changed;
1.488 raeburn 2704: }
2705:
2706: sub apply_fixups {
1.529 raeburn 2707: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2708: $oldurl,$url,$caller) = @_;
2709: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2710: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2711: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2712: if (ref($updated) eq 'HASH') {
2713: if (ref($updated->{'rewrites'}) eq 'HASH') {
2714: %rewrites = %{$updated->{'rewrites'}};
2715: }
2716: if (ref($updated->{'zombies'}) eq 'HASH') {
2717: %zombies = %{$updated->{'zombies'}};
2718: }
2719: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2720: %removefrommap = %{$updated->{'removefrommap'}};
2721: }
2722: if (ref($updated->{'removeparam'}) eq 'HASH') {
2723: %removeparam = %{$updated->{'removeparam'}};
2724: }
2725: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2726: %dbcopies = %{$updated->{'dbcopies'}};
2727: }
2728: if (ref($updated->{'retitles'}) eq 'HASH') {
2729: %retitles = %{$updated->{'retitles'}};
2730: }
1.597 raeburn 2731: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2732: %resdatacopy = %{$updated->{'resdatacopy'}};
2733: }
1.529 raeburn 2734: }
2735: if (ref($info) eq 'HASH') {
2736: if (ref($info->{'newsubdir'}) eq 'HASH') {
2737: %newsubdir = %{$info->{'newsubdir'}};
2738: }
2739: if (ref($info->{'params'}) eq 'HASH') {
2740: %params = %{$info->{'params'}};
2741: }
2742: if (ref($info->{'before'}) eq 'HASH') {
2743: %before = %{$info->{'before'}};
2744: }
2745: if (ref($info->{'after'}) eq 'HASH') {
2746: %after = %{$info->{'after'}};
2747: }
2748: }
2749: if (ref($moves) eq 'HASH') {
2750: if (ref($moves->{'copies'}) eq 'HASH') {
2751: %copies = %{$moves->{'copies'}};
2752: }
2753: if (ref($moves->{'docmoves'}) eq 'HASH') {
2754: %docmoves = %{$moves->{'docmoves'}};
2755: }
2756: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2757: %mapmoves = %{$moves->{'mapmoves'}};
2758: }
2759: }
2760: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2761: my @allcopies;
1.529 raeburn 2762: if (exists($copies{$key})) {
2763: if (ref($copies{$key}) eq 'HASH') {
2764: my %added;
2765: foreach my $innerkey (keys(%{$copies{$key}})) {
2766: if (($innerkey ne '') && (!$added{$innerkey})) {
2767: push(@allcopies,$innerkey);
2768: $added{$innerkey} = 1;
2769: }
1.491 raeburn 2770: }
1.529 raeburn 2771: undef(%added);
1.491 raeburn 2772: }
2773: }
2774: if ($key eq $oldurl) {
1.529 raeburn 2775: if ((exists($docmoves{$key}))) {
1.532 raeburn 2776: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2777: push(@allcopies,$oldurl);
2778: }
2779: }
2780: }
2781: if (@allcopies > 0) {
2782: foreach my $item (@allcopies) {
1.492 raeburn 2783: my ($relpath,$oldsubdir,$fname) =
2784: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2785: if ($fname ne '') {
2786: my $content = &Apache::lonnet::getfile($item);
2787: unless ($content eq '-1') {
2788: my $storefn;
1.529 raeburn 2789: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2790: $storefn = $docmoves{$key};
1.491 raeburn 2791: } else {
2792: $storefn = $relpath;
2793: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2794: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2795: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2796: }
1.529 raeburn 2797: if ($newsubdir{$key}) {
1.532 raeburn 2798: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2799: }
2800: }
2801: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2802: my $copyurl =
2803: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2804: $storefn.$fname,$content);
2805: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2806: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2807: return &mt('Paste failed: an error occurred copying the file.');
2808: } elsif (ref($errors) eq 'HASH') {
2809: $errors->{$item} = 1;
1.489 raeburn 2810: }
2811: }
1.488 raeburn 2812: }
2813: }
1.491 raeburn 2814: }
2815: }
2816: }
1.529 raeburn 2817: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2818: my $storefn=$key;
2819: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2820: if ($prefixchg && $before{'map'} && $after{'map'}) {
2821: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2822: }
1.529 raeburn 2823: if ($newsubdir{$key}) {
2824: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2825: }
1.491 raeburn 2826: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2827: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2828: ($after{'map'} eq 'default') &&
2829: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2830: $mapcontent = '<map>'."\n".
2831: '<resource id="1" src="" type="start" />'."\n".
2832: '<link from="1" to="2" index="1" />'."\n".
2833: '<resource id="2" src="" type="finish" />'."\n".
2834: '</map>';
2835: }
1.491 raeburn 2836: if ($mapcontent eq '-1') {
2837: if (ref($errors) eq 'HASH') {
2838: $errors->{$key} = 1;
2839: }
2840: } else {
2841: my $newmap =
2842: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2843: $mapcontent);
2844: if ($newmap eq '/adm/notfound.html') {
2845: if (ref($errors) eq 'HASH') {
2846: $errors->{$key} = 1;
1.489 raeburn 2847: }
1.488 raeburn 2848: }
2849: }
2850: }
1.491 raeburn 2851: my %updates;
2852: if ($is_map) {
1.529 raeburn 2853: if (ref($updated) eq 'HASH') {
2854: foreach my $type (keys(%{$updated})) {
2855: if (ref($updated->{$type}) eq 'HASH') {
2856: foreach my $key (keys(%{$updated->{$type}})) {
2857: $updates{$key} = 1;
2858: }
2859: }
2860: }
1.491 raeburn 2861: }
2862: foreach my $key (keys(%updates)) {
1.492 raeburn 2863: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2864: if (ref($rewrites{$key}) eq 'HASH') {
2865: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2866: }
1.529 raeburn 2867: if (ref($retitles{$key}) eq 'HASH') {
2868: %toretitle = %{$retitles{$key}};
1.491 raeburn 2869: }
1.529 raeburn 2870: if (ref($removefrommap{$key}) eq 'HASH') {
2871: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2872: }
1.529 raeburn 2873: if (ref($removeparam{$key}) eq 'HASH') {
2874: %remparam = %{$removeparam{$key}};
1.492 raeburn 2875: }
1.529 raeburn 2876: if (ref($zombies{$key}) eq 'HASH') {
2877: %zombie = %{$zombies{$key}};
1.491 raeburn 2878: }
1.529 raeburn 2879: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2880: foreach my $idx (keys(%{$dbcopies{$key}})) {
2881: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2882: my ($newurl,$result,$errtext) =
2883: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2884: if ($result eq 'ok') {
2885: $newdb{$idx} = $newurl;
2886: } elsif (ref($errors) eq 'HASH') {
2887: $errors->{$key} = 1;
2888: }
2889: push(@msgs,$errtext);
2890: }
1.491 raeburn 2891: }
2892: }
1.597 raeburn 2893: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2894: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2895: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2896: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2897: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2898: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2899: my $template = $1;
2900: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2901: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2902: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2903: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2904: unless ($gotnewmapname) {
2905: ($newmapname) = ($key =~ m{/([^/]+)$});
2906: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2907: if ($newsubdir{$key}) {
2908: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2909: }
2910: $gotnewmapname = 1;
2911: }
1.597 raeburn 2912: my $srcmapinfo = $srcfolder.':'.$idx;
2913: if ($srccontainer eq 'page') {
2914: $srcmapinfo .= ':1';
2915: }
2916: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2917: $cnum,$template,$idx,$newmapname);
2918: }
2919: }
2920: }
2921: }
2922: }
1.529 raeburn 2923: if (ref($params{$key}) eq 'HASH') {
2924: %currparam = %{$params{$key}};
1.492 raeburn 2925: }
2926: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2927: if ($fatal) {
1.533 raeburn 2928: return ($errtext);
1.492 raeburn 2929: }
2930: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2931: if (defined($LONCAPA::map::zombies[$i])) {
2932: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2933: if ($zombie{$i} eq $src) {
1.492 raeburn 2934: undef($LONCAPA::map::zombies[$i]);
2935: }
2936: }
2937: }
1.646 raeburn 2938: my $total = scalar(@LONCAPA::map::order) - 1;
2939: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2940: my $idx = $LONCAPA::map::order[$i];
2941: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2942: my $changed;
1.529 raeburn 2943: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2944: if ((exists($toremove{$idx})) &&
2945: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2946: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2947: if (ref($currparam{$idx}) eq 'ARRAY') {
2948: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2949: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2950: }
2951: }
2952: next;
2953: }
2954: my $origsrc = $src;
1.532 raeburn 2955: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2956: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2957: $changed = 1;
1.491 raeburn 2958: }
1.492 raeburn 2959: }
1.532 raeburn 2960: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2961: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2962: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2963: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2964: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2965: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2966: } else {
1.529 raeburn 2967: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2968: }
1.491 raeburn 2969: }
1.532 raeburn 2970: if ($origsrc =~ /\.(page|sequence)$/) {
2971: if ($newsubdir{$origsrc}) {
1.529 raeburn 2972: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2973: }
1.532 raeburn 2974: } elsif ($newsubdir{$key}) {
2975: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2976: }
2977: }
1.492 raeburn 2978: $changed = 1;
1.533 raeburn 2979: } elsif ($newdb{$idx} ne '') {
2980: $src = $newdb{$idx};
1.492 raeburn 2981: $changed = 1;
2982: }
2983: if ($changed) {
1.538 raeburn 2984: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2985: }
2986: }
2987: }
2988: foreach my $idx (keys(%remparam)) {
2989: if (ref($remparam{$idx}) eq 'ARRAY') {
2990: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2991: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2992: }
2993: }
2994: }
1.533 raeburn 2995: if (values(%lockerrors) > 0) {
2996: $lockmsg = join('<br />',values(%lockerrors));
2997: }
1.491 raeburn 2998: my $storefn;
2999: if ($key eq $oldurl) {
3000: $storefn = $url;
3001: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3002: } else {
3003: $storefn = $key;
3004: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3005: if ($prefixchg && $before{'map'} && $after{'map'}) {
3006: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3007: }
1.529 raeburn 3008: if ($newsubdir{$key}) {
3009: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3010: }
1.491 raeburn 3011: }
1.492 raeburn 3012: my $report;
3013: if ($folder !~ /^supplemental/) {
3014: $report = 1;
3015: }
1.527 raeburn 3016: (my $outtext,$errtext) =
1.492 raeburn 3017: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3018: if ($errtext) {
1.529 raeburn 3019: if ($caller eq 'paste') {
1.533 raeburn 3020: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3021: }
1.491 raeburn 3022: }
3023: }
3024: }
1.533 raeburn 3025: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3026: }
3027:
3028: sub copy_dependencies {
3029: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3030: my $content;
3031: if (ref($contentref)) {
3032: $content = $$contentref;
3033: } else {
3034: $content = &Apache::lonnet::getfile($item);
3035: }
3036: unless ($content eq '-1') {
3037: my $mm = new File::MMagic;
3038: my $mimetype = $mm->checktype_contents($content);
3039: if ($mimetype eq 'text/html') {
3040: my (%allfiles,%codebase,$state);
3041: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3042: if ($res eq 'ok') {
3043: my ($numexisting,$numpathchanges,$existing);
3044: (undef,$numexisting,$numpathchanges,$existing) =
3045: &Apache::loncommon::ask_for_embedded_content(
3046: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3047: {'error_on_invalid_names' => 1,
3048: 'ignore_remote_references' => 1,
3049: 'docs_url' => $item,
3050: 'context' => 'paste'});
3051: if ($numexisting > 0) {
3052: if (ref($existing) eq 'HASH') {
3053: foreach my $dep (keys(%{$existing})) {
3054: my $depfile = $dep;
3055: unless ($depfile =~ m{^\Q$relpath\E}) {
3056: $depfile = $relpath.$dep;
3057: }
3058: my $depcontent = &Apache::lonnet::getfile($depfile);
3059: unless ($depcontent eq '-1') {
3060: my $storedep = $dep;
3061: $storedep =~ s{^\Q$relpath\E}{};
3062: my $dep_url =
3063: &Apache::lonclonecourse::writefile(
3064: $env{'request.course.id'},
3065: $storefn.$storedep,$depcontent);
3066: if ($dep_url eq '/adm/notfound.html') {
3067: if (ref($errors) eq 'HASH') {
3068: $errors->{$depfile} = 1;
3069: }
3070: } else {
3071: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3072: }
3073: }
3074: }
1.488 raeburn 3075: }
3076: }
3077: }
3078: }
3079: }
3080: return;
3081: }
3082:
1.329 droeschl 3083: my %parameter_type = ( 'randompick' => 'int_pos',
3084: 'hiddenresource' => 'string_yesno',
3085: 'encrypturl' => 'string_yesno',
3086: 'randomorder' => 'string_yesno',);
3087: my $valid_parameters_re = join('|',keys(%parameter_type));
3088: # set parameters
3089: sub update_parameter {
1.537 raeburn 3090: if ($env{'form.changeparms'} eq 'all') {
3091: my (@allidx,@allmapidx,%allchecked,%currchecked);
3092: %allchecked = (
3093: 'hiddenresource' => {},
3094: 'encrypturl' => {},
3095: 'randompick' => {},
3096: 'randomorder' => {},
3097: );
3098: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3099: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3100: if ($which eq 'randompick') {
3101: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3102: my ($res,$value) = split(/:/,$item);
3103: if ($value =~ /^\d+$/) {
3104: $allchecked{$which}{$res} = $value;
3105: }
3106: }
3107: } else {
1.539 raeburn 3108: if ($env{'form.all'.$which}) {
3109: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3110: }
1.537 raeburn 3111: }
3112: }
3113: my $haschanges = 0;
3114: foreach my $res (@LONCAPA::map::order) {
3115: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3116: $name=&LONCAPA::map::qtescape($name);
3117: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3118: next unless $url;
1.537 raeburn 3119: my $is_map;
3120: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3121: $is_map = 1;
3122: }
3123: foreach my $which (keys(%allchecked)) {
3124: if (($which eq 'randompick' || $which eq 'randomorder')) {
3125: next if (!$is_map);
3126: }
3127: my $oldvalue = 0;
3128: my $newvalue = 0;
3129: if ($allchecked{$which}{$res}) {
3130: $newvalue = $allchecked{$which}{$res};
3131: }
3132: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3133: if ($which eq 'randompick') {
3134: if ($current =~ /^(\d+)$/) {
3135: $oldvalue = $1;
3136: }
3137: } else {
3138: if ($current =~ /^yes$/i) {
3139: $oldvalue = 1;
3140: }
3141: }
3142: if ($oldvalue ne $newvalue) {
3143: $haschanges = 1;
3144: if ($newvalue) {
3145: my $storeval = 'yes';
3146: if ($which eq 'randompick') {
3147: $storeval = $newvalue;
3148: }
3149: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3150: $storeval,
3151: $parameter_type{$which});
3152: &remember_parms($res,$which,'set',$storeval);
3153: } elsif ($oldvalue) {
3154: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3155: &remember_parms($res,$which,'del');
3156: }
3157: }
3158: }
3159: }
3160: return $haschanges;
3161: } else {
1.588 raeburn 3162: my $haschanges = 0;
3163: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3164:
1.537 raeburn 3165: my $which = $env{'form.changeparms'};
3166: my $idx = $env{'form.setparms'};
1.588 raeburn 3167: my $oldvalue = 0;
3168: my $newvalue = 0;
3169: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3170: if ($which eq 'randompick') {
3171: if ($current =~ /^(\d+)$/) {
3172: $oldvalue = $1;
3173: }
3174: } elsif ($current =~ /^yes$/i) {
3175: $oldvalue = 1;
3176: }
1.537 raeburn 3177: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3178: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3179: : 1;
3180: }
3181: if ($oldvalue ne $newvalue) {
3182: $haschanges = 1;
3183: if ($newvalue) {
3184: my $storeval = 'yes';
3185: if ($which eq 'randompick') {
3186: $storeval = $newvalue;
3187: }
3188: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3189: $parameter_type{$which});
3190: &remember_parms($idx,$which,'set',$storeval);
3191: } else {
3192: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3193: &remember_parms($idx,$which,'del');
3194: }
1.537 raeburn 3195: }
1.588 raeburn 3196: return $haschanges;
1.329 droeschl 3197: }
3198: }
3199:
3200: sub handle_edit_cmd {
3201: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3202: my $haschanges = 0;
1.543 raeburn 3203: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3204: return $haschanges;
1.543 raeburn 3205: }
1.329 droeschl 3206: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3207:
3208: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3209: my ($title, $url, @rrest) = split(':', $ratstr);
3210:
1.538 raeburn 3211: if ($cmd eq 'remove') {
1.329 droeschl 3212: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3213: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3214: &Apache::lonnet::removeuploadedurl($url);
3215: } else {
3216: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3217: }
3218: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3219: $haschanges = 1;
1.329 droeschl 3220: } elsif ($cmd eq 'cut') {
3221: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3222: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3223: $haschanges = 1;
1.344 bisitz 3224: } elsif ($cmd eq 'up'
1.329 droeschl 3225: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3226: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3227: $haschanges = 1;
1.329 droeschl 3228: } elsif ($cmd eq 'down'
3229: && defined($LONCAPA::map::order[$idx+1])) {
3230: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3231: $haschanges = 1;
1.329 droeschl 3232: } elsif ($cmd eq 'rename') {
3233: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3234: if ($comment=~/\S/) {
3235: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3236: $comment.':'.join(':', $url, @rrest);
3237: }
3238: # Devalidate title cache
3239: my $renamed_url=&LONCAPA::map::qtescape($url);
3240: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3241: $haschanges = 1;
3242: } elsif ($cmd eq 'setalias') {
3243: my $newvalue = $env{'form.alias'};
3244: if ($newvalue ne '') {
3245: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3246: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3247: 'string');
3248: &remember_parms($idx,'mapalias','set',$newvalue);
3249: $haschanges = 1;
3250: }
3251: }
3252: } elsif ($cmd eq 'delalias') {
3253: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3254: if ($current ne '') {
3255: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3256: &remember_parms($idx,'mapalias','del');
3257: $haschanges = 1;
3258: }
1.329 droeschl 3259: }
1.633 raeburn 3260: return $haschanges;
1.329 droeschl 3261: }
3262:
3263: sub editor {
1.458 raeburn 3264: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3265: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3266: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3267: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3268: if ($allowed) {
1.519 raeburn 3269: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3270: $is_random_order,$container) =
1.510 raeburn 3271: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3272: $r->print($breadcrumbtrail);
1.519 raeburn 3273: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3274: $container = 'page';
3275: } else {
3276: $container = 'sequence';
1.510 raeburn 3277: }
1.484 raeburn 3278:
1.525 raeburn 3279: my $jumpto;
3280:
3281: unless ($supplementalflag) {
1.546 raeburn 3282: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3283: }
1.484 raeburn 3284:
3285: unless ($allowed) {
3286: $randompick = -1;
3287: }
3288:
1.615 raeburn 3289: my ($errtext,$fatal);
3290: if (($folder eq '') && (!$supplementalflag)) {
3291: if (@LONCAPA::map::order) {
3292: undef(@LONCAPA::map::order);
3293: undef(@LONCAPA::map::resources);
3294: undef(@LONCAPA::map::resparms);
3295: undef(@LONCAPA::map::zombies);
3296: }
3297: $folder = 'default';
3298: $container = 'sequence';
3299: } else {
3300: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3301: $folder.'.'.$container);
3302: return $errtext if ($fatal);
3303: }
1.329 droeschl 3304:
3305: if ($#LONCAPA::map::order<1) {
3306: my $idx=&LONCAPA::map::getresidx();
3307: if ($idx<=0) { $idx=1; }
3308: $LONCAPA::map::order[0]=$idx;
3309: $LONCAPA::map::resources[$idx]='';
3310: }
1.364 bisitz 3311:
1.329 droeschl 3312: # ------------------------------------------------------------ Process commands
3313:
3314: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3315: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3316: # set parameters and change order
3317: &snapshotbefore();
3318:
3319: if (&update_parameter()) {
1.588 raeburn 3320: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3321: return $errtext if ($fatal);
3322: }
3323:
3324: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3325: # change order
3326: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3327: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3328:
3329: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3330: return $errtext if ($fatal);
3331: }
1.364 bisitz 3332:
1.329 droeschl 3333: if ($env{'form.pastemarked'}) {
1.491 raeburn 3334: my %paste_errors;
1.533 raeburn 3335: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3336: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3337: \%paste_errors);
1.541 raeburn 3338: if (ref($pastemsgarray) eq 'ARRAY') {
3339: if (@{$pastemsgarray} > 0) {
3340: $r->print('<p class="LC_info">'.
3341: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3342: '</p>');
3343: }
1.541 raeburn 3344: }
3345: if ($lockerror) {
3346: $r->print('<p class="LC_error">'.
3347: $lockerror.
3348: '</p>');
3349: }
3350: if ($save_error ne '') {
3351: return $save_error;
3352: }
3353: if ($paste_res) {
3354: my %errortext = &Apache::lonlocal::texthash (
3355: fail => 'Storage of folder contents failed',
3356: failread => 'Reading folder contents failed',
3357: failstore => 'Storage of folder contents failed',
3358: );
3359: if ($errortext{$paste_res}) {
3360: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3361: }
1.329 droeschl 3362: }
1.491 raeburn 3363: if (keys(%paste_errors) > 0) {
1.538 raeburn 3364: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3365: &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".
3366: '<ul>'."\n");
3367: foreach my $key (sort(keys(%paste_errors))) {
3368: $r->print('<li>'.$key.'</li>'."\n");
3369: }
3370: $r->print('</ul></p>'."\n");
3371: }
1.538 raeburn 3372: } elsif ($env{'form.clearmarked'}) {
3373: my $output = &do_buffer_empty();
3374: if ($output) {
3375: $r->print('<p class="LC_info">'.$output.'</p>');
3376: }
3377: }
1.329 droeschl 3378:
3379: $r->print($upload_output);
3380:
1.538 raeburn 3381: # Rename, cut, copy or remove a single resource
1.602 raeburn 3382: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3383: my $contentchg;
1.633 raeburn 3384: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3385: $contentchg = 1;
3386: }
3387: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3388: return $errtext if ($fatal);
3389: }
1.538 raeburn 3390:
3391: # Cut, copy and/or remove multiple resources
3392: if ($env{'form.multichange'}) {
3393: my %allchecked = (
3394: cut => {},
3395: remove => {},
3396: );
3397: my $needsupdate;
3398: foreach my $which (keys(%allchecked)) {
3399: $env{'form.multi'.$which} =~ s/,$//;
3400: if ($env{'form.multi'.$which}) {
3401: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3402: if (ref($allchecked{$which}) eq 'HASH') {
3403: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3404: }
3405: }
3406: }
3407: if ($needsupdate) {
3408: my $haschanges = 0;
3409: my %curr_groups = &Apache::longroup::coursegroups();
3410: my $total = scalar(@LONCAPA::map::order) - 1;
3411: for (my $i=$total; $i>=0; $i--) {
3412: my $res = $LONCAPA::map::order[$i];
3413: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3414: $name=&LONCAPA::map::qtescape($name);
3415: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3416: next unless $url;
1.538 raeburn 3417: my %denied =
3418: &action_restrictions($coursenum,$coursedom,$url,
3419: $env{'form.folderpath'},\%curr_groups);
3420: foreach my $which (keys(%allchecked)) {
3421: next if ($denied{$which});
3422: next unless ($allchecked{$which}{$res});
3423: if ($which eq 'remove') {
3424: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3425: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3426: &Apache::lonnet::removeuploadedurl($url);
3427: } else {
3428: &LONCAPA::map::makezombie($res);
3429: }
3430: splice(@LONCAPA::map::order,$i,1);
3431: $haschanges ++;
3432: } elsif ($which eq 'cut') {
3433: &LONCAPA::map::makezombie($res);
3434: splice(@LONCAPA::map::order,$i,1);
3435: $haschanges ++;
3436: }
3437: }
3438: }
3439: if ($haschanges) {
3440: ($errtext,$fatal) =
3441: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3442: return $errtext if ($fatal);
3443: }
3444: }
3445: }
3446:
1.329 droeschl 3447: # Group import/search
3448: if ($env{'form.importdetail'}) {
3449: my @imports;
3450: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3451: if (defined($item)) {
3452: my ($name,$url,$residx)=
1.533 raeburn 3453: map { &unescape($_); } split(/\=/,$item);
3454: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3455: my ($suffix,$errortxt,$locknotfreed) =
3456: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3457: if ($locknotfreed) {
3458: $r->print($locknotfreed);
3459: }
3460: if ($suffix) {
3461: $url =~ s/_new\./_$suffix./;
3462: } else {
3463: return $errortxt;
3464: }
1.533 raeburn 3465: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3466: my $type = $1;
3467: my ($suffix,$errortxt,$locknotfreed) =
3468: &new_timebased_suffix($coursedom,$coursenum,$type);
3469: if ($locknotfreed) {
3470: $r->print($locknotfreed);
3471: }
3472: if ($suffix) {
3473: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3474: } else {
3475: return $errortxt;
3476: }
1.626 raeburn 3477: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3478: my ($suffix,$errortxt,$locknotfreed) =
3479: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3480: if ($locknotfreed) {
3481: $r->print($locknotfreed);
3482: }
3483: if ($suffix) {
3484: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3485: } else {
3486: return $errortxt;
3487: }
1.534 raeburn 3488: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3489: if ($supplementalflag) {
3490: next unless ($1 eq 'supplemental');
3491: if ($folder eq 'supplemental') {
3492: next unless ($2 eq 'default');
3493: } else {
3494: next unless ($folder eq 'supplemental_'.$2);
3495: }
3496: } else {
3497: next unless ($1 eq 'docs');
3498: if ($folder eq 'default') {
3499: next unless ($2 eq 'default');
3500: } else {
3501: next unless ($folder eq 'default_'.$2);
3502: }
3503: }
1.504 raeburn 3504: }
1.329 droeschl 3505: push(@imports, [$name, $url, $residx]);
3506: }
3507: }
1.530 raeburn 3508: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3509: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3510: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3511: return $errtext if ($fatal);
1.529 raeburn 3512: if ($fixuperrors) {
3513: $r->print($fixuperrors);
3514: }
1.329 droeschl 3515: }
3516: # Loading a complete map
3517: if ($env{'form.loadmap'}) {
3518: if ($env{'form.importmap'}=~/\w/) {
3519: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3520: my ($title,$url,$ext,$type)=split(/\:/,$res);
3521: my $idx=&LONCAPA::map::getresidx($url);
3522: $LONCAPA::map::resources[$idx]=$res;
3523: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3524: }
3525: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3526: $folder.'.'.$container,1);
1.329 droeschl 3527: return $errtext if ($fatal);
3528: } else {
3529: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3530:
1.329 droeschl 3531: }
3532: }
3533: &log_differences($plain);
3534: }
3535: # ---------------------------------------------------------------- End commands
3536: # ---------------------------------------------------------------- Print screen
3537: my $idx=0;
3538: my $shown=0;
3539: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3540: $r->print('<div class="LC_Box">'.
1.432 raeburn 3541: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3542: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3543: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3544: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3545: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3546: '</ol>');
1.381 bisitz 3547: if ($randompick>=0) {
3548: $r->print('<p class="LC_warning">'
3549: .&mt('Caution: this folder is set to randomly pick a subset'
3550: .' of resources. Adding or removing resources from this'
3551: .' folder will change the set of resources that the'
3552: .' students see, resulting in spurious or missing credit'
3553: .' for completed problems, not limited to ones you'
3554: .' modify. Do not modify the contents of this folder if'
3555: .' it is in active student use.')
3556: .'</p>'
3557: );
3558: }
3559: if ($is_random_order) {
3560: $r->print('<p class="LC_warning">'
3561: .&mt('Caution: this folder is set to randomly order its'
3562: .' contents. Adding or removing resources from this folder'
3563: .' will change the order of resources shown.')
3564: .'</p>'
3565: );
3566: }
3567: $r->print('</div>');
1.364 bisitz 3568: }
1.381 bisitz 3569:
1.685 raeburn 3570: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3571: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3572: if (ref($supplemental) eq 'HASH') {
3573: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3574: (ref($supplemental->{'ids'}) eq 'HASH')) {
3575: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3576: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3577: if ($supplemental->{'hidden'}->{$mapnum}) {
3578: $ishidden = 1;
3579: }
3580: }
3581: }
3582: }
3583: }
3584:
1.538 raeburn 3585: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3586: %filters = (
1.543 raeburn 3587: canremove => [],
3588: cancut => [],
3589: cancopy => [],
3590: hiddenresource => [],
3591: encrypturl => [],
3592: randomorder => [],
3593: randompick => [],
1.538 raeburn 3594: );
3595: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3596: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3597: foreach my $res (@LONCAPA::map::order) {
3598: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3599: $name=&LONCAPA::map::qtescape($name);
3600: $url=&LONCAPA::map::qtescape($url);
3601: unless ($name) { $name=(split(/\//,$url))[-1]; }
3602: unless ($name) { $idx++; next; }
1.537 raeburn 3603: push(@allidx,$res);
3604: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3605: push(@allmapidx,$res);
3606: }
1.617 raeburn 3607:
1.682 raeburn 3608: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3609: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3610: $idx++;
3611: next;
3612: }
1.682 raeburn 3613: }
1.381 bisitz 3614: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3615: $coursenum,$coursedom,$crstype,
1.538 raeburn 3616: $pathitem,$supplementalflag,$container,
1.620 raeburn 3617: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3618: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3619: $idx++;
3620: $shown++;
1.329 droeschl 3621: }
1.424 onken 3622: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3623:
1.538 raeburn 3624: my $need_save;
1.611 raeburn 3625: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3626: my $toolslink;
1.682 raeburn 3627: if ($allowed || $canedit) {
3628: my $helpitem = 'Navigation_Screen';
3629: if (!$allowed) {
3630: $helpitem = 'Supplemental_Navigation';
3631: }
1.544 raeburn 3632: $toolslink = '<table><tr><td>'
1.520 raeburn 3633: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3634: $helpitem,undef,'RAT')
1.520 raeburn 3635: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3636: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3637: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3638: .'id="LC_content_toolbar_edittoplevel" '
3639: .'class="LC_toolbarItem" '
3640: .'title="'.&mt('Supplemental Content Editor').'">'
3641: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3642: }
1.510 raeburn 3643: if ($shown) {
3644: if ($allowed) {
3645: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3646: .&Apache::loncommon::start_data_table(undef,'contentlist')
3647: .&Apache::loncommon::start_data_table_header_row()
3648: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3649: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3650: .'<th>'.&mt('Document').'</th>'
3651: .'<th colspan="2">'.&mt('Settings').'</th>'
3652: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3653: if ($folder !~ /^supplemental/) {
1.538 raeburn 3654: $lists{'canhide'} = join(',',@allidx);
3655: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3656: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3657: 'randomorder','randompick');
3658: foreach my $item (@possfilters) {
1.538 raeburn 3659: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3660: if (@{$filters{$item}} > 0) {
3661: $lists{$item} = join(',',@{$filters{$item}});
3662: }
1.538 raeburn 3663: }
3664: }
1.537 raeburn 3665: if (@allidx > 0) {
3666: my $path;
3667: if ($env{'form.folderpath'}) {
1.630 raeburn 3668: $path =
1.537 raeburn 3669: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3670: }
1.538 raeburn 3671: if (@allidx > 1) {
1.630 raeburn 3672: $to_show .=
1.538 raeburn 3673: &Apache::loncommon::continue_data_table_row().
3674: '<td colspan="2"> </td>'.
3675: '<td>'.
1.611 raeburn 3676: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3677: '</td>'.
1.633 raeburn 3678: '<td colspan="3"> </td>'.
3679: '<td colspan="2">'.
1.611 raeburn 3680: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3681: '</td>'.
3682: &Apache::loncommon::end_data_table_row();
3683: $need_save = 1;
3684: }
1.537 raeburn 3685: }
3686: }
3687: $to_show .= $output.' '
1.510 raeburn 3688: .&Apache::loncommon::end_data_table()
3689: .'<br style="line-height:2px;" />'
3690: .&Apache::loncommon::end_scrollbox();
3691: } else {
1.520 raeburn 3692: $to_show .= $toolslink
1.510 raeburn 3693: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3694: .$output.' '
3695: .&Apache::loncommon::end_data_table();
1.393 raeburn 3696: }
1.510 raeburn 3697: } else {
1.520 raeburn 3698: if (!$allowed) {
3699: $to_show .= $toolslink;
3700: }
1.615 raeburn 3701: my $noresmsg;
3702: if ($allowed && $hiddentop && !$supplementalflag) {
3703: $noresmsg = &mt('Main Content Hidden');
3704: } else {
3705: $noresmsg = &mt('Currently empty');
3706: }
1.510 raeburn 3707: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3708: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3709: .$noresmsg
1.510 raeburn 3710: .'</div>'
3711: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3712: }
3713: } else {
1.510 raeburn 3714: if ($shown) {
3715: $to_show = '<div>'
3716: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3717: .$output
3718: .&Apache::loncommon::end_data_table()
3719: .'</div>';
3720: } else {
3721: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3722: .&mt('Currently empty')
1.510 raeburn 3723: .'</div>'
3724: }
1.458 raeburn 3725: }
3726: my $tid = 1;
3727: if ($supplementalflag) {
3728: $tid = 2;
1.329 droeschl 3729: }
3730: if ($allowed) {
1.484 raeburn 3731: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3732: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3733: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3734: if ($canedit) {
3735: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3736: }
1.460 raeburn 3737: } else {
3738: $r->print($to_show);
1.329 droeschl 3739: }
3740: return;
3741: }
3742:
1.538 raeburn 3743: sub multiple_check_form {
1.611 raeburn 3744: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3745: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3746: my $disabled;
3747: unless ($canedit) {
3748: $disabled = 'disabled="disabled"';
3749: }
1.538 raeburn 3750: my $output =
3751: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3752: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3753: '<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>'.
3754: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3755: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3756: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3757: if ($caller eq 'settings') {
3758: $output .=
3759: '<table><tr>'.
3760: '<td class="LC_docs_entry_parameter">'.
3761: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3762: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3763: '</label></span></td>'.
3764: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3765: '<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 3766: '</span></td>'.
3767: '</tr>'."\n".
3768: '<tr>'.
3769: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3770: '<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 3771: '</label></span>'.
3772: '</td></tr></table>'."\n";
3773: } else {
3774: $output .=
3775: '<table><tr>'.
3776: '<td class="LC_docs_entry_parameter">'.
3777: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3778: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3779: '</label></span></td>'.
3780: '<td class="LC_docs_entry_parameter">'.
3781: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3782: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3783: '</label></span></td>'."\n".
3784: '<td class="LC_docs_entry_parameter">'.
3785: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3786: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3787: '</label></span></td>'.
3788: '</tr></table>'."\n";
3789: }
3790: $output .=
3791: '</fieldset>'.
3792: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3793: if ($caller eq 'settings') {
3794: $output .=
1.543 raeburn 3795: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3796: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3797: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3798: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3799: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3800: } elsif ($caller eq 'actions') {
3801: $output .=
3802: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3803: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3804: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3805: }
3806: $output .=
3807: '</form>'.
3808: '</div>';
3809: return $output;
3810: }
3811:
1.329 droeschl 3812: sub process_file_upload {
1.552 raeburn 3813: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3814: # upload a file, if present
1.552 raeburn 3815: my $filesize = length($env{'form.uploaddoc'});
3816: if (!$filesize) {
3817: $$upload_output = '<div class="LC_error">'.
3818: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3819: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3820: $filesize).'<br />'.
3821: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3822: '</div>';
3823: return;
3824: }
3825: my $quotatype = 'unofficial';
3826: if ($crstype eq 'Community') {
1.601 raeburn 3827: $quotatype = 'community';
3828: } elsif ($crstype eq 'Placement') {
3829: $quotatype = 'placement';
1.580 raeburn 3830: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3831: $quotatype = 'official';
1.573 raeburn 3832: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3833: $quotatype = 'textbook';
1.552 raeburn 3834: }
3835: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3836: $filesize = int($filesize/1000); #expressed in kb
3837: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3838: $env{'form.uploaddoc.filename'},$filesize,
3839: 'upload',$quotatype);
1.552 raeburn 3840: return if ($$upload_output);
3841: }
1.440 raeburn 3842: my ($parseaction,$showupload,$nextphase,$mimetype);
3843: if ($env{'form.parserflag'}) {
1.329 droeschl 3844: $parseaction = 'parse';
3845: }
3846: my $folder=$env{'form.folder'};
3847: if ($folder eq '') {
3848: $folder='default';
3849: }
3850: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3851: my $errtext='';
3852: my $fatal=0;
3853: my $container='sequence';
1.519 raeburn 3854: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3855: $container='page';
3856: }
3857: ($errtext,$fatal)=
1.534 raeburn 3858: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3859: if ($#LONCAPA::map::order<1) {
3860: $LONCAPA::map::order[0]=1;
3861: $LONCAPA::map::resources[1]='';
3862: }
3863: my $destination = 'docs/';
3864: if ($folder =~ /^supplemental/) {
3865: $destination = 'supplemental/';
3866: }
3867: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3868: $destination .= 'default/';
3869: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3870: $destination .= $2.'/';
3871: }
1.534 raeburn 3872: if ($fatal) {
3873: $$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>';
3874: return;
3875: }
1.440 raeburn 3876: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3877: my $newidx=&LONCAPA::map::getresidx();
3878: $destination .= $newidx;
1.439 raeburn 3879: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3880: $parseaction,$allfiles,
1.440 raeburn 3881: $codebase,undef,undef,undef,undef,
3882: undef,undef,\$mimetype);
3883: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3884: my $stored = $1;
3885: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3886: $stored.'</span>').'</p>';
3887: } else {
3888: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3889:
1.457 raeburn 3890: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3891: return;
3892: }
1.329 droeschl 3893: my $ext='false';
3894: if ($url=~m{^http://}) { $ext='true'; }
3895: $url = &LONCAPA::map::qtunescape($url);
3896: my $comment=$env{'form.comment'};
3897: $comment = &LONCAPA::map::qtunescape($comment);
3898: if ($folder=~/^supplemental/) {
3899: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3900: $env{'user.domain'}.'___&&&___'.$comment;
3901: }
3902:
3903: $LONCAPA::map::resources[$newidx]=
3904: $comment.':'.$url.':'.$ext.':normal:res';
3905: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3906: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3907: $folder.'.'.$container,1);
1.329 droeschl 3908: if ($fatal) {
1.457 raeburn 3909: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3910: return;
1.329 droeschl 3911: } else {
1.440 raeburn 3912: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3913: $$upload_output = $showupload;
1.384 raeburn 3914: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3915: if ($total_embedded > 0) {
1.440 raeburn 3916: my $uploadphase = 'upload_embedded';
3917: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3918: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3919: my ($embedded,$num) =
1.440 raeburn 3920: &Apache::loncommon::ask_for_embedded_content(
3921: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3922: if ($embedded) {
3923: if ($num) {
3924: $$upload_output .=
3925: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3926: $nextphase = $uploadphase;
3927: } else {
3928: $$upload_output .= $embedded;
3929: }
3930: } else {
3931: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3932: }
1.329 droeschl 3933: } else {
1.440 raeburn 3934: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3935: }
1.457 raeburn 3936: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3937: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3938: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3939: $nextphase = 'decompress_uploaded';
3940: my $position = scalar(@LONCAPA::map::order)-1;
3941: my $noextract = &return_to_editor();
3942: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3943: my %archiveitems = (
3944: folderpath => $env{'form.folderpath'},
3945: cmd => $nextphase,
3946: newidx => $newidx,
3947: position => $position,
3948: phase => $nextphase,
1.477 raeburn 3949: comment => $comment,
1.480 raeburn 3950: );
3951: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3952: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3953: $$upload_output = $showupload.
3954: &Apache::loncommon::decompress_form($mimetype,
3955: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3956: \%archiveitems,\@current);
1.329 droeschl 3957: }
3958: }
3959: }
1.440 raeburn 3960: return $nextphase;
1.329 droeschl 3961: }
3962:
1.480 raeburn 3963: sub get_dir_list {
3964: my ($url,$coursenum,$coursedom,$newidx) = @_;
3965: my ($destination,$dir_root) = &embedded_destination();
3966: my ($dirlistref,$listerror) =
3967: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3968: my @dir_lines;
3969: my $dirptr=16384;
3970: if (ref($dirlistref) eq 'ARRAY') {
3971: foreach my $dir_line (sort
3972: {
3973: my ($afile)=split('&',$a,2);
3974: my ($bfile)=split('&',$b,2);
3975: return (lc($afile) cmp lc($bfile));
3976: } (@{$dirlistref})) {
3977: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3978: $filename =~ s/\s+$//;
3979: next if ($filename =~ /^\.\.?$/);
3980: my $isdir = 0;
3981: if ($dirptr&$testdir) {
3982: $isdir = 1;
3983: }
3984: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3985: }
3986: }
3987: return @dir_lines;
3988: }
3989:
1.329 droeschl 3990: sub is_supplemental_title {
3991: my ($title) = @_;
3992: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3993: }
3994:
3995: # --------------------------------------------------------------- An entry line
3996:
3997: sub entryline {
1.501 raeburn 3998: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3999: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4000: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4001: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4002: if (&is_supplemental_title($title)) {
1.488 raeburn 4003: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4004: $encodedtitle=$title;
1.329 droeschl 4005: } else {
4006: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4007: $encodedtitle=$title;
1.329 droeschl 4008: $renametitle=$title;
4009: $foldertitle=$title;
4010: }
4011:
1.611 raeburn 4012: my ($disabled,$readonly,$js_lt);
4013: unless ($canedit) {
4014: $disabled = 'disabled="disabled"';
4015: $readonly = 1;
4016: }
4017:
1.329 droeschl 4018: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4019:
1.329 droeschl 4020: $renametitle=~s/\\/\\\\/g;
4021: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4022: $renametitle=~s/"/%22/g;
1.581 raeburn 4023: $renametitle=~s/ /%20/g;
4024: $oldtitle = $renametitle;
1.576 raeburn 4025: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4026: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4027: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4028: # Edit commands
1.679 raeburn 4029: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4030: if ($env{'form.folderpath'}) {
4031: $esc_path=&escape($env{'form.folderpath'});
4032: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4033: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4034: }
1.505 raeburn 4035: my $isexternal;
1.510 raeburn 4036: if ($residx) {
1.501 raeburn 4037: my $currurl = $url;
4038: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4039: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4040: $isexternal = 1;
4041: }
1.510 raeburn 4042: if (!$supplementalflag) {
4043: my $path = 'uploaded/'.
4044: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4045: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4046: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4047: $residx,
4048: &Apache::lonnet::declutter($currurl));
4049: }
1.501 raeburn 4050: }
1.538 raeburn 4051: my ($renamelink,%lt,$ishash);
4052: if (ref($filtersref) eq 'HASH') {
4053: $ishash = 1;
4054: }
4055:
1.329 droeschl 4056: if ($allowed) {
1.538 raeburn 4057: $form_start = '
4058: <form action="/adm/coursedocs" method="post">
4059: ';
4060: $form_common=(<<END);
4061: <input type="hidden" name="folderpath" value="$path" />
4062: <input type="hidden" name="symb" value="$symb" />
4063: END
4064: $form_param=(<<END);
4065: <input type="hidden" name="setparms" value="$orderidx" />
4066: <input type="hidden" name="changeparms" value="0" />
4067: END
4068: $form_end = '</form>';
4069:
1.329 droeschl 4070: my $incindex=$index+1;
4071: my $selectbox='';
1.471 raeburn 4072: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4073: ((split(/\:/,
1.344 bisitz 4074: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4075: ne '') &&
1.329 droeschl 4076: ((split(/\:/,
1.344 bisitz 4077: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4078: ne '')) {
4079: $selectbox=
4080: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4081: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4082: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4083: if ($i==$incindex) {
1.358 bisitz 4084: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4085: } else {
4086: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4087: }
4088: }
4089: $selectbox.='</select>';
4090: }
1.501 raeburn 4091: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4092: 'up' => 'Move Up',
4093: 'dw' => 'Move Down',
4094: 'rm' => 'Remove',
4095: 'ct' => 'Cut',
4096: 'rn' => 'Rename',
1.501 raeburn 4097: 'cp' => 'Copy',
1.633 raeburn 4098: 'da' => 'Unset alias',
4099: 'sa' => 'Set alias',
1.501 raeburn 4100: 'ex' => 'External Resource',
1.598 raeburn 4101: 'et' => 'External Tool',
1.501 raeburn 4102: 'ed' => 'Edit',
4103: 'pr' => 'Preview',
4104: 'sv' => 'Save',
4105: 'ul' => 'URL',
1.611 raeburn 4106: 'ti' => 'Title',
1.618 raeburn 4107: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4108: );
1.538 raeburn 4109: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4110: $env{'form.folderpath'},
4111: $currgroups);
1.517 raeburn 4112: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4113: my $skip_confirm = 0;
1.603 raeburn 4114: my $confirm_removal = 0;
1.329 droeschl 4115: if ( $folder =~ /^supplemental/
4116: || ($url =~ m{( /smppg$
4117: |/syllabus$
4118: |/aboutme$
4119: |/navmaps$
4120: |/bulletinboard$
1.626 raeburn 4121: |/ext\.tool$
1.505 raeburn 4122: |\.html$)}x)
4123: || $isexternal) {
1.329 droeschl 4124: $skip_confirm = 1;
4125: }
1.603 raeburn 4126: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4127: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4128: $confirm_removal = 1;
4129: }
1.633 raeburn 4130: if ($url =~ /$LONCAPA::assess_re/) {
4131: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4132: }
1.329 droeschl 4133:
1.538 raeburn 4134: if ($denied{'copy'}) {
1.543 raeburn 4135: $copylink=(<<ENDCOPY)
1.507 raeburn 4136: <span style="visibility: hidden;">$lt{'cp'}</span>
4137: ENDCOPY
4138: } else {
1.538 raeburn 4139: my $formname = 'edit_copy_'.$orderidx;
4140: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4141: $copylink=(<<ENDCOPY);
1.538 raeburn 4142: <form name="$formname" method="post" action="/adm/coursedocs">
4143: $form_common
1.611 raeburn 4144: <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 4145: $form_end
1.329 droeschl 4146: ENDCOPY
1.538 raeburn 4147: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4148: push(@{$filtersref->{'cancopy'}},$orderidx);
4149: }
1.329 droeschl 4150: }
1.538 raeburn 4151: if ($denied{'cut'}) {
1.507 raeburn 4152: $cutlink=(<<ENDCUT);
4153: <span style="visibility: hidden;">$lt{'ct'}</span>
4154: ENDCUT
4155: } else {
1.538 raeburn 4156: my $formname = 'edit_cut_'.$orderidx;
4157: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4158: $cutlink=(<<ENDCUT);
1.538 raeburn 4159: <form name="$formname" method="post" action="/adm/coursedocs">
4160: $form_common
1.542 raeburn 4161: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4162: <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 4163: $form_end
1.329 droeschl 4164: ENDCUT
1.538 raeburn 4165: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4166: push(@{$filtersref->{'cancut'}},$orderidx);
4167: }
1.329 droeschl 4168: }
1.538 raeburn 4169: if ($denied{'remove'}) {
1.507 raeburn 4170: $removelink=(<<ENDREM);
4171: <span style="visibility: hidden;">$lt{'rm'}</a>
4172: ENDREM
4173: } else {
1.538 raeburn 4174: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4175: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4176: $removelink=(<<ENDREM);
1.538 raeburn 4177: <form name="$formname" method="post" action="/adm/coursedocs">
4178: $form_common
1.542 raeburn 4179: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4180: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4181: <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 4182: $form_end
1.497 raeburn 4183: ENDREM
1.538 raeburn 4184: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4185: push(@{$filtersref->{'canremove'}},$orderidx);
4186: }
1.497 raeburn 4187: }
1.551 raeburn 4188: $renamelink=(<<ENDREN);
1.581 raeburn 4189: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4190: ENDREN
1.611 raeburn 4191: my ($uplink,$downlink);
4192: if ($canedit) {
4193: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4194: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4195: } else {
4196: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4197: $downlink = $uplink;
4198: }
1.329 droeschl 4199: $line.=(<<END);
4200: <td>
1.379 bisitz 4201: <div class="LC_docs_entry_move">
1.611 raeburn 4202: <a href="$uplink">
1.501 raeburn 4203: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4204: </a>
4205: </div>
4206: <div class="LC_docs_entry_move">
1.611 raeburn 4207: <a href="$downlink">
1.501 raeburn 4208: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4209: </a>
4210: </div>
1.329 droeschl 4211: </td>
4212: <td>
4213: $form_start
1.538 raeburn 4214: $form_param
1.478 raeburn 4215: $form_common
1.329 droeschl 4216: $selectbox
4217: $form_end
4218: </td>
1.540 raeburn 4219: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4220: $removelink
1.329 droeschl 4221: $cutlink
4222: $copylink
4223: </td>
4224: END
4225: }
4226: # Figure out what kind of a resource this is
4227: my ($extension)=($url=~/\.(\w+)$/);
4228: my $uploaded=($url=~/^\/*uploaded\//);
4229: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4230: my $isfolder;
4231: my $ispage;
4232: my $containerarg;
1.615 raeburn 4233: my $folderurl;
1.685 raeburn 4234: my $plainurl;
1.329 droeschl 4235: if ($uploaded) {
1.472 raeburn 4236: if (($extension eq 'sequence') || ($extension eq 'page')) {
4237: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4238: $containerarg = $1;
1.472 raeburn 4239: if ($extension eq 'sequence') {
4240: $icon=$iconpath.'navmap.folder.closed.gif';
4241: $isfolder=1;
4242: } else {
4243: $icon=$iconpath.'page.gif';
4244: $ispage=1;
4245: }
1.615 raeburn 4246: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4247: if ($allowed) {
4248: $url='/adm/coursedocs?';
4249: } else {
4250: $url='/adm/supplemental?';
4251: }
1.329 droeschl 4252: } else {
1.685 raeburn 4253: $plainurl = $url;
1.329 droeschl 4254: }
4255: }
1.364 bisitz 4256:
1.621 raeburn 4257: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4258: my $orig_url = $url;
1.340 raeburn 4259: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4260: if ($container eq 'page') {
4261: $url=~s{^http(|s)(:|:)//}{/ext/};
4262: } else {
4263: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4264: }
1.501 raeburn 4265: if (!$supplementalflag && $residx && $symb) {
4266: if ((!$isfolder) && (!$ispage)) {
4267: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4268: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4269: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4270: } else {
4271: $url=&Apache::lonnet::clutter($url);
4272: }
1.501 raeburn 4273: if ($url=~/^\/*uploaded\//) {
4274: $url=~/\.(\w+)$/;
4275: my $embstyle=&Apache::loncommon::fileembstyle($1);
4276: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4277: $url='/adm/wrapper'.$url;
4278: } elsif ($embstyle eq 'ssi') {
4279: #do nothing with these
4280: } elsif ($url!~/\.(sequence|page)$/) {
4281: $url='/adm/coursedocs/showdoc'.$url;
4282: }
1.623 raeburn 4283: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4284: my $wrapped = $1;
4285: my $exturl = $2;
1.668 raeburn 4286: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4287: $url='/adm/wrapper'.$url;
4288: }
4289: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4290: $nomodal = 1;
4291: }
1.626 raeburn 4292: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4293: $url='/adm/wrapper'.$url;
1.621 raeburn 4294: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4295: if (($ENV{'SERVER_PORT'} == 443) &&
4296: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4297: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4298: $url .= '?usehttp=1';
4299: }
1.621 raeburn 4300: $nomodal = 1;
4301: }
1.598 raeburn 4302: }
1.696 raeburn 4303: my $checkencrypt;
1.680 raeburn 4304: if (!$env{'request.role.adv'}) {
1.615 raeburn 4305: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4306: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4307: $checkencrypt = 1;
1.620 raeburn 4308: } elsif (ref($navmapref)) {
1.615 raeburn 4309: unless (ref($$navmapref)) {
4310: $$navmapref = Apache::lonnavmaps::navmap->new();
4311: }
4312: if (ref($$navmapref)) {
4313: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4314: $checkencrypt = 1;
1.615 raeburn 4315: }
4316: }
4317: }
1.680 raeburn 4318: }
4319: if ($checkencrypt) {
4320: my $currenc = $env{'request.enc'};
4321: $env{'request.enc'} = 1;
4322: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 4323: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 4324: if (&Apache::lonnet::symbverify($symb,$url)) {
4325: $url = $shownurl;
4326: } else {
4327: $url = '';
4328: }
4329: $env{'request.enc'} = $currenc;
4330: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4331: $shownsymb = $symb;
4332: if ($isexternal) {
4333: $url =~ s/\#[^#]+$//;
4334: if ($container eq 'page') {
4335: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4336: }
1.612 raeburn 4337: }
1.696 raeburn 4338: } else {
4339: $url = '';
1.680 raeburn 4340: }
4341: unless ($env{'request.role.adv'}) {
4342: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4343: $url = '';
4344: }
4345: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4346: $url = '';
4347: $hiddenres = 1;
4348: }
4349: }
1.696 raeburn 4350: if (($url ne '') && ($shownsymb ne '')) {
4351: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4352: }
1.329 droeschl 4353: }
1.621 raeburn 4354: } elsif ($supplementalflag) {
1.610 raeburn 4355: if ($isexternal) {
4356: if ($url =~ /^([^#]+)#([^#]+)$/) {
4357: $url = $1;
4358: $anchor = $2;
1.623 raeburn 4359: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4360: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4361: if ($hostname ne '') {
4362: $url = 'http://'.$hostname.$url;
4363: }
4364: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4365: }
4366: $nomodal = 1;
4367: }
1.610 raeburn 4368: }
1.621 raeburn 4369: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4370: if (($ENV{'SERVER_PORT'} == 443) &&
4371: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4372: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4373: if ($hostname ne '') {
4374: $url = 'http://'.$hostname.$url;
4375: }
4376: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4377: }
1.621 raeburn 4378: $nomodal = 1;
4379: }
1.686 raeburn 4380: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4381: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4382: unless ($embstyle eq 'ssi') {
4383: if (($embstyle eq 'img')
4384: || ($embstyle eq 'emb')
4385: || ($embstyle eq 'wrp')) {
4386: $url='/adm/wrapper'.$url;
4387: } elsif ($url !~ /\.(sequence|page)$/) {
4388: $url='/adm/coursedocs/showdoc'.$url;
4389: }
4390: }
1.610 raeburn 4391: }
1.685 raeburn 4392: unless ($allowed && $env{'request.role.adv'}) {
4393: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4394: $hiddenres = 1;
4395: }
4396: }
1.329 droeschl 4397: }
1.615 raeburn 4398: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4399: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4400: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4401: my $foldername=&escape($foldertitle);
4402: my $folderpath=$env{'form.folderpath'};
4403: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4404: if (!$allowed && $supplementalflag) {
1.519 raeburn 4405: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4406: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4407: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4408: $hiddenfolder = 1;
1.682 raeburn 4409: }
1.510 raeburn 4410: } else {
1.617 raeburn 4411: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4412: 'parameter_randompick'))[0];
4413: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4414: 'parameter_randomorder'))[0]=~/^yes$/i);
4415: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4416: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4417: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4418: 'parameter_encrypturl'))[0]=~/^yes$/i);
4419: unless ($hiddenmap) {
1.620 raeburn 4420: if (ref($navmapref)) {
4421: unless (ref($$navmapref)) {
4422: $$navmapref = Apache::lonnavmaps::navmap->new();
4423: }
4424: if (ref($$navmapref)) {
4425: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4426: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4427: unless (@resources) {
4428: $hiddenmap = 1;
4429: unless ($env{'request.role.adv'}) {
4430: $url = '';
4431: $hiddenfolder = 1;
4432: }
1.617 raeburn 4433: }
1.615 raeburn 4434: }
4435: }
4436: }
4437: }
1.617 raeburn 4438: unless ($encryptmap) {
1.620 raeburn 4439: if ((ref($navmapref)) && (ref($$navmapref))) {
4440: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4441: $encryptmap = 1;
4442: }
1.617 raeburn 4443: }
4444: }
1.630 raeburn 4445:
1.617 raeburn 4446: # Append randompick number, hidden, and encrypted with ":" to foldername,
4447: # so it gets transferred between levels
4448: $folderpath.=$containerarg.'&'.$foldername.
4449: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4450: unless ($url eq '') {
1.612 raeburn 4451: $url.='folderpath='.&escape($folderpath);
4452: }
1.510 raeburn 4453: my $rpckchk;
4454: if ($rpicknum) {
4455: $rpckchk = ' checked="checked"';
1.543 raeburn 4456: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4457: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4458: }
1.510 raeburn 4459: }
1.537 raeburn 4460: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4461: $rand_pick_text =
1.478 raeburn 4462: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4463: $form_param."\n".
1.478 raeburn 4464: $form_common."\n".
1.611 raeburn 4465: '<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 4466: if ($rpicknum ne '') {
4467: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4468: }
1.537 raeburn 4469: $rand_pick_text .= '</span></span>'.
4470: $form_end;
1.543 raeburn 4471: my $ro_set;
1.617 raeburn 4472: if ($randorder) {
1.543 raeburn 4473: $ro_set = 'checked="checked"';
4474: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4475: push(@{$filtersref->{'randomorder'}},$orderidx);
4476: }
4477: }
1.564 raeburn 4478: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4479: $rand_order_text =
1.537 raeburn 4480: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4481: $form_param."\n".
1.537 raeburn 4482: $form_common."\n".
1.611 raeburn 4483: '<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 4484: $form_end;
1.510 raeburn 4485: }
1.509 raeburn 4486: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4487: my $isexttool;
1.626 raeburn 4488: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4489: $url='/adm/wrapper'.$url;
4490: $isexttool = 1;
4491: }
1.510 raeburn 4492: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4493: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4494: if ($title) {
1.687 raeburn 4495: $url .= '&title='.$encodedtitle;
1.510 raeburn 4496: }
1.598 raeburn 4497: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4498: $url .= '&idx='.$orderidx;
4499: }
1.610 raeburn 4500: if ($anchor ne '') {
4501: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4502: }
1.329 droeschl 4503: }
1.519 raeburn 4504: my ($tdalign,$tdwidth);
1.501 raeburn 4505: if ($allowed) {
1.630 raeburn 4506: my $fileloc =
1.501 raeburn 4507: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4508: if ($isexternal) {
1.630 raeburn 4509: ($editlink,$extresform) =
1.611 raeburn 4510: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4511: undef,undef,undef,undef,undef,undef,
4512: undef,$disabled);
1.626 raeburn 4513: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4514: ($editlink,$extresform) =
4515: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4516: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4517: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4518: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4519: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4520: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4521: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4522: my $suppanchor;
4523: if ($supplementalflag) {
4524: $suppanchor = $anchor;
4525: }
1.630 raeburn 4526: my $jscall =
1.501 raeburn 4527: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4528: $switchserver,
1.503 raeburn 4529: $forceedit,
1.679 raeburn 4530: undef,$symb,$shownsymb,
1.511 raeburn 4531: &escape($env{'form.folderpath'}),
1.622 raeburn 4532: $renametitle,$hostname,
4533: '','',1,$suppanchor);
1.501 raeburn 4534: if ($jscall) {
1.518 raeburn 4535: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4536: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4537: }
4538: }
4539: }
1.519 raeburn 4540: $tdalign = ' align="right" valign="top"';
4541: $tdwidth = ' width="80%"';
1.329 droeschl 4542: }
1.408 raeburn 4543: my $reinit;
4544: if ($crstype eq 'Community') {
4545: $reinit = &mt('(re-initialize community to access)');
4546: } else {
4547: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4548: }
4549: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4550: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4551: $line.= '<br />';
4552: if ($curralias ne '') {
4553: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4554: $lt{'da'}.'</a></span>';
4555: } else {
4556: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4557: $lt{'sa'}.'</a></span>';
4558: }
4559: }
4560: $line.='</td><td>';
1.685 raeburn 4561: my ($link,$nolink);
1.472 raeburn 4562: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4563: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4564: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4565: $nolink = 1;
4566: }
4567: }
4568: if ($nolink) {
4569: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4570: } else {
4571: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4572: }
1.469 www 4573: } elsif ($url) {
1.610 raeburn 4574: if ($anchor ne '') {
4575: if ($supplementalflag) {
4576: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4577: } else {
4578: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4579: }
4580: }
1.622 raeburn 4581: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4582: $link = 'http://'.$hostname.$url;
4583: } else {
4584: $link = $url;
4585: }
1.659 raeburn 4586: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4587: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4588: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4589: $nolink = 1;
4590: }
4591: }
4592: if ($nolink) {
4593: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4594: } elsif ($nomodal) {
1.621 raeburn 4595: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4596: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4597: } else {
4598: $line.=&Apache::loncommon::modal_link($link,
4599: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4600: }
1.469 www 4601: } else {
4602: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4603: }
1.519 raeburn 4604: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4605: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4606: if ($nolink) {
4607: $line.=$title;
4608: } else {
4609: $line.='<a href="'.$url.'">'.$title.'</a>';
4610: }
1.682 raeburn 4611: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4612: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4613: my $editurl = $url;
4614: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4615: $line .= ' '.'<a href="'.$editurl.'">'.
4616: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4617: '</a>';
4618: }
4619: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4620: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4621: }
1.469 www 4622: } elsif ($url) {
1.685 raeburn 4623: if ($nolink) {
4624: $line.=$title;
4625: } elsif ($nomodal) {
1.621 raeburn 4626: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4627: $title.'</a>';
4628: } else {
4629: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4630: }
1.617 raeburn 4631: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4632: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4633: } else {
4634: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4635: }
1.633 raeburn 4636: if (($allowed) && ($curralias ne '')) {
4637: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4638: } else {
4639: $line .= $extresform;
4640: }
4641: $line .= '</td>';
1.478 raeburn 4642: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4643: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4644: if ($uploaded && $url && !$isfolder && !$ispage) {
4645: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4646: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4647: }
4648: }
1.682 raeburn 4649: if ($allowed) {
4650: my %lt=&Apache::lonlocal::texthash(
4651: 'hd' => 'Hidden',
4652: 'ec' => 'URL hidden');
4653: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4654: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4655: $hidtext = ' checked="checked"';
1.694 raeburn 4656: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 4657: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4658: }
4659: }
1.682 raeburn 4660: $formhidden = 'edit_hiddenresource_'.$orderidx;
4661: $line.=(<<ENDPARMS);
1.329 droeschl 4662: <td class="LC_docs_entry_parameter">
1.537 raeburn 4663: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4664: $form_param
1.478 raeburn 4665: $form_common
1.611 raeburn 4666: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4667: $form_end
1.682 raeburn 4668: ENDPARMS
4669: if ($folder =~/^supplemental/) {
4670: $line.= "\n <td>";
4671: } else {
4672: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4673: $enctext = ' checked="checked"';
4674: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4675: push(@{$filtersref->{'encrypturl'}},$orderidx);
4676: }
4677: }
4678: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4679: $line.=(<<ENDPARMS);
1.458 raeburn 4680: <br />
1.537 raeburn 4681: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4682: $form_param
1.478 raeburn 4683: $form_common
1.611 raeburn 4684: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4685: $form_end
4686: </td>
1.478 raeburn 4687: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4688: $rand_order_text</td>
1.329 droeschl 4689: ENDPARMS
1.682 raeburn 4690: }
1.329 droeschl 4691: }
1.379 bisitz 4692: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4693: return $line;
4694: }
4695:
1.538 raeburn 4696: sub action_restrictions {
4697: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4698: my %denied = (
4699: cut => 0,
4700: copy => 0,
4701: remove => 0,
4702: );
4703: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4704: # no copy for published maps
4705: $denied{'copy'} = 1;
1.597 raeburn 4706: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4707: unless ($1 eq 'simpleproblem') {
4708: $denied{'copy'} = 1;
4709: }
4710: $denied{'cut'} = 1;
1.538 raeburn 4711: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4712: if ($folderpath =~ /^default&[^\&]+$/) {
4713: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4714: $denied{'remove'} = 1;
4715: }
4716: $denied{'cut'} = 1;
4717: $denied{'copy'} = 1;
4718: }
4719: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4720: my $group = $1;
4721: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4722: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4723: $denied{'remove'} = 1;
4724: }
4725: }
4726: $denied{'cut'} = 1;
4727: $denied{'copy'} = 1;
4728: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4729: my $group = $1;
4730: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4731: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4732: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4733: if (keys(%groupsettings) > 0) {
4734: $denied{'remove'} = 1;
4735: }
4736: $denied{'cut'} = 1;
4737: $denied{'copy'} = 1;
4738: }
4739: }
4740: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4741: my $group = $1;
4742: if ($url =~ /group_boards_\Q$group\E/) {
4743: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4744: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4745: if (keys(%groupsettings) > 0) {
4746: if (ref($groupsettings{'functions'}) eq 'HASH') {
4747: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4748: $denied{'remove'} = 1;
4749: }
4750: }
4751: }
4752: $denied{'cut'} = 1;
4753: $denied{'copy'} = 1;
4754: }
4755: }
4756: }
4757: return %denied;
4758: }
4759:
1.533 raeburn 4760: sub new_timebased_suffix {
1.538 raeburn 4761: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4762: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4763: if ($type eq 'paste') {
4764: $prefix = $type;
4765: $namespace = 'courseeditor';
1.587 raeburn 4766: $idtype = 'addcode';
1.538 raeburn 4767: } elsif ($type eq 'map') {
1.533 raeburn 4768: $prefix = 'docs';
4769: if ($area eq 'supplemental') {
4770: $prefix = 'supp';
4771: }
4772: $prefix .= $container;
4773: $namespace = 'uploadedmaps';
4774: } else {
4775: $prefix = $type;
4776: $namespace = 'templated';
1.504 raeburn 4777: }
4778: my ($suffix,$freedlock,$error) =
1.587 raeburn 4779: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4780: if (!$suffix) {
1.538 raeburn 4781: if ($type eq 'paste') {
4782: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4783: } elsif ($type eq 'map') {
1.533 raeburn 4784: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4785: } elsif ($type eq 'smppg') {
4786: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4787: } elsif ($type eq 'exttool') {
4788: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4789: } else {
1.565 bisitz 4790: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4791: }
1.504 raeburn 4792: if ($error) {
4793: $errtext .= '<br />'.$error;
4794: }
4795: }
4796: if ($freedlock ne 'ok') {
1.630 raeburn 4797: $locknotfreed =
1.533 raeburn 4798: '<div class="LC_error">'.
4799: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4800: if ($type eq 'paste') {
1.591 raeburn 4801: if ($freedlock eq 'nolock') {
4802: $locknotfreed =
4803: '<div class="LC_error">'.
4804: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4805:
1.593 droeschl 4806: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4807: } else {
4808: $locknotfreed .=
4809: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4810: }
1.538 raeburn 4811: } elsif ($type eq 'map') {
1.591 raeburn 4812: $locknotfreed .=
4813: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4814: } elsif ($type eq 'smppg') {
4815: $locknotfreed .=
4816: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4817: } elsif ($type eq 'exttool') {
4818: $locknotfreed .=
4819: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4820: } else {
4821: $locknotfreed .=
1.565 bisitz 4822: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4823: }
1.538 raeburn 4824: unless ($type eq 'paste') {
4825: $locknotfreed .=
1.560 raeburn 4826: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4827: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4828: }
4829: $locknotfreed .= '</div>';
1.504 raeburn 4830: }
4831: return ($suffix,$errtext,$locknotfreed);
4832: }
4833:
1.329 droeschl 4834: =pod
4835:
4836: =item tiehash()
4837:
4838: tie the hash
4839:
4840: =cut
4841:
4842: sub tiehash {
4843: my ($mode)=@_;
4844: $hashtied=0;
4845: if ($env{'request.course.fn'}) {
4846: if ($mode eq 'write') {
4847: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4848: &GDBM_WRCREAT(),0640)) {
4849: $hashtied=2;
4850: }
4851: } else {
4852: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4853: &GDBM_READER(),0640)) {
4854: $hashtied=1;
4855: }
4856: }
1.364 bisitz 4857: }
1.329 droeschl 4858: }
4859:
4860: sub untiehash {
4861: if ($hashtied) { untie %hash; }
4862: $hashtied=0;
4863: return OK;
4864: }
4865:
4866:
4867:
4868:
4869: sub checkonthis {
1.637 raeburn 4870: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4871: $url=&unescape($url);
4872: $alreadyseen{$url}=1;
4873: $r->rflush();
4874: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4875: $r->print("\n<br />");
4876: if ($level==0) {
4877: $r->print("<br />");
4878: }
4879: for (my $i=0;$i<=$level*5;$i++) {
4880: $r->print(' ');
4881: }
4882: $r->print('<a href="'.$url.'" target="cat">'.
4883: ($title?$title:$url).'</a> ');
4884: if ($url=~/^\/res\//) {
1.637 raeburn 4885: my $updated;
4886: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4887: ($url !~ /\.\d+\.\w+$/)) {
4888: $updated = &Apache::lonnet::remove_stale_resfile($url);
4889: }
1.329 droeschl 4890: my $result=&Apache::lonnet::repcopy(
4891: &Apache::lonnet::filelocation('',$url));
4892: if ($result eq 'ok') {
4893: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4894: if ($updated) {
4895: $r->print('<br />');
4896: for (my $i=0;$i<=$level*5;$i++) {
4897: $r->print(' ');
4898: }
4899: $r->print('- '.&mt('Outdated copy removed'));
4900: }
1.329 droeschl 4901: $r->rflush();
4902: &Apache::lonnet::countacc($url);
4903: $url=~/\.(\w+)$/;
4904: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4905: $r->print('<br />');
4906: $r->rflush();
4907: for (my $i=0;$i<=$level*5;$i++) {
4908: $r->print(' ');
4909: }
4910: $r->print('- '.&mt('Rendering:').' ');
4911: my ($errorcount,$warningcount)=split(/:/,
4912: &Apache::lonnet::ssi_body($url,
4913: ('grade_target'=>'web',
4914: 'return_only_error_and_warning_counts' => 1)));
4915: if (($errorcount) ||
4916: ($warningcount)) {
4917: if ($errorcount) {
1.369 bisitz 4918: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4919: &mt('[quant,_1,error]',$errorcount).'</span>');
4920: }
4921: if ($warningcount) {
4922: $r->print('<span class="LC_warning">'.
4923: &mt('[quant,_1,warning]',$warningcount).'</span>');
4924: }
4925: } else {
4926: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4927: }
4928: $r->rflush();
4929: }
4930: my $dependencies=
4931: &Apache::lonnet::metadata($url,'dependencies');
4932: foreach my $dep (split(/\,/,$dependencies)) {
4933: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4934: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4935: }
4936: }
4937: } elsif ($result eq 'unavailable') {
4938: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4939: } elsif ($result eq 'not_found') {
4940: unless ($url=~/\$/) {
1.521 bisitz 4941: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4942: } else {
1.366 bisitz 4943: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4944: }
4945: } else {
4946: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4947: }
1.637 raeburn 4948: if (($updated) && ($result ne 'ok')) {
4949: $r->print('<br />'.&mt('Outdated copy removed'));
4950: }
1.329 droeschl 4951: }
4952: }
4953: }
4954:
4955:
4956:
4957: =pod
4958:
4959: =item list_symbs()
4960:
1.485 raeburn 4961: List Content Identifiers
1.329 droeschl 4962:
4963: =cut
4964:
4965: sub list_symbs {
4966: my ($r) = @_;
4967:
1.408 raeburn 4968: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4969: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4970: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4971: $r->print(&startContentScreen('tools'));
1.329 droeschl 4972: my $navmap = Apache::lonnavmaps::navmap->new();
4973: if (!defined($navmap)) {
4974: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4975: '<div class="LC_error">'.
4976: &mt('Unable to retrieve information about course contents').
4977: '</div>');
1.408 raeburn 4978: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4979: } else {
1.484 raeburn 4980: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4981: &Apache::loncommon::start_data_table().
4982: &Apache::loncommon::start_data_table_header_row().
4983: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4984: &Apache::loncommon::end_data_table_header_row()."\n");
4985: my $count;
1.329 droeschl 4986: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4987: $r->print(&Apache::loncommon::start_data_table_row().
4988: '<td>'.$res->compTitle().'</td>'.
4989: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4990: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4991: $count ++;
4992: }
4993: if (!$count) {
4994: $r->print(&Apache::loncommon::start_data_table_row().
4995: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4996: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4997: }
1.484 raeburn 4998: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4999: }
1.521 bisitz 5000: $r->print(&endContentScreen());
1.329 droeschl 5001: }
5002:
1.651 raeburn 5003: sub short_urls {
5004: my ($r,$canedit) = @_;
5005: my $crstype = &Apache::loncommon::course_type();
5006: my $formname = 'shortenurl';
5007: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5008: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5009: $r->print(&startContentScreen('tools'));
5010: my ($navmap,$errormsg) =
5011: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5012: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5013: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5014: my (%maps,%resources,%titles);
5015: if (!ref($navmap)) {
5016: $r->print($errormsg.
5017: &endContentScreen());
5018: return '';
5019: } else {
1.652 raeburn 5020: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5021: $r->rflush();
5022: my $readonly;
5023: if ($canedit) {
1.671 raeburn 5024: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5025: if ($numnew) {
5026: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5027: }
5028: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5029: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5030: foreach my $error (@{$errors}) {
5031: $r->print('<li>'.$error.'</li>');
5032: }
5033: $r->print('</ul><br />');
5034: }
5035: } else {
5036: $readonly = 1;
5037: }
5038: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5039: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5040: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5041: }
5042: $r->print(&endContentScreen());
5043: }
5044:
1.637 raeburn 5045: sub contentverifyform {
5046: my ($r) = @_;
5047: my $crstype = &Apache::loncommon::course_type();
5048: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5049: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5050: $r->print(&startContentScreen('tools'));
5051: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5052: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5053: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5054: ' <span class="LC_nobreak">'.
5055: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5056: &mt('No').'</label>'.(' 'x2).
5057: '<label><input type="radio" name="checkstale" value="1" />'.
5058: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5059: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5060: '<input type="hidden" value="1" name="tools" />'.
5061: '<input type="hidden" value="1" name="verify" /></p></form>');
5062: $r->print(&endContentScreen());
5063: return;
5064: }
1.329 droeschl 5065:
5066: sub verifycontent {
1.637 raeburn 5067: my ($r,$checkstale) = @_;
1.408 raeburn 5068: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5069: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5070: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5071: $r->print(&startContentScreen('tools'));
5072: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5073: $hashtied=0;
5074: undef %alreadyseen;
5075: %alreadyseen=();
5076: &tiehash();
1.484 raeburn 5077:
1.329 droeschl 5078: foreach my $key (keys(%hash)) {
5079: if ($hash{$key}=~/\.(page|sequence)$/) {
5080: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5081: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5082: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5083: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5084: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5085: }
5086: }
5087: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5088: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5089: }
5090: }
5091: &untiehash();
1.442 www 5092: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5093: $r->print(&endContentScreen());
1.329 droeschl 5094: }
5095:
5096: sub devalidateversioncache {
5097: my $src=shift;
5098: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5099: &Apache::lonnet::clutter($src));
5100: }
5101:
5102: sub checkversions {
1.611 raeburn 5103: my ($r,$canedit) = @_;
1.408 raeburn 5104: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5105: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5106: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5107: $r->print(&startContentScreen('tools'));
1.442 www 5108:
1.329 droeschl 5109: my $header='';
5110: my $startsel='';
5111: my $monthsel='';
5112: my $weeksel='';
5113: my $daysel='';
5114: my $allsel='';
5115: my %changes=();
5116: my $starttime=0;
5117: my $haschanged=0;
5118: my %setversions=&Apache::lonnet::dump('resourceversions',
5119: $env{'course.'.$env{'request.course.id'}.'.domain'},
5120: $env{'course.'.$env{'request.course.id'}.'.num'});
5121:
5122: $hashtied=0;
5123: &tiehash();
1.611 raeburn 5124: if ($canedit) {
5125: my %newsetversions=();
5126: if ($env{'form.setmostrecent'}) {
5127: $haschanged=1;
5128: foreach my $key (keys(%hash)) {
5129: if ($key=~/^ids\_(\/res\/.+)$/) {
5130: $newsetversions{$1}='mostrecent';
5131: &devalidateversioncache($1);
5132: }
5133: }
5134: } elsif ($env{'form.setcurrent'}) {
5135: $haschanged=1;
5136: foreach my $key (keys(%hash)) {
5137: if ($key=~/^ids\_(\/res\/.+)$/) {
5138: my $getvers=&Apache::lonnet::getversion($1);
5139: if ($getvers>0) {
5140: $newsetversions{$1}=$getvers;
5141: &devalidateversioncache($1);
5142: }
5143: }
1.329 droeschl 5144: }
1.611 raeburn 5145: } elsif ($env{'form.setversions'}) {
5146: $haschanged=1;
5147: foreach my $key (keys(%env)) {
5148: if ($key=~/^form\.set_version_(.+)$/) {
5149: my $src=$1;
5150: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5151: $newsetversions{$src}=$env{$key};
5152: &devalidateversioncache($src);
5153: }
5154: }
1.329 droeschl 5155: }
1.611 raeburn 5156: }
5157: if ($haschanged) {
5158: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5159: $env{'course.'.$env{'request.course.id'}.'.domain'},
5160: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5161: $r->print(&Apache::loncommon::confirmwrapper(
5162: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5163: } else {
5164: $r->print(&Apache::loncommon::confirmwrapper(
5165: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5166: }
1.611 raeburn 5167: &mark_hash_old();
5168: }
5169: &changewarning($r,'');
1.329 droeschl 5170: }
5171: if ($env{'form.timerange'} eq 'all') {
5172: # show all documents
1.549 raeburn 5173: $header=&mt('All content in '.$crstype);
1.521 bisitz 5174: $allsel=' selected="selected"';
1.329 droeschl 5175: foreach my $key (keys(%hash)) {
5176: if ($key=~/^ids\_(\/res\/.+)$/) {
5177: my $src=$1;
5178: $changes{$src}=1;
5179: }
5180: }
5181: } else {
5182: # show documents which changed
5183: %changes=&Apache::lonnet::dump
5184: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5185: $env{'course.'.$env{'request.course.id'}.'.num'});
5186: my $firstkey=(keys(%changes))[0];
5187: unless ($firstkey=~/^error\:/) {
5188: unless ($env{'form.timerange'}) {
5189: $env{'form.timerange'}=604800;
5190: }
5191: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5192: .&mt('seconds');
5193: if ($env{'form.timerange'}==-1) {
5194: $seltext='since start of course';
1.521 bisitz 5195: $startsel=' selected="selected"';
1.329 droeschl 5196: $env{'form.timerange'}=time;
5197: }
5198: $starttime=time-$env{'form.timerange'};
5199: if ($env{'form.timerange'}==2592000) {
5200: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5201: $monthsel=' selected="selected"';
1.329 droeschl 5202: } elsif ($env{'form.timerange'}==604800) {
5203: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5204: $weeksel=' selected="selected"';
1.329 droeschl 5205: } elsif ($env{'form.timerange'}==86400) {
5206: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5207: $daysel=' selected="selected"';
1.329 droeschl 5208: }
5209: $header=&mt('Content changed').' '.$seltext;
5210: } else {
5211: $header=&mt('No content modifications yet.');
5212: }
5213: }
5214: %setversions=&Apache::lonnet::dump('resourceversions',
5215: $env{'course.'.$env{'request.course.id'}.'.domain'},
5216: $env{'course.'.$env{'request.course.id'}.'.num'});
5217: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5218: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5219: 'lm' => 'Version changes since last Month',
5220: 'lw' => 'Version changes since last Week',
5221: 'sy' => 'Version changes since Yesterday',
5222: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5223: 'cd' => 'Change display',
1.329 droeschl 5224: 'sd' => 'Display',
5225: 'fi' => 'File',
5226: 'md' => 'Modification Date',
5227: 'mr' => 'Most recently published Version',
1.408 raeburn 5228: 've' => 'Version used in '.$crstype,
5229: 'vu' => 'Set Version to be used in '.$crstype,
5230: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5231: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5232: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5233: 'di' => 'Differences',
1.484 raeburn 5234: 'save' => 'Save changes',
5235: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5236: 'act' => 'Actions');
1.611 raeburn 5237: my ($disabled,$readonly);
5238: unless ($canedit) {
5239: $disabled = 'disabled="disabled"';
5240: $readonly = 1;
5241: }
1.329 droeschl 5242: $r->print(<<ENDHEADERS);
1.484 raeburn 5243: <h4 class="LC_info">$header</h4>
1.329 droeschl 5244: <form action="/adm/coursedocs" method="post">
5245: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5246: <div class="LC_left_float">
1.479 golterma 5247: <fieldset>
1.484 raeburn 5248: <legend>$lt{'cd'}</legend>
1.329 droeschl 5249: <select name="timerange">
1.521 bisitz 5250: <option value='all'$allsel>$lt{'al'}</option>
5251: <option value="-1"$startsel>$lt{'st'}</option>
5252: <option value="2592000"$monthsel>$lt{'lm'}</option>
5253: <option value="604800"$weeksel>$lt{'lw'}</option>
5254: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5255: </select>
5256: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5257: </fieldset>
5258: </div>
5259: <div class="LC_left_float">
5260: <fieldset>
5261: <legend>$lt{'act'}</legend>
1.611 raeburn 5262: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5263: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5264: </fieldset>
5265: </div>
5266: <br clear="all" />
5267: <hr />
5268: <h4>$lt{'vers'}</h4>
1.329 droeschl 5269: ENDHEADERS
1.479 golterma 5270: #number of columns for version history
1.571 raeburn 5271: my %changedbytime;
5272: foreach my $key (keys(%changes)) {
5273: #excludes not versionable problems from resource version history:
5274: next if ($key =~ /^\/res\/lib\/templates/);
5275: my $chg;
5276: if ($env{'form.timerange'} eq 'all') {
5277: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5278: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5279: } else {
5280: $chg = $changes{$key};
5281: next if ($chg < $starttime);
5282: }
5283: push(@{$changedbytime{$chg}},$key);
5284: }
5285: if (keys(%changedbytime) == 0) {
5286: &untiehash();
5287: $r->print(&mt('No content changes in imported content in specified time frame').
5288: &endContentScreen());
5289: return;
5290: }
1.479 golterma 5291: $r->print(
1.611 raeburn 5292: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5293: &Apache::loncommon::start_data_table().
5294: &Apache::loncommon::start_data_table_header_row().
5295: '<th>'.&mt('Resources').'</th>'.
5296: "<th>$lt{'mr'}</th>".
5297: "<th>$lt{'ve'}</th>".
5298: "<th>$lt{'vu'}</th>".
5299: '<th>'.&mt('History').'</th>'.
5300: &Apache::loncommon::end_data_table_header_row()
5301: );
1.571 raeburn 5302: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5303: foreach my $key (sort(@{$changedbytime{$chg}})) {
5304: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5305: my $currentversion=&Apache::lonnet::getversion($key);
5306: if ($currentversion<0) {
5307: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5308: }
5309: my $linkurl=&Apache::lonnet::clutter($key);
5310: $r->print(
5311: &Apache::loncommon::start_data_table_row().
5312: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5313: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5314: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5315: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5316: '<td align="right">'
5317: );
5318: # Used in course
5319: my $usedversion=$hash{'version_'.$linkurl};
5320: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5321: if ($usedversion != $currentversion) {
1.479 golterma 5322: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5323: } else {
1.479 golterma 5324: $r->print($usedversion);
5325: }
1.329 droeschl 5326: } else {
1.521 bisitz 5327: $r->print($currentversion);
1.329 droeschl 5328: }
1.571 raeburn 5329: $r->print('</td><td title="'.$lt{'vu'}.'">');
5330: # Set version
5331: $r->print(&Apache::loncommon::select_form(
5332: $setversions{$linkurl},
5333: 'set_version_'.$linkurl,
5334: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5335: '' => '',
5336: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5337: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5338: my $lastold=1;
5339: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5340: my $url=$root.'.'.$prevvers.'.'.$extension;
5341: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5342: $lastold=$prevvers;
5343: }
5344: }
5345: $r->print('</td>');
5346: # List all available versions
5347: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5348: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5349: my $url=$root.'.'.$prevvers.'.'.$extension;
5350: $r->print(
5351: '<span class="LC_nobreak">'
5352: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5353: .&mt('Version [_1]',$prevvers).'</a>'
5354: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5355: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5356: .')');
5357: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5358: $r->print(
5359: ' <a href="/adm/diff?filename='.
5360: &Apache::lonnet::clutter($root.'.'.$extension).
5361: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5362: '" target="diffs">'.&mt('Diffs').'</a>');
5363: }
5364: $r->print('</span><br />');
1.329 droeschl 5365: }
1.571 raeburn 5366: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5367: }
1.329 droeschl 5368: }
1.521 bisitz 5369: $r->print(
5370: &Apache::loncommon::end_data_table().
1.611 raeburn 5371: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5372: '</form>'
5373: );
1.329 droeschl 5374:
5375: &untiehash();
1.521 bisitz 5376: $r->print(&endContentScreen());
1.571 raeburn 5377: return;
1.329 droeschl 5378: }
5379:
5380: sub mark_hash_old {
5381: my $retie_hash=0;
5382: if ($hashtied) {
5383: $retie_hash=1;
5384: &untiehash();
5385: }
5386: &tiehash('write');
5387: $hash{'old'}=1;
5388: &untiehash();
5389: if ($retie_hash) { &tiehash(); }
5390: }
5391:
5392: sub is_hash_old {
5393: my $untie_hash=0;
5394: if (!$hashtied) {
5395: $untie_hash=1;
5396: &tiehash();
5397: }
5398: my $return=$hash{'old'};
5399: if ($untie_hash) { &untiehash(); }
5400: return $return;
5401: }
5402:
5403: sub changewarning {
5404: my ($r,$postexec,$message,$url)=@_;
5405: if (!&is_hash_old()) { return; }
5406: my $pathvar='folderpath';
5407: my $path=&escape($env{'form.folderpath'});
5408: if (!defined($url)) {
5409: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5410: }
5411: my $course_type = &Apache::loncommon::course_type();
5412: if (!defined($message)) {
5413: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5414: }
1.653 raeburn 5415: my $windowname = 'loncapaclient';
5416: if ($env{'request.lti.login'}) {
5417: $windowname .= 'lti';
5418: }
1.329 droeschl 5419: $r->print("\n\n".
1.372 bisitz 5420: '<script type="text/javascript">'."\n".
5421: '// <![CDATA['."\n".
5422: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5423: '// ]]>'."\n".
1.369 bisitz 5424: '</script>'."\n".
1.653 raeburn 5425: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5426: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5427: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5428: &mt($message,' <input type="hidden" name="'.
5429: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5430: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5431: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5432: }
5433:
5434:
5435: sub init_breadcrumbs {
1.571 raeburn 5436: my ($form,$text,$help)=@_;
1.329 droeschl 5437: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5438: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5439: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5440: faq=>273,
5441: bug=>'Instructor Interface',
1.571 raeburn 5442: help => $help});
1.329 droeschl 5443: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5444: text=>$text,
5445: faq=>273,
5446: bug=>'Instructor Interface'});
5447: }
5448:
1.441 www 5449: # subroutine to list form elements
5450: sub create_list_elements {
5451: my @formarr = @_;
5452: my $list = '';
1.501 raeburn 5453: foreach my $button (@formarr){
5454: foreach my $picture (keys(%{$button})) {
5455: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5456: }
5457: }
5458: return $list;
5459: }
1.329 droeschl 5460:
1.441 www 5461: # subroutine to create ul from list elements
5462: sub create_form_ul {
5463: my $list = shift;
5464: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5465: return $ul;
5466: }
1.329 droeschl 5467:
1.442 www 5468: #
5469: # Start tabs
5470: #
5471:
5472: sub startContentScreen {
1.484 raeburn 5473: my ($mode) = @_;
5474: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5475: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5476: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5477: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5478: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5479: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5480: } else {
1.549 raeburn 5481: $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 5482: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5483: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5484: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5485: }
5486: $output .= "\n".'</ul>'."\n";
5487: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5488: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5489: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5490: return $output;
1.442 www 5491: }
5492:
5493: #
5494: # End tabs
5495: #
5496:
5497: sub endContentScreen {
1.484 raeburn 5498: return '</div></div></div>';
1.442 www 5499: }
1.329 droeschl 5500:
1.446 www 5501: sub supplemental_base {
1.548 raeburn 5502: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5503: }
5504:
1.329 droeschl 5505: sub handler {
5506: my $r = shift;
5507: &Apache::loncommon::content_type($r,'text/html');
5508: $r->send_http_header;
5509: return OK if $r->header_only;
1.484 raeburn 5510:
5511: # get course data
1.408 raeburn 5512: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5513: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5514: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5515:
1.606 raeburn 5516: # get docroot
5517: my $londocroot = $r->dir_config('lonDocRoot');
5518:
1.484 raeburn 5519: # graphics settings
5520: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5521:
1.443 www 5522: #
1.329 droeschl 5523: # --------------------------------------------- Initialize help topics for this
5524: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5525: 'Adding_External_Resource','Adding_External_Tool',
5526: 'Navigate_Content','Adding_Folders','Docs_Overview',
5527: 'Load_Map','Supplemental','Score_Upload_Form',
5528: 'Adding_Pages','Importing_LON-CAPA_Resource',
5529: 'Importing_IMS_Course','Uploading_From_Harddrive',
5530: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5531: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5532: }
5533: # Composite help files
5534: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5535: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5536: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5537: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5538: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5539: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5540: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5541: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5542: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5543: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5544:
1.611 raeburn 5545: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5546: # does this user have privileges to modify content.
5547: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5548: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5549: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5550: $allowed = 1;
1.682 raeburn 5551: }
5552: $canedit = 1;
5553: $canview = 1;
5554: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5555: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5556: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5557: $allowed = 1;
5558: }
1.682 raeburn 5559: $canview = 1;
1.611 raeburn 5560: }
5561: unless ($canedit) {
5562: $disabled = ' disabled="disabled"';
1.472 raeburn 5563: }
1.582 raeburn 5564: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5565: if ($env{'form.inhibitmenu'}) {
5566: unless ($env{'form.inhibitmenu'} eq 'yes') {
5567: delete($env{'form.inhibitmenu'});
5568: }
5569: }
5570:
1.582 raeburn 5571: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5572: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5573: if (!$canedit) {
5574: &verifycontent($r);
5575: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5576: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5577: text=>'Results',
5578: faq=>273,
5579: bug=>'Instructor Interface'});
5580: &verifycontent($r,$env{'form.checkstale'});
5581: } else {
5582: &contentverifyform($r);
5583: }
1.329 droeschl 5584: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5585: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5586: &list_symbs($r);
1.651 raeburn 5587: } elsif ($allowed && $env{'form.shorturls'}) {
5588: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5589: &short_urls($r,$canedit);
1.329 droeschl 5590: } elsif ($allowed && $env{'form.docslog'}) {
5591: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5592: my $folder = $env{'form.folder'};
5593: if ($folder eq '') {
5594: $folder='default';
5595: }
1.611 raeburn 5596: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5597: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5598: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5599: &checkversions($r,$canedit);
5600: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5601: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5602: &dumpcourse($r);
1.611 raeburn 5603: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5604: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5605: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5606: } else {
1.611 raeburn 5607: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5608: $noendpage = 1;
5609: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5610: if ($redirect) {
5611: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5612: my $container = 'sequence';
5613: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5614: $is_random_order,$container) =
5615: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5616: my (@folders)=split('&',$env{'form.folderpath'});
5617: $env{'form.foldername'}=&unescape(pop(@folders));
5618: my $folder=pop(@folders);
5619: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5620: $folder.'.'.$container);
5621: my $warning;
5622: if ($fatal) {
5623: if ($container eq 'page') {
5624: $warning = &mt('An error occurred retrieving the contents of the current page.');
5625: } else {
5626: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5627: }
5628: } else {
5629: my $url = $redirect;
5630: my $srcfile = $londocroot.$url;
5631: $url =~ s{^/priv/}{/res/};
5632: my $targetfile = $londocroot.$url;
5633: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5634: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5635: $env{'form.folder'} = $folder;
5636: &snapshotbefore();
5637: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5638: my $ext = 'false';
5639: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5640: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5641: ':'.$ext.':normal:res';
5642: push(@LONCAPA::map::order,$newidx);
5643: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5644: 'string_yesno');
5645: &remember_parms($newidx,'hiddenresource','set','yes');
5646: ($errtext,$fatal) =
5647: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5648: &log_differences($plain);
5649: &mark_hash_old();
5650: $r->internal_redirect($redirect);
5651: return OK;
5652: }
1.654 raeburn 5653: } else {
5654: $r->internal_redirect($redirect);
1.606 raeburn 5655: }
5656: }
5657: }
1.445 www 5658: #
5659: # Done catching special calls
1.484 raeburn 5660: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5661: # Get the parameters that may be needed
5662: #
5663: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5664: ['folderpath','title',
1.519 raeburn 5665: 'forcesupplement','forcestandard',
1.510 raeburn 5666: 'tools','symb','command','supppath']);
1.445 www 5667:
1.635 raeburn 5668: foreach my $item ('forcesupplement','forcestandard','tools') {
5669: next if ($env{'form.'.$item} eq '');
5670: unless ($env{'form.'.$item} eq '1') {
5671: delete($env{'form.'.$item});
5672: }
5673: }
5674:
5675: if ($env{'form.command'}) {
5676: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5677: delete($env{'form.command'});
5678: }
5679: }
5680:
5681: if ($env{'form.symb'}) {
5682: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5683: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5684: delete($env{'form.symb'});
5685: }
5686: }
5687:
1.445 www 5688: # standard=1: this is a "new-style" course with an uploaded map as top level
5689: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5690:
5691: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5692:
1.484 raeburn 5693: # Decide whether this should display supplemental or main content or utilities
1.445 www 5694: # supplementalflag=1: show supplemental documents
5695: # supplementalflag=0: show standard documents
1.484 raeburn 5696: # toolsflag=1: show utilities
1.445 www 5697:
1.561 raeburn 5698: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5699: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5700: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5701: $supplementalflag=0;
5702: }
5703: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5704: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5705: unless ($allowed) { $supplementalflag=1; }
5706: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5707: my $toolsflag=0;
5708: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5709:
1.635 raeburn 5710: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5711: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5712: }
5713:
1.685 raeburn 5714: my $backto_supppath;
1.635 raeburn 5715: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5716: if ($supplementalflag && $allowed) {
5717: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5718: }
1.635 raeburn 5719: }
5720:
1.329 droeschl 5721: my $script='';
5722: my $showdoc=0;
1.457 raeburn 5723: my $addentries = {};
1.475 raeburn 5724: my $container;
1.329 droeschl 5725: my $containertag;
1.508 raeburn 5726: my $pathitem;
1.598 raeburn 5727: my %ltitools;
1.617 raeburn 5728: my $hiddentop;
1.615 raeburn 5729: my $navmap;
1.617 raeburn 5730: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5731:
1.464 www 5732: # Do we directly jump somewhere?
1.525 raeburn 5733: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5734: if ($env{'form.symb'} ne '') {
1.522 raeburn 5735: $env{'form.folderpath'}=
1.617 raeburn 5736: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5737: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5738: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5739: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5740: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5741: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5742: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5743: }
1.472 raeburn 5744: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5745: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5746: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5747: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5748: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5749: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5750: } elsif ($env{'form.command'} eq 'contents') {
5751: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5752: } elsif ($env{'form.command'} eq 'home') {
5753: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5754: }
5755:
1.525 raeburn 5756:
1.445 www 5757: # Where do we store these for when we come back?
5758: my $stored_folderpath='docs_folderpath';
5759: if ($supplementalflag) {
5760: $stored_folderpath='docs_sup_folderpath';
5761: }
1.464 www 5762:
1.519 raeburn 5763: # No folderpath, and in edit mode, see if we have something stored
5764: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5765: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5766: {'folderpath' => 'scalar'});
1.615 raeburn 5767:
5768: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5769: if ($supplementalflag) {
5770: undef($env{'form.folderpath'}) if ($1 eq 'default');
5771: } else {
5772: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5773: }
5774: } else {
1.523 raeburn 5775: undef($env{'form.folderpath'});
5776: }
1.677 raeburn 5777: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5778: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5779: }
1.329 droeschl 5780: }
1.446 www 5781:
5782: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5783: if (!$allowed) {
1.446 www 5784: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5785: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5786: }
5787: }
1.446 www 5788: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5789: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5790: $env{'form.folderpath'} = &supplemental_base()
5791: .'&'.
1.329 droeschl 5792: $env{'form.folderpath'};
5793: }
1.685 raeburn 5794: # If allowed and user's role is not advanced check folderpath is not hidden
5795: my $hidden_and_empty;
1.687 raeburn 5796: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5797: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5798: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5799: my $folder = $pathitems[-2];
5800: if ($folder eq '') {
5801: undef($env{'form.folderpath'});
5802: } else {
5803: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5804: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5805: $folderurl .= '.page';
5806: } else {
5807: $folderurl .= '.sequence';
5808: }
1.685 raeburn 5809: if ($supplementalflag) {
5810: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5811: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5812: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5813: if (ref($supplemental) eq 'HASH') {
5814: my ($suppmap,$suppmapnum);
5815: if ($folder eq 'supplemental') {
5816: $suppmap = 'default';
5817: $suppmapnum = 0;
5818: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5819: $suppmap = $1;
5820: $suppmapnum = $suppmap;
5821: }
5822: if ($hiddenfolder) {
5823: my $hascontent;
5824: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5825: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5826: $hascontent = 1;
5827: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5828: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5829: if ($id =~ /^$suppmapnum\:/) {
5830: $hascontent = 1;
5831: last;
5832: }
5833: }
5834: }
5835: last if ($hascontent);
5836: }
5837: unless ($hascontent) {
5838: if ($foldername ne '') {
5839: $hidden_and_empty = $foldername;
5840: } else {
5841: $hidden_and_empty = $folder;
5842: }
5843: }
5844: }
5845: }
5846: } else {
5847: unless (ref($navmap)) {
5848: $navmap = Apache::lonnavmaps::navmap->new();
5849: }
5850: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5851: $foldername = &HTML::Entities::decode(&unescape($foldername));
5852: if (ref($navmap)) {
5853: if ($hiddenfolder ||
5854: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5855: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5856: unless (@resources) {
5857: if ($foldername ne '') {
5858: $hidden_and_empty = $foldername;
5859: } else {
5860: $hidden_and_empty = $folder;
5861: }
5862: }
5863: }
5864: }
1.617 raeburn 5865: }
1.685 raeburn 5866: if ($hidden_and_empty ne '') {
5867: splice(@pathitems,-2);
5868: if (@pathitems) {
5869: $env{'form.folderpath'} = join('&',@pathitems);
5870: } else {
5871: undef($env{'form.folderpath'});
1.615 raeburn 5872: }
5873: }
5874: }
5875: }
5876:
1.446 www 5877: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5878: unless ($env{'form.folderpath'}) {
1.446 www 5879: if ($supplementalflag) {
5880: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5881: } elsif ($allowed) {
5882: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5883: }
1.472 raeburn 5884: }
1.446 www 5885:
1.445 www 5886: # Store this
1.484 raeburn 5887: unless ($toolsflag) {
1.615 raeburn 5888: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5889: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5890: {'folderpath' => 'scalar'});
1.510 raeburn 5891: }
1.519 raeburn 5892: my $folderpath;
1.484 raeburn 5893: if ($env{'form.folderpath'}) {
1.519 raeburn 5894: $folderpath = $env{'form.folderpath'};
5895: my (@folders)=split('&',$env{'form.folderpath'});
5896: $env{'form.foldername'}=&unescape(pop(@folders));
5897: if ($env{'form.foldername'} =~ /\:1$/) {
5898: $container = 'page';
5899: } else {
5900: $container = 'sequence';
5901: }
5902: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5903: } else {
1.519 raeburn 5904: if ($env{'form.folder'} eq '' ||
5905: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5906: if ($env{'form.folder'} eq 'supplemental') {
5907: $folderpath=&supplemental_base();
5908: } elsif (!$hiddentop) {
5909: $folderpath='default&'.
5910: &escape(&mt('Main Content').':::::');
5911: }
1.484 raeburn 5912: }
5913: }
1.519 raeburn 5914: $containertag = '<input type="hidden" name="folderpath" value="" />';
5915: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5916: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5917: $showdoc='/'.$1;
5918: }
5919: if ($showdoc) { # got called in sequence from course
5920: $allowed=0;
5921: } else {
1.611 raeburn 5922: if ($canedit) {
1.484 raeburn 5923: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5924: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5925: }
5926: }
1.329 droeschl 5927: }
5928:
1.344 bisitz 5929: # get personal data
1.329 droeschl 5930: my $uname=$env{'user.name'};
5931: my $udom=$env{'user.domain'};
5932: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5933:
5934: if ($allowed) {
1.484 raeburn 5935: if ($toolsflag) {
5936: $script .= &inject_data_js();
5937: my ($home,$other,%outhash)=&authorhosts();
5938: if (!$home && $other) {
5939: my @hosts;
5940: foreach my $aurole (keys(%outhash)) {
5941: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5942: push(@hosts,$outhash{$aurole});
5943: }
5944: }
5945: $script .= &dump_switchserver_js(@hosts);
5946: }
1.458 raeburn 5947: } else {
1.570 raeburn 5948: my $tid = 1;
1.484 raeburn 5949: my @tabids;
5950: if ($supplementalflag) {
1.655 raeburn 5951: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5952: $tid = 2;
1.484 raeburn 5953: } else {
5954: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5955: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5956: unshift(@tabids,'001');
5957: push(@tabids,('dd1','ee1'));
5958: }
1.458 raeburn 5959: }
1.484 raeburn 5960: my $tabidstr = join("','",@tabids);
1.644 raeburn 5961: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5962: my $posslti = keys(%ltitools);
1.622 raeburn 5963: my $hostname = $r->hostname();
1.606 raeburn 5964: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5965: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5966: &history_tab_js().
5967: &inject_data_js().
1.570 raeburn 5968: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5969: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 5970: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5971: if ($hidden_and_empty ne '') {
5972: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5973: $hidden_and_empty);
5974: $onload .= "javascript:alert('".&js_escape($alert)."');";
5975: }
1.484 raeburn 5976: $addentries = {
1.685 raeburn 5977: onload => $onload,
1.484 raeburn 5978: };
1.458 raeburn 5979: }
1.538 raeburn 5980: $script .= &paste_popup_js();
1.501 raeburn 5981: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5982: &mt('Switch server?');
5983:
5984:
1.329 droeschl 5985: }
5986: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5987: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5988: .'// <![CDATA['."\n"
5989: .$script."\n"
5990: .'// ]]>'."\n"
1.595 musolffc 5991: .'</script>'."\n"
5992: .'<script type="text/javascript"
5993: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5994:
5995: # Breadcrumbs
5996: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5997:
5998: if ($showdoc) {
1.682 raeburn 5999: my $args;
6000: if ($supplementalflag) {
1.687 raeburn 6001: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6002: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 6003: $args = {'bread_crumbs' => $brcrum};
6004: } else {
6005: $args = {'force_register' => $showdoc};
6006: }
6007: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6008: } elsif ($toolsflag) {
1.611 raeburn 6009: my ($breadtext,$breadtitle);
1.617 raeburn 6010: $breadtext = "$crstype Editor";
1.611 raeburn 6011: if ($canedit) {
6012: $breadtitle = 'Editing '.$crstype.' Contents';
6013: } else {
6014: $breadtext .= ' (View-only mode)';
6015: $breadtitle = 'Viewing '.$crstype.' Contents';
6016: }
1.571 raeburn 6017: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6018: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6019: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6020: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6021: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6022: $breadtitle)
1.571 raeburn 6023: );
1.510 raeburn 6024: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6025: unless ($env{'request.role.adv'}) {
6026: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6027: $r->internal_redirect('/adm/navmaps');
6028: return OK;
6029: }
6030: }
1.510 raeburn 6031: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6032: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6033: {'bread_crumbs' => $brcrum,}));
6034: } else {
1.611 raeburn 6035: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6036: $breadtext = "$crstype Editor";
1.611 raeburn 6037: if ($canedit) {
6038: $breadtitle = 'Editing '.$crstype.' Contents';
6039: $helpitem = 'Docs_Adding_Course_Doc';
6040: } else {
6041: $breadtext .= ' (View-only mode)';
6042: $breadtitle = 'Viewing '.$crstype.' Contents';
6043: $helpitem = 'Docs_Viewing_Course_Doc';
6044: }
1.392 raeburn 6045: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6046: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6047: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6048: {'add_entries' => $addentries}
6049: )
1.392 raeburn 6050: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6051: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6052: $breadtitle,
6053: $helpitem)
1.392 raeburn 6054: );
6055: }
1.364 bisitz 6056:
1.329 droeschl 6057: my %allfiles = ();
6058: my %codebase = ();
1.440 raeburn 6059: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6060: if ($canedit) {
1.684 raeburn 6061: undef($suppchanges);
1.329 droeschl 6062: if (($env{'form.uploaddoc.filename'}) &&
6063: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6064: my $context = $1;
6065: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6066: undef($hadchanges);
1.440 raeburn 6067: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6068: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6069: undef($navmap);
1.329 droeschl 6070: if ($hadchanges) {
6071: &mark_hash_old();
6072: }
1.684 raeburn 6073: if ($suppchanges) {
6074: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6075: undef($suppchanges);
6076: }
1.440 raeburn 6077: $r->print($upload_output);
6078: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6079: # Process file upload - phase two - upload embedded objects
6080: $uploadphase = 'check_embedded';
6081: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6082: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6083: $env{'form.newidx'});
6084: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6085: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6086: my ($destination,$dir_root) = &embedded_destination();
6087: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6088: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6089: my ($result,$flag) =
1.440 raeburn 6090: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6091: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6092: $actionurl);
6093: $r->print($result.&return_to_editor());
6094: } elsif ($env{'form.phase'} eq 'check_embedded') {
6095: # Process file upload - phase three - modify references in HTML file
6096: $uploadphase = 'modified_orightml';
6097: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6098: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6099: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6100: my $result =
1.482 raeburn 6101: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6102: $docuname,$docudom,undef,
6103: $dir_root);
1.630 raeburn 6104: $r->print($result.&return_to_editor());
1.476 raeburn 6105: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6106: $uploadphase = 'decompress_phase_one';
6107: $r->print(&decompression_phase_one().
6108: &return_to_editor());
6109: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6110: $uploadphase = 'decompress_phase_two';
6111: $r->print(&decompression_phase_two().
6112: &return_to_editor());
1.329 droeschl 6113: }
6114: }
6115:
1.484 raeburn 6116: if ($allowed && $toolsflag) {
6117: $r->print(&startContentScreen('tools'));
1.611 raeburn 6118: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6119: $r->print(&endContentScreen());
6120: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6121: # -----------------------------------------------------------------------------
6122: my %lt=&Apache::lonlocal::texthash(
6123: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6124: 'upfi' => 'Upload File',
1.553 raeburn 6125: 'upld' => 'Upload Content',
1.329 droeschl 6126: 'srch' => 'Search',
6127: 'impo' => 'Import',
1.487 raeburn 6128: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6129: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6130: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6131: 'extr' => 'External Resource',
6132: 'extt' => 'External Tool',
1.329 droeschl 6133: 'selm' => 'Select Map',
6134: 'load' => 'Load Map',
6135: 'newf' => 'New Folder',
6136: 'newp' => 'New Composite Page',
6137: 'syll' => 'Syllabus',
1.425 raeburn 6138: 'navc' => 'Table of Contents',
1.343 biermanm 6139: 'sipa' => 'Simple Course Page',
1.329 droeschl 6140: 'sipr' => 'Simple Problem',
1.630 raeburn 6141: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6142: 'stpr' => 'Standard Problem',
6143: 'news' => 'New sub-directory',
6144: 'crpr' => 'Create Problem',
1.689 raeburn 6145: 'swit' => 'Switch Server',
1.329 droeschl 6146: 'drbx' => 'Drop Box',
1.451 www 6147: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6148: 'bull' => 'Discussion Board',
1.347 weissno 6149: 'mypi' => 'My Personal Information Page',
1.353 weissno 6150: 'grpo' => 'Group Portfolio',
1.329 droeschl 6151: 'rost' => 'Course Roster',
1.528 raeburn 6152: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6153: 'imsf' => 'IMS Upload',
6154: 'imsl' => 'Upload IMS package',
1.501 raeburn 6155: 'cms' => 'Origin of IMS package',
6156: 'se' => 'Select',
1.329 droeschl 6157: 'file' => 'File',
6158: 'title' => 'Title',
1.606 raeburn 6159: 'addp' => 'Add Placeholder to course?',
6160: 'uste' => 'Use Template?',
6161: 'fnam' => 'File Name:',
6162: 'loca' => 'Location:',
6163: 'dire' => 'Directory:',
6164: 'cate' => 'Category:',
6165: 'tmpl' => 'Template:',
1.698 ! raeburn 6166: 'empd' => 'No resources found',
1.329 droeschl 6167: 'comment' => 'Comment',
1.403 raeburn 6168: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6169: 'bb5' => 'Blackboard 5',
6170: 'bb6' => 'Blackboard 6',
6171: 'angel5' => 'ANGEL 5.5',
6172: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6173: 'yes' => 'Yes',
6174: 'no' => 'No',
1.618 raeburn 6175: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6176: );
1.329 droeschl 6177: # -----------------------------------------------------------------------------
1.595 musolffc 6178:
6179: # Calculate free quota space for a user or course. A javascript function checks
6180: # file size to determine if upload should be allowed.
6181: my $quotatype = 'unofficial';
6182: if ($crstype eq 'Community') {
1.601 raeburn 6183: $quotatype = 'community';
6184: } elsif ($crstype eq 'Placement') {
6185: $quotatype = 'placement';
1.595 musolffc 6186: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6187: $quotatype = 'official';
6188: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6189: $quotatype = 'textbook';
6190: }
6191: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6192: 'course',$quotatype); # expressed in MB
6193: my $current_disk_usage = 0;
6194: foreach my $subdir ('docs','supplemental') {
6195: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6196: "userfiles/$subdir",1); # expressed in kB
6197: }
6198: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6199: my $usage = $current_disk_usage/1024; # in MB
6200: my $quota = $disk_quota;
6201: my $percent;
6202: if ($disk_quota == 0) {
6203: $percent = 100.0;
6204: } else {
1.619 raeburn 6205: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6206: }
6207: $usage = sprintf("%.2f",$usage);
6208: $quota = sprintf("%.2f",$quota);
6209: $percent = sprintf("%.0f",$percent);
6210: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6211: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6212:
1.329 droeschl 6213: my $fileupload=(<<FIUP);
1.605 raeburn 6214: $quotainfo
1.329 droeschl 6215: $lt{'file'}:<br />
1.662 raeburn 6216: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6217: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6218: FIUP
6219:
6220: my $checkbox=(<<CHBO);
6221: <!-- <label>$lt{'parse'}?
6222: <input type="checkbox" name="parserflag" />
6223: </label> -->
6224: <label>
1.611 raeburn 6225: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6226: </label>
6227: CHBO
1.501 raeburn 6228: my $imsfolder = $env{'form.folder'};
6229: if ($imsfolder eq '') {
6230: $imsfolder = 'default';
6231: }
6232: my $imspform=(<<IMSFORM);
6233: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6234: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6235: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6236: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6237: <legend>$lt{'imsf'}</legend>
6238: $fileupload
6239: <br />
6240: <p>
6241: $lt{'cms'}:
1.611 raeburn 6242: <select name="source" $disabled>
1.501 raeburn 6243: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6244: <option value="bb5">$lt{'bb5'}</option>
6245: <option value="bb6">$lt{'bb6'}</option>
6246: <option value="angel5">$lt{'angel5'}</option>
6247: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6248: </select>
6249: <input type="hidden" name="folder" value="$imsfolder" />
6250: </p>
6251: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6252: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6253: </fieldset>
6254: </form>
6255: IMSFORM
1.329 droeschl 6256:
6257: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6258: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6259: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6260: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6261: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6262: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6263: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6264: $fileupload
1.329 droeschl 6265: <br />
6266: $lt{'title'}:<br />
1.611 raeburn 6267: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6268: $pathitem
1.329 droeschl 6269: <input type="hidden" name="cmd" value="upload_default" />
6270: <br />
1.458 raeburn 6271: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6272: $checkbox
6273: </span>
1.501 raeburn 6274: <br clear="all" />
1.611 raeburn 6275: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6276: </fieldset>
6277: </form>
1.383 tempelho 6278: FUFORM
1.329 droeschl 6279:
1.611 raeburn 6280: my $mapimportjs;
6281: if ($canedit) {
6282: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6283: } else {
6284: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6285: }
1.502 raeburn 6286: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6287: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6288: $lt{'impm'}</a>$help{'Load_Map'}
6289: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6290: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6291: <legend>$lt{'impm'}</legend>
1.371 tempelho 6292: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6293: $lt{'copm'}<br />
6294: <span class="LC_nobreak">
6295: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6296: onfocus="this.blur();$mapimportjs" $disabled />
6297: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6298: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6299: </fieldset>
6300: </form>
6301:
1.383 tempelho 6302: SEDFFORM
1.606 raeburn 6303: my $importcrsresform;
1.608 raeburn 6304: my ($numdirs,$pickfile) =
1.690 raeburn 6305: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6306: "resize_scrollbox('contentscroll','1','0');",
6307: undef,'res');
1.606 raeburn 6308: if ($pickfile) {
6309: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6310: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6311: $lt{'imcr'}</a>$help{'Course_Resources'}
6312: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6313: <fieldset id="importcrsresform" style="display: none;">
6314: <legend>$lt{'imcr'}</legend>
1.698 ! raeburn 6315: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 6316: <input type="hidden" name="active" value="bb" />
6317: $pickfile
6318: <p>
1.611 raeburn 6319: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6320: </p>
6321: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6322: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 ! raeburn 6323: </div>
! 6324: <div id="importcrsresempty" style="display: none;">
! 6325: <p>
! 6326: $lt{'empd'}
! 6327: </p>
! 6328: </div>
1.606 raeburn 6329: </fieldset>
6330: </form>
6331: CRSFORM
6332: }
6333:
1.611 raeburn 6334: my $fromstoredjs;
6335: if ($canedit) {
6336: $fromstoredjs = 'open_StoredLinks_Import()';
6337: } else {
6338: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6339: }
6340:
1.502 raeburn 6341: my @importpubforma = (
1.508 raeburn 6342: { '<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 6343: { '<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 6344: { '<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 6345: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6346: );
6347: if ($pickfile) {
1.690 raeburn 6348: 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 6349: }
1.502 raeburn 6350: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6351: my $extresourcesform =
6352: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6353: $help{'Adding_External_Resource'},
6354: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6355: my $exttoolform =
6356: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6357: $help{'Adding_External_Tool'},undef,
6358: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6359: \%ltitools,$disabled);
1.329 droeschl 6360: if ($allowed) {
1.492 raeburn 6361: my $folder = $env{'form.folder'};
6362: if ($folder eq '') {
6363: $folder='default';
6364: }
1.615 raeburn 6365: if ($canedit) {
6366: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6367: if ($output) {
6368: $r->print($output);
6369: }
1.538 raeburn 6370: }
1.337 ehlerst 6371: $r->print(<<HIDDENFORM);
6372: <form name="renameform" method="post" action="/adm/coursedocs">
6373: <input type="hidden" name="title" />
6374: <input type="hidden" name="cmd" />
6375: <input type="hidden" name="markcopy" />
6376: <input type="hidden" name="copyfolder" />
6377: $containertag
6378: </form>
1.633 raeburn 6379: <form name="aliasform" method="post" action="/adm/coursedocs">
6380: <input type="hidden" name="alias" />
6381: <input type="hidden" name="cmd" />
6382: $containertag
6383: </form>
1.484 raeburn 6384:
1.337 ehlerst 6385: HIDDENFORM
1.508 raeburn 6386: $r->print(&makesimpleeditform($pathitem)."\n".
6387: &makedocslogform($pathitem."\n".
1.484 raeburn 6388: '<input type="hidden" name="folder" value="'.
6389: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6390: }
1.442 www 6391:
6392: # Generate the tabs
1.510 raeburn 6393: my ($mode,$needs_end);
1.472 raeburn 6394: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6395: my @folders = split('&',$env{'form.folderpath'});
6396: unless (@folders > 2) {
6397: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6398: $needs_end = 1;
6399: }
1.472 raeburn 6400: } else {
1.484 raeburn 6401: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6402: $needs_end = 1;
1.472 raeburn 6403: }
1.443 www 6404:
1.442 www 6405: #
1.622 raeburn 6406: my $hostname = $r->hostname();
1.442 www 6407: my $savefolderpath;
6408:
1.395 raeburn 6409: if ($allowed) {
1.329 droeschl 6410: my $folder=$env{'form.folder'};
1.615 raeburn 6411: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6412: $folder='default';
1.356 tempelho 6413: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6414: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6415: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6416: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6417: }
6418: my $postexec='';
6419: if ($folder eq 'default') {
1.653 raeburn 6420: my $windowname = 'loncapaclient';
6421: if ($env{'request.lti.login'}) {
6422: $windowname .= 'lti';
6423: }
1.372 bisitz 6424: $r->print('<script type="text/javascript">'."\n"
6425: .'// <![CDATA['."\n"
1.653 raeburn 6426: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6427: .'// ]]>'."\n"
6428: .'</script>'."\n"
1.369 bisitz 6429: );
1.329 droeschl 6430: } else {
6431: #$postexec='self.close();';
6432: }
1.504 raeburn 6433: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6434: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6435: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6436:
6437: my $newnavform=(<<NNFORM);
6438: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6439: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6440: $pathitem
1.329 droeschl 6441: <input type="hidden" name="importdetail"
6442: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6443: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6444: $help{'Navigate_Content'}
6445: </form>
6446: NNFORM
6447: my $newsmppageform=(<<NSPFORM);
6448: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6449: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6450: $pathitem
1.329 droeschl 6451: <input type="hidden" name="importdetail" value="" />
1.423 onken 6452: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6453: $help{'Simple Page'}
1.329 droeschl 6454: </form>
6455: NSPFORM
6456:
6457: my $newsmpproblemform=(<<NSPROBFORM);
6458: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6459: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6460: $pathitem
1.329 droeschl 6461: <input type="hidden" name="importdetail" value="" />
1.423 onken 6462: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6463: $help{'Simple_Problem'}
1.329 droeschl 6464: </form>
6465:
6466: NSPROBFORM
6467:
6468: my $newdropboxform=(<<NDBFORM);
6469: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6470: <input type="hidden" name="active" value="dd" />
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:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6474: $help{'Dropbox'}
1.344 bisitz 6475: </form>
1.329 droeschl 6476: NDBFORM
6477:
6478: my $newexuploadform=(<<NEXUFORM);
6479: <form action="/adm/coursedocs" method="post" name="newexamupload">
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:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6484: $help{'Score_Upload_Form'}
6485: </form>
6486: NEXUFORM
6487:
6488: my $newbulform=(<<NBFORM);
6489: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6490: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6491: $pathitem
1.329 droeschl 6492: <input type="hidden" name="importdetail" value="" />
1.423 onken 6493: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6494: $help{'Bulletin Board'}
6495: </form>
6496: NBFORM
6497:
6498: my $newaboutmeform=(<<NAMFORM);
6499: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6500: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6501: $pathitem
1.329 droeschl 6502: <input type="hidden" name="importdetail"
6503: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6504: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6505: $help{'My Personal Information Page'}
1.329 droeschl 6506: </form>
6507: NAMFORM
6508:
6509: my $newaboutsomeoneform=(<<NASOFORM);
6510: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
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:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6515: </form>
6516: NASOFORM
6517:
6518: my $newrosterform=(<<NROSTFORM);
6519: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6520: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6521: $pathitem
1.329 droeschl 6522: <input type="hidden" name="importdetail"
6523: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6524: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6525: $help{'Course_Roster'}
1.329 droeschl 6526: </form>
6527: NROSTFORM
6528:
1.534 raeburn 6529: my $newwebpage;
6530: if ($folder =~ /^default_?(\d*)$/) {
6531: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6532: if ($1) {
6533: $newwebpage .= $1;
6534: } else {
6535: $newwebpage .= 'default';
6536: }
6537: $newwebpage .= '/new.html';
6538: }
6539: my $newwebpageform =(<<NWEBFORM);
6540: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6541: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6542: $pathitem
6543: <input type="hidden" name="importdetail" value="$newwebpage" />
6544: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6545: $help{'Web_Page'}
1.534 raeburn 6546: </form>
6547: NWEBFORM
1.604 raeburn 6548:
1.606 raeburn 6549: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6550: my $machines_str = "'".join("','",@ids)."'";
6551: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6552: if ($env{'user.author'}) {
6553: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6554: $is_home{'author'} = 1;
1.606 raeburn 6555: }
1.691 raeburn 6556: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6557: }
6558: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6559: ['active'],['ca','aa']);
1.691 raeburn 6560: my %by_roletype;
1.606 raeburn 6561: if (keys(%roleshash)) {
6562: foreach my $entry (keys(%roleshash)) {
6563: my ($auname,$audom,$roletype) = split(/:/,$entry);
6564: my $key = $entry;
6565: $key =~ s/:/___/g;
1.691 raeburn 6566: my $author = $auname.'___'.$audom;
6567: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6568: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6569: $toppath{$author} = "/priv/$audom/$auname";
6570: if (grep(/^\Q$rolehome\E$/,@ids)) {
6571: $is_home{$author} = 1;
1.606 raeburn 6572: }
1.691 raeburn 6573: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6574: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6575: }
1.691 raeburn 6576: }
6577: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6578: if (grep(/^\Q$crshome\E$/,@ids)) {
6579: $is_home{'course'} = 1;
6580: }
6581: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6582: my $pickdir = $lt{'loca'}.
6583: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6584: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6585: if ($env{'user.author'}) {
6586: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6587: }
6588: if (keys(%by_roletype)) {
6589: foreach my $possrole ('ca','aa') {
6590: if (ref($by_roletype{$possrole}) eq 'HASH') {
6591: my $roletitle = &Apache::lonnet::plaintext($possrole);
6592: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6593: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6594: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6595: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6596: }
6597: }
6598: }
6599: }
1.691 raeburn 6600: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6601: '</select><br />'."\n".
6602: $lt{'dire'}.
6603: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6604: '<option value=""></option>'.
6605: '</select><br />'."\n";
1.606 raeburn 6606:
6607: my %seltemplate_menus;
6608: my @files = &Apache::lonhomework::get_template_list('problem');
6609: my @noexamplelink = ('blank.problem','blank.library','script.library');
6610: my $currentcategory = '';
6611: my @ordered = ('');
6612: my %templatehelp;
6613: my $defcategory = '';
6614: my @catorder = ($defcategory);
6615: $seltemplate_menus{$defcategory}->{'order'} = [''];
6616: $seltemplate_menus{$defcategory}->{'text'} = '';
6617: foreach my $file (@files) {
6618: if (ref($file) eq 'ARRAY') {
6619: my ($path,$title,$category,$help) = @{$file};
6620: next if ($title !~ /\S/);
6621: if (&js_escape($category) ne $currentcategory) {
6622: $currentcategory = &js_escape($category);
6623: push(@catorder,&js_escape($currentcategory));
6624: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6625: $seltemplate_menus{$currentcategory}->{'default'} = '';
6626: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6627: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6628: }
6629: if ($path) {
6630: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6631: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6632: if ($help) {
6633: $templatehelp{$path} = $help;
6634: }
6635: }
6636: }
6637: }
6638:
6639: my $templates = $lt{'cate'}.' '.
6640: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6641: $defcategory,'tempcategory','template',
6642: \%seltemplate_menus,\@catorder,
6643: "resize_scrollbox('contentscroll','1','0');",
6644: "toggleExampleText();",'template').'<br />';
6645: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6646: '<span id="newresexample">'.&mt('Example').'<span></a>';
6647: my $crsresform=(<<RESFORM);
1.691 raeburn 6648: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 6649: $lt{'stpr'}</a>$help{'Course_Resource'}
6650: <form action="/adm/coursedocs" method="post" name="courseresform">
6651: <fieldset id="crsresform" style="display:none;">
6652: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6653: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6654: <p>
6655: $pickdir
1.691 raeburn 6656: <div id="newstdproblem" style="display:none;">
1.606 raeburn 6657: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6658: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6659:
1.611 raeburn 6660: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6661: </span><span id="newsubdir"></span>
6662: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6663: </p>
6664: $lt{'fnam'}
1.611 raeburn 6665: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6666: <p>
1.691 raeburn 6667: <div id="newresource" style="display:none">
1.606 raeburn 6668: $lt{'addp'}
1.611 raeburn 6669: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6670: $lt{'no'}</label>
1.611 raeburn 6671: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6672: $lt{'yes'}</label>
6673: <span id="newrestitle"></span>
1.611 raeburn 6674: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6675: </div>
6676: </p>
6677: <p>
6678: $lt{'uste'}
1.611 raeburn 6679: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6680: $lt{'no'}</label>
1.611 raeburn 6681: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6682: $lt{'yes'}</label>
6683: <div id="newrestemplate" style="display:none">
6684: $templates
6685: $templatepreview
6686: </div>
6687: </p>
6688: <span class="LC_nobreak">
6689: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6690: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6691: </span>
1.689 raeburn 6692: </div>
1.691 raeburn 6693: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 6694: $rolehomes
6695: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6696: </div>
1.606 raeburn 6697: </fieldset>
6698: </form>
6699:
6700: RESFORM
1.534 raeburn 6701:
1.342 ehlerst 6702: my $specialdocumentsform;
1.383 tempelho 6703: my @specialdocumentsforma;
1.451 www 6704: my $gradingform;
6705: my @gradingforma;
6706: my $communityform;
6707: my @communityforma;
1.351 ehlerst 6708: my $newfolderform;
1.390 tempelho 6709: my $newfolderb;
1.342 ehlerst 6710:
1.451 www 6711: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6712:
1.329 droeschl 6713: my $newpageform=(<<NPFORM);
6714: <form action="/adm/coursedocs" method="post" name="newpage">
6715: <input type="hidden" name="folderpath" value="$path" />
6716: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6717: <input type="hidden" name="active" value="ee" />
1.423 onken 6718: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6719: $help{'Adding_Pages'}
1.329 droeschl 6720: </form>
6721: NPFORM
1.390 tempelho 6722:
6723:
1.351 ehlerst 6724: $newfolderform=(<<NFFORM);
1.329 droeschl 6725: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6726: $pathitem
1.329 droeschl 6727: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6728: <input type="hidden" name="active" value="" />
1.422 onken 6729: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6730: </form>
6731: NFFORM
6732:
6733: my $newsylform=(<<NSYLFORM);
6734: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6735: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6736: $pathitem
1.329 droeschl 6737: <input type="hidden" name="importdetail"
6738: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6739: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6740: $help{'Syllabus'}
1.383 tempelho 6741:
1.329 droeschl 6742: </form>
6743: NSYLFORM
1.364 bisitz 6744:
1.329 droeschl 6745: my $newgroupfileform=(<<NGFFORM);
6746: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6747: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6748: $pathitem
1.329 droeschl 6749: <input type="hidden" name="importdetail"
6750: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6751: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6752: $help{'Group Portfolio'}
1.329 droeschl 6753: </form>
6754: NGFFORM
1.672 raeburn 6755: if ($container eq 'page') {
6756: @specialdocumentsforma=(
6757: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6758: );
6759: } else {
6760: @specialdocumentsforma=(
1.421 onken 6761: {'<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 6762: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6763: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6764: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6765: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6766: );
6767: }
1.451 www 6768: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6769:
1.655 raeburn 6770: my @external = (
6771: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6772: );
1.598 raeburn 6773: if (keys(%ltitools)) {
1.655 raeburn 6774: push(@external,
6775: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6776: );
1.598 raeburn 6777: }
1.655 raeburn 6778: my $externalform = &create_form_ul(&create_list_elements(@external));
6779:
6780: my @importdoc = ();
1.519 raeburn 6781: unless ($container eq 'page') {
6782: push(@importdoc,
6783: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6784: );
6785: }
6786: push(@importdoc,
1.558 raeburn 6787: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6788: );
1.501 raeburn 6789: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6790:
1.451 www 6791: @gradingforma=(
6792: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6794: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 6795: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 6796: );
6797: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6798:
6799: @communityforma=(
6800: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6801: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6802: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6803: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6804: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6805: );
6806: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6807:
1.330 tempelho 6808: my %orderhash = (
1.553 raeburn 6809: 'aa' => ['Upload',$fileuploadform],
6810: 'bb' => ['Import',$importpubform],
1.655 raeburn 6811: 'cc' => ['External',$externalform],
6812: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6813: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6814: );
1.519 raeburn 6815: unless ($container eq 'page') {
1.434 raeburn 6816: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6817: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6818: }
6819:
1.341 ehlerst 6820: $hadchanges=0;
1.484 raeburn 6821: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6822: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6823: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6824: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6825: undef($navmap);
1.443 www 6826: if ($error) {
6827: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6828: }
1.639 raeburn 6829: if ($hadchanges) {
6830: unless (&is_hash_old()) {
1.638 raeburn 6831: &mark_hash_old();
6832: }
6833: }
1.341 ehlerst 6834:
1.443 www 6835: &changewarning($r,'');
6836: }
1.458 raeburn 6837: }
1.442 www 6838:
1.443 www 6839: # Supplemental documents start here
6840:
1.329 droeschl 6841: my $folder=$env{'form.folder'};
1.443 www 6842: unless ($supplementalflag) {
1.329 droeschl 6843: $folder='supplemental';
6844: }
1.685 raeburn 6845: if (($folder eq 'supplemental') &&
1.329 droeschl 6846: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6847: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6848: } elsif ($allowed) {
1.356 tempelho 6849: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6850: }
1.508 raeburn 6851: $pathitem = '<input type="hidden" name="folderpath" value="'.
6852: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6853: if ($allowed) {
6854: my $folderseq=
1.504 raeburn 6855: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6856:
6857: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6858: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6859: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6860: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6861: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6862: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6863: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6864: $fileupload
6865: <br />
6866: <br />
6867: <span class="LC_nobreak">
6868: $checkbox
6869: </span>
6870: <br /><br />
6871: $lt{'comment'}:<br />
1.383 tempelho 6872: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6873: <br />
1.508 raeburn 6874: $pathitem
1.329 droeschl 6875: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6876: <input type='submit' value="$lt{'upld'}" />
6877: </form>
1.329 droeschl 6878: SUPDOCFORM
6879:
6880: my $supnewfolderform=(<<SNFFORM);
6881: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6882: <input type="hidden" name="active" value="" />
1.508 raeburn 6883: $pathitem
1.329 droeschl 6884: <input type="hidden" name="importdetail" value="" />
1.423 onken 6885: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6886: $help{'Adding_Folders'}
1.329 droeschl 6887: </form>
6888: SNFFORM
1.383 tempelho 6889:
1.510 raeburn 6890: my $supextform =
6891: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6892: $help{'Adding_External_Resource'},
6893: undef,undef,undef,undef,undef,undef,
6894: $disabled);
1.329 droeschl 6895:
1.598 raeburn 6896: my $supexttoolform =
6897: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6898: $help{'Adding_External_Tool'},
6899: undef,undef,'tool',$coursedom,
1.611 raeburn 6900: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6901:
1.329 droeschl 6902: my $supnewsylform=(<<SNSFORM);
6903: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6904: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6905: $pathitem
1.329 droeschl 6906: <input type="hidden" name="importdetail"
6907: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6908: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6909: $help{'Syllabus'}
6910: </form>
6911: SNSFORM
6912:
6913: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6914: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6915: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6916: $pathitem
1.329 droeschl 6917: <input type="hidden" name="importdetail"
6918: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6919: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6920: $help{'My Personal Information Page'}
1.329 droeschl 6921: </form>
6922: SNAMFORM
6923:
1.534 raeburn 6924: my $supwebpage;
6925: if ($folder =~ /^supplemental_?(\d*)$/) {
6926: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6927: if ($1) {
6928: $supwebpage .= $1;
6929: } else {
6930: $supwebpage .= 'default';
6931: }
6932: $supwebpage .= '/new.html';
6933: }
6934: my $supwebpageform =(<<SWEBFORM);
6935: <form action="/adm/coursedocs" method="post" name="supwebpage">
6936: <input type="hidden" name="active" value="cc" />
6937: $pathitem
6938: <input type="hidden" name="importdetail" value="$supwebpage" />
6939: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6940: $help{'Web_Page'}
1.534 raeburn 6941: </form>
6942: SWEBFORM
6943:
1.333 muellerd 6944:
1.383 tempelho 6945: my @specialdocs = (
1.618 raeburn 6946: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6947: =>$supnewsylform},
1.611 raeburn 6948: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6949: =>$supnewaboutmeform},
1.534 raeburn 6950: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6951:
1.383 tempelho 6952: );
1.655 raeburn 6953: my @supexternal = (
6954: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6955: =>$supextform});
1.598 raeburn 6956: if (keys(%ltitools)) {
1.655 raeburn 6957: push(@supexternal,
6958: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6959: =>$supexttoolform});
6960: }
1.655 raeburn 6961: my @supimportdoc = (
1.598 raeburn 6962: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6963: =>$supupdocform},
1.598 raeburn 6964: );
1.501 raeburn 6965:
6966: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6967: my %suporderhash = (
1.390 tempelho 6968: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6969: 'dd' => ['Upload',$supupdocform],
6970: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6971: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6972: );
1.443 www 6973: if ($supplementalflag) {
1.682 raeburn 6974: $suppchanges = 0;
6975: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6976: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6977: \%ltitools,$canedit,$hostname);
6978: if ($error) {
6979: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6980: }
6981: if ($suppchanges) {
1.684 raeburn 6982: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 6983: undef($suppchanges);
6984: }
1.393 raeburn 6985: }
1.443 www 6986: } elsif ($supplementalflag) {
1.458 raeburn 6987: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 6988: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6989: $hostname);
1.393 raeburn 6990: if ($error) {
6991: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6992: }
1.393 raeburn 6993: }
1.389 tempelho 6994:
1.510 raeburn 6995: if ($needs_end) {
6996: $r->print(&endContentScreen());
6997: }
1.383 tempelho 6998:
1.329 droeschl 6999: if ($allowed) {
7000: $r->print('
7001: <form method="post" name="extimport" action="/adm/coursedocs">
7002: <input type="hidden" name="title" />
7003: <input type="hidden" name="url" />
7004: <input type="hidden" name="useform" />
7005: <input type="hidden" name="residx" />
7006: </form>');
7007: }
1.484 raeburn 7008: } elsif ($showdoc) {
1.329 droeschl 7009: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7010: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7011: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7012: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7013: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7014: }
7015: }
1.630 raeburn 7016: unless ($noendpage) {
1.606 raeburn 7017: $r->print(&Apache::loncommon::end_page());
7018: }
1.329 droeschl 7019: return OK;
1.364 bisitz 7020: }
1.329 droeschl 7021:
1.440 raeburn 7022: sub embedded_form_elems {
7023: my ($phase,$primaryurl,$newidx) = @_;
7024: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7025: $newidx =~s /\D+//g;
1.440 raeburn 7026: return <<STATE;
7027: <input type="hidden" name="folderpath" value="$folderpath" />
7028: <input type="hidden" name="cmd" value="upload_embedded" />
7029: <input type="hidden" name="newidx" value="$newidx" />
7030: <input type="hidden" name="phase" value="$phase" />
7031: <input type="hidden" name="primaryurl" value="$primaryurl" />
7032: STATE
7033: }
7034:
7035: sub embedded_destination {
7036: my $folder=$env{'form.folder'};
7037: my $destination = 'docs/';
7038: if ($folder =~ /^supplemental/) {
7039: $destination = 'supplemental/';
7040: }
7041: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7042: $destination .= 'default/';
7043: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7044: $destination .= $2.'/';
7045: }
1.634 raeburn 7046: my $newidx = $env{'form.newidx'};
7047: $newidx =~s /\D+//g;
7048: if ($newidx) {
7049: $destination .= $newidx;
7050: }
1.440 raeburn 7051: my $dir_root = '/userfiles';
7052: return ($destination,$dir_root);
7053: }
7054:
7055: sub return_to_editor {
7056: my $actionurl = '/adm/coursedocs';
7057: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7058: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7059: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7060: '</a></p>';
7061: }
7062:
1.476 raeburn 7063: sub decompression_info {
7064: my ($destination,$dir_root) = &embedded_destination();
7065: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7066: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7067: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7068: my $container='sequence';
1.480 raeburn 7069: my ($pathitem,$hiddenelem);
1.583 raeburn 7070: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7071: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7072: $container='page';
7073: }
1.480 raeburn 7074: unshift(@hiddens,$pathitem);
7075: foreach my $item (@hiddens) {
1.634 raeburn 7076: if ($item eq 'newidx') {
7077: next if ($env{'form.'.$item} =~ /\D/);
7078: }
1.480 raeburn 7079: if ($env{'form.'.$item}) {
7080: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7081: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7082: }
1.477 raeburn 7083: }
1.476 raeburn 7084: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7085: $hiddenelem);
7086: }
7087:
7088: sub decompression_phase_one {
7089: my ($dir,$file,$warning,$error,$output);
7090: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7091: &decompression_info();
1.490 raeburn 7092: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7093: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7094: } else {
7095: my $file = $1;
1.630 raeburn 7096: $output =
1.481 raeburn 7097: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7098: $destination,$dir_root,
7099: $hiddenelem);
7100: if ($env{'form.autoextract_camtasia'}) {
7101: $output .= &remove_archive($docudom,$docuname,$container);
7102: }
1.476 raeburn 7103: }
7104: if ($error) {
7105: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7106: $error.'</p>'."\n";
7107: }
7108: if ($warning) {
7109: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7110: }
7111: return $output;
7112: }
7113:
7114: sub decompression_phase_two {
7115: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7116: &decompression_info();
1.481 raeburn 7117: my $output;
1.480 raeburn 7118: if ($env{'form.archivedelete'}) {
1.481 raeburn 7119: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7120: }
7121: $output .=
1.481 raeburn 7122: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7123: $destination,$dir_root,$hiddenelem);
7124: return $output;
7125: }
7126:
1.480 raeburn 7127: sub remove_archive {
7128: my ($docudom,$docuname,$container) = @_;
7129: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7130: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7131: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7132: if ($fatal) {
7133: if ($container eq 'page') {
7134: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7135: } else {
7136: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7137: }
1.583 raeburn 7138: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7139: } else {
7140: my $currcmd = $env{'form.cmd'};
7141: my $position = $env{'form.position'};
1.583 raeburn 7142: my $archiveidx = $position;
1.563 raeburn 7143: if ($position > 0) {
1.583 raeburn 7144: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7145: $archiveidx = $position-1;
7146: }
7147: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7148: my ($title,$url,@rrest) =
1.583 raeburn 7149: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7150: if ($url eq $env{'form.archiveurl'}) {
7151: if (&handle_edit_cmd($docuname,$docudom)) {
7152: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7153: if ($suppchanges) {
7154: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7155: undef($suppchanges);
7156: }
1.583 raeburn 7157: if ($fatal) {
7158: if ($container eq 'page') {
7159: $delwarning = &mt('An error occurred updating the contents of the current page.');
7160: } else {
7161: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7162: }
1.480 raeburn 7163: } else {
1.583 raeburn 7164: $delresult = &mt('Archive file removed.');
1.480 raeburn 7165: }
7166: }
1.583 raeburn 7167: } else {
7168: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7169: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7170: }
7171: }
7172: $env{'form.cmd'} = $currcmd;
7173: }
7174: if ($delwarning) {
7175: $output = '<p class="LC_warning">'.
7176: $delwarning.
7177: '</p>';
7178: }
7179: if ($delresult) {
7180: $output .= '<p class="LC_info">'.
7181: $delresult.
7182: '</p>';
7183: }
1.481 raeburn 7184: return $output;
1.480 raeburn 7185: }
7186:
1.484 raeburn 7187: sub generate_admin_menu {
1.611 raeburn 7188: my ($crstype,$canedit) = @_;
1.484 raeburn 7189: my $lc_crstype = lc($crstype);
7190: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7191: my %lt= ( # do not translate here
1.484 raeburn 7192: 'vc' => 'Verify Content',
7193: 'cv' => 'Check/Set Resource Versions',
7194: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7195: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7196: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7197: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7198: );
1.484 raeburn 7199: my ($candump,$dumpurl);
7200: if ($home + $other > 0) {
7201: $candump = 'F';
7202: if ($home) {
7203: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7204: } else {
7205: my @hosts;
7206: foreach my $aurole (keys(%outhash)) {
7207: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7208: push(@hosts,$outhash{$aurole});
1.538 raeburn 7209: }
1.484 raeburn 7210: }
7211: if (@hosts == 1) {
7212: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7213: '&role='.
7214: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7215: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7216: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7217: } else {
7218: $dumpurl = "javascript:choose_switchserver_window()";
7219: }
7220: }
7221: }
7222: my @menu=
7223: ({ categorytitle=>'Administration',
7224: items =>[
7225: { linktext => $lt{'vc'},
7226: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7227: permission => 'F',
1.571 raeburn 7228: help => 'Docs_Verify_Content',
1.484 raeburn 7229: icon => 'verify.png',
7230: linktitle => 'Verify contents can be retrieved/rendered',
7231: },
7232: { linktext => $lt{'cv'},
7233: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7234: permission => 'F',
1.571 raeburn 7235: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7236: icon => 'resversion.png',
7237: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7238: },
7239: { linktext => $lt{'ls'},
7240: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7241: permission => 'F',
7242: #help => '',
7243: icon => 'symbs.png',
7244: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7245: },
1.651 raeburn 7246: { linktext => $lt{'ct'},
7247: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7248: permission => 'F',
7249: help => 'Docs_Short_URLs',
7250: icon => 'shorturls.png',
7251: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7252: },
1.484 raeburn 7253: ]
1.611 raeburn 7254: });
7255: if ($canedit) {
7256: push(@menu,
1.484 raeburn 7257: { categorytitle=>'Export',
7258: items =>[
7259: { linktext => $lt{'imse'},
7260: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7261: permission => 'F',
7262: help => 'Docs_Export_Course_Docs',
7263: icon => 'imsexport.png',
7264: linktitle => $lt{'imse'},
7265: },
7266: { linktext => $lt{'dcd'},
7267: url => $dumpurl,
7268: permission => $candump,
1.571 raeburn 7269: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7270: icon => 'dump.png',
7271: linktitle => $lt{'dcd'},
7272: },
7273: ]
7274: });
1.611 raeburn 7275: }
1.484 raeburn 7276: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7277: '<input type="hidden" id="dummy" />'."\n".
7278: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7279: '</form>';
1.329 droeschl 7280: }
7281:
7282: sub generate_edit_table {
1.538 raeburn 7283: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7284: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7285: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7286: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7287: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7288: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7289: $activetab = $env{'form.active'};
7290: }
1.611 raeburn 7291: unless ($canedit) {
7292: $disabled = ' disabled="disabled"';
7293: }
1.472 raeburn 7294: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7295: my $backtext = &mt('Exit Editor');
1.458 raeburn 7296: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7297: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7298: '<li class="goback">'.
1.546 raeburn 7299: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7300: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7301: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7302: '<li>'.
7303: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7304: &mt('Undo Delete').'</a></li>'."\n";
7305: if ($env{'form.docslog'}) {
7306: $form .= '<li class="active">';
7307: } else {
7308: $form .= '<li>';
7309: }
7310: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7311: &mt('History').'</a></li>'."\n";
7312: if ($env{'form.docslog'}) {
7313: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7314: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7315: }
1.458 raeburn 7316: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7317: if($name ne '00'){
1.371 tempelho 7318: if($activetab eq '' || $activetab ne $name){
7319: $active = '';
7320: }elsif($activetab eq $name){
7321: $active = 'class="active"';
7322: }
1.458 raeburn 7323: $form .= '<li style="float:right" '.$active
1.484 raeburn 7324: .' 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 7325: } else {
1.570 raeburn 7326: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7327:
7328: }
1.329 droeschl 7329: }
1.484 raeburn 7330: $form .= '</ul>'."\n";
7331: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7332:
7333: if ($to_show ne '') {
1.538 raeburn 7334: my $saveform;
7335: if ($need_save) {
7336: my $button = &mt('Make changes');
7337: my $path;
7338: if ($env{'form.folderpath'}) {
7339: $path =
7340: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7341: }
7342: $saveform = <<"END";
7343: <div id="multisave" style="display:none; clear:both;" >
7344: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7345: <input type="hidden" name="folderpath" value="$path" />
7346: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7347: <input type="hidden" name="allhiddenresource" value="" />
7348: <input type="hidden" name="allencrypturl" value="" />
7349: <input type="hidden" name="allrandompick" value="" />
7350: <input type="hidden" name="allrandomorder" value="" />
7351: <input type="hidden" name="changeparms" value="" />
7352: <input type="hidden" name="multiremove" value="" />
7353: <input type="hidden" name="multicut" value="" />
7354: <input type="hidden" name="multicopy" value="" />
7355: <input type="hidden" name="multichange" value="" />
7356: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7357: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7358: </form>
7359: </div>
7360: END
7361: }
7362: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7363: }
1.363 ehlerst 7364: foreach my $field (keys(%orderhash)){
1.390 tempelho 7365: if($field ne '00'){
1.422 onken 7366: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7367: $active = 'style="display: none;float:left"';
1.422 onken 7368: }elsif($activetab eq $field){
1.458 raeburn 7369: $active = 'style="display:block;float:left"';
1.422 onken 7370: }
7371: $form .= '<div id="'.$field.$tid.'"'
7372: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7373: .'</div>'."\n";
1.363 ehlerst 7374: }
7375: }
1.484 raeburn 7376: unless ($env{'form.docslog'}) {
7377: $form .= '</div></div>'."\n";
7378: }
1.329 droeschl 7379: return $form;
7380: }
7381:
7382: sub editing_js {
1.622 raeburn 7383: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7384: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7385: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7386: p_mnf => 'Name of New Folder',
7387: t_mnf => 'New Folder',
7388: p_mnp => 'Name of New Page',
7389: t_mnp => 'New Page',
1.451 www 7390: p_mxu => 'Title for the External Score',
1.349 biermanm 7391: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7392: p_msb => 'Title for the Problem',
7393: p_mdb => 'Title for the Drop Box',
1.336 schafran 7394: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7395: p_mwp => 'Title for Web Page',
1.606 raeburn 7396: p_mnr => 'Title for the Resource',
1.348 weissno 7397: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7398: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7399: p_mab_alrt1 => 'Not a valid user:domain',
7400: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7401: p_chn => 'New Title',
7402: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7403: p_rmr2a => 'Remove',
7404: p_rmr2b => '?',
7405: p_rmr3a => 'Remove those',
7406: p_rmr3b => 'items?',
7407: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7408: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7409: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7410: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7411: p_ctr2a => 'Cut',
7412: p_ctr2b => '?',
7413: p_ctr3a => 'Cut those',
7414: p_ctr3b => 'items?',
1.633 raeburn 7415: setal => 'Enter a (unique) alias',
7416: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7417: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7418: imsfile => 'You must choose an IMS package for import',
7419: imscms => 'You must select which Course Management System was the source of the IMS package',
7420: invurl => 'Invalid URL',
7421: titbl => 'Title is blank',
1.538 raeburn 7422: more => '(More ...)',
7423: less => '(Less ...)',
1.543 raeburn 7424: noor => 'No actions selected or changes to settings specified.',
7425: noch => 'No changes to settings specified.',
7426: noac => 'No actions selected.',
1.606 raeburn 7427: nofi => 'No file selected',
7428: tinc => 'Title in course',
7429: sunm => 'Sub-directory name',
1.618 raeburn 7430: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7431: sele => 'Select',
7432: swit => 'Switch server required',
1.329 droeschl 7433: );
1.594 damieng 7434: &js_escape(\%js_lt);
1.433 raeburn 7435: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7436: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7437: my $main_container_page;
1.519 raeburn 7438: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7439: $main_container_page = 1;
1.434 raeburn 7440: }
1.617 raeburn 7441: my $backtourl;
7442: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7443: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7444: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7445: my @ids=&Apache::lonnet::current_machine_ids();
7446: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7447: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7448: my $caller = $1;
1.525 raeburn 7449: if ($caller =~ /^supplemental/) {
7450: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7451: } else {
7452: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7453: $res = &Apache::lonnet::clutter($res);
7454: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7455: my ($url,$anchor);
7456: if ($res =~ /^([^#]+)#([^#]+)$/) {
7457: $url = $1;
7458: $anchor = $2;
7459: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7460: $caller = $1.&escape('#').$anchor;
7461: }
1.614 raeburn 7462: } else {
7463: $url = $res;
1.609 raeburn 7464: }
1.640 raeburn 7465: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7466: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7467: $backtourl .= '?navmap=1';
7468: } else {
7469: $backtourl .= '?symb='.
7470: &HTML::Entities::encode($caller,'<>&"');
7471: }
1.622 raeburn 7472: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7473: if (($ENV{'SERVER_PORT'} == 443) &&
7474: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7475: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7476: if ($hostname ne '') {
7477: $backtourl = 'http://'.$hostname.$backtourl;
7478: }
7479: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7480: }
7481: }
1.623 raeburn 7482: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7483: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7484: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7485: if ($hostname ne '') {
7486: $backtourl = 'http://'.$hostname.$backtourl;
7487: }
7488: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7489: }
1.623 raeburn 7490: }
1.622 raeburn 7491: }
1.609 raeburn 7492: if ($anchor ne '') {
7493: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7494: }
1.590 raeburn 7495: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7496: } else {
7497: $backtourl = '/adm/navmaps';
1.525 raeburn 7498: }
7499: }
7500: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7501: $backtourl = '/adm/menu';
7502: } elsif ($supplementalflag) {
1.682 raeburn 7503: if (($env{'request.role.adv'}) ||
7504: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7505: $backtourl = '/adm/supplemental';
7506: } else {
7507: $backtourl = '/adm/navmaps';
7508: }
1.525 raeburn 7509: } else {
7510: $backtourl = '/adm/navmaps';
1.472 raeburn 7511: }
7512:
1.655 raeburn 7513: my $fieldsets = "'doc'";
1.519 raeburn 7514: unless ($main_container_page) {
7515: $fieldsets .=",'ims'";
7516: }
1.655 raeburn 7517: my $extfieldsets = "'ext'";
7518: if ($posslti) {
7519: $extfieldsets .= ",'tool'";
7520: }
1.501 raeburn 7521: if ($supplementalflag) {
1.655 raeburn 7522: $fieldsets = "'suppdoc'";
7523: $extfieldsets = "'suppext'";
1.600 raeburn 7524: if ($posslti) {
1.655 raeburn 7525: $extfieldsets .= ",'supptool'";
1.600 raeburn 7526: }
1.501 raeburn 7527: }
1.655 raeburn 7528:
1.611 raeburn 7529: my $jsmakefunctions;
7530: if ($canedit) {
7531: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7532: function makenewfolder(targetform,folderseq) {
1.594 damieng 7533: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7534: if (foldername) {
1.676 raeburn 7535: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7536: targetform.submit();
7537: }
7538: }
7539:
7540: function makenewpage(targetform,folderseq) {
1.594 damieng 7541: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7542: if (pagename) {
1.676 raeburn 7543: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7544: targetform.submit();
7545: }
7546: }
7547:
7548: function makeexamupload() {
1.594 damieng 7549: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7550: if (title) {
1.329 droeschl 7551: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7552: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7553: this.document.forms.newexamupload.submit();
7554: }
7555: }
7556:
7557: function makesmppage() {
1.594 damieng 7558: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7559: if (title) {
1.329 droeschl 7560: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7561: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7562: this.document.forms.newsmppg.submit();
7563: }
7564: }
7565:
1.534 raeburn 7566: function makewebpage(type) {
1.594 damieng 7567: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7568: var formname;
7569: if (type == 'supp') {
7570: formname = this.document.forms.supwebpage;
7571: } else {
7572: formname = this.document.forms.newwebpage;
7573: }
7574: if (title) {
7575: var webpage = formname.importdetail.value;
1.675 raeburn 7576: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7577: formname.submit();
7578: }
7579: }
7580:
1.329 droeschl 7581: function makesmpproblem() {
1.594 damieng 7582: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7583: if (title) {
1.329 droeschl 7584: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7585: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7586: this.document.forms.newsmpproblem.submit();
7587: }
7588: }
7589:
7590: function makedropbox() {
1.594 damieng 7591: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7592: if (title) {
1.329 droeschl 7593: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7594: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7595: this.document.forms.newdropbox.submit();
7596: }
7597: }
7598:
7599: function makebulboard() {
1.594 damieng 7600: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7601: if (title) {
7602: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7603: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7604: this.document.forms.newbul.submit();
7605: }
7606: }
7607:
7608: function makeabout() {
1.594 damieng 7609: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7610: if (user) {
7611: var comp=new Array();
7612: comp=user.split(':');
7613: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7614: if ((comp[0]) && (comp[1])) {
7615: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7616: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7617: this.document.forms.newaboutsomeone.submit();
7618: } else {
7619: alert("$js_lt{'p_mab_alrt1'}");
7620: }
7621: } else {
7622: alert("$js_lt{'p_mab_alrt2'}");
7623: }
7624: }
7625: }
7626:
7627: function makenew(targetform) {
7628: targetform.submit();
7629: }
7630:
7631: function changename(folderpath,index,oldtitle) {
7632: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7633: if (title) {
7634: this.document.forms.renameform.markcopy.value='';
7635: this.document.forms.renameform.title.value=title;
7636: this.document.forms.renameform.cmd.value='rename_'+index;
7637: this.document.forms.renameform.folderpath.value=folderpath;
7638: this.document.forms.renameform.submit();
7639: }
7640: }
7641:
1.633 raeburn 7642: function setalias(folderpath,index) {
7643: var alias = prompt('$js_lt{"setal"}');
7644: if ((alias != null) && (alias != '')) {
7645: this.document.forms.aliasform.alias.value=alias;
7646: this.document.forms.aliasform.cmd.value='setalias_'+index;
7647: this.document.forms.aliasform.folderpath.value=folderpath;
7648: this.document.forms.aliasform.submit();
7649: }
7650: }
7651:
7652: function delalias(folderpath,index) {
7653: if (confirm('$js_lt{"delal"}')) {
7654: this.document.forms.aliasform.cmd.value='delalias_'+index;
7655: this.document.forms.aliasform.folderpath.value=folderpath;
7656: this.document.forms.aliasform.submit();
7657: }
7658: }
7659:
1.611 raeburn 7660: ENDNEWSCRIPT
7661: } else {
7662: $jsmakefunctions = <<ENDNEWSCRIPT;
7663:
7664: function makenewfolder() {
7665: alert("$js_lt{'edri'}");
7666: }
7667:
7668: function makenewpage() {
7669: alert("$js_lt{'edri'}");
7670: }
7671:
7672: function makeexamupload() {
7673: alert("$js_lt{'edri'}");
7674: }
7675:
7676: function makesmppage() {
7677: alert("$js_lt{'edri'}");
7678: }
7679:
7680: function makewebpage(type) {
7681: alert("$js_lt{'edri'}");
7682: }
7683:
7684: function makesmpproblem() {
7685: alert("$js_lt{'edri'}");
7686: }
7687:
7688: function makedropbox() {
7689: alert("$js_lt{'edri'}");
7690: }
7691:
7692: function makebulboard() {
7693: alert("$js_lt{'edri'}");
7694: }
7695:
7696: function makeabout() {
7697: alert("$js_lt{'edri'}");
7698: }
7699:
7700: function changename() {
7701: alert("$js_lt{'edri'}");
7702: }
7703:
1.633 raeburn 7704: function setalias() {
7705: alert("$js_lt{'edri'}");
7706: }
7707:
7708: function delalias() {
7709: alert("$js_lt{'edri'}");
7710: }
7711:
1.611 raeburn 7712: function makenew() {
7713: alert("$js_lt{'edri'}");
7714: }
7715:
7716: function groupimport() {
7717: alert("$js_lt{'edri'}");
1.335 ehlerst 7718: }
1.611 raeburn 7719:
7720: function groupsearch() {
7721: alert("$js_lt{'edri'}");
1.335 ehlerst 7722: }
1.611 raeburn 7723:
7724: function groupopen(url,recover) {
7725: var options="scrollbars=1,resizable=1,menubar=0";
7726: idxflag=1;
7727: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7728: idx.focus();
1.329 droeschl 7729: }
7730:
1.611 raeburn 7731: ENDNEWSCRIPT
7732:
7733: }
7734: return <<ENDSCRIPT;
7735:
7736: $jsmakefunctions
7737:
1.501 raeburn 7738: function toggleUpload(caller) {
7739: var blocks = Array($fieldsets);
7740: for (var i=0; i<blocks.length; i++) {
7741: var disp = 'none';
7742: if (caller == blocks[i]) {
7743: var curr = document.getElementById('upload'+caller+'form').style.display;
7744: if (curr == 'none') {
7745: disp='block';
7746: }
7747: }
7748: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7749: }
7750: resize_scrollbox('contentscroll','1','1');
7751: return;
7752: }
7753:
7754: function toggleExternal(caller) {
7755: var blocks = Array($extfieldsets);
7756: for (var i=0; i<blocks.length; i++) {
7757: var disp = 'none';
7758: if (caller == blocks[i]) {
7759: var curr = document.getElementById('external'+caller+'form').style.display;
7760: if (curr == 'none') {
7761: disp='block';
7762: }
7763: }
7764: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7765: if ((caller == 'tool') || (caller == 'supptool')) {
7766: if (disp == 'block') {
1.655 raeburn 7767: if (document.getElementById('LC_exttoolid')) {
7768: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7769: var suppflag = 0;
7770: if (caller == 'supptool') {
7771: suppflag = 1;
7772: }
7773: currForm = document.getElementById('new'+caller);
1.655 raeburn 7774: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7775: }
7776: }
7777: }
1.501 raeburn 7778: }
1.502 raeburn 7779: resize_scrollbox('contentscroll','1','1');
7780: return;
7781: }
7782:
1.514 raeburn 7783: function toggleMap(caller) {
1.502 raeburn 7784: var disp = 'none';
1.510 raeburn 7785: if (document.getElementById('importmapform')) {
1.514 raeburn 7786: if (caller == 'map') {
7787: var curr = document.getElementById('importmapform').style.display;
7788: if (curr == 'none') {
7789: disp='block';
7790: }
1.510 raeburn 7791: }
7792: document.getElementById('importmapform').style.display=disp;
7793: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7794: }
1.501 raeburn 7795: return;
1.329 droeschl 7796: }
7797:
1.691 raeburn 7798: function toggleCrsRes(caller) {
1.606 raeburn 7799: var disp = 'none';
7800: if (document.getElementById('crsresform')) {
7801: if (caller == 'res') {
1.691 raeburn 7802: var form = document.getElementById('crsresform');
7803: var curr = form.style.display;
1.606 raeburn 7804: if (curr == 'none') {
7805: disp='block';
1.691 raeburn 7806: document.courseresform.authorrole.selectedIndex = 0;
7807: document.courseresform.authorpath.selectedIndex = 0;
7808: document.courseresform.newresourceadd.selectedIndex = 0;
7809: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7810: toggleNewInCourse(document.courseresform);
7811: if (document.getElementById('newresource')) {
7812: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 7813: }
7814: if (document.courseresform.newresusetemp.length) {
7815: document.courseresform.newresusetemp[0].checked = true;
7816: toggleWithTemplate(document.courseresform);
7817: }
7818: document.courseresform.newresourcename.value = '';
7819: }
7820: }
7821: if (document.courseresform.newsubdir.length) {
7822: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7823: if (document.courseresform.newsubdir[j].value == 0) {
7824: document.courseresform.newsubdir[j].checked = true;
7825: }
7826: break;
7827: }
7828: if (document.getElementById('newsubdirname')) {
7829: document.getElementById('newsubdirname').type = "hidden";
7830: document.getElementById('newsubdirname').value = "";
7831: }
7832: if (document.getElementById('newsubdir')) {
7833: document.getElementById('newsubdir').innerHTML = "";
7834: }
7835: }
7836: document.getElementById('crsresform').style.display=disp;
7837: resize_scrollbox('contentscroll','1','0');
7838: }
7839: return;
7840: }
7841:
7842: function toggleNewsubdir(form) {
7843: if (form.newsubdir.length) {
7844: for (var j=0; j<form.newsubdir.length; j++) {
7845: if (form.newsubdir[j].checked) {
7846: if (document.getElementById('newsubdirname')) {
7847: if (form.newsubdir[j].value == '1') {
7848: document.getElementById('newsubdirname').type = "text";
7849: if (document.getElementById('newsubdir')) {
7850: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7851: }
7852: } else {
7853: document.getElementById('newsubdirname').type = "hidden";
7854: document.getElementById('newsubdirname').value = "";
7855: document.getElementById('newsubdir').innerHTML = "";
7856: }
7857: }
7858: break;
7859: }
7860: }
7861: }
7862: }
7863:
7864: function toggleCrsResTitle() {
7865: if (document.getElementById('newresource')) {
1.691 raeburn 7866: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7867: if (selloc == 'course') {
1.606 raeburn 7868: document.getElementById('newresource').style.display = 'inline';
7869: document.courseresform.newresourceadd[0].checked = true;
7870: toggleNewInCourse(document.courseresform);
7871: } else {
7872: document.getElementById('newresource').style.display = 'none';
7873: }
1.689 raeburn 7874: }
7875: if (document.getElementById('newstdproblem')) {
7876: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7877: document.getElementById('newstdproblem').style.display = 'none';
7878: if (document.getElementById('stdprobswitch')) {
7879: document.getElementById('stdprobswitch').style.display = 'block';
7880: }
7881: } else {
7882: document.getElementById('newstdproblem').style.display = 'block';
7883: if (document.getElementById('stdprobswitch')) {
7884: document.getElementById('stdprobswitch').style.display = 'none';
7885: }
7886: }
7887: }
1.606 raeburn 7888: }
7889:
7890: function toggleNewInCourse(form) {
7891: if (form.newresourceadd.length) {
7892: for (var i=0; i<form.newresourceadd.length; i++) {
7893: if (form.newresourceadd[i].checked) {
7894: if (document.getElementById('newresourcetitle')) {
7895: if (form.newresourceadd[i].value == '1') {
7896: document.getElementById('newresourcetitle').type = 'text';
7897: if (document.getElementById('newrestitle')) {
7898: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7899: }
7900: } else {
7901: document.getElementById('newresourcetitle').type = 'hidden';
7902: document.getElementById('newresourcetitle').value = '';
7903: if (document.getElementById('newrestitle')) {
7904: document.getElementById('newrestitle').innerHTML = '';
7905: }
7906: }
7907: }
7908: break;
7909: }
7910: }
7911: }
7912: }
7913:
7914: function toggleWithTemplate(form) {
7915: if (form.newresusetemp.length) {
7916: for (var i=0; i<form.newresusetemp.length; i++) {
7917: if (form.newresusetemp[i].checked) {
7918: if (document.getElementById('newrestemplate')) {
7919: if (form.newresusetemp[i].value == '1') {
7920: document.getElementById('newrestemplate').style.display = 'inline';
7921: toggleExampleText();
7922: } else {
7923: form.tempcategory.selectedIndex = 0;
7924: select1template_changed();
7925: document.getElementById('newrestemplate').style.display = 'none';
7926: }
7927: }
7928: }
7929: }
7930: }
7931: }
7932:
7933: function toggleExampleText() {
7934: if (document.getElementById('newresexample')) {
7935: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7936: if (url == '') {
7937: document.getElementById('newresexample').style.fontWeight = 'normal';
7938: } else {
7939: document.getElementById('newresexample').style.fontWeight = 'bold';
7940: }
7941: }
7942: }
7943:
7944: function getExample(width,height,scrolling,transparency) {
7945: var url;
7946: if (document.courseresform.newresusetemp.length) {
7947: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7948: if (document.courseresform.newresusetemp[i].checked) {
7949: if (document.courseresform.newresusetemp[i].value == '1') {
7950: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7951: if (url == '') {
7952: alert('Pick a category and template');
7953: } else {
7954: url = url.replace("$londocroot","");
7955: url += '?inhibitmenu=yes';
7956: }
7957: }
7958: break;
7959: }
7960: }
7961: }
7962: if (url != '') {
7963: openMyModal(url,width,height,scrolling,transparency,'');
7964: }
7965: }
7966:
1.690 raeburn 7967: function toggleImportCrsres(caller) {
1.606 raeburn 7968: var disp = 'none';
7969: if (document.getElementById('importcrsresform')) {
7970: if (caller == 'res') {
7971: var curr = document.getElementById('importcrsresform').style.display;
7972: if (curr == 'none') {
7973: disp='block';
1.698 ! raeburn 7974: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
! 7975: if ((document.getElementById('importcrsrescontent')) &&
! 7976: (document.getElementById('importcrsresempty'))) {
! 7977: var selelem = document.crsresimportform.elements['coursepath'];
! 7978: var numdirs = 0;
! 7979: if (selelem.options.length) {
! 7980: numdirs = selelem.options.length - 1;
! 7981: }
! 7982: if (numdirs) {
! 7983: document.getElementById('importcrsrescontent').style.display='block';
! 7984: document.getElementById('importcrsresempty').style.display='none';
! 7985: } else {
! 7986: document.getElementById('importcrsrescontent').style.display='none';
! 7987: document.getElementById('importcrsresempty').style.display='block';
! 7988: }
! 7989: }
1.606 raeburn 7990: }
7991: }
7992: document.getElementById('importcrsresform').style.display=disp;
7993: resize_scrollbox('contentscroll','1','0');
7994: }
7995: return;
7996: }
7997:
1.690 raeburn 7998: $showfile_js
7999:
1.691 raeburn 8000: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8001: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8002: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8003: var selelem = form.elements[dirsel];
8004: var i, numfiles = selelem.options.length -1;
8005: if (numfiles >=0) {
8006: for (i = numfiles; i >= 0; i--) {
8007: selelem.remove(i);
8008: }
8009: }
8010: if ((location == '') || (location == null) || (location == 'undefined')) {
8011: if (selelem.options.length == 0) {
8012: selelem.options[selelem.options.length] = new Option('','');
8013: selelem.selectedIndex = 0;
8014: }
8015: if (document.getElementById('newstdproblem')) {
8016: document.getElementById('newstdproblem').style.display = 'none';
8017: }
8018: return;
8019: }
8020: var machineIds = new Array($machines_str);
8021: var athome = 0;
8022: var role = location;
8023: if ((location == 'author') || (location == 'course')) {
8024: if (document.getElementById('rolehome_'+location)) {
8025: var currhome = document.getElementById('rolehome_'+location).value;
8026: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8027: if (machineIds.includes(currhome)) {
8028: athome = 1;
8029: }
8030: }
8031: }
8032: } else {
8033: const roleinfo = location.split('___');
8034: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8035: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8036: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8037: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8038: if (machineIds.includes(currhome)) {
8039: athome = 1;
8040: }
8041: }
8042: }
8043: }
8044: if (athome) {
8045: if (document.getElementById('stdprobswitch')) {
8046: document.getElementById('stdprobswitch').style.display = 'none';
8047: }
8048: if (document.getElementById('newstdproblem')) {
8049: document.getElementById('newstdproblem').style.display = 'none';
8050: }
8051: var http = new XMLHttpRequest();
8052: var url = "/adm/courseauthor";
1.698 ! raeburn 8053: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8054: http.open("POST", url, true);
8055: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8056: http.onreadystatechange = function() {
8057: if (http.readyState == 4 && http.status == 200) {
8058: var data = JSON.parse(http.responseText);
8059: if (Array.isArray(data.dirs)) {
8060: var len = data.dirs.length;
8061: if (len) {
8062: if (len > 1) {
8063: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8064: }
8065: }
8066: if (len) {
8067: var j;
8068: for (j = 0; j < len; j++) {
8069: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8070: }
8071: selelem.selectedIndex = 0;
1.697 raeburn 8072: if (len == 1) {
8073: toggleCrsResTitle();
8074: }
1.691 raeburn 8075: }
8076: }
8077: }
8078: }
8079: http.send(params);
8080: } else {
8081: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8082: selelem.selectedIndex = 0;
8083: if (document.getElementById('stdprobswitch')) {
8084: document.getElementById('stdprobswitch').style.display = 'block';
8085: }
8086: if (document.getElementById('newstdproblem')) {
8087: document.getElementById('newstdproblem').style.display = 'none';
8088: }
8089: }
8090: }
8091: return;
8092: }
8093:
1.689 raeburn 8094: function switchForProb() {
8095: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8096: var url = '/adm/switchserver?otherserver=';
8097: var newhostid = '';
8098: var role = '';
8099: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8100: if (selloc == 'author') {
8101: newhostid = document.courseresform.rolehome_author.value;
8102: role = "au./&js_escape($env{'user.domain'})/";
8103: } else if (selloc == 'course') {
8104: newhostid = document.courseresform.rolehome_course.value;
8105: role = "&js_escape($env{'request.role'})";
8106: } else {
8107: var items = new Array();
8108: items = selloc.split('___');
8109: var len = document.courseresform.rolehome_coauthor.length;
8110: if (null == len) {
8111: var currval = document.courseresform.rolehome_coauthor.value;
8112: if (null != currval) {
8113: var info = new Array();
8114: info = currval.split('=');
8115: newhostid = info[2];
8116: role = info[0]+'./'+info[1];
8117: }
8118: } else {
8119: for (var i=0; i<len; i++) {
8120: var currval = document.courseresform.rolehome_coauthor[i].value;
8121: if (null != currval) {
8122: var info = new Array();
8123: info = currval.split('=');
8124: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8125: newhostid = info[2];
8126: role = info[0]+'./'+info[1];
8127: break;
8128: }
8129: }
8130: }
8131: }
8132: }
8133: if (newhostid != '') {
8134: url += newhostid;
8135: if (role != '') {
8136: url += '&role='+role;
8137: }
8138: document.location.href = url;
8139: }
8140: }
8141: return;
8142: }
8143:
1.501 raeburn 8144: function makeims(imsform) {
8145: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8146: alert("$js_lt{'imsfile'}");
1.501 raeburn 8147: return;
8148: }
8149: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8150: alert("$js_lt{'imscms'}");
1.501 raeburn 8151: return;
8152: }
8153: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8154: imsform.submit();
8155: }
8156:
1.478 raeburn 8157: function updatePick(targetform,index,caller) {
1.537 raeburn 8158: var pickitem;
8159: var picknumitem;
8160: var picknumtext;
8161: if (index == 'all') {
8162: pickitem = document.getElementById('randompickall');
8163: picknumitem = document.getElementById('rpicknumall');
8164: picknumtext = document.getElementById('rpicktextall');
8165: } else {
8166: pickitem = document.getElementById('randompick_'+index);
8167: picknumitem = document.getElementById('rpicknum_'+index);
8168: picknumtext = document.getElementById('randompicknum_'+index);
8169: }
1.478 raeburn 8170: if (pickitem.checked) {
1.594 damieng 8171: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8172: if (picknum == '' || picknum == null) {
8173: if (caller == 'check') {
8174: pickitem.checked=false;
1.537 raeburn 8175: if (index == 'all') {
8176: picknumtext.innerHTML = '';
8177: if (caller == 'link') {
8178: propagateState(targetform,'rpicknum');
8179: }
8180: } else {
1.538 raeburn 8181: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8182: }
1.478 raeburn 8183: }
8184: } else {
8185: picknum.toString();
8186: var regexdigit=/^\\d+\$/;
8187: if (regexdigit.test(picknum)) {
8188: picknumitem.value = picknum;
1.537 raeburn 8189: if (index == 'all') {
1.538 raeburn 8190: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8191: if (caller == 'link') {
8192: propagateState(targetform,'rpicknum');
8193: }
8194: } else {
8195: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8196: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8197: }
1.478 raeburn 8198: } else {
8199: if (caller == 'check') {
1.537 raeburn 8200: if (index == 'all') {
8201: picknumtext.innerHTML = '';
8202: if (caller == 'link') {
8203: propagateState(targetform,'rpicknum');
8204: }
8205: } else {
8206: pickitem.checked=false;
1.538 raeburn 8207: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8208: }
1.478 raeburn 8209: }
8210: return;
8211: }
8212: }
8213: } else {
1.537 raeburn 8214: picknumitem.value = '';
8215: picknumtext.innerHTML = '';
8216: if (index == 'all') {
8217: if (caller == 'link') {
8218: propagateState(targetform,'rpicknum');
8219: }
8220: } else {
1.538 raeburn 8221: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8222: }
8223: }
8224: }
8225:
8226: function propagateState(form,param) {
8227: if (document.getElementById(param+'all')) {
8228: var setcheck = 0;
8229: var rpick = 0;
8230: if (param == 'rpicknum') {
8231: if (document.getElementById('randompickall')) {
8232: if (document.getElementById('randompickall').checked) {
8233: if (document.getElementById('rpicknumall')) {
8234: rpick = document.getElementById('rpicknumall').value;
8235: }
8236: }
8237: }
8238: } else {
8239: if (document.getElementById(param+'all').checked) {
8240: setcheck = 1;
8241: }
8242: }
1.538 raeburn 8243: var allidxlist;
8244: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8245: if (document.getElementById('all'+param+'idx')) {
8246: allidxlist = document.getElementById('all'+param+'idx').value;
8247: }
8248: var actions = new Array ('remove','cut','copy');
8249: for (var i=0; i<actions.length; i++) {
8250: if (actions[i] != param) {
8251: if (document.getElementById(actions[i]+'all')) {
8252: document.getElementById(actions[i]+'all').checked = false;
8253: }
8254: }
8255: }
8256: }
1.537 raeburn 8257: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8258: allidxlist = form.allidx.value;
8259: }
8260: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8261: allidxlist = form.allmapidx.value;
8262: }
8263: if ((allidxlist != '') && (allidxlist != null)) {
8264: var allidxs = allidxlist.split(',');
8265: if (allidxs.length > 1) {
8266: for (var i=0; i<allidxs.length; i++) {
8267: if (document.getElementById(param+'_'+allidxs[i])) {
8268: if (param == 'rpicknum') {
8269: if (document.getElementById('randompick_'+allidxs[i])) {
8270: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8271: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8272: if (rpick > 0) {
8273: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8274: } else {
8275: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8276: }
8277: }
8278: }
8279: } else {
1.537 raeburn 8280: if (setcheck == 1) {
8281: document.getElementById(param+'_'+allidxs[i]).checked = true;
8282: } else {
8283: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8284: if (param == 'randompick') {
8285: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8286: }
1.537 raeburn 8287: }
8288: }
8289: }
8290: }
1.538 raeburn 8291: if (setcheck == 1) {
8292: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8293: var actions = new Array('copy','cut','remove');
8294: for (var i=0; i<actions.length; i++) {
8295: var otheractions;
8296: var otheridxs;
8297: if (actions[i] === param) {
8298: continue;
8299: } else {
8300: if (document.getElementById('all'+actions[i]+'idx')) {
8301: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8302: otheridxs = otheractions.split(',');
8303: if (otheridxs.length > 1) {
8304: for (var j=0; j<otheridxs.length; j++) {
8305: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8306: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8307: }
1.537 raeburn 8308: }
8309: }
8310: }
1.538 raeburn 8311: }
8312: }
8313: }
8314: }
8315: }
8316: }
8317: }
8318: return;
8319: }
8320:
1.603 raeburn 8321: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8322: var canedit = '$canedit';
8323: if (canedit == '') {
8324: alert("$js_lt{'edri'}");
8325: return;
8326: }
1.539 raeburn 8327: var dosettings;
8328: var doaction;
1.538 raeburn 8329: var control = document.togglemultsettings;
8330: if (context == 'actions') {
8331: control = document.togglemultactions;
1.539 raeburn 8332: doaction = 1;
8333: } else {
8334: dosettings = 1;
1.538 raeburn 8335: }
1.539 raeburn 8336: if (control) {
8337: if (control.showmultpick.length) {
8338: for (var i=0; i<control.showmultpick.length; i++) {
8339: if (control.showmultpick[i].checked) {
8340: if (control.showmultpick[i].value == 1) {
8341: if (context == 'settings') {
8342: dosettings = 0;
8343: } else {
8344: doaction = 0;
1.538 raeburn 8345: }
8346: }
8347: }
1.537 raeburn 8348: }
8349: }
1.539 raeburn 8350: }
8351: if (context == 'settings') {
8352: if (dosettings == 1) {
1.538 raeburn 8353: targetform.changeparms.value=param;
8354: targetform.submit();
8355: }
1.537 raeburn 8356: }
1.539 raeburn 8357: if (context == 'actions') {
8358: if (doaction == 1) {
8359: targetform.cmd.value=param+'_'+index;
8360: targetform.folderpath.value=folderpath;
8361: targetform.markcopy.value=idx+':'+param;
8362: targetform.copyfolder.value=folder+'.'+container;
8363: if (param == 'remove') {
1.603 raeburn 8364: var doremove = 0;
8365: if (skip_confirm) {
8366: if (confirm_removal) {
8367: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8368: doremove = 1;
8369: }
8370: } else {
8371: doremove = 1;
8372: }
8373: } else {
8374: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8375: doremove = 1;
8376: }
8377: }
8378: if (doremove) {
1.539 raeburn 8379: targetform.markcopy.value='';
8380: targetform.copyfolder.value='';
8381: targetform.submit();
8382: }
8383: }
8384: if (param == 'cut') {
1.594 damieng 8385: 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 8386: targetform.submit();
8387: return;
8388: }
8389: }
8390: if (param == 'copy') {
8391: targetform.submit();
8392: return;
8393: }
8394: targetform.markcopy.value='';
8395: targetform.copyfolder.value='';
8396: targetform.cmd.value='';
8397: targetform.folderpath.value='';
8398: return;
8399: } else {
8400: if (document.getElementById(param+'_'+idx)) {
8401: item = document.getElementById(param+'_'+idx);
8402: if (item.type == 'checkbox') {
8403: if (item.checked) {
8404: item.checked = false;
8405: } else {
8406: item.checked = true;
8407: singleCheck(item,idx,param);
8408: }
8409: }
8410: }
8411: }
8412: }
1.537 raeburn 8413: return;
8414: }
8415:
1.538 raeburn 8416: function singleCheck(caller,idx,action) {
8417: actions = new Array('cut','copy','remove');
8418: if (caller.checked) {
8419: for (var i=0; i<actions.length; i++) {
8420: if (actions[i] != action) {
8421: if (document.getElementById(actions[i]+'_'+idx)) {
8422: if (document.getElementById(actions[i]+'_'+idx).checked) {
8423: document.getElementById(actions[i]+'_'+idx).checked = false;
8424: }
1.537 raeburn 8425: }
8426: }
8427: }
1.478 raeburn 8428: }
1.537 raeburn 8429: return;
1.478 raeburn 8430: }
8431:
1.334 muellerd 8432: function unselectInactive(nav) {
1.335 ehlerst 8433: currentNav = document.getElementById(nav);
8434: currentLis = currentNav.getElementsByTagName('LI');
8435: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8436: if (currentLis[i].className == 'goback') {
8437: currentLis[i].className = 'goback';
8438: } else {
8439: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8440: currentLis[i].className = 'right';
1.472 raeburn 8441: } else {
1.374 tempelho 8442: currentLis[i].className = 'i';
1.472 raeburn 8443: }
8444: }
1.335 ehlerst 8445: }
1.332 tempelho 8446: }
8447:
1.334 muellerd 8448: function hideAll(current, nav, data) {
1.335 ehlerst 8449: unselectInactive(nav);
1.570 raeburn 8450: if (current) {
8451: if (current.className == 'right'){
8452: current.className = 'right active'
8453: } else {
8454: current.className = 'active';
8455: }
1.374 tempelho 8456: }
1.335 ehlerst 8457: currentData = document.getElementById(data);
8458: currentDivs = currentData.getElementsByTagName('DIV');
8459: for (i = 0; i < currentDivs.length; i++) {
8460: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8461: currentDivs[i].style.display = 'none';
1.330 tempelho 8462: }
8463: }
1.335 ehlerst 8464: }
1.330 tempelho 8465:
1.374 tempelho 8466: function openTabs(pageId) {
8467: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8468: if(tabnav.length > 2 ){
1.389 tempelho 8469: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8470: currentLis = currentNav.getElementsByTagName('LI');
8471: for(i = 0; i< currentLis.length; i++){
8472: if(currentLis[i].className == 'active') {
1.375 tempelho 8473: funcString = currentLis[i].onclick.toString();
8474: tab = funcString.split('"');
1.420 onken 8475: if(tab.length < 2) {
8476: tab = funcString.split("'");
8477: }
1.375 tempelho 8478: currentData = document.getElementById(tab[1]);
8479: currentData.style.display = 'block';
1.374 tempelho 8480: }
8481: }
8482: }
8483: }
8484:
1.334 muellerd 8485: function showPage(current, pageId, nav, data) {
1.570 raeburn 8486: currstate = current.className;
1.334 muellerd 8487: hideAll(current, nav, data);
1.375 tempelho 8488: openTabs(pageId);
1.334 muellerd 8489: unselectInactive(nav);
1.570 raeburn 8490: if ((currstate == 'active') || (currstate == 'right active')) {
8491: if (currstate == 'active') {
8492: current.className = '';
8493: } else {
8494: current.className = 'right';
8495: }
8496: activeTab = '';
1.656 raeburn 8497: toggleExternal();
1.570 raeburn 8498: toggleUpload();
8499: toggleMap();
1.606 raeburn 8500: toggleCrsRes();
8501: toggleImportCrsres();
1.570 raeburn 8502: resize_scrollbox('contentscroll','1','0');
8503: return;
8504: } else {
8505: current.className = 'active';
8506: }
1.330 tempelho 8507: currentData = document.getElementById(pageId);
8508: currentData.style.display = 'block';
1.458 raeburn 8509: activeTab = pageId;
1.656 raeburn 8510: toggleExternal();
1.501 raeburn 8511: toggleUpload();
1.503 raeburn 8512: toggleMap();
1.606 raeburn 8513: toggleCrsRes();
8514: toggleImportCrsres();
1.433 raeburn 8515: if (nav == 'mainnav') {
8516: var storedpath = "$docs_folderpath";
1.434 raeburn 8517: var storedpage = "$main_container_page";
1.433 raeburn 8518: var reg = new RegExp("^supplemental");
8519: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8520: if (storedpage == 1) {
8521: document.simpleedit.folderpath.value = '';
8522: document.uploaddocument.folderpath.value = '';
8523: } else {
8524: if (reg.test(storedpath)) {
8525: document.simpleedit.folderpath.value = '$toplevelmain';
8526: document.uploaddocument.folderpath.value = '$toplevelmain';
8527: document.newext.folderpath.value = '$toplevelmain';
8528: } else {
8529: document.simpleedit.folderpath.value = storedpath;
8530: document.uploaddocument.folderpath.value = storedpath;
8531: document.newext.folderpath.value = storedpath;
8532: }
1.433 raeburn 8533: }
8534: } else {
1.434 raeburn 8535: if (reg.test(storedpath)) {
8536: document.simpleedit.folderpath.value = storedpath;
8537: document.supuploaddocument.folderpath.value = storedpath;
8538: document.supnewext.folderpath.value = storedpath;
8539: } else {
1.433 raeburn 8540: document.simpleedit.folderpath.value = '$toplevelsupp';
8541: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8542: document.supnewext.folderpath.value = '$toplevelsupp';
8543: }
8544: }
8545: }
1.485 raeburn 8546: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8547: return false;
8548: }
1.329 droeschl 8549:
1.472 raeburn 8550: function toContents(jumpto) {
8551: var newurl = '$backtourl';
1.525 raeburn 8552: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8553: newurl = newurl+'?postdata='+jumpto;
8554: }
8555: location.href=newurl;
8556: }
8557:
1.538 raeburn 8558: function togglePick(caller,value) {
8559: var disp = 'none';
8560: if (document.getElementById('multi'+caller)) {
8561: var curr = document.getElementById('multi'+caller).style.display;
8562: if (value == 1) {
8563: disp='block';
8564: }
8565: if (curr == disp) {
8566: return;
8567: }
8568: document.getElementById('multi'+caller).style.display=disp;
8569: if (value == 1) {
1.594 damieng 8570: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8571: } else {
8572: document.getElementById('more'+caller).innerHTML = '';
8573: }
8574: if (caller == 'actions') {
8575: setClass(value);
8576: setBoxes(value);
8577: }
8578: }
8579: var showButton = multiSettings();
8580: if (showButton != 1) {
8581: showButton = multiActions();
8582: }
8583: if (document.getElementById('multisave')) {
8584: if (showButton == 1) {
8585: document.getElementById('multisave').style.display='block';
8586: } else {
8587: document.getElementById('multisave').style.display='none';
8588: }
8589: }
8590: resize_scrollbox('contentscroll','1','1');
8591: return;
8592: }
8593:
8594: function toggleCheckUncheck(caller,more) {
8595: if (more == 1) {
1.594 damieng 8596: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8597: document.getElementById('allfields'+caller).style.display='block';
8598: } else {
1.594 damieng 8599: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8600: document.getElementById('allfields'+caller).style.display='none';
8601: }
8602: resize_scrollbox('contentscroll','1','1');
8603: }
8604:
8605: function multiSettings() {
8606: var inuse = 0;
8607: var settingsform = document.togglemultsettings;
8608: if (settingsform.showmultpick.length > 1) {
8609: for (var i=0; i<settingsform.showmultpick.length; i++) {
8610: if (settingsform.showmultpick[i].checked) {
8611: if (settingsform.showmultpick[i].value == 1) {
8612: inuse = 1;
8613: }
8614: }
8615: }
8616: }
8617: return inuse;
8618: }
8619:
8620: function multiActions() {
8621: var inuse = 0;
8622: var actionsform = document.togglemultactions;
8623: if (actionsform.showmultpick.length > 1) {
8624: for (var i=0; i<actionsform.showmultpick.length; i++) {
8625: if (actionsform.showmultpick[i].checked) {
8626: if (actionsform.showmultpick[i].value == 1) {
8627: inuse = 1;
8628: }
8629: }
8630: }
8631: }
8632: return inuse;
8633: }
8634:
8635: function checkSubmits() {
8636: var numchanges = 0;
8637: var form = document.saveactions;
8638: var doactions = multiActions();
1.542 raeburn 8639: var cutwarnings = 0;
8640: var remwarnings = 0;
1.603 raeburn 8641: var removalinfo = 0;
1.538 raeburn 8642: if (doactions == 1) {
8643: var remidxlist = document.cumulativeactions.allremoveidx.value;
8644: if ((remidxlist != '') && (remidxlist != null)) {
8645: var remidxs = remidxlist.split(',');
8646: for (var i=0; i<remidxs.length; i++) {
8647: if (document.getElementById('remove_'+remidxs[i])) {
8648: if (document.getElementById('remove_'+remidxs[i]).checked) {
8649: form.multiremove.value += remidxs[i]+',';
8650: numchanges ++;
1.542 raeburn 8651: if (document.getElementById('skip_remove_'+remidxs[i])) {
8652: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8653: remwarnings ++;
8654: }
8655: }
1.603 raeburn 8656: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8657: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8658: removalinfo ++;
8659: }
8660: }
1.537 raeburn 8661: }
8662: }
1.538 raeburn 8663: }
8664: }
8665: var cutidxlist = document.cumulativeactions.allcutidx.value;
8666: if ((cutidxlist != '') && (cutidxlist != null)) {
8667: var cutidxs = cutidxlist.split(',');
8668: for (var i=0; i<cutidxs.length; i++) {
8669: if (document.getElementById('cut_'+cutidxs[i])) {
8670: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8671: form.multicut.value += cutidxs[i]+',';
8672: numchanges ++;
1.542 raeburn 8673: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8674: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8675: cutwarnings ++;
8676: }
8677: }
1.537 raeburn 8678: }
8679: }
8680: }
8681: }
1.538 raeburn 8682: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8683: if ((copyidxlist != '') && (copyidxlist != null)) {
8684: var copyidxs = copyidxlist.split(',');
8685: for (var i=0; i<copyidxs.length; i++) {
8686: if (document.getElementById('copy_'+copyidxs[i])) {
8687: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8688: form.multicopy.value += copyidxs[i]+',';
8689: numchanges ++;
8690: }
8691: }
8692: }
8693: }
8694: if (numchanges > 0) {
8695: form.multichange.value = numchanges;
8696: }
1.537 raeburn 8697: }
1.538 raeburn 8698: var dosettings = multiSettings();
1.543 raeburn 8699: var haschanges = 0;
1.538 raeburn 8700: if (dosettings == 1) {
8701: form.allencrypturl.value = '';
8702: form.allhiddenresource.value = '';
1.543 raeburn 8703: form.changeparms.value = 'all';
8704: var patt=new RegExp(",\$");
1.538 raeburn 8705: var allidxlist = document.cumulativesettings.allidx.value;
8706: if ((allidxlist != '') && (allidxlist != null)) {
8707: var allidxs = allidxlist.split(',');
8708: if (allidxs.length > 1) {
8709: for (var i=0; i<allidxs.length; i++) {
8710: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8711: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8712: form.allhiddenresource.value += allidxs[i]+',';
8713: }
8714: }
8715: if (document.getElementById('encrypturl_'+allidxs[i])) {
8716: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8717: form.allencrypturl.value += allidxs[i]+',';
8718: }
8719: }
8720: }
1.543 raeburn 8721: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8722: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8723: }
1.538 raeburn 8724: }
8725: form.allrandompick.value = '';
8726: form.allrandomorder.value = '';
8727: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8728: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8729: var allmapidxs = allmapidxlist.split(',');
8730: for (var i=0; i<allmapidxs.length; i++) {
8731: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8732: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8733: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8734: if ((randompick.checked) && (rpicknum.value != '')) {
8735: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8736: }
8737: if (randorder.checked) {
8738: form.allrandomorder.value += allmapidxs[i]+',';
8739: }
1.537 raeburn 8740: }
1.543 raeburn 8741: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8742: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8743: }
8744: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8745: haschanges = 1;
8746: }
8747: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8748: haschanges = 1;
8749: }
8750: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8751: haschanges = 1;
8752: }
8753: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8754: haschanges = 1;
1.537 raeburn 8755: }
8756: }
1.543 raeburn 8757: if (doactions == 1) {
1.542 raeburn 8758: if (numchanges > 0) {
1.603 raeburn 8759: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8760: if (remwarnings > 0) {
1.594 damieng 8761: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8762: return false;
8763: }
8764: }
1.603 raeburn 8765: if (removalinfo > 0) {
8766: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8767: return false;
8768: }
8769: }
1.542 raeburn 8770: if (cutwarnings > 0) {
1.594 damieng 8771: 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 8772: return false;
8773: }
8774: }
8775: }
8776: form.submit();
8777: return true;
1.543 raeburn 8778: }
8779: }
8780: if (dosettings == 1) {
8781: if (haschanges == 1) {
1.542 raeburn 8782: form.submit();
8783: return true;
8784: }
1.543 raeburn 8785: }
8786: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8787: alert("$js_lt{'noor'}");
1.543 raeburn 8788: } else {
8789: if (dosettings == 1) {
1.594 damieng 8790: alert("$js_lt{'noch'}");
1.543 raeburn 8791: } else {
1.594 damieng 8792: alert("$js_lt{'noac'}");
1.543 raeburn 8793: }
8794: }
1.538 raeburn 8795: return false;
8796: }
8797:
8798: function setClass(value) {
8799: var cutclass = 'LC_docs_cut';
8800: var copyclass = 'LC_docs_copy';
8801: var removeclass = 'LC_docs_remove';
8802: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8803: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8804: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8805: var links = document.getElementsByTagName('a');
8806: for (var i=0; i<links.length; i++) {
8807: var classes = links[i].className;
8808: if (cutreg.test(classes)) {
8809: links[i].className = cutclass;
8810: if (value == 1) {
8811: links[i].className += " LC_menubuttons_link";
8812: }
8813: } else {
8814: if (copyreg.test(classes)) {
8815: links[i].className = copyclass;
8816: if (value == 1) {
8817: links[i].className += " LC_menubuttons_link";
8818: }
8819: } else {
8820: if (removereg.test(classes)) {
8821: links[i].className = removeclass;
8822: if (value == 1) {
8823: links[i].className += " LC_menubuttons_link";
8824: }
8825: }
8826: }
8827: }
8828: }
8829: return;
1.537 raeburn 8830: }
8831:
1.538 raeburn 8832: function setBoxes(value) {
8833: var remidxlist = document.cumulativeactions.allremoveidx.value;
8834: if ((remidxlist != '') && (remidxlist != null)) {
8835: var remidxs = remidxlist.split(',');
8836: for (var i=0; i<remidxs.length; i++) {
8837: if (document.getElementById('remove_'+remidxs[i])) {
8838: var item = document.getElementById('remove_'+remidxs[i]);
8839: if (value == 1) {
8840: item.className = 'LC_docs_remove';
8841: } else {
8842: item.className = 'LC_hidden';
8843: }
8844: }
8845: }
8846: }
8847: var cutidxlist = document.cumulativeactions.allcutidx.value;
8848: if ((cutidxlist != '') && (cutidxlist != null)) {
8849: var cutidxs = cutidxlist.split(',');
8850: for (var i=0; i<cutidxs.length; i++) {
8851: if (document.getElementById('cut_'+cutidxs[i])) {
8852: var item = document.getElementById('cut_'+cutidxs[i]);
8853: if (value == 1) {
8854: item.className = 'LC_docs_cut';
8855: } else {
8856: item.className = 'LC_hidden';
8857: }
8858: }
1.537 raeburn 8859: }
8860: }
1.538 raeburn 8861: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8862: if ((copyidxlist != '') && (copyidxlist != null)) {
8863: var copyidxs = copyidxlist.split(',');
8864: for (var i=0; i<copyidxs.length; i++) {
8865: if (document.getElementById('copy_'+copyidxs[i])) {
8866: var item = document.getElementById('copy_'+copyidxs[i]);
8867: if (value == 1) {
8868: item.className = 'LC_docs_copy';
8869: } else {
8870: item.className = 'LC_hidden';
8871: }
8872: }
1.537 raeburn 8873: }
8874: }
8875: return;
8876: }
8877:
1.606 raeburn 8878: function validImportCrsRes() {
8879: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8880: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8881: if ((fname == '') || (fname == null)) {
8882: alert("$js_lt{'nofi'}");
8883: return false;
8884: }
8885: var url = '/res/$coursedom/$coursenum/';
8886: if (path && path != '/') {
8887: url += path+'/';
8888: }
8889: if (fname != '') {
8890: url += fname;
8891: }
8892: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8893: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8894: return true;
8895: }
8896:
8897: function validateNewRes(caller) {
8898: if (caller == 'single') {
8899: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8900: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8901: var resname = document.courseresform.newresourcename.value;
8902: }
8903: }
8904:
1.611 raeburn 8905: ENDSCRIPT
1.329 droeschl 8906: }
1.457 raeburn 8907:
1.483 raeburn 8908: sub history_tab_js {
8909: return <<"ENDHIST";
8910: function toggleHistoryDisp(choice) {
8911: document.docslogform.docslog.value = choice;
8912: document.docslogform.submit();
8913: return;
8914: }
8915:
8916: ENDHIST
8917: }
8918:
1.484 raeburn 8919: sub inject_data_js {
8920: return <<ENDINJECT;
8921:
8922: function injectData(current, hiddenField, name, value) {
8923: currentElement = document.getElementById(hiddenField);
8924: currentElement.name = name;
8925: currentElement.value = value;
8926: current.submit();
8927: }
8928:
8929: ENDINJECT
8930: }
8931:
8932: sub dump_switchserver_js {
8933: my @hosts = @_;
1.594 damieng 8934: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8935: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8936: swit => 'Switch server?',
1.594 damieng 8937: );
8938: my %html_js_lt = &Apache::lonlocal::texthash(
8939: swit => 'Switch server?',
1.568 raeburn 8940: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8941: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8942: chos => 'Choose server',
8943: );
1.594 damieng 8944: &js_escape(\%js_lt);
8945: &html_escape(\%html_js_lt);
8946: &js_escape(\%html_js_lt);
1.484 raeburn 8947: my $role = $env{'request.role'};
8948: my $js = <<"ENDSWJS";
8949: <script type="text/javascript">
8950: function write_switchserver() {
8951: var server;
8952: if (document.setserver.posshosts.length > 0) {
8953: for (var i=0; i<document.setserver.posshosts.length; i++) {
8954: if (document.setserver.posshosts[i].checked) {
8955: server = document.setserver.posshosts[i].value;
8956: }
8957: }
8958: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8959: }
8960: window.close();
8961: }
8962: </script>
8963:
8964: ENDSWJS
8965:
8966: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8967: {'only_body' => 1,
8968: 'js_ready' => 1,});
8969: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8970:
8971: my $hostpicker;
8972: my $count = 0;
8973: foreach my $host (sort(@hosts)) {
8974: my $checked;
8975: if ($count == 0) {
8976: $checked = ' checked="checked"';
8977: }
8978: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8979: $host.'"'.$checked.' />'.$host.'</label> ';
8980: $count++;
8981: }
8982:
8983: return <<"ENDSWITCHJS";
8984:
8985: function dump_needs_switchserver(url) {
8986: if (url!='' && url!= null) {
1.594 damieng 8987: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8988: go(url);
8989: }
8990: }
8991: return;
8992: }
8993:
8994: function choose_switchserver_window() {
8995: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8996: newWindow.document.open();
8997: newWindow.document.writeln('$startpage');
1.594 damieng 8998: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8999: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9000: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9001: '<form name="setserver" method="post" action="" \\/>\\n'+
9002: '$hostpicker\\n'+
9003: '<br \\/><br \\/>\\n'+
1.594 damieng 9004: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9005: 'onclick="write_switchserver();" \\/>\\n'+
9006: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9007: newWindow.document.writeln('$endpage');
9008: newWindow.document.close();
9009: newWindow.focus();
9010: }
9011:
9012: ENDSWITCHJS
9013: }
9014:
9015: sub makedocslogform {
9016: my ($formelems,$docslog) = @_;
9017: return <<"LOGSFORM";
9018: <form action="/adm/coursedocs" method="post" name="docslogform">
9019: <input type="hidden" name="docslog" value="$docslog" />
9020: $formelems
9021: </form>
9022: LOGSFORM
9023: }
9024:
9025: sub makesimpleeditform {
9026: my ($formelems) = @_;
9027: return <<"SIMPFORM";
9028: <form name="simpleedit" method="post" action="/adm/coursedocs">
9029: <input type="hidden" name="importdetail" value="" />
9030: $formelems
9031: </form>
9032: SIMPFORM
9033: }
9034:
1.606 raeburn 9035: sub makenewproblem {
9036: my ($r,$coursedom,$coursenum) = @_;
9037: # Creating a new problem
9038: my ($redirect,$error);
9039: if ($env{'form.authorrole'}) {
9040: my ($newsubdir,$filename);
9041: if ($env{'form.newsubdir'}) {
9042: if ($env{'form.newsubdirname'} ne '') {
9043: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9044: }
1.606 raeburn 9045: }
9046: if ($env{'form.newresourcename'}) {
9047: $filename = $env{'form.newresourcename'};
9048: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9049: $filename =~ s/`//g;
9050: $filename =~ s{/\.\./}{_}g;
9051: $filename =~ s/\.+/./g;
9052: $filename =~ s{/+}{_}g;
9053: if ($filename ne '') {
9054: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9055: if (($ext) && ($ext ne '.problem')) {
9056: $filename = $name.'.problem';
9057: } elsif ($ext eq '') {
9058: $filename .= '.problem';
9059: }
9060: my $docroot = $r->dir_config('lonDocRoot');
9061: my @ids=&Apache::lonnet::current_machine_ids();
9062: if ($env{'form.authorrole'} eq 'author') {
9063: if ($env{'user.author'}) {
9064: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9065: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9066: my $path = $docroot.$url;
9067: my $subdir = $env{'form.authorpath'};
9068: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9069: }
9070: }
9071: } elsif ($env{'form.authorrole'} eq 'course') {
9072: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9073: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9074: my $url = "/priv/$coursedom/$coursenum";
9075: my $path=$docroot.$url;
9076: my $subdir = $env{'form.authorpath'};
9077: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9078: if ($redirect) {
9079: my $rightsfile = 'default.rights';
9080: my $sourcerights = "$path/$rightsfile";
9081: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9082: my $now = time;
9083: if (!-e $sourcerights) {
9084: my $cid = $coursedom.'_'.$coursenum;
9085: if (open(my $fh,">$sourcerights")) {
9086: print $fh <<END;
9087: <accessrule effect="deny" realm="" type="course" role="" />
9088: <accessrule effect="allow" realm="$cid" type="course" role="" />
9089: END
9090: close($fh);
9091: }
9092: }
9093: if (!-e "$sourcerights.meta") {
9094: if (open(my $fh,">$sourcerights.meta")) {
9095: my $author=$env{'environment.firstname'}.' '.
9096: $env{'environment.middlename'}.' '.
9097: $env{'environment.lastname'}.' '.
9098: $env{'environment.generation'};
9099: $author =~ s/\s+$//;
9100: print $fh <<"END";
9101:
9102: <abstract></abstract>
9103: <author>$author</author>
9104: <authorspace>$coursenum:$coursedom</authorspace>
9105: <copyright>private</copyright>
9106: <creationdate>$now</creationdate>
9107: <customdistributionfile></customdistributionfile>
9108: <dependencies></dependencies>
9109: <domain>$coursedom</domain>
9110: <highestgradelevel>0</highestgradelevel>
9111: <keywords></keywords>
9112: <language>notset </language>
9113: <lastrevisiondate>$now</lastrevisiondate>
9114: <lowestgradelevel>0</lowestgradelevel>
9115: <mime>rights</mime>
9116: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9117: <notes></notes>
9118: <obsolete></obsolete>
9119: <obsoletereplacement></obsoletereplacement>
9120: <owner>$coursenum:$coursedom</owner>
9121: <rule>deny:::course,allow:$cid::course</rule>
9122: <sourceavail></sourceavail>
9123: <standards></standards>
9124: <subject></subject>
9125: <title></title>
9126: END
1.654 raeburn 9127: close($fh);
9128: }
9129: }
9130: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9131: if (!-e "$docroot/res/$coursedom") {
9132: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9133: }
1.654 raeburn 9134: if (!-e "$docroot/res/$coursedom/$coursenum") {
9135: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9136: }
9137: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9138: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9139: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9140: }
9141: }
1.654 raeburn 9142: my $source = $docroot.$redirect;
9143: if (!-e "$source.meta") {
9144: my $cid = $coursedom.'_'.$coursenum;
9145: my $now = time;
9146: if (open(my $fh,">$source.meta")) {
9147: my $author=$env{'environment.firstname'}.' '.
9148: $env{'environment.middlename'}.' '.
9149: $env{'environment.lastname'}.' '.
9150: $env{'environment.generation'};
9151: $author =~ s/\s+$//;
9152: my $title = $env{'form.newresourcetitle'};
9153: $title =~ s/^\s+|\s+$//g;
9154: print $fh <<END;
1.606 raeburn 9155:
9156: <abstract></abstract>
9157: <author>$author</author>
9158: <authorspace>$coursenum:$coursedom</authorspace>
9159: <copyright>custom</copyright>
9160: <creationdate>$now</creationdate>
9161: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9162: <dependencies></dependencies>
9163: <domain>$coursedom</domain>
9164: <highestgradelevel>0</highestgradelevel>
9165: <keywords></keywords>
9166: <language>notset </language>
9167: <lastrevisiondate>$now</lastrevisiondate>
9168: <lowestgradelevel>0</lowestgradelevel>
9169: <mime>problem</mime>
9170: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9171: <notes></notes>
9172: <obsolete></obsolete>
9173: <obsoletereplacement></obsoletereplacement>
9174: <owner>$coursenum:$coursedom</owner>
9175: <sourceavail></sourceavail>
9176: <standards></standards>
9177: <subject></subject>
9178: <title>$title</title>
9179: END
1.654 raeburn 9180: close($fh);
1.606 raeburn 9181: }
9182: }
9183: }
9184: }
9185: } else {
9186: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9187: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9188: if (grep(/^\Q$rolehome\E$/,@ids)) {
9189: my $now = time;
9190: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9191: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9192: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9193: my $url = "/priv/$audom/$auname";
9194: my $path = $r->dir_config('lonDocRoot').$url;
9195: my $subdir = $env{'form.authorpath'};
9196: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9197: }
9198: }
9199: }
9200: }
9201: }
9202: }
9203: }
9204: return ($redirect,$error);
9205: }
9206:
9207: sub finishnewprob {
1.654 raeburn 9208: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9209: unless (-d $path) {
9210: unless (mkdir($path,02770)) {
9211: return;
9212: }
9213: }
1.606 raeburn 9214: my $redirect;
9215: if ($subdir ne '/') {
9216: $subdir = &cleandir($subdir);
9217: if (($subdir ne '') && (-d "$path/$subdir")) {
9218: $path .= "/$subdir";
9219: $url .= "/$subdir";
9220: }
9221: }
9222: my $dest;
9223: if ($newsubdir ne '') {
9224: $newsubdir = &cleandir($newsubdir);
9225: }
9226: if ($newsubdir ne '') {
9227: if (-d "$path/$newsubdir") {
9228: $dest = "$path/$newsubdir/$filename";
9229: } else {
9230: my $dirok;
9231: unless (-e "$path/$newsubdir") {
9232: if (mkdir("$path/$newsubdir",02770)) {
9233: if (chmod(02770,"$path/$newsubdir")) {
9234: $dirok = 1;
9235: }
9236: }
9237: }
9238: if ($dirok) {
9239: $dest = "$path/$newsubdir/$filename";
9240: }
9241: }
9242: if (($dest ne '') && (!-e $dest)) {
9243: $redirect = "$url/$newsubdir/$filename";
9244: }
9245: } else {
9246: $dest = "$path/$filename";
9247: if (($dest ne '') && (!-e $dest)) {
9248: $redirect = "$url/$filename";
9249: }
9250: }
1.654 raeburn 9251: if ((!-e $dest) && ($context ne 'upload')) {
9252: my $template = $env{'form.template'};
9253: my $copyfrom;
9254: if ($template ne '') {
9255: my %templates;
9256: my @files = &Apache::lonhomework::get_template_list('problem');
9257: foreach my $poss (@files) {
9258: if (ref($poss) eq 'ARRAY') {
9259: if ($template eq $poss->[0]) {
9260: $templates{$template} = 1;
9261: last;
9262: }
9263: }
9264: }
9265: if ($templates{$template}) {
9266: $copyfrom = $template;
9267: }
9268: }
9269: if ($filename =~ /\.problem$/) {
9270: unless ($copyfrom) {
9271: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9272: }
9273: &File::Copy::copy($copyfrom,$dest);
9274: }
9275: }
1.606 raeburn 9276: return $redirect;
9277: }
9278:
9279: sub cleandir {
9280: my ($dir) = @_;
9281: $dir =~ s/^\s+//;
9282: $dir =~ s/\s+$//;
9283: $dir =~ s/\.+//g;
9284: $dir =~ s/[\#\?&%\":]//g;
9285: return $dir;
9286: }
9287:
1.329 droeschl 9288: 1;
9289: __END__
9290:
9291:
9292: =head1 NAME
9293:
9294: Apache::londocs.pm
9295:
9296: =head1 SYNOPSIS
9297:
9298: This is part of the LearningOnline Network with CAPA project
9299: described at http://www.lon-capa.org.
9300:
9301: =head1 SUBROUTINES
9302:
9303: =over
9304:
9305: =item %help=()
9306:
9307: Available help topics
9308:
9309: =item mapread()
9310:
1.344 bisitz 9311: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9312: @order and @resources, determines status
9313: sets @order - pointer to resources in right order
9314: sets @resources - array with the resources with correct idx
9315:
9316: =item authorhosts()
9317:
9318: Return hash with valid author names
9319:
9320: =item clean()
9321:
9322: =item dumpcourse()
9323:
9324: Actually dump course
9325:
9326: =item group_import()
9327:
9328: Imports the given (name, url) resources into the course
9329: coursenum, coursedom, and folder must precede the list
9330:
9331: =item breadcrumbs()
9332:
9333: =item log_docs()
9334:
9335: =item docs_change_log()
9336:
9337: =item update_paste_buffer()
9338:
9339: =item print_paste_buffer()
9340:
9341: =item do_paste_from_buffer()
9342:
1.538 raeburn 9343: =item do_buffer_empty()
9344:
9345: =item clear_from_buffer()
9346:
1.492 raeburn 9347: =item get_newmap_url()
9348:
9349: =item dbcopy()
9350:
9351: =item uniqueness_check()
9352:
9353: =item contained_map_check()
9354:
9355: =item url_paste_fixups()
9356:
9357: =item apply_fixups()
9358:
9359: =item copy_dependencies()
9360:
1.329 droeschl 9361: =item update_parameter()
9362:
9363: =item handle_edit_cmd()
9364:
9365: =item editor()
9366:
9367: =item process_file_upload()
9368:
9369: =item process_secondary_uploads()
9370:
9371: =item is_supplemental_title()
9372:
9373: =item entryline()
9374:
9375: =item tiehash()
9376:
9377: =item untiehash()
9378:
9379: =item checkonthis()
9380:
9381: check on this
9382:
9383: =item verifycontent()
9384:
9385: Verify Content
9386:
1.636 raeburn 9387: =item devalidateversioncache()
9388:
9389: =item checkversions()
1.329 droeschl 9390:
9391: Check Versions
9392:
9393: =item mark_hash_old()
9394:
9395: =item is_hash_old()
9396:
9397: =item changewarning()
9398:
9399: =item init_breadcrumbs()
9400:
9401: Breadcrumbs for special functions
9402:
1.484 raeburn 9403: =item create_list_elements()
9404:
9405: =item create_form_ul()
9406:
9407: =item startContentScreen()
9408:
9409: =item endContentScreen()
9410:
9411: =item supplemental_base()
9412:
9413: =item embedded_form_elems()
9414:
9415: =item embedded_destination()
9416:
9417: =item return_to_editor()
9418:
9419: =item decompression_info()
9420:
9421: =item decompression_phase_one()
9422:
9423: =item decompression_phase_two()
9424:
9425: =item remove_archive()
9426:
9427: =item generate_admin_menu()
9428:
9429: =item generate_edit_table()
9430:
9431: =item editing_js()
9432:
9433: =item history_tab_js()
9434:
9435: =item inject_data_js()
9436:
9437: =item dump_switchserver_js()
9438:
1.485 raeburn 9439: =item resize_scrollbox_js()
1.484 raeburn 9440:
9441: =item makedocslogform()
9442:
1.485 raeburn 9443: =item makesimpleeditform()
9444:
1.329 droeschl 9445: =back
9446:
9447: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>