Annotation of loncom/interface/londocs.pm, revision 1.694
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.694 ! raeburn 4: # $Id: londocs.pm,v 1.693 2023/01/19 16:43:49 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{/([^/]+)$});
1213: }
1214: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1215: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1216: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1217: # FIXME: internationalization seems wrong here
1.329 droeschl 1218: $r->print('<li>'.
1219: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1220: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1221: .'</li>');
1222: }
1223: }
1224: $r->print('</ul>');
1225: }
1226: # End
1227: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1228: $shown++;
1229: if (!($env{'form.show'} eq &mt('all')
1230: || $shown<=$env{'form.show'})) { last; }
1231: }
1.484 raeburn 1232: $r->print(&Apache::loncommon::end_data_table()."\n".
1233: &makesimpleeditform($pathitem)."\n".
1234: '</div></div>');
1235: $r->print(&endContentScreen());
1.329 droeschl 1236: }
1237:
1238: sub update_paste_buffer {
1.492 raeburn 1239: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1240: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1241: if ($env{'form.multiremove'}) {
1242: $env{'form.multiremove'} =~ s/,$//;
1243: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1244: }
1245: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1246: if ($env{'form.multicut'}) {
1247: $env{'form.multicut'} =~ s/,$//;
1248: foreach my $item (split(/,/,$env{'form.multicut'})) {
1249: unless ($removals{$item}) {
1250: $cuts{$item} = 1;
1251: push(@possibles,$item.':cut');
1252: }
1253: }
1254: }
1255: if ($env{'form.multicopy'}) {
1256: $env{'form.multicopy'} =~ s/,$//;
1257: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1258: unless ($removals{$item} || $cuts{$item}) {
1259: push(@possibles,$item.':copy');
1260: }
1261: }
1262: }
1263: } elsif ($env{'form.markcopy'}) {
1264: @possibles = split(/,/,$env{'form.markcopy'});
1265: }
1.329 droeschl 1266:
1.538 raeburn 1267: return if (@possibles == 0);
1.329 droeschl 1268: return if (!defined($env{'form.copyfolder'}));
1269:
1270: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1271: $env{'form.copyfolder'});
1.538 raeburn 1272: return if ($fatal);
1273:
1274: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1275:
1.538 raeburn 1276: # Retrieve current paste buffer suffixes.
1277: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1278: my (%pasteurls,@newpaste);
1279:
1280: # Construct identifiers for current contents of user's paste buffer
1281: if (@currpaste) {
1282: foreach my $suffix (@currpaste) {
1.667 raeburn 1283: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1284: my $url = $env{'docs.markedcopy_url_'.$suffix};
1285: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1286: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1287: ($url ne '')) {
1288: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1289: $pasteurls{$cid.'_'.$mapidx} = 1;
1290: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1291: $pasteurls{$url} = 1;
1292: } else {
1.669 raeburn 1293: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1294: }
1295: }
1.538 raeburn 1296: }
1297: }
1298:
1299: # Mark items for copying (skip any items already in user's paste buffer)
1300: my %addtoenv;
1.597 raeburn 1301:
1302: my @pathitems = split(/\&/,$env{'form.folderpath'});
1303: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1304: my $ispage = $folderconf[5];
1.597 raeburn 1305:
1.538 raeburn 1306: foreach my $item (@possibles) {
1307: my ($orderidx,$cmd) = split(/:/,$item);
1308: next if ($orderidx =~ /\D/);
1309: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1310: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1311: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1312: my %denied = &action_restrictions($coursenum,$coursedom,
1313: &LONCAPA::map::qtescape($url),
1314: $env{'form.folderpath'},\%curr_groups);
1315: next if ($denied{'copy'});
1316: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1317: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1318: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1319: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1320: next if (exists($pasteurls{$url}));
1321: } else {
1322: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1323: }
1.538 raeburn 1324: my ($suffix,$errortxt,$locknotfreed) =
1325: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1326: if ($suffix ne '') {
1327: push(@newpaste,$suffix);
1328: } else {
1329: if ($locknotfreed) {
1330: return $locknotfreed;
1331: }
1.538 raeburn 1332: }
1333: if (&is_supplemental_title($title)) {
1334: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1335: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1336: }
1.329 droeschl 1337:
1.538 raeburn 1338: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1339: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1340: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1341: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1342: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1343: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1344: my $prefix = $1;
1345: my $subdir =$2;
1346: if ($subdir eq '') {
1347: $subdir = $prefix;
1.492 raeburn 1348: }
1.538 raeburn 1349: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1350: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1351: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1352: if (ref($hierarchy{$url}) eq 'HASH') {
1353: my ($nested,$nestednames);
1354: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1355: $nested =~ s/\&$//;
1356: $nestednames =~ s/\Q___&&&___\E$//;
1357: if ($nested ne '') {
1358: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1359: }
1360: if ($nestednames ne '') {
1361: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1362: }
1.492 raeburn 1363: }
1364: }
1.591 raeburn 1365: if ($locknotfreed) {
1366: $output = $locknotfreed;
1367: last;
1368: }
1.492 raeburn 1369: }
1.538 raeburn 1370: if (@newpaste) {
1371: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1372: }
1.492 raeburn 1373: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1374: delete($env{'form.markcopy'});
1.591 raeburn 1375: return $output;
1.329 droeschl 1376: }
1377:
1.492 raeburn 1378: sub recurse_uploaded_maps {
1379: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1380: if (ref($hierarchy->{$url}) eq 'HASH') {
1381: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1382: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1383: my (@uploaded,@names,%shorter);
1384: for (my $i=0; $i<@maps; $i++) {
1385: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1386: if ($inner ne '') {
1387: push(@uploaded,$inner);
1388: push(@names,&escape($titles[$i]));
1389: $shorter{$maps[$i]} = $inner;
1390: }
1391: }
1392: $$nestref .= "$dir:".join(',',@uploaded).'&';
1393: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1394: foreach my $map (@maps) {
1395: if ($shorter{$map} ne '') {
1396: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1397: }
1398: }
1399: }
1400: return;
1401: }
1402:
1.329 droeschl 1403: sub print_paste_buffer {
1.492 raeburn 1404: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1405: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1406:
1.538 raeburn 1407: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1408: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1409: }
1410:
1.538 raeburn 1411: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1412: my ($pasteitems,@pasteable);
1.575 raeburn 1413: my $clipboardcount = 0;
1.488 raeburn 1414:
1.538 raeburn 1415: # Construct identifiers for current contents of user's paste buffer
1416: foreach my $suffix (@currpaste) {
1417: next if ($suffix =~ /\D/);
1418: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1419: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1420: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1421: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1422: ($url ne '')) {
1.575 raeburn 1423: $clipboardcount ++;
1.538 raeburn 1424: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1425: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1426: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1427: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1428: $is_external = 1;
1.626 raeburn 1429: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1430: $is_exttool = 1;
1.538 raeburn 1431: }
1432: if ($folder =~ /^supplemental/) {
1433: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1434: unless ($canpaste) {
1435: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1436: }
1437: } else {
1438: $canpaste = 1;
1439: }
1440: if ($canpaste) {
1441: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1442: my $srcdom = $1;
1443: my $srcnum = $2;
1444: my $rem = $3;
1445: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1446: $othercourse = 1;
1447: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1448: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1449: } else {
1450: $canpaste = 0;
1451: $nopaste = &mt('Paste from another course unavailable.');
1452: }
1453: }
1454: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1455: my $prefix = $1;
1456: $parent = $2;
1457: if ($folder !~ /^\Q$prefix\E/) {
1458: $areachange = 1;
1459: }
1460: $is_uploaded_map = 1;
1.492 raeburn 1461: }
1.597 raeburn 1462: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1463: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1464: if ($cid ne $env{'request.course.id'}) {
1465: my ($srcdom,$srcnum) = split(/_/,$cid);
1466: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1467: if (($is_exttool) && ($srcdom ne $coursedom)) {
1468: $canpaste = 0;
1469: $nopaste = &mt('Paste from another domain unavailable.');
1470: } else {
1471: $othercrs = '<br />'.&mt('(from another course)');
1472: }
1.596 raeburn 1473: } else {
1474: $canpaste = 0;
1475: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1476: }
1.596 raeburn 1477: }
1.492 raeburn 1478: }
1.596 raeburn 1479: if ($canpaste) {
1480: push(@pasteable,$suffix);
1.629 raeburn 1481: }
1.538 raeburn 1482: }
1483: my $buffer;
1.627 raeburn 1484: if ($is_external) {
1.538 raeburn 1485: $buffer = &mt('External Resource').': '.
1486: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1487: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1488: } elsif ($is_exttool) {
1489: $buffer = &mt('External Tool').': '.
1490: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1491: } else {
1492: my $icon = &Apache::loncommon::icon($extension);
1493: if ($extension eq 'sequence' &&
1494: $url =~ m{/default_\d+\.sequence$}x) {
1495: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1496: $icon .= '/navmap.folder.closed.gif';
1497: }
1.589 raeburn 1498: my $title = $env{'docs.markedcopy_title_'.$suffix};
1499: if ($title eq '') {
1500: ($title) = ($url =~ m{/([^/]+)$});
1501: }
1.538 raeburn 1502: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1503: ': '.
1504: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1505: &LONCAPA::map::qtescape($title));
1.538 raeburn 1506: }
1507: $pasteitems .= '<div class="LC_left_float">';
1508: my ($options,$onclick);
1509: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1510: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1511: if (($is_uploaded_map) ||
1512: ($url =~ /(bulletinboard|smppg)$/) ||
1513: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1514: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1515: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1516: }
1517: }
1518: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1519: if ($nopaste) {
1.681 raeburn 1520: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1521: } else {
1522: if ($othercrs) {
1523: $pasteitems .= $othercrs;
1524: }
1525: if ($options) {
1526: $pasteitems .= $options;
1.492 raeburn 1527: }
1528: }
1.538 raeburn 1529: $pasteitems .= '</div>';
1530: }
1531: }
1532: if ($pasteitems eq '') {
1533: &Apache::lonnet::delenv('docs.markedcopies');
1534: }
1535: my ($pasteform,$form_start,$buttons,$form_end);
1536: if ($pasteitems) {
1537: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1538: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1539: if (@pasteable) {
1.575 raeburn 1540: my $value = &mt('Paste to current folder');
1541: if ($container eq 'page') {
1542: $value = &mt('Paste to current page');
1543: }
1544: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1545: }
1546: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1547: if ($clipboardcount > 1) {
1548: $buttons .=
1549: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1550: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1551: (' 'x2).
1552: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1553: (' 'x2);
1.492 raeburn 1554: }
1.575 raeburn 1555: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1556: '</form>';
1.538 raeburn 1557: } else {
1558: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1559: }
1.538 raeburn 1560: $r->print($form_start
1561: .'<fieldset>'
1562: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1563: .$pasteitems
1564: .'</fieldset>'
1565: .$form_end);
1566: }
1567:
1568: sub paste_options {
1569: my ($suffix,$is_uploaded_map,$parent) = @_;
1570: my ($copytext,$movetext);
1571: if ($is_uploaded_map) {
1572: $copytext = &mt('Copy to new folder');
1573: $movetext = &mt('Move old');
1574: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1575: $copytext = &mt('Copy to new board');
1576: $movetext = &mt('Move (not posts)');
1577: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1578: $copytext = &mt('Copy to new page');
1579: $movetext = &mt('Move');
1.533 raeburn 1580: } else {
1.538 raeburn 1581: $copytext = &mt('Copy to new file');
1582: $movetext = &mt('Move');
1583: }
1584: my $output = '<br />'.
1585: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1586: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1587: '<label>'.
1588: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1589: $copytext.'</label></span>'.(' 'x2).' '.
1590: '<span class="LC_nobreak"><label>'.
1591: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1592: $movetext.'</label></span>';
1593: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1594: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1595: '</legend><table border="0">';
1596: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1597: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1598: my $lastdir = $parent;
1599: my %depths = (
1600: $lastdir => 0,
1601: );
1602: my (%display,%deps);
1603: for (my $i=0; $i<@pastemaps; $i++) {
1604: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1605: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1606: my @subfolders = split(/,/,$subfolderstr);
1607: $deps{$lastdir} = \@subfolders;
1608: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1609: my $depth = $depths{$lastdir} + 1;
1610: my $offset = int($depth * 4);
1611: my $indent = (' ' x $offset);
1612: for (my $j=0; $j<@subfolders; $j++) {
1613: $depths{$subfolders[$j]} = $depth;
1614: $display{$subfolders[$j]} =
1615: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1616: '<td><label>'.
1617: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1618: '<label>'.
1619: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1620: &mt('Move old').'</label>'.
1621: '</td></tr>';
1622: }
1.492 raeburn 1623: }
1.538 raeburn 1624: &recurse_print(\$output,$parent,\%deps,\%display);
1625: $output .= '</table></fieldset>';
1.329 droeschl 1626: }
1.538 raeburn 1627: $output .= '</div>';
1628: return $output;
1.488 raeburn 1629: }
1630:
1.492 raeburn 1631: sub recurse_print {
1.538 raeburn 1632: my ($outputref,$dir,$deps,$display) = @_;
1633: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1634: if (ref($deps->{$dir}) eq 'ARRAY') {
1635: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1636: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1637: }
1638: }
1639: }
1640:
1.488 raeburn 1641: sub supp_pasteable {
1642: my ($url) = @_;
1643: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1644: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1645: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1646: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1647: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1648: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1649: return 1;
1650: }
1651: return;
1.329 droeschl 1652: }
1653:
1.492 raeburn 1654: sub paste_popup_js {
1.594 damieng 1655: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1656: show => 'Show Options',
1657: hide => 'Hide Options',
1.594 damieng 1658: );
1659: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1660: none => 'No items selected from clipboard.',
1.492 raeburn 1661: );
1.594 damieng 1662: &html_escape(\%html_js_lt);
1663: &js_escape(\%html_js_lt);
1664: &js_escape(\%js_lt);
1.492 raeburn 1665: return <<"END";
1666:
1.538 raeburn 1667: function showPasteOptions(suffix) {
1668: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1669: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1670: return;
1671: }
1672:
1.538 raeburn 1673: function hidePasteOptions(suffix) {
1674: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1675: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1676: return;
1677: }
1678:
1679: function showOptions(caller,suffix) {
1680: if (document.getElementById('pasteoptionstext_'+suffix)) {
1681: if (caller.checked) {
1.594 damieng 1682: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1683: } else {
1684: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1685: }
1686: if (document.getElementById('pasteoptions_'+suffix)) {
1687: document.getElementById('pasteoptions_'+suffix).style.display='none';
1688: }
1689: }
1.492 raeburn 1690: return;
1691: }
1692:
1.541 raeburn 1693: function validateClipboard() {
1694: var numchk = 0;
1695: if (document.pasteform.pasting.length > 1) {
1696: for (var i=0; i<document.pasteform.pasting.length; i++) {
1697: if (document.pasteform.pasting[i].checked) {
1698: numchk ++;
1699: }
1700: }
1701: } else {
1702: if (document.pasteform.pasting.type == 'checkbox') {
1703: if (document.pasteform.pasting.checked) {
1704: numchk ++;
1705: }
1706: }
1707: }
1708: if (numchk > 0) {
1709: return true;
1710: } else {
1.594 damieng 1711: alert("$js_lt{'none'}");
1.541 raeburn 1712: return false;
1713: }
1714: }
1715:
1.575 raeburn 1716: function checkClipboard() {
1717: if (document.pasteform.pasting.length > 1) {
1718: for (var i=0; i<document.pasteform.pasting.length; i++) {
1719: document.pasteform.pasting[i].checked = true;
1720: }
1721: }
1722: return;
1723: }
1724:
1725: function uncheckClipboard() {
1726: if (document.pasteform.pasting.length >1) {
1727: for (var i=0; i<document.pasteform.pasting.length; i++) {
1728: document.pasteform.pasting[i].checked = false;
1729: }
1730: }
1731: return;
1732: }
1733:
1.492 raeburn 1734: END
1735:
1736: }
1737:
1.329 droeschl 1738: sub do_paste_from_buffer {
1.492 raeburn 1739: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1740:
1.538 raeburn 1741: # Array of items in paste buffer
1742: my (@currpaste,%pastebuffer,%allerrors);
1743: @currpaste = split(/,/,$env{'docs.markedcopies'});
1744:
1.492 raeburn 1745: # Early out if paste buffer is empty
1.538 raeburn 1746: if (@currpaste == 0) {
1.492 raeburn 1747: return ();
1.538 raeburn 1748: }
1749: map { $pastebuffer{$_} = 1; } @currpaste;
1750:
1751: # Array of items selected items to paste
1752: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1753:
1754: # Early out if nothing selected to paste
1755: if (@reqpaste == 0) {
1756: return();
1757: }
1758: my @topaste;
1759: foreach my $suffix (@reqpaste) {
1760: next if ($suffix =~ /\D/);
1761: next unless (exists($pastebuffer{$suffix}));
1762: push(@topaste,$suffix);
1763: }
1764:
1765: # Early out if nothing available to paste
1766: if (@topaste == 0) {
1767: return();
1.329 droeschl 1768: }
1769:
1.627 raeburn 1770: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1771: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1772:
1773: foreach my $suffix (@topaste) {
1774: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1775: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1776: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1777: # Supplemental content may only include certain types of content
1778: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1779: if ($folder =~ /^supplemental/) {
1780: unless (&supp_pasteable($url)) {
1781: $notinsupp{$suffix} = 1;
1782: next;
1783: }
1.492 raeburn 1784: }
1.538 raeburn 1785: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1786: my $srcd = $1;
1787: my $srcn = $2;
1.492 raeburn 1788: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1789: # check for mdc privilege in the course from which the resource was pasted
1790: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1791: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1792: $notincrs{$suffix} = 1;
1793: next;
1794: }
1.491 raeburn 1795: }
1.538 raeburn 1796: $srcdom{$suffix} = $srcd;
1797: $srcnum{$suffix} = $srcn;
1.597 raeburn 1798: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1799: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1800: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1801: my ($srcd,$srcn) = split(/_/,$cid);
1802: # When paste buffer was populated using an active role in a different course
1803: # check for mdc privilege in the course from which the resource was pasted
1804: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1805: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1806: $notincrs{$suffix} = 1;
1807: next;
1808: }
1809: }
1.632 raeburn 1810: # When buffer was populated using an active role in a different course
1811: # disallow pasting of External Tool if course is in a different domain.
1812: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1813: $notindom{$suffix} = 1;
1814: next;
1815: }
1.596 raeburn 1816: $srcdom{$suffix} = $srcd;
1817: $srcnum{$suffix} = $srcn;
1.491 raeburn 1818: }
1.597 raeburn 1819: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1820: push(@dopaste,$suffix);
1821: if ($url=~/\.(page|sequence)$/) {
1822: $is_map{$suffix} = 1;
1823: }
1824: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1825: my $oldprefix = $1;
1.492 raeburn 1826: # When pasting content from Main Content to Supplemental Content and vice versa
1827: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1828: # a folder/page or a document).
1.538 raeburn 1829: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1830: $prefixchg{$suffix} = 'docstosupp';
1831: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1832: $prefixchg{$suffix} = 'supptodocs';
1833: }
1.491 raeburn 1834:
1.492 raeburn 1835: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1836: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1837: my @nested;
1838: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1839: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1840: my @deps = map { /\d+:([\d,]+$)/ } @items;
1841: foreach my $dep (@deps) {
1842: if ($dep =~ /,/) {
1843: push(@nested,split(/,/,$dep));
1844: } else {
1845: push(@nested,$dep);
1846: }
1.492 raeburn 1847: }
1.538 raeburn 1848: foreach my $item (@nested) {
1849: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1850: push(@{$marktomove{$suffix}},$type.'_'.$item);
1851: }
1.492 raeburn 1852: }
1853: }
1.488 raeburn 1854: }
1855: }
1856:
1.538 raeburn 1857: # Early out if nothing available to paste
1858: if (@dopaste == 0) {
1859: return ();
1860: }
1861:
1862: # Populate message hash and hashes used for main content <=> supplemental content
1863: # changes
1864:
1865: %msgs = &Apache::lonlocal::texthash (
1866: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1867: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1868: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1869: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1870: );
1871:
1872: %before = (
1873: docstosupp => {
1874: map => 'default',
1875: doc => 'docs',
1876: },
1877: supptodocs => {
1878: map => 'supplemental',
1879: doc => 'supplemental',
1880: },
1881: );
1882:
1883: %after = (
1884: docstosupp => {
1885: map => 'supplemental',
1886: doc => 'supplemental'
1887: },
1888: supptodocs => {
1889: map => 'default',
1890: doc => 'docs',
1891: },
1892: );
1893:
1894: # Retrieve information about all course maps in main content area
1895:
1896: my $allmaps = {};
1.660 raeburn 1897: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1898:
1899: # Loop over the items to paste
1900: foreach my $suffix (@dopaste) {
1.329 droeschl 1901: # Maps need to be copied first
1.538 raeburn 1902: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1903: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1904: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1905: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1906: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1907: }
1908: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1909: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1910: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1911: my $oldurl = $url;
1912: if ($is_map{$suffix}) {
1.491 raeburn 1913: # If pasting a map, check if map contains other maps
1.538 raeburn 1914: my (%hierarchy,%titles);
1.660 raeburn 1915: if (($folder =~ /^default/) && (!$donechk)) {
1916: $allmaps =
1917: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1918: $env{"course.$env{'request.course.id'}.home"},
1919: $env{'request.course.id'});
1920: $donechk = 1;
1921: }
1.627 raeburn 1922: &contained_map_check($url,$folder,$coursenum,$coursedom,
1923: \%removefrommap,\%removeparam,\%addedmaps,
1924: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1925: if ($url=~ m{^/uploaded/}) {
1926: my $newurl;
1927: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1928: ($newurl,my $error) =
1929: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1930: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1931: \$title,$allmaps,\%newurls);
1932: if ($error) {
1933: $allerrors{$suffix} = $error;
1934: next;
1935: }
1936: if ($newurl ne '') {
1937: if ($newurl ne $url) {
1938: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1939: $newsubdir{$url} = $1;
1940: }
1941: $mapchanges{$url} = 1;
1.492 raeburn 1942: }
1.538 raeburn 1943: }
1944: }
1945: if (($srcdom{$suffix} ne $coursedom) ||
1946: ($srcnum{$suffix} ne $coursenum) ||
1947: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1948: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1949: $coursedom,$coursenum,$srcdom{$suffix},
1950: $srcnum{$suffix},$allmaps,\%rewrites,
1951: \%retitles,\%copies,\%dbcopies,
1952: \%zombies,\%params,\%mapmoves,
1953: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1954: \%newurls,\%resdatacopy)) {
1.538 raeburn 1955: $mapmoves{$url} = 1;
1956: }
1957: $url = $newurl;
1958: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1959: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1960: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1961: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1962: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1963: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1964: }
1965: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1966: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1967: push(@toclear,$suffix);
1968: # if pasting published map (main content area only) check map not already in course
1969: if ($folder =~ /^default/) {
1970: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1971: $duplicate{$suffix} = 1;
1972: next;
1.492 raeburn 1973: }
1.491 raeburn 1974: }
1975: }
1.538 raeburn 1976: }
1.627 raeburn 1977: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1978: my $prefix = $1;
1.648 raeburn 1979: my $fromothercrs;
1.538 raeburn 1980: #need to copy the db contents to a new one, unless this is a move.
1981: my %info = (
1982: src => $url,
1983: cdom => $coursedom,
1984: cnum => $coursenum,
1.596 raeburn 1985: );
1.649 raeburn 1986: if ($prefix eq 'ext.tool') {
1.655 raeburn 1987: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1988: $info{'delgradable'} = 1;
1989: }
1990: }
1.596 raeburn 1991: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1992: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1993: $fromothercrs = 1;
1994: $info{'cdom'} = $srcdom{$suffix};
1995: $info{'cnum'} = $srcnum{$suffix};
1996: }
1997: }
1998: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1999: my (%lockerr,$msg);
1.538 raeburn 2000: my ($newurl,$result,$errtext) =
2001: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2002: if ($result eq 'ok') {
2003: $url = $newurl;
2004: $title=&mt('Copy of').' '.$title;
2005: } else {
2006: if ($prefix eq 'smppg') {
2007: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2008: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2009: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2010: } elsif ($prefix eq 'ext.tool') {
2011: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2012: }
2013: $results{$suffix} = $result;
2014: $msgerrs{$suffix} = $msg;
2015: $lockerrs{$suffix} = $lockerr{$prefix};
2016: next;
2017: }
2018: if ($lockerr{$prefix}) {
2019: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2020: }
1.489 raeburn 2021: }
2022: }
1.538 raeburn 2023: $title = &LONCAPA::map::qtunescape($title);
2024: my $ext='false';
2025: if ($url=~m{^http(|s)://}) { $ext='true'; }
2026: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2027: if ($folder !~ /^supplemental/) {
2028: (undef,undef,$title) =
2029: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2030: }
2031: } else {
2032: if ($folder=~/^supplemental/) {
2033: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2034: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2035: }
1.533 raeburn 2036: }
1.491 raeburn 2037:
2038: # For uploaded files (excluding pages/sequences) path in copied file is changed
2039: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2040: # courses.
2041:
1.538 raeburn 2042: unless ($is_map{$suffix}) {
2043: my $newidx;
1.492 raeburn 2044: # Now insert the URL at the bottom
1.538 raeburn 2045: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2046: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2047: my $relpath = $1;
2048: if ($relpath ne '') {
2049: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2050: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2051: my $newprefix = $newloc;
2052: if ($newloc eq 'default') {
2053: $newprefix = 'docs';
2054: }
2055: if ($newdocsdir eq '') {
2056: $newdocsdir = 'default';
2057: }
1.630 raeburn 2058: if (($prefixchg{$suffix}) ||
2059: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2060: ($srcnum{$suffix} ne $coursenum) ||
2061: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2062: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2063: $url =
2064: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2065: &Apache::lonnet::getfile($oldurl));
2066: if ($url eq '/adm/notfound.html') {
2067: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2068: next;
2069: } else {
2070: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2071: $newsubpath =~ s{/+$}{/};
2072: $docmoves{$oldurl} = $newsubpath;
2073: }
1.491 raeburn 2074: }
2075: }
1.597 raeburn 2076: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2077: my $template = $1;
2078: if ($newidx) {
2079: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2080: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2081: }
1.649 raeburn 2082: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2083: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2084: my $marker = (split(m{/},$url))[4];
2085: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2086: my $val = 'no';
2087: if ($toolsettings{'gradable'}) {
2088: $val = 'yes';
2089: }
2090: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2091: 'string_yesno');
2092: &remember_parms($newidx,'gradable','set',$val);
2093: }
1.491 raeburn 2094: }
1.538 raeburn 2095: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2096: ':'.$ext.':normal:res';
2097: push(@LONCAPA::map::order,$newidx);
2098: # Store the result
2099: my ($errtext,$fatal) =
2100: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2101: if ($fatal) {
2102: $save_err .= $errtext;
2103: $allresult = 'fail';
2104: }
1.488 raeburn 2105: }
1.538 raeburn 2106:
1.597 raeburn 2107: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2108: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2109: unless ($allresult eq 'fail') {
2110: my %updated = (
2111: rewrites => \%rewrites,
2112: zombies => \%zombies,
2113: removefrommap => \%removefrommap,
2114: removeparam => \%removeparam,
2115: dbcopies => \%dbcopies,
1.597 raeburn 2116: resdatacopy => \%resdatacopy,
1.538 raeburn 2117: retitles => \%retitles,
2118: );
2119: my %info = (
2120: newsubdir => \%newsubdir,
2121: params => \%params,
2122: );
2123: if ($prefixchg{$suffix}) {
2124: $info{'before'} = $before{$prefixchg{$suffix}};
2125: $info{'after'} = $after{$prefixchg{$suffix}};
2126: }
2127: my %moves = (
2128: copies => \%copies,
2129: docmoves => \%docmoves,
2130: mapmoves => \%mapmoves,
2131: );
2132: (my $result,$msgs{$suffix},my $lockerror) =
2133: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2134: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2135: $url,'paste');
2136: $lockerrors .= $lockerror;
2137: if ($result eq 'ok') {
2138: if ($is_map{$suffix}) {
2139: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2140: $folder.'.'.$container);
2141: if ($fatal) {
2142: $allresult = 'failread';
2143: } else {
2144: if ($#LONCAPA::map::order<1) {
2145: my $idx=&LONCAPA::map::getresidx();
2146: if ($idx<=0) { $idx=1; }
2147: $LONCAPA::map::order[0]=$idx;
2148: $LONCAPA::map::resources[$idx]='';
2149: }
2150: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2151: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2152: ':'.$ext.':normal:res';
2153: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2154:
2155: # Store the result
1.538 raeburn 2156: my ($errtext,$fatal) =
2157: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2158: if ($fatal) {
2159: $save_err .= $errtext;
2160: $allresult = 'failstore';
2161: }
2162: }
2163: }
2164: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2165: push(@toclear,$suffix);
2166: }
2167: }
1.492 raeburn 2168: }
2169: }
1.538 raeburn 2170: &clear_from_buffer(\@toclear,\@currpaste);
2171: my $msgsarray;
2172: foreach my $suffix (keys(%msgs)) {
2173: if (ref($msgs{$suffix}) eq 'ARRAY') {
2174: $msgsarray .= join(',',@{$msgs{$suffix}});
2175: }
2176: }
2177: return ($allresult,$save_err,$msgsarray,$lockerrors);
2178: }
1.533 raeburn 2179:
1.538 raeburn 2180: sub do_buffer_empty {
2181: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2182: if (@currpaste == 0) {
2183: return &mt('Clipboard is already empty');
2184: }
2185: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2186: if (@toclear == 0) {
2187: return &mt('Nothing selected to clear from clipboard');
2188: }
2189: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2190: if ($numdel) {
2191: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2192: } else {
2193: return &mt('Clipboard unchanged');
1.492 raeburn 2194: }
1.538 raeburn 2195: return;
2196: }
2197:
2198: sub clear_from_buffer {
2199: my ($toclear,$currpaste) = @_;
2200: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2201: my %pastebuffer;
2202: map { $pastebuffer{$_} = 1; } @{$currpaste};
2203: my $numdel = 0;
2204: foreach my $suffix (@{$toclear}) {
2205: next if ($suffix =~ /\D/);
2206: next unless (exists($pastebuffer{$suffix}));
2207: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2208: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2209: delete($pastebuffer{$suffix});
2210: $numdel ++;
2211: }
2212: }
2213: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2214: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2215: return $numdel;
1.492 raeburn 2216: }
2217:
2218: sub get_newmap_url {
2219: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2220: $titleref,$allmaps,$newurls) = @_;
2221: my $newurl;
2222: if ($url=~ m{^/uploaded/}) {
2223: $$titleref=&mt('Copy of').' '.$$titleref;
2224: }
2225: my $now = time;
2226: my $suffix=$$.int(rand(100)).$now;
2227: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2228: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2229: my $path = $1;
2230: my $prefix = $2;
2231: my $ancestor = $3;
2232: if (length($ancestor) > 10) {
2233: $ancestor = substr($ancestor,-10,10);
2234: }
2235: my $newid;
2236: if ($prefixchg) {
2237: if ($folder =~ /^supplemental/) {
2238: $prefix =~ s/^default/supplemental/;
2239: } else {
2240: $prefix =~ s/^supplemental/default/;
2241: }
2242: }
2243: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2244: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2245: } else {
2246: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2247: }
2248: my $counter = 0;
2249: my $is_unique = &uniqueness_check($newurl);
2250: if ($folder =~ /^default/) {
2251: if ($allmaps->{$newurl}) {
2252: $is_unique = 0;
2253: }
2254: }
2255: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2256: $counter ++;
2257: $suffix ++;
2258: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2259: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2260: } else {
2261: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2262: }
2263: $is_unique = &uniqueness_check($newurl);
2264: }
2265: if ($is_unique) {
2266: $newurls->{$newurl} = 1;
2267: } else {
2268: if ($url=~/\.page$/) {
2269: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2270: } else {
2271: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2272: }
2273: }
1.329 droeschl 2274: }
1.492 raeburn 2275: return ($newurl);
1.329 droeschl 2276: }
2277:
1.488 raeburn 2278: sub dbcopy {
1.533 raeburn 2279: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2280: my ($url,$result,$errtext);
2281: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2282: $url = $dbref->{'src'};
1.627 raeburn 2283: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2284: my $prefix = $1;
1.627 raeburn 2285: if ($prefix eq 'ext.tool') {
2286: $prefix = 'exttool';
2287: }
1.533 raeburn 2288: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2289: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2290: my $db_name;
2291: my $marker = (split(m{/},$url))[4];
2292: $marker=~s/\D//g;
2293: if ($dbref->{'src'} =~ m{/smppg$}) {
2294: $db_name =
2295: &Apache::lonsimplepage::get_db_name($url,$marker,
2296: $dbref->{'cdom'},
2297: $dbref->{'cnum'});
1.627 raeburn 2298: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2299: $db_name = 'exttool_'.$marker;
1.533 raeburn 2300: } else {
2301: $db_name = 'bulletinpage_'.$marker;
2302: }
2303: my ($suffix,$freedlock,$error) =
2304: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2305: $coursedom,$coursenum,
2306: 'concat');
2307: if (!$suffix) {
2308: if ($prefix eq 'smppg') {
2309: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2310: } elsif ($prefix eq 'exttool') {
2311: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2312: } else {
1.565 bisitz 2313: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2314: }
2315: if ($error) {
2316: $errtext .= '<br />'.$error;
2317: }
2318: } else {
2319: #need to copy the db contents to a new one.
2320: my %contents=&Apache::lonnet::dump($db_name,
2321: $dbref->{'cdom'},
2322: $dbref->{'cnum'});
2323: if (exists($contents{'uploaded.photourl'})) {
2324: my $photo = $contents{'uploaded.photourl'};
2325: my ($subdir,$fname) =
2326: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2327: my $newphoto;
1.533 raeburn 2328: if ($fname ne '') {
2329: my $content = &Apache::lonnet::getfile($photo);
2330: unless ($content eq '-1') {
2331: $env{'form.'.$suffix.'.photourl'} = $content;
2332: $newphoto =
2333: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2334: delete($env{'form.'.$suffix.'.photourl'});
2335: }
2336: }
2337: if ($newphoto =~ m{^/uploaded/}) {
2338: $contents{'uploaded.photourl'} = $newphoto;
2339: }
2340: }
2341: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2342: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2343: delete($contents{'gradable'});
2344: }
1.533 raeburn 2345: $result=&Apache::lonnet::put($db_name,\%contents,
2346: $coursedom,$coursenum);
2347: if ($result eq 'ok') {
1.627 raeburn 2348: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2349: }
2350: }
2351: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2352: $lockerrorsref->{$prefix} =
1.533 raeburn 2353: '<div class="LC_error">'.
2354: &mt('There was a problem removing a lockfile.');
2355: if ($prefix eq 'smppg') {
1.560 raeburn 2356: $lockerrorsref->{$prefix} .=
1.559 raeburn 2357: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2358: } elsif ($prefix eq 'exttool') {
2359: $lockerrorsref->{$prefix} .=
2360: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2361: } else {
1.565 bisitz 2362: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2363: }
1.560 raeburn 2364: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2365: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2366: '</div>';
1.533 raeburn 2367: }
2368: }
2369: } elsif ($url =~ m{/syllabus$}) {
2370: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2371: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2372: if (($dbref->{'cdom'} ne $coursedom) ||
2373: ($dbref->{'cnum'} ne $coursenum)) {
2374: my %contents=&Apache::lonnet::dump('syllabus',
2375: $dbref->{'cdom'},
2376: $dbref->{'cnum'});
2377: $result=&Apache::lonnet::put('syllabus',\%contents,
2378: $coursedom,$coursenum);
2379: }
2380: }
1.488 raeburn 2381: }
2382: }
1.533 raeburn 2383: return ($url,$result,$errtext);
1.488 raeburn 2384: }
2385:
1.597 raeburn 2386: sub copy_templated_files {
2387: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2388: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2389: my $srccontainer = 'sequence';
2390: if ($srcwaspage) {
2391: $srccontainer = 'page';
2392: }
2393: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2394: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2395: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2396: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2397: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2398: $template.'.problem';
2399: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2400: if ($template eq 'simpleproblem') {
2401: $srcprefix .= '.0.';
2402: my $weightprefix = $newprefix;
2403: $newprefix .= '.0.';
2404: my @simpleprobqtypes = qw(radio option string essay numerical);
2405: my $qtype=$srcparms{$srcprefix.'questiontype'};
2406: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2407: my %newdata = (
2408: $newprefix.'questiontype' => $qtype,
2409: );
1.597 raeburn 2410: foreach my $type (@simpleprobqtypes) {
2411: if ($type eq $qtype) {
2412: $newdata{"$weightprefix.$type.weight"}=1;
2413: } else {
2414: $newdata{"$weightprefix.$type.weight"}=0;
2415: }
2416: }
2417: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2418: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2419: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2420: if ($qtype eq 'numerical') {
2421: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2422: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2423: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2424: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2425: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2426: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2427: unless (defined($maxfoils)) { $maxfoils=10; }
2428: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2429: if ($maxfoils<=0) { $maxfoils=10; }
2430: my $randomize=$srcparms{$srcprefix.'randomize'};
2431: unless (defined($randomize)) { $randomize='yes'; }
2432: unless ($randomize eq 'no') { $randomize='yes'; }
2433: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2434: $newdata{$newprefix.'randomize'} = $randomize;
2435: if ($qtype eq 'option') {
2436: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2437: }
2438: for (my $i=1; $i<=10; $i++) {
2439: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2440: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2441: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2442: }
2443:
2444: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2445: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2446: unless (defined($maxfoils)) { $maxfoils=10; }
2447: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2448: if ($maxfoils<=0) { $maxfoils=10; }
2449: my $randomize=$srcparms{$srcprefix.'randomize'};
2450: unless (defined($randomize)) { $randomize='yes'; }
2451: unless ($randomize eq 'no') { $randomize='yes'; }
2452: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2453: $newdata{$newprefix.'randomize'} = $randomize;
2454: if ($qtype eq 'option') {
2455: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2456: }
2457: for (my $i=1; $i<=10; $i++) {
2458: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2459: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2460: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2461: }
2462: } elsif ($qtype eq 'string') {
2463: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2464: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2465: }
2466: if (keys(%newdata)) {
2467: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2468: $coursenum);
2469: if ($putres eq 'ok') {
2470: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2471: }
2472: }
2473: }
2474: }
2475: }
2476:
1.329 droeschl 2477: sub uniqueness_check {
2478: my ($newurl) = @_;
2479: my $unique = 1;
2480: foreach my $res (@LONCAPA::map::order) {
2481: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2482: $url=&LONCAPA::map::qtescape($url);
2483: if ($newurl eq $url) {
2484: $unique = 0;
1.344 bisitz 2485: last;
1.329 droeschl 2486: }
2487: }
2488: return $unique;
2489: }
2490:
1.488 raeburn 2491: sub contained_map_check {
1.627 raeburn 2492: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2493: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2494: my $content = &Apache::lonnet::getfile($url);
2495: unless ($content eq '-1') {
2496: my $parser = HTML::TokeParser->new(\$content);
2497: $parser->attr_encoded(1);
2498: while (my $token = $parser->get_token) {
2499: next if ($token->[0] ne 'S');
2500: if ($token->[1] eq 'resource') {
2501: next if ($token->[2]->{'type'} eq 'zombie');
2502: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2503: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2504: my $srcdom = $1;
2505: unless ($srcdom eq $coursedom) {
2506: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2507: next;
2508: }
2509: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2510: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2511: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2512: next;
2513: }
2514: }
1.492 raeburn 2515: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2516: if ($1 eq 'uploaded') {
2517: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2518: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2519: } else {
1.492 raeburn 2520: if ($allmaps->{$ressrc}) {
1.529 raeburn 2521: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2522: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2523: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2524: } else {
2525: $addedmaps->{$ressrc} = [$url];
2526: }
1.488 raeburn 2527: }
1.627 raeburn 2528: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2529: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2530: }
1.492 raeburn 2531: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2532: if ($folder =~ /^supplemental/) {
1.492 raeburn 2533: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2534: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2535: } else {
2536: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2537: }
1.488 raeburn 2538: }
2539: }
2540: }
2541: }
2542: return;
2543: }
2544:
2545: sub url_paste_fixups {
1.533 raeburn 2546: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2547: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2548: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2549: my $checktitle;
2550: if (($prefixchg) &&
1.492 raeburn 2551: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2552: $checktitle = 1;
2553: }
1.492 raeburn 2554: my $skip;
2555: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2556: my $mapid = $1.$2;
2557: if ($tomove->{$mapid}) {
2558: $skip = 1;
2559: }
2560: }
1.491 raeburn 2561: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2562: return if ($file eq '-1');
2563: my $parser = HTML::TokeParser->new(\$file);
2564: $parser->attr_encoded(1);
1.491 raeburn 2565: my $changed = 0;
1.488 raeburn 2566: while (my $token = $parser->get_token) {
2567: next if ($token->[0] ne 'S');
2568: if ($token->[1] eq 'resource') {
2569: my $ressrc = $token->[2]->{'src'};
2570: next if ($ressrc eq '');
1.491 raeburn 2571: my $id = $token->[2]->{'id'};
1.492 raeburn 2572: my $title = $token->[2]->{'title'};
1.491 raeburn 2573: if ($checktitle) {
2574: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2575: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2576: }
2577: }
1.488 raeburn 2578: next if ($token->[2]->{'type'} eq 'external');
2579: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2580: next if ($skip);
1.532 raeburn 2581: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2582: $changed = 1;
2583: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2584: my $srcdom = $1;
2585: my $srcnum = $2;
1.488 raeburn 2586: my $rem = $3;
1.492 raeburn 2587: my $newurl;
2588: my $mapname;
2589: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2590: my $prefix = $1;
2591: $mapname = $prefix.$2;
2592: if ($tomove->{$mapname}) {
1.533 raeburn 2593: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2594: $srcdom,$srcnum,$allmaps,$rewrites,
2595: $retitles,$copies,$dbcopies,$zombies,
2596: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2597: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2598: next;
2599: } else {
2600: ($newurl,my $error) =
2601: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2602: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2603: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2604: $newsubdir->{$ressrc} = $1;
2605: }
2606: if ($error) {
2607: next;
2608: }
2609: }
2610: }
2611: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2612: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2613:
1.488 raeburn 2614: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2615: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2616: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2617: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2618: $cnum,$srcdom,$srcnum,$allmaps,
2619: $rewrites,$retitles,$copies,$dbcopies,
2620: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2621: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2622: $mapmoves->{$ressrc} = 1;
2623: }
2624: $changed = 1;
1.488 raeburn 2625: } else {
1.532 raeburn 2626: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2627: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2628: $changed = 1;
1.488 raeburn 2629: }
2630: }
1.649 raeburn 2631: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2632: next if ($skip);
1.492 raeburn 2633: my $srcdom = $1;
2634: my $srcnum = $2;
1.649 raeburn 2635: my $rem = $3;
2636: my ($is_exttool,$exttoolchg);
2637: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2638: $is_exttool = 1;
1.649 raeburn 2639: }
1.492 raeburn 2640: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2641: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2642: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2643: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2644: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2645: $changed = 1;
1.649 raeburn 2646: if ($is_exttool) {
2647: $exttoolchg = 1;
2648: }
2649: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2650: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2651: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2652: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2653: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2654: $changed = 1;
2655: $exttoolchg = 1;
2656: }
2657: if (($is_exttool) && ($prefixchg)) {
2658: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2659: if ($exttoolchg) {
2660: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2661: }
2662: }
1.533 raeburn 2663: }
2664: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2665: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2666: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2667: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2668: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2669: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2670: $changed = 1;
1.488 raeburn 2671: }
1.597 raeburn 2672: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2673: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2674: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2675: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2676: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2677: }
1.488 raeburn 2678: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2679: next if ($skip);
2680: my $srcdom = $1;
2681: my $srcnum = $2;
2682: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2683: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2684: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2685: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2686: $changed = 1;
1.488 raeburn 2687: }
2688: }
2689: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2690: next if ($skip);
1.488 raeburn 2691: my $to = $token->[2]->{'to'};
2692: if ($to ne '') {
2693: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2694: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2695: } else {
2696: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2697: }
2698: }
2699: }
2700: }
1.491 raeburn 2701: return $changed;
1.488 raeburn 2702: }
2703:
2704: sub apply_fixups {
1.529 raeburn 2705: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2706: $oldurl,$url,$caller) = @_;
2707: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2708: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2709: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2710: if (ref($updated) eq 'HASH') {
2711: if (ref($updated->{'rewrites'}) eq 'HASH') {
2712: %rewrites = %{$updated->{'rewrites'}};
2713: }
2714: if (ref($updated->{'zombies'}) eq 'HASH') {
2715: %zombies = %{$updated->{'zombies'}};
2716: }
2717: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2718: %removefrommap = %{$updated->{'removefrommap'}};
2719: }
2720: if (ref($updated->{'removeparam'}) eq 'HASH') {
2721: %removeparam = %{$updated->{'removeparam'}};
2722: }
2723: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2724: %dbcopies = %{$updated->{'dbcopies'}};
2725: }
2726: if (ref($updated->{'retitles'}) eq 'HASH') {
2727: %retitles = %{$updated->{'retitles'}};
2728: }
1.597 raeburn 2729: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2730: %resdatacopy = %{$updated->{'resdatacopy'}};
2731: }
1.529 raeburn 2732: }
2733: if (ref($info) eq 'HASH') {
2734: if (ref($info->{'newsubdir'}) eq 'HASH') {
2735: %newsubdir = %{$info->{'newsubdir'}};
2736: }
2737: if (ref($info->{'params'}) eq 'HASH') {
2738: %params = %{$info->{'params'}};
2739: }
2740: if (ref($info->{'before'}) eq 'HASH') {
2741: %before = %{$info->{'before'}};
2742: }
2743: if (ref($info->{'after'}) eq 'HASH') {
2744: %after = %{$info->{'after'}};
2745: }
2746: }
2747: if (ref($moves) eq 'HASH') {
2748: if (ref($moves->{'copies'}) eq 'HASH') {
2749: %copies = %{$moves->{'copies'}};
2750: }
2751: if (ref($moves->{'docmoves'}) eq 'HASH') {
2752: %docmoves = %{$moves->{'docmoves'}};
2753: }
2754: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2755: %mapmoves = %{$moves->{'mapmoves'}};
2756: }
2757: }
2758: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2759: my @allcopies;
1.529 raeburn 2760: if (exists($copies{$key})) {
2761: if (ref($copies{$key}) eq 'HASH') {
2762: my %added;
2763: foreach my $innerkey (keys(%{$copies{$key}})) {
2764: if (($innerkey ne '') && (!$added{$innerkey})) {
2765: push(@allcopies,$innerkey);
2766: $added{$innerkey} = 1;
2767: }
1.491 raeburn 2768: }
1.529 raeburn 2769: undef(%added);
1.491 raeburn 2770: }
2771: }
2772: if ($key eq $oldurl) {
1.529 raeburn 2773: if ((exists($docmoves{$key}))) {
1.532 raeburn 2774: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2775: push(@allcopies,$oldurl);
2776: }
2777: }
2778: }
2779: if (@allcopies > 0) {
2780: foreach my $item (@allcopies) {
1.492 raeburn 2781: my ($relpath,$oldsubdir,$fname) =
2782: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2783: if ($fname ne '') {
2784: my $content = &Apache::lonnet::getfile($item);
2785: unless ($content eq '-1') {
2786: my $storefn;
1.529 raeburn 2787: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2788: $storefn = $docmoves{$key};
1.491 raeburn 2789: } else {
2790: $storefn = $relpath;
2791: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2792: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2793: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2794: }
1.529 raeburn 2795: if ($newsubdir{$key}) {
1.532 raeburn 2796: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2797: }
2798: }
2799: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2800: my $copyurl =
2801: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2802: $storefn.$fname,$content);
2803: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2804: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2805: return &mt('Paste failed: an error occurred copying the file.');
2806: } elsif (ref($errors) eq 'HASH') {
2807: $errors->{$item} = 1;
1.489 raeburn 2808: }
2809: }
1.488 raeburn 2810: }
2811: }
1.491 raeburn 2812: }
2813: }
2814: }
1.529 raeburn 2815: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2816: my $storefn=$key;
2817: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2818: if ($prefixchg && $before{'map'} && $after{'map'}) {
2819: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2820: }
1.529 raeburn 2821: if ($newsubdir{$key}) {
2822: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2823: }
1.491 raeburn 2824: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2825: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2826: ($after{'map'} eq 'default') &&
2827: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2828: $mapcontent = '<map>'."\n".
2829: '<resource id="1" src="" type="start" />'."\n".
2830: '<link from="1" to="2" index="1" />'."\n".
2831: '<resource id="2" src="" type="finish" />'."\n".
2832: '</map>';
2833: }
1.491 raeburn 2834: if ($mapcontent eq '-1') {
2835: if (ref($errors) eq 'HASH') {
2836: $errors->{$key} = 1;
2837: }
2838: } else {
2839: my $newmap =
2840: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2841: $mapcontent);
2842: if ($newmap eq '/adm/notfound.html') {
2843: if (ref($errors) eq 'HASH') {
2844: $errors->{$key} = 1;
1.489 raeburn 2845: }
1.488 raeburn 2846: }
2847: }
2848: }
1.491 raeburn 2849: my %updates;
2850: if ($is_map) {
1.529 raeburn 2851: if (ref($updated) eq 'HASH') {
2852: foreach my $type (keys(%{$updated})) {
2853: if (ref($updated->{$type}) eq 'HASH') {
2854: foreach my $key (keys(%{$updated->{$type}})) {
2855: $updates{$key} = 1;
2856: }
2857: }
2858: }
1.491 raeburn 2859: }
2860: foreach my $key (keys(%updates)) {
1.492 raeburn 2861: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2862: if (ref($rewrites{$key}) eq 'HASH') {
2863: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2864: }
1.529 raeburn 2865: if (ref($retitles{$key}) eq 'HASH') {
2866: %toretitle = %{$retitles{$key}};
1.491 raeburn 2867: }
1.529 raeburn 2868: if (ref($removefrommap{$key}) eq 'HASH') {
2869: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2870: }
1.529 raeburn 2871: if (ref($removeparam{$key}) eq 'HASH') {
2872: %remparam = %{$removeparam{$key}};
1.492 raeburn 2873: }
1.529 raeburn 2874: if (ref($zombies{$key}) eq 'HASH') {
2875: %zombie = %{$zombies{$key}};
1.491 raeburn 2876: }
1.529 raeburn 2877: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2878: foreach my $idx (keys(%{$dbcopies{$key}})) {
2879: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2880: my ($newurl,$result,$errtext) =
2881: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2882: if ($result eq 'ok') {
2883: $newdb{$idx} = $newurl;
2884: } elsif (ref($errors) eq 'HASH') {
2885: $errors->{$key} = 1;
2886: }
2887: push(@msgs,$errtext);
2888: }
1.491 raeburn 2889: }
2890: }
1.597 raeburn 2891: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2892: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2893: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2894: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2895: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2896: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2897: my $template = $1;
2898: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2899: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2900: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2901: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2902: unless ($gotnewmapname) {
2903: ($newmapname) = ($key =~ m{/([^/]+)$});
2904: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2905: if ($newsubdir{$key}) {
2906: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2907: }
2908: $gotnewmapname = 1;
2909: }
1.597 raeburn 2910: my $srcmapinfo = $srcfolder.':'.$idx;
2911: if ($srccontainer eq 'page') {
2912: $srcmapinfo .= ':1';
2913: }
2914: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2915: $cnum,$template,$idx,$newmapname);
2916: }
2917: }
2918: }
2919: }
2920: }
1.529 raeburn 2921: if (ref($params{$key}) eq 'HASH') {
2922: %currparam = %{$params{$key}};
1.492 raeburn 2923: }
2924: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2925: if ($fatal) {
1.533 raeburn 2926: return ($errtext);
1.492 raeburn 2927: }
2928: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2929: if (defined($LONCAPA::map::zombies[$i])) {
2930: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2931: if ($zombie{$i} eq $src) {
1.492 raeburn 2932: undef($LONCAPA::map::zombies[$i]);
2933: }
2934: }
2935: }
1.646 raeburn 2936: my $total = scalar(@LONCAPA::map::order) - 1;
2937: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2938: my $idx = $LONCAPA::map::order[$i];
2939: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2940: my $changed;
1.529 raeburn 2941: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2942: if ((exists($toremove{$idx})) &&
2943: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2944: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2945: if (ref($currparam{$idx}) eq 'ARRAY') {
2946: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2947: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2948: }
2949: }
2950: next;
2951: }
2952: my $origsrc = $src;
1.532 raeburn 2953: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2954: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2955: $changed = 1;
1.491 raeburn 2956: }
1.492 raeburn 2957: }
1.532 raeburn 2958: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2959: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2960: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2961: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2962: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2963: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2964: } else {
1.529 raeburn 2965: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2966: }
1.491 raeburn 2967: }
1.532 raeburn 2968: if ($origsrc =~ /\.(page|sequence)$/) {
2969: if ($newsubdir{$origsrc}) {
1.529 raeburn 2970: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2971: }
1.532 raeburn 2972: } elsif ($newsubdir{$key}) {
2973: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2974: }
2975: }
1.492 raeburn 2976: $changed = 1;
1.533 raeburn 2977: } elsif ($newdb{$idx} ne '') {
2978: $src = $newdb{$idx};
1.492 raeburn 2979: $changed = 1;
2980: }
2981: if ($changed) {
1.538 raeburn 2982: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2983: }
2984: }
2985: }
2986: foreach my $idx (keys(%remparam)) {
2987: if (ref($remparam{$idx}) eq 'ARRAY') {
2988: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2989: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2990: }
2991: }
2992: }
1.533 raeburn 2993: if (values(%lockerrors) > 0) {
2994: $lockmsg = join('<br />',values(%lockerrors));
2995: }
1.491 raeburn 2996: my $storefn;
2997: if ($key eq $oldurl) {
2998: $storefn = $url;
2999: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3000: } else {
3001: $storefn = $key;
3002: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3003: if ($prefixchg && $before{'map'} && $after{'map'}) {
3004: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3005: }
1.529 raeburn 3006: if ($newsubdir{$key}) {
3007: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3008: }
1.491 raeburn 3009: }
1.492 raeburn 3010: my $report;
3011: if ($folder !~ /^supplemental/) {
3012: $report = 1;
3013: }
1.527 raeburn 3014: (my $outtext,$errtext) =
1.492 raeburn 3015: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3016: if ($errtext) {
1.529 raeburn 3017: if ($caller eq 'paste') {
1.533 raeburn 3018: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3019: }
1.491 raeburn 3020: }
3021: }
3022: }
1.533 raeburn 3023: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3024: }
3025:
3026: sub copy_dependencies {
3027: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3028: my $content;
3029: if (ref($contentref)) {
3030: $content = $$contentref;
3031: } else {
3032: $content = &Apache::lonnet::getfile($item);
3033: }
3034: unless ($content eq '-1') {
3035: my $mm = new File::MMagic;
3036: my $mimetype = $mm->checktype_contents($content);
3037: if ($mimetype eq 'text/html') {
3038: my (%allfiles,%codebase,$state);
3039: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3040: if ($res eq 'ok') {
3041: my ($numexisting,$numpathchanges,$existing);
3042: (undef,$numexisting,$numpathchanges,$existing) =
3043: &Apache::loncommon::ask_for_embedded_content(
3044: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3045: {'error_on_invalid_names' => 1,
3046: 'ignore_remote_references' => 1,
3047: 'docs_url' => $item,
3048: 'context' => 'paste'});
3049: if ($numexisting > 0) {
3050: if (ref($existing) eq 'HASH') {
3051: foreach my $dep (keys(%{$existing})) {
3052: my $depfile = $dep;
3053: unless ($depfile =~ m{^\Q$relpath\E}) {
3054: $depfile = $relpath.$dep;
3055: }
3056: my $depcontent = &Apache::lonnet::getfile($depfile);
3057: unless ($depcontent eq '-1') {
3058: my $storedep = $dep;
3059: $storedep =~ s{^\Q$relpath\E}{};
3060: my $dep_url =
3061: &Apache::lonclonecourse::writefile(
3062: $env{'request.course.id'},
3063: $storefn.$storedep,$depcontent);
3064: if ($dep_url eq '/adm/notfound.html') {
3065: if (ref($errors) eq 'HASH') {
3066: $errors->{$depfile} = 1;
3067: }
3068: } else {
3069: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3070: }
3071: }
3072: }
1.488 raeburn 3073: }
3074: }
3075: }
3076: }
3077: }
3078: return;
3079: }
3080:
1.329 droeschl 3081: my %parameter_type = ( 'randompick' => 'int_pos',
3082: 'hiddenresource' => 'string_yesno',
3083: 'encrypturl' => 'string_yesno',
3084: 'randomorder' => 'string_yesno',);
3085: my $valid_parameters_re = join('|',keys(%parameter_type));
3086: # set parameters
3087: sub update_parameter {
1.537 raeburn 3088: if ($env{'form.changeparms'} eq 'all') {
3089: my (@allidx,@allmapidx,%allchecked,%currchecked);
3090: %allchecked = (
3091: 'hiddenresource' => {},
3092: 'encrypturl' => {},
3093: 'randompick' => {},
3094: 'randomorder' => {},
3095: );
3096: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3097: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3098: if ($which eq 'randompick') {
3099: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3100: my ($res,$value) = split(/:/,$item);
3101: if ($value =~ /^\d+$/) {
3102: $allchecked{$which}{$res} = $value;
3103: }
3104: }
3105: } else {
1.539 raeburn 3106: if ($env{'form.all'.$which}) {
3107: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3108: }
1.537 raeburn 3109: }
3110: }
3111: my $haschanges = 0;
3112: foreach my $res (@LONCAPA::map::order) {
3113: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3114: $name=&LONCAPA::map::qtescape($name);
3115: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3116: next unless $url;
1.537 raeburn 3117: my $is_map;
3118: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3119: $is_map = 1;
3120: }
3121: foreach my $which (keys(%allchecked)) {
3122: if (($which eq 'randompick' || $which eq 'randomorder')) {
3123: next if (!$is_map);
3124: }
3125: my $oldvalue = 0;
3126: my $newvalue = 0;
3127: if ($allchecked{$which}{$res}) {
3128: $newvalue = $allchecked{$which}{$res};
3129: }
3130: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3131: if ($which eq 'randompick') {
3132: if ($current =~ /^(\d+)$/) {
3133: $oldvalue = $1;
3134: }
3135: } else {
3136: if ($current =~ /^yes$/i) {
3137: $oldvalue = 1;
3138: }
3139: }
3140: if ($oldvalue ne $newvalue) {
3141: $haschanges = 1;
3142: if ($newvalue) {
3143: my $storeval = 'yes';
3144: if ($which eq 'randompick') {
3145: $storeval = $newvalue;
3146: }
3147: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3148: $storeval,
3149: $parameter_type{$which});
3150: &remember_parms($res,$which,'set',$storeval);
3151: } elsif ($oldvalue) {
3152: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3153: &remember_parms($res,$which,'del');
3154: }
3155: }
3156: }
3157: }
3158: return $haschanges;
3159: } else {
1.588 raeburn 3160: my $haschanges = 0;
3161: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3162:
1.537 raeburn 3163: my $which = $env{'form.changeparms'};
3164: my $idx = $env{'form.setparms'};
1.588 raeburn 3165: my $oldvalue = 0;
3166: my $newvalue = 0;
3167: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3168: if ($which eq 'randompick') {
3169: if ($current =~ /^(\d+)$/) {
3170: $oldvalue = $1;
3171: }
3172: } elsif ($current =~ /^yes$/i) {
3173: $oldvalue = 1;
3174: }
1.537 raeburn 3175: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3176: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3177: : 1;
3178: }
3179: if ($oldvalue ne $newvalue) {
3180: $haschanges = 1;
3181: if ($newvalue) {
3182: my $storeval = 'yes';
3183: if ($which eq 'randompick') {
3184: $storeval = $newvalue;
3185: }
3186: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3187: $parameter_type{$which});
3188: &remember_parms($idx,$which,'set',$storeval);
3189: } else {
3190: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3191: &remember_parms($idx,$which,'del');
3192: }
1.537 raeburn 3193: }
1.588 raeburn 3194: return $haschanges;
1.329 droeschl 3195: }
3196: }
3197:
3198: sub handle_edit_cmd {
3199: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3200: my $haschanges = 0;
1.543 raeburn 3201: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3202: return $haschanges;
1.543 raeburn 3203: }
1.329 droeschl 3204: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3205:
3206: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3207: my ($title, $url, @rrest) = split(':', $ratstr);
3208:
1.538 raeburn 3209: if ($cmd eq 'remove') {
1.329 droeschl 3210: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3211: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3212: &Apache::lonnet::removeuploadedurl($url);
3213: } else {
3214: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3215: }
3216: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3217: $haschanges = 1;
1.329 droeschl 3218: } elsif ($cmd eq 'cut') {
3219: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3220: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3221: $haschanges = 1;
1.344 bisitz 3222: } elsif ($cmd eq 'up'
1.329 droeschl 3223: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3224: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3225: $haschanges = 1;
1.329 droeschl 3226: } elsif ($cmd eq 'down'
3227: && defined($LONCAPA::map::order[$idx+1])) {
3228: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3229: $haschanges = 1;
1.329 droeschl 3230: } elsif ($cmd eq 'rename') {
3231: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3232: if ($comment=~/\S/) {
3233: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3234: $comment.':'.join(':', $url, @rrest);
3235: }
3236: # Devalidate title cache
3237: my $renamed_url=&LONCAPA::map::qtescape($url);
3238: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3239: $haschanges = 1;
3240: } elsif ($cmd eq 'setalias') {
3241: my $newvalue = $env{'form.alias'};
3242: if ($newvalue ne '') {
3243: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3244: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3245: 'string');
3246: &remember_parms($idx,'mapalias','set',$newvalue);
3247: $haschanges = 1;
3248: }
3249: }
3250: } elsif ($cmd eq 'delalias') {
3251: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3252: if ($current ne '') {
3253: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3254: &remember_parms($idx,'mapalias','del');
3255: $haschanges = 1;
3256: }
1.329 droeschl 3257: }
1.633 raeburn 3258: return $haschanges;
1.329 droeschl 3259: }
3260:
3261: sub editor {
1.458 raeburn 3262: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3263: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3264: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3265: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3266: if ($allowed) {
1.519 raeburn 3267: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3268: $is_random_order,$container) =
1.510 raeburn 3269: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3270: $r->print($breadcrumbtrail);
1.519 raeburn 3271: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3272: $container = 'page';
3273: } else {
3274: $container = 'sequence';
1.510 raeburn 3275: }
1.484 raeburn 3276:
1.525 raeburn 3277: my $jumpto;
3278:
3279: unless ($supplementalflag) {
1.546 raeburn 3280: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3281: }
1.484 raeburn 3282:
3283: unless ($allowed) {
3284: $randompick = -1;
3285: }
3286:
1.615 raeburn 3287: my ($errtext,$fatal);
3288: if (($folder eq '') && (!$supplementalflag)) {
3289: if (@LONCAPA::map::order) {
3290: undef(@LONCAPA::map::order);
3291: undef(@LONCAPA::map::resources);
3292: undef(@LONCAPA::map::resparms);
3293: undef(@LONCAPA::map::zombies);
3294: }
3295: $folder = 'default';
3296: $container = 'sequence';
3297: } else {
3298: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3299: $folder.'.'.$container);
3300: return $errtext if ($fatal);
3301: }
1.329 droeschl 3302:
3303: if ($#LONCAPA::map::order<1) {
3304: my $idx=&LONCAPA::map::getresidx();
3305: if ($idx<=0) { $idx=1; }
3306: $LONCAPA::map::order[0]=$idx;
3307: $LONCAPA::map::resources[$idx]='';
3308: }
1.364 bisitz 3309:
1.329 droeschl 3310: # ------------------------------------------------------------ Process commands
3311:
3312: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3313: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3314: # set parameters and change order
3315: &snapshotbefore();
3316:
3317: if (&update_parameter()) {
1.588 raeburn 3318: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3319: return $errtext if ($fatal);
3320: }
3321:
3322: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3323: # change order
3324: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3325: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3326:
3327: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3328: return $errtext if ($fatal);
3329: }
1.364 bisitz 3330:
1.329 droeschl 3331: if ($env{'form.pastemarked'}) {
1.491 raeburn 3332: my %paste_errors;
1.533 raeburn 3333: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3334: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3335: \%paste_errors);
1.541 raeburn 3336: if (ref($pastemsgarray) eq 'ARRAY') {
3337: if (@{$pastemsgarray} > 0) {
3338: $r->print('<p class="LC_info">'.
3339: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3340: '</p>');
3341: }
1.541 raeburn 3342: }
3343: if ($lockerror) {
3344: $r->print('<p class="LC_error">'.
3345: $lockerror.
3346: '</p>');
3347: }
3348: if ($save_error ne '') {
3349: return $save_error;
3350: }
3351: if ($paste_res) {
3352: my %errortext = &Apache::lonlocal::texthash (
3353: fail => 'Storage of folder contents failed',
3354: failread => 'Reading folder contents failed',
3355: failstore => 'Storage of folder contents failed',
3356: );
3357: if ($errortext{$paste_res}) {
3358: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3359: }
1.329 droeschl 3360: }
1.491 raeburn 3361: if (keys(%paste_errors) > 0) {
1.538 raeburn 3362: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3363: &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".
3364: '<ul>'."\n");
3365: foreach my $key (sort(keys(%paste_errors))) {
3366: $r->print('<li>'.$key.'</li>'."\n");
3367: }
3368: $r->print('</ul></p>'."\n");
3369: }
1.538 raeburn 3370: } elsif ($env{'form.clearmarked'}) {
3371: my $output = &do_buffer_empty();
3372: if ($output) {
3373: $r->print('<p class="LC_info">'.$output.'</p>');
3374: }
3375: }
1.329 droeschl 3376:
3377: $r->print($upload_output);
3378:
1.538 raeburn 3379: # Rename, cut, copy or remove a single resource
1.602 raeburn 3380: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3381: my $contentchg;
1.633 raeburn 3382: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3383: $contentchg = 1;
3384: }
3385: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3386: return $errtext if ($fatal);
3387: }
1.538 raeburn 3388:
3389: # Cut, copy and/or remove multiple resources
3390: if ($env{'form.multichange'}) {
3391: my %allchecked = (
3392: cut => {},
3393: remove => {},
3394: );
3395: my $needsupdate;
3396: foreach my $which (keys(%allchecked)) {
3397: $env{'form.multi'.$which} =~ s/,$//;
3398: if ($env{'form.multi'.$which}) {
3399: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3400: if (ref($allchecked{$which}) eq 'HASH') {
3401: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3402: }
3403: }
3404: }
3405: if ($needsupdate) {
3406: my $haschanges = 0;
3407: my %curr_groups = &Apache::longroup::coursegroups();
3408: my $total = scalar(@LONCAPA::map::order) - 1;
3409: for (my $i=$total; $i>=0; $i--) {
3410: my $res = $LONCAPA::map::order[$i];
3411: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3412: $name=&LONCAPA::map::qtescape($name);
3413: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3414: next unless $url;
1.538 raeburn 3415: my %denied =
3416: &action_restrictions($coursenum,$coursedom,$url,
3417: $env{'form.folderpath'},\%curr_groups);
3418: foreach my $which (keys(%allchecked)) {
3419: next if ($denied{$which});
3420: next unless ($allchecked{$which}{$res});
3421: if ($which eq 'remove') {
3422: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3423: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3424: &Apache::lonnet::removeuploadedurl($url);
3425: } else {
3426: &LONCAPA::map::makezombie($res);
3427: }
3428: splice(@LONCAPA::map::order,$i,1);
3429: $haschanges ++;
3430: } elsif ($which eq 'cut') {
3431: &LONCAPA::map::makezombie($res);
3432: splice(@LONCAPA::map::order,$i,1);
3433: $haschanges ++;
3434: }
3435: }
3436: }
3437: if ($haschanges) {
3438: ($errtext,$fatal) =
3439: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3440: return $errtext if ($fatal);
3441: }
3442: }
3443: }
3444:
1.329 droeschl 3445: # Group import/search
3446: if ($env{'form.importdetail'}) {
3447: my @imports;
3448: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3449: if (defined($item)) {
3450: my ($name,$url,$residx)=
1.533 raeburn 3451: map { &unescape($_); } split(/\=/,$item);
3452: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3453: my ($suffix,$errortxt,$locknotfreed) =
3454: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3455: if ($locknotfreed) {
3456: $r->print($locknotfreed);
3457: }
3458: if ($suffix) {
3459: $url =~ s/_new\./_$suffix./;
3460: } else {
3461: return $errortxt;
3462: }
1.533 raeburn 3463: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3464: my $type = $1;
3465: my ($suffix,$errortxt,$locknotfreed) =
3466: &new_timebased_suffix($coursedom,$coursenum,$type);
3467: if ($locknotfreed) {
3468: $r->print($locknotfreed);
3469: }
3470: if ($suffix) {
3471: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3472: } else {
3473: return $errortxt;
3474: }
1.626 raeburn 3475: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3476: my ($suffix,$errortxt,$locknotfreed) =
3477: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3478: if ($locknotfreed) {
3479: $r->print($locknotfreed);
3480: }
3481: if ($suffix) {
3482: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3483: } else {
3484: return $errortxt;
3485: }
1.534 raeburn 3486: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3487: if ($supplementalflag) {
3488: next unless ($1 eq 'supplemental');
3489: if ($folder eq 'supplemental') {
3490: next unless ($2 eq 'default');
3491: } else {
3492: next unless ($folder eq 'supplemental_'.$2);
3493: }
3494: } else {
3495: next unless ($1 eq 'docs');
3496: if ($folder eq 'default') {
3497: next unless ($2 eq 'default');
3498: } else {
3499: next unless ($folder eq 'default_'.$2);
3500: }
3501: }
1.504 raeburn 3502: }
1.329 droeschl 3503: push(@imports, [$name, $url, $residx]);
3504: }
3505: }
1.530 raeburn 3506: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3507: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3508: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3509: return $errtext if ($fatal);
1.529 raeburn 3510: if ($fixuperrors) {
3511: $r->print($fixuperrors);
3512: }
1.329 droeschl 3513: }
3514: # Loading a complete map
3515: if ($env{'form.loadmap'}) {
3516: if ($env{'form.importmap'}=~/\w/) {
3517: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3518: my ($title,$url,$ext,$type)=split(/\:/,$res);
3519: my $idx=&LONCAPA::map::getresidx($url);
3520: $LONCAPA::map::resources[$idx]=$res;
3521: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3522: }
3523: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3524: $folder.'.'.$container,1);
1.329 droeschl 3525: return $errtext if ($fatal);
3526: } else {
3527: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3528:
1.329 droeschl 3529: }
3530: }
3531: &log_differences($plain);
3532: }
3533: # ---------------------------------------------------------------- End commands
3534: # ---------------------------------------------------------------- Print screen
3535: my $idx=0;
3536: my $shown=0;
3537: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3538: $r->print('<div class="LC_Box">'.
1.432 raeburn 3539: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3540: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3541: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3542: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3543: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3544: '</ol>');
1.381 bisitz 3545: if ($randompick>=0) {
3546: $r->print('<p class="LC_warning">'
3547: .&mt('Caution: this folder is set to randomly pick a subset'
3548: .' of resources. Adding or removing resources from this'
3549: .' folder will change the set of resources that the'
3550: .' students see, resulting in spurious or missing credit'
3551: .' for completed problems, not limited to ones you'
3552: .' modify. Do not modify the contents of this folder if'
3553: .' it is in active student use.')
3554: .'</p>'
3555: );
3556: }
3557: if ($is_random_order) {
3558: $r->print('<p class="LC_warning">'
3559: .&mt('Caution: this folder is set to randomly order its'
3560: .' contents. Adding or removing resources from this folder'
3561: .' will change the order of resources shown.')
3562: .'</p>'
3563: );
3564: }
3565: $r->print('</div>');
1.364 bisitz 3566: }
1.381 bisitz 3567:
1.685 raeburn 3568: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3569: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3570: if (ref($supplemental) eq 'HASH') {
3571: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3572: (ref($supplemental->{'ids'}) eq 'HASH')) {
3573: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3574: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3575: if ($supplemental->{'hidden'}->{$mapnum}) {
3576: $ishidden = 1;
3577: }
3578: }
3579: }
3580: }
3581: }
3582:
1.538 raeburn 3583: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3584: %filters = (
1.543 raeburn 3585: canremove => [],
3586: cancut => [],
3587: cancopy => [],
3588: hiddenresource => [],
3589: encrypturl => [],
3590: randomorder => [],
3591: randompick => [],
1.538 raeburn 3592: );
3593: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3594: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3595: foreach my $res (@LONCAPA::map::order) {
3596: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3597: $name=&LONCAPA::map::qtescape($name);
3598: $url=&LONCAPA::map::qtescape($url);
3599: unless ($name) { $name=(split(/\//,$url))[-1]; }
3600: unless ($name) { $idx++; next; }
1.537 raeburn 3601: push(@allidx,$res);
3602: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3603: push(@allmapidx,$res);
3604: }
1.617 raeburn 3605:
1.682 raeburn 3606: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3607: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3608: $idx++;
3609: next;
3610: }
1.682 raeburn 3611: }
1.381 bisitz 3612: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3613: $coursenum,$coursedom,$crstype,
1.538 raeburn 3614: $pathitem,$supplementalflag,$container,
1.620 raeburn 3615: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3616: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3617: $idx++;
3618: $shown++;
1.329 droeschl 3619: }
1.424 onken 3620: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3621:
1.538 raeburn 3622: my $need_save;
1.611 raeburn 3623: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3624: my $toolslink;
1.682 raeburn 3625: if ($allowed || $canedit) {
3626: my $helpitem = 'Navigation_Screen';
3627: if (!$allowed) {
3628: $helpitem = 'Supplemental_Navigation';
3629: }
1.544 raeburn 3630: $toolslink = '<table><tr><td>'
1.520 raeburn 3631: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3632: $helpitem,undef,'RAT')
1.520 raeburn 3633: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3634: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3635: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3636: .'id="LC_content_toolbar_edittoplevel" '
3637: .'class="LC_toolbarItem" '
3638: .'title="'.&mt('Supplemental Content Editor').'">'
3639: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3640: }
1.510 raeburn 3641: if ($shown) {
3642: if ($allowed) {
3643: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3644: .&Apache::loncommon::start_data_table(undef,'contentlist')
3645: .&Apache::loncommon::start_data_table_header_row()
3646: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3647: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3648: .'<th>'.&mt('Document').'</th>'
3649: .'<th colspan="2">'.&mt('Settings').'</th>'
3650: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3651: if ($folder !~ /^supplemental/) {
1.538 raeburn 3652: $lists{'canhide'} = join(',',@allidx);
3653: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3654: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3655: 'randomorder','randompick');
3656: foreach my $item (@possfilters) {
1.538 raeburn 3657: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3658: if (@{$filters{$item}} > 0) {
3659: $lists{$item} = join(',',@{$filters{$item}});
3660: }
1.538 raeburn 3661: }
3662: }
1.537 raeburn 3663: if (@allidx > 0) {
3664: my $path;
3665: if ($env{'form.folderpath'}) {
1.630 raeburn 3666: $path =
1.537 raeburn 3667: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3668: }
1.538 raeburn 3669: if (@allidx > 1) {
1.630 raeburn 3670: $to_show .=
1.538 raeburn 3671: &Apache::loncommon::continue_data_table_row().
3672: '<td colspan="2"> </td>'.
3673: '<td>'.
1.611 raeburn 3674: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3675: '</td>'.
1.633 raeburn 3676: '<td colspan="3"> </td>'.
3677: '<td colspan="2">'.
1.611 raeburn 3678: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3679: '</td>'.
3680: &Apache::loncommon::end_data_table_row();
3681: $need_save = 1;
3682: }
1.537 raeburn 3683: }
3684: }
3685: $to_show .= $output.' '
1.510 raeburn 3686: .&Apache::loncommon::end_data_table()
3687: .'<br style="line-height:2px;" />'
3688: .&Apache::loncommon::end_scrollbox();
3689: } else {
1.520 raeburn 3690: $to_show .= $toolslink
1.510 raeburn 3691: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3692: .$output.' '
3693: .&Apache::loncommon::end_data_table();
1.393 raeburn 3694: }
1.510 raeburn 3695: } else {
1.520 raeburn 3696: if (!$allowed) {
3697: $to_show .= $toolslink;
3698: }
1.615 raeburn 3699: my $noresmsg;
3700: if ($allowed && $hiddentop && !$supplementalflag) {
3701: $noresmsg = &mt('Main Content Hidden');
3702: } else {
3703: $noresmsg = &mt('Currently empty');
3704: }
1.510 raeburn 3705: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3706: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3707: .$noresmsg
1.510 raeburn 3708: .'</div>'
3709: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3710: }
3711: } else {
1.510 raeburn 3712: if ($shown) {
3713: $to_show = '<div>'
3714: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3715: .$output
3716: .&Apache::loncommon::end_data_table()
3717: .'</div>';
3718: } else {
3719: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3720: .&mt('Currently empty')
1.510 raeburn 3721: .'</div>'
3722: }
1.458 raeburn 3723: }
3724: my $tid = 1;
3725: if ($supplementalflag) {
3726: $tid = 2;
1.329 droeschl 3727: }
3728: if ($allowed) {
1.484 raeburn 3729: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3730: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3731: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3732: if ($canedit) {
3733: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3734: }
1.460 raeburn 3735: } else {
3736: $r->print($to_show);
1.329 droeschl 3737: }
3738: return;
3739: }
3740:
1.538 raeburn 3741: sub multiple_check_form {
1.611 raeburn 3742: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3743: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3744: my $disabled;
3745: unless ($canedit) {
3746: $disabled = 'disabled="disabled"';
3747: }
1.538 raeburn 3748: my $output =
3749: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3750: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3751: '<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>'.
3752: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3753: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3754: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3755: if ($caller eq 'settings') {
3756: $output .=
3757: '<table><tr>'.
3758: '<td class="LC_docs_entry_parameter">'.
3759: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3760: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3761: '</label></span></td>'.
3762: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3763: '<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 3764: '</span></td>'.
3765: '</tr>'."\n".
3766: '<tr>'.
3767: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3768: '<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 3769: '</label></span>'.
3770: '</td></tr></table>'."\n";
3771: } else {
3772: $output .=
3773: '<table><tr>'.
3774: '<td class="LC_docs_entry_parameter">'.
3775: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3776: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3777: '</label></span></td>'.
3778: '<td class="LC_docs_entry_parameter">'.
3779: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3780: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3781: '</label></span></td>'."\n".
3782: '<td class="LC_docs_entry_parameter">'.
3783: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3784: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3785: '</label></span></td>'.
3786: '</tr></table>'."\n";
3787: }
3788: $output .=
3789: '</fieldset>'.
3790: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3791: if ($caller eq 'settings') {
3792: $output .=
1.543 raeburn 3793: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3794: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3795: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3796: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3797: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3798: } elsif ($caller eq 'actions') {
3799: $output .=
3800: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3801: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3802: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3803: }
3804: $output .=
3805: '</form>'.
3806: '</div>';
3807: return $output;
3808: }
3809:
1.329 droeschl 3810: sub process_file_upload {
1.552 raeburn 3811: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3812: # upload a file, if present
1.552 raeburn 3813: my $filesize = length($env{'form.uploaddoc'});
3814: if (!$filesize) {
3815: $$upload_output = '<div class="LC_error">'.
3816: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3817: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3818: $filesize).'<br />'.
3819: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3820: '</div>';
3821: return;
3822: }
3823: my $quotatype = 'unofficial';
3824: if ($crstype eq 'Community') {
1.601 raeburn 3825: $quotatype = 'community';
3826: } elsif ($crstype eq 'Placement') {
3827: $quotatype = 'placement';
1.580 raeburn 3828: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3829: $quotatype = 'official';
1.573 raeburn 3830: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3831: $quotatype = 'textbook';
1.552 raeburn 3832: }
3833: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3834: $filesize = int($filesize/1000); #expressed in kb
3835: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3836: $env{'form.uploaddoc.filename'},$filesize,
3837: 'upload',$quotatype);
1.552 raeburn 3838: return if ($$upload_output);
3839: }
1.440 raeburn 3840: my ($parseaction,$showupload,$nextphase,$mimetype);
3841: if ($env{'form.parserflag'}) {
1.329 droeschl 3842: $parseaction = 'parse';
3843: }
3844: my $folder=$env{'form.folder'};
3845: if ($folder eq '') {
3846: $folder='default';
3847: }
3848: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3849: my $errtext='';
3850: my $fatal=0;
3851: my $container='sequence';
1.519 raeburn 3852: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3853: $container='page';
3854: }
3855: ($errtext,$fatal)=
1.534 raeburn 3856: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3857: if ($#LONCAPA::map::order<1) {
3858: $LONCAPA::map::order[0]=1;
3859: $LONCAPA::map::resources[1]='';
3860: }
3861: my $destination = 'docs/';
3862: if ($folder =~ /^supplemental/) {
3863: $destination = 'supplemental/';
3864: }
3865: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3866: $destination .= 'default/';
3867: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3868: $destination .= $2.'/';
3869: }
1.534 raeburn 3870: if ($fatal) {
3871: $$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>';
3872: return;
3873: }
1.440 raeburn 3874: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3875: my $newidx=&LONCAPA::map::getresidx();
3876: $destination .= $newidx;
1.439 raeburn 3877: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3878: $parseaction,$allfiles,
1.440 raeburn 3879: $codebase,undef,undef,undef,undef,
3880: undef,undef,\$mimetype);
3881: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3882: my $stored = $1;
3883: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3884: $stored.'</span>').'</p>';
3885: } else {
3886: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3887:
1.457 raeburn 3888: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3889: return;
3890: }
1.329 droeschl 3891: my $ext='false';
3892: if ($url=~m{^http://}) { $ext='true'; }
3893: $url = &LONCAPA::map::qtunescape($url);
3894: my $comment=$env{'form.comment'};
3895: $comment = &LONCAPA::map::qtunescape($comment);
3896: if ($folder=~/^supplemental/) {
3897: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3898: $env{'user.domain'}.'___&&&___'.$comment;
3899: }
3900:
3901: $LONCAPA::map::resources[$newidx]=
3902: $comment.':'.$url.':'.$ext.':normal:res';
3903: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3904: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3905: $folder.'.'.$container,1);
1.329 droeschl 3906: if ($fatal) {
1.457 raeburn 3907: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3908: return;
1.329 droeschl 3909: } else {
1.440 raeburn 3910: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3911: $$upload_output = $showupload;
1.384 raeburn 3912: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3913: if ($total_embedded > 0) {
1.440 raeburn 3914: my $uploadphase = 'upload_embedded';
3915: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3916: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3917: my ($embedded,$num) =
1.440 raeburn 3918: &Apache::loncommon::ask_for_embedded_content(
3919: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3920: if ($embedded) {
3921: if ($num) {
3922: $$upload_output .=
3923: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3924: $nextphase = $uploadphase;
3925: } else {
3926: $$upload_output .= $embedded;
3927: }
3928: } else {
3929: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3930: }
1.329 droeschl 3931: } else {
1.440 raeburn 3932: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3933: }
1.457 raeburn 3934: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3935: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3936: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3937: $nextphase = 'decompress_uploaded';
3938: my $position = scalar(@LONCAPA::map::order)-1;
3939: my $noextract = &return_to_editor();
3940: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3941: my %archiveitems = (
3942: folderpath => $env{'form.folderpath'},
3943: cmd => $nextphase,
3944: newidx => $newidx,
3945: position => $position,
3946: phase => $nextphase,
1.477 raeburn 3947: comment => $comment,
1.480 raeburn 3948: );
3949: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3950: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3951: $$upload_output = $showupload.
3952: &Apache::loncommon::decompress_form($mimetype,
3953: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3954: \%archiveitems,\@current);
1.329 droeschl 3955: }
3956: }
3957: }
1.440 raeburn 3958: return $nextphase;
1.329 droeschl 3959: }
3960:
1.480 raeburn 3961: sub get_dir_list {
3962: my ($url,$coursenum,$coursedom,$newidx) = @_;
3963: my ($destination,$dir_root) = &embedded_destination();
3964: my ($dirlistref,$listerror) =
3965: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3966: my @dir_lines;
3967: my $dirptr=16384;
3968: if (ref($dirlistref) eq 'ARRAY') {
3969: foreach my $dir_line (sort
3970: {
3971: my ($afile)=split('&',$a,2);
3972: my ($bfile)=split('&',$b,2);
3973: return (lc($afile) cmp lc($bfile));
3974: } (@{$dirlistref})) {
3975: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3976: $filename =~ s/\s+$//;
3977: next if ($filename =~ /^\.\.?$/);
3978: my $isdir = 0;
3979: if ($dirptr&$testdir) {
3980: $isdir = 1;
3981: }
3982: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3983: }
3984: }
3985: return @dir_lines;
3986: }
3987:
1.329 droeschl 3988: sub is_supplemental_title {
3989: my ($title) = @_;
3990: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3991: }
3992:
3993: # --------------------------------------------------------------- An entry line
3994:
3995: sub entryline {
1.501 raeburn 3996: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3997: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 3998: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 3999: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4000: if (&is_supplemental_title($title)) {
1.488 raeburn 4001: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4002: $encodedtitle=$title;
1.329 droeschl 4003: } else {
4004: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4005: $encodedtitle=$title;
1.329 droeschl 4006: $renametitle=$title;
4007: $foldertitle=$title;
4008: }
4009:
1.611 raeburn 4010: my ($disabled,$readonly,$js_lt);
4011: unless ($canedit) {
4012: $disabled = 'disabled="disabled"';
4013: $readonly = 1;
4014: }
4015:
1.329 droeschl 4016: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4017:
1.329 droeschl 4018: $renametitle=~s/\\/\\\\/g;
4019: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4020: $renametitle=~s/"/%22/g;
1.581 raeburn 4021: $renametitle=~s/ /%20/g;
4022: $oldtitle = $renametitle;
1.576 raeburn 4023: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4024: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4025: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4026: # Edit commands
1.679 raeburn 4027: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4028: if ($env{'form.folderpath'}) {
4029: $esc_path=&escape($env{'form.folderpath'});
4030: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4031: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4032: }
1.505 raeburn 4033: my $isexternal;
1.510 raeburn 4034: if ($residx) {
1.501 raeburn 4035: my $currurl = $url;
4036: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4037: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4038: $isexternal = 1;
4039: }
1.510 raeburn 4040: if (!$supplementalflag) {
4041: my $path = 'uploaded/'.
4042: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4043: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4044: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4045: $residx,
4046: &Apache::lonnet::declutter($currurl));
4047: }
1.501 raeburn 4048: }
1.538 raeburn 4049: my ($renamelink,%lt,$ishash);
4050: if (ref($filtersref) eq 'HASH') {
4051: $ishash = 1;
4052: }
4053:
1.329 droeschl 4054: if ($allowed) {
1.538 raeburn 4055: $form_start = '
4056: <form action="/adm/coursedocs" method="post">
4057: ';
4058: $form_common=(<<END);
4059: <input type="hidden" name="folderpath" value="$path" />
4060: <input type="hidden" name="symb" value="$symb" />
4061: END
4062: $form_param=(<<END);
4063: <input type="hidden" name="setparms" value="$orderidx" />
4064: <input type="hidden" name="changeparms" value="0" />
4065: END
4066: $form_end = '</form>';
4067:
1.329 droeschl 4068: my $incindex=$index+1;
4069: my $selectbox='';
1.471 raeburn 4070: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4071: ((split(/\:/,
1.344 bisitz 4072: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4073: ne '') &&
1.329 droeschl 4074: ((split(/\:/,
1.344 bisitz 4075: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4076: ne '')) {
4077: $selectbox=
4078: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4079: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4080: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4081: if ($i==$incindex) {
1.358 bisitz 4082: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4083: } else {
4084: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4085: }
4086: }
4087: $selectbox.='</select>';
4088: }
1.501 raeburn 4089: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4090: 'up' => 'Move Up',
4091: 'dw' => 'Move Down',
4092: 'rm' => 'Remove',
4093: 'ct' => 'Cut',
4094: 'rn' => 'Rename',
1.501 raeburn 4095: 'cp' => 'Copy',
1.633 raeburn 4096: 'da' => 'Unset alias',
4097: 'sa' => 'Set alias',
1.501 raeburn 4098: 'ex' => 'External Resource',
1.598 raeburn 4099: 'et' => 'External Tool',
1.501 raeburn 4100: 'ed' => 'Edit',
4101: 'pr' => 'Preview',
4102: 'sv' => 'Save',
4103: 'ul' => 'URL',
1.611 raeburn 4104: 'ti' => 'Title',
1.618 raeburn 4105: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4106: );
1.538 raeburn 4107: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4108: $env{'form.folderpath'},
4109: $currgroups);
1.517 raeburn 4110: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4111: my $skip_confirm = 0;
1.603 raeburn 4112: my $confirm_removal = 0;
1.329 droeschl 4113: if ( $folder =~ /^supplemental/
4114: || ($url =~ m{( /smppg$
4115: |/syllabus$
4116: |/aboutme$
4117: |/navmaps$
4118: |/bulletinboard$
1.626 raeburn 4119: |/ext\.tool$
1.505 raeburn 4120: |\.html$)}x)
4121: || $isexternal) {
1.329 droeschl 4122: $skip_confirm = 1;
4123: }
1.603 raeburn 4124: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4125: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4126: $confirm_removal = 1;
4127: }
1.633 raeburn 4128: if ($url =~ /$LONCAPA::assess_re/) {
4129: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4130: }
1.329 droeschl 4131:
1.538 raeburn 4132: if ($denied{'copy'}) {
1.543 raeburn 4133: $copylink=(<<ENDCOPY)
1.507 raeburn 4134: <span style="visibility: hidden;">$lt{'cp'}</span>
4135: ENDCOPY
4136: } else {
1.538 raeburn 4137: my $formname = 'edit_copy_'.$orderidx;
4138: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4139: $copylink=(<<ENDCOPY);
1.538 raeburn 4140: <form name="$formname" method="post" action="/adm/coursedocs">
4141: $form_common
1.611 raeburn 4142: <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 4143: $form_end
1.329 droeschl 4144: ENDCOPY
1.538 raeburn 4145: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4146: push(@{$filtersref->{'cancopy'}},$orderidx);
4147: }
1.329 droeschl 4148: }
1.538 raeburn 4149: if ($denied{'cut'}) {
1.507 raeburn 4150: $cutlink=(<<ENDCUT);
4151: <span style="visibility: hidden;">$lt{'ct'}</span>
4152: ENDCUT
4153: } else {
1.538 raeburn 4154: my $formname = 'edit_cut_'.$orderidx;
4155: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4156: $cutlink=(<<ENDCUT);
1.538 raeburn 4157: <form name="$formname" method="post" action="/adm/coursedocs">
4158: $form_common
1.542 raeburn 4159: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4160: <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 4161: $form_end
1.329 droeschl 4162: ENDCUT
1.538 raeburn 4163: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4164: push(@{$filtersref->{'cancut'}},$orderidx);
4165: }
1.329 droeschl 4166: }
1.538 raeburn 4167: if ($denied{'remove'}) {
1.507 raeburn 4168: $removelink=(<<ENDREM);
4169: <span style="visibility: hidden;">$lt{'rm'}</a>
4170: ENDREM
4171: } else {
1.538 raeburn 4172: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4173: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4174: $removelink=(<<ENDREM);
1.538 raeburn 4175: <form name="$formname" method="post" action="/adm/coursedocs">
4176: $form_common
1.542 raeburn 4177: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4178: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4179: <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 4180: $form_end
1.497 raeburn 4181: ENDREM
1.538 raeburn 4182: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4183: push(@{$filtersref->{'canremove'}},$orderidx);
4184: }
1.497 raeburn 4185: }
1.551 raeburn 4186: $renamelink=(<<ENDREN);
1.581 raeburn 4187: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4188: ENDREN
1.611 raeburn 4189: my ($uplink,$downlink);
4190: if ($canedit) {
4191: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4192: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4193: } else {
4194: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4195: $downlink = $uplink;
4196: }
1.329 droeschl 4197: $line.=(<<END);
4198: <td>
1.379 bisitz 4199: <div class="LC_docs_entry_move">
1.611 raeburn 4200: <a href="$uplink">
1.501 raeburn 4201: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4202: </a>
4203: </div>
4204: <div class="LC_docs_entry_move">
1.611 raeburn 4205: <a href="$downlink">
1.501 raeburn 4206: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4207: </a>
4208: </div>
1.329 droeschl 4209: </td>
4210: <td>
4211: $form_start
1.538 raeburn 4212: $form_param
1.478 raeburn 4213: $form_common
1.329 droeschl 4214: $selectbox
4215: $form_end
4216: </td>
1.540 raeburn 4217: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4218: $removelink
1.329 droeschl 4219: $cutlink
4220: $copylink
4221: </td>
4222: END
4223: }
4224: # Figure out what kind of a resource this is
4225: my ($extension)=($url=~/\.(\w+)$/);
4226: my $uploaded=($url=~/^\/*uploaded\//);
4227: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4228: my $isfolder;
4229: my $ispage;
4230: my $containerarg;
1.615 raeburn 4231: my $folderurl;
1.685 raeburn 4232: my $plainurl;
1.329 droeschl 4233: if ($uploaded) {
1.472 raeburn 4234: if (($extension eq 'sequence') || ($extension eq 'page')) {
4235: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4236: $containerarg = $1;
1.472 raeburn 4237: if ($extension eq 'sequence') {
4238: $icon=$iconpath.'navmap.folder.closed.gif';
4239: $isfolder=1;
4240: } else {
4241: $icon=$iconpath.'page.gif';
4242: $ispage=1;
4243: }
1.615 raeburn 4244: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4245: if ($allowed) {
4246: $url='/adm/coursedocs?';
4247: } else {
4248: $url='/adm/supplemental?';
4249: }
1.329 droeschl 4250: } else {
1.685 raeburn 4251: $plainurl = $url;
1.329 droeschl 4252: }
4253: }
1.364 bisitz 4254:
1.621 raeburn 4255: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4256: my $orig_url = $url;
1.340 raeburn 4257: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4258: if ($container eq 'page') {
4259: $url=~s{^http(|s)(:|:)//}{/ext/};
4260: } else {
4261: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4262: }
1.501 raeburn 4263: if (!$supplementalflag && $residx && $symb) {
4264: if ((!$isfolder) && (!$ispage)) {
4265: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4266: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4267: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4268: } else {
4269: $url=&Apache::lonnet::clutter($url);
4270: }
1.501 raeburn 4271: if ($url=~/^\/*uploaded\//) {
4272: $url=~/\.(\w+)$/;
4273: my $embstyle=&Apache::loncommon::fileembstyle($1);
4274: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4275: $url='/adm/wrapper'.$url;
4276: } elsif ($embstyle eq 'ssi') {
4277: #do nothing with these
4278: } elsif ($url!~/\.(sequence|page)$/) {
4279: $url='/adm/coursedocs/showdoc'.$url;
4280: }
1.623 raeburn 4281: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4282: my $wrapped = $1;
4283: my $exturl = $2;
1.668 raeburn 4284: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4285: $url='/adm/wrapper'.$url;
4286: }
4287: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4288: $nomodal = 1;
4289: }
1.626 raeburn 4290: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4291: $url='/adm/wrapper'.$url;
1.621 raeburn 4292: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4293: if (($ENV{'SERVER_PORT'} == 443) &&
4294: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4295: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4296: $url .= '?usehttp=1';
4297: }
1.621 raeburn 4298: $nomodal = 1;
4299: }
1.598 raeburn 4300: }
1.680 raeburn 4301: my ($checkencrypt,$shownurl);
4302: if (!$env{'request.role.adv'}) {
1.615 raeburn 4303: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4304: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4305: $checkencrypt = 1;
1.620 raeburn 4306: } elsif (ref($navmapref)) {
1.615 raeburn 4307: unless (ref($$navmapref)) {
4308: $$navmapref = Apache::lonnavmaps::navmap->new();
4309: }
4310: if (ref($$navmapref)) {
4311: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4312: $checkencrypt = 1;
1.615 raeburn 4313: }
4314: }
4315: }
1.680 raeburn 4316: }
4317: if ($checkencrypt) {
4318: my $currenc = $env{'request.enc'};
4319: $env{'request.enc'} = 1;
4320: $shownsymb = &Apache::lonenc::encrypted($symb);
4321: $shownurl = &Apache::lonenc::encrypted($url);
4322: if (&Apache::lonnet::symbverify($symb,$url)) {
4323: $url = $shownurl;
4324: } else {
4325: $url = '';
4326: }
4327: $env{'request.enc'} = $currenc;
4328: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4329: $shownsymb = $symb;
4330: if ($isexternal) {
4331: $url =~ s/\#[^#]+$//;
4332: if ($container eq 'page') {
4333: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4334: }
1.612 raeburn 4335: }
1.680 raeburn 4336: $shownurl = $url;
4337: }
4338: unless ($env{'request.role.adv'}) {
4339: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4340: $url = '';
4341: }
4342: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4343: $url = '';
4344: $hiddenres = 1;
4345: }
4346: }
4347: if ($url ne '') {
4348: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4349: }
1.329 droeschl 4350: }
1.621 raeburn 4351: } elsif ($supplementalflag) {
1.610 raeburn 4352: if ($isexternal) {
4353: if ($url =~ /^([^#]+)#([^#]+)$/) {
4354: $url = $1;
4355: $anchor = $2;
1.623 raeburn 4356: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4357: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4358: if ($hostname ne '') {
4359: $url = 'http://'.$hostname.$url;
4360: }
4361: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4362: }
4363: $nomodal = 1;
4364: }
1.610 raeburn 4365: }
1.621 raeburn 4366: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4367: if (($ENV{'SERVER_PORT'} == 443) &&
4368: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4369: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4370: if ($hostname ne '') {
4371: $url = 'http://'.$hostname.$url;
4372: }
4373: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4374: }
1.621 raeburn 4375: $nomodal = 1;
4376: }
1.686 raeburn 4377: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4378: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4379: unless ($embstyle eq 'ssi') {
4380: if (($embstyle eq 'img')
4381: || ($embstyle eq 'emb')
4382: || ($embstyle eq 'wrp')) {
4383: $url='/adm/wrapper'.$url;
4384: } elsif ($url !~ /\.(sequence|page)$/) {
4385: $url='/adm/coursedocs/showdoc'.$url;
4386: }
4387: }
1.610 raeburn 4388: }
1.685 raeburn 4389: unless ($allowed && $env{'request.role.adv'}) {
4390: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4391: $hiddenres = 1;
4392: }
4393: }
1.329 droeschl 4394: }
1.615 raeburn 4395: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4396: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4397: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4398: my $foldername=&escape($foldertitle);
4399: my $folderpath=$env{'form.folderpath'};
4400: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4401: if (!$allowed && $supplementalflag) {
1.519 raeburn 4402: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4403: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4404: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4405: $hiddenfolder = 1;
1.682 raeburn 4406: }
1.510 raeburn 4407: } else {
1.617 raeburn 4408: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4409: 'parameter_randompick'))[0];
4410: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4411: 'parameter_randomorder'))[0]=~/^yes$/i);
4412: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4413: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4414: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4415: 'parameter_encrypturl'))[0]=~/^yes$/i);
4416: unless ($hiddenmap) {
1.620 raeburn 4417: if (ref($navmapref)) {
4418: unless (ref($$navmapref)) {
4419: $$navmapref = Apache::lonnavmaps::navmap->new();
4420: }
4421: if (ref($$navmapref)) {
4422: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4423: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4424: unless (@resources) {
4425: $hiddenmap = 1;
4426: unless ($env{'request.role.adv'}) {
4427: $url = '';
4428: $hiddenfolder = 1;
4429: }
1.617 raeburn 4430: }
1.615 raeburn 4431: }
4432: }
4433: }
4434: }
1.617 raeburn 4435: unless ($encryptmap) {
1.620 raeburn 4436: if ((ref($navmapref)) && (ref($$navmapref))) {
4437: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4438: $encryptmap = 1;
4439: }
1.617 raeburn 4440: }
4441: }
1.630 raeburn 4442:
1.617 raeburn 4443: # Append randompick number, hidden, and encrypted with ":" to foldername,
4444: # so it gets transferred between levels
4445: $folderpath.=$containerarg.'&'.$foldername.
4446: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4447: unless ($url eq '') {
1.612 raeburn 4448: $url.='folderpath='.&escape($folderpath);
4449: }
1.510 raeburn 4450: my $rpckchk;
4451: if ($rpicknum) {
4452: $rpckchk = ' checked="checked"';
1.543 raeburn 4453: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4454: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4455: }
1.510 raeburn 4456: }
1.537 raeburn 4457: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4458: $rand_pick_text =
1.478 raeburn 4459: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4460: $form_param."\n".
1.478 raeburn 4461: $form_common."\n".
1.611 raeburn 4462: '<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 4463: if ($rpicknum ne '') {
4464: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4465: }
1.537 raeburn 4466: $rand_pick_text .= '</span></span>'.
4467: $form_end;
1.543 raeburn 4468: my $ro_set;
1.617 raeburn 4469: if ($randorder) {
1.543 raeburn 4470: $ro_set = 'checked="checked"';
4471: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4472: push(@{$filtersref->{'randomorder'}},$orderidx);
4473: }
4474: }
1.564 raeburn 4475: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4476: $rand_order_text =
1.537 raeburn 4477: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4478: $form_param."\n".
1.537 raeburn 4479: $form_common."\n".
1.611 raeburn 4480: '<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 4481: $form_end;
1.510 raeburn 4482: }
1.509 raeburn 4483: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4484: my $isexttool;
1.626 raeburn 4485: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4486: $url='/adm/wrapper'.$url;
4487: $isexttool = 1;
4488: }
1.510 raeburn 4489: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4490: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4491: if ($title) {
1.687 raeburn 4492: $url .= '&title='.$encodedtitle;
1.510 raeburn 4493: }
1.598 raeburn 4494: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4495: $url .= '&idx='.$orderidx;
4496: }
1.610 raeburn 4497: if ($anchor ne '') {
4498: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4499: }
1.329 droeschl 4500: }
1.519 raeburn 4501: my ($tdalign,$tdwidth);
1.501 raeburn 4502: if ($allowed) {
1.630 raeburn 4503: my $fileloc =
1.501 raeburn 4504: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4505: if ($isexternal) {
1.630 raeburn 4506: ($editlink,$extresform) =
1.611 raeburn 4507: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4508: undef,undef,undef,undef,undef,undef,
4509: undef,$disabled);
1.626 raeburn 4510: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4511: ($editlink,$extresform) =
4512: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4513: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4514: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4515: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4516: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4517: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4518: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4519: my $suppanchor;
4520: if ($supplementalflag) {
4521: $suppanchor = $anchor;
4522: }
1.630 raeburn 4523: my $jscall =
1.501 raeburn 4524: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4525: $switchserver,
1.503 raeburn 4526: $forceedit,
1.679 raeburn 4527: undef,$symb,$shownsymb,
1.511 raeburn 4528: &escape($env{'form.folderpath'}),
1.622 raeburn 4529: $renametitle,$hostname,
4530: '','',1,$suppanchor);
1.501 raeburn 4531: if ($jscall) {
1.518 raeburn 4532: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4533: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4534: }
4535: }
4536: }
1.519 raeburn 4537: $tdalign = ' align="right" valign="top"';
4538: $tdwidth = ' width="80%"';
1.329 droeschl 4539: }
1.408 raeburn 4540: my $reinit;
4541: if ($crstype eq 'Community') {
4542: $reinit = &mt('(re-initialize community to access)');
4543: } else {
4544: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4545: }
4546: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4547: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4548: $line.= '<br />';
4549: if ($curralias ne '') {
4550: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4551: $lt{'da'}.'</a></span>';
4552: } else {
4553: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4554: $lt{'sa'}.'</a></span>';
4555: }
4556: }
4557: $line.='</td><td>';
1.685 raeburn 4558: my ($link,$nolink);
1.472 raeburn 4559: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4560: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4561: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4562: $nolink = 1;
4563: }
4564: }
4565: if ($nolink) {
4566: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4567: } else {
4568: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4569: }
1.469 www 4570: } elsif ($url) {
1.610 raeburn 4571: if ($anchor ne '') {
4572: if ($supplementalflag) {
4573: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4574: } else {
4575: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4576: }
4577: }
1.622 raeburn 4578: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4579: $link = 'http://'.$hostname.$url;
4580: } else {
4581: $link = $url;
4582: }
1.659 raeburn 4583: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4584: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4585: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4586: $nolink = 1;
4587: }
4588: }
4589: if ($nolink) {
4590: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4591: } elsif ($nomodal) {
1.621 raeburn 4592: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4593: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4594: } else {
4595: $line.=&Apache::loncommon::modal_link($link,
4596: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4597: }
1.469 www 4598: } else {
4599: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4600: }
1.519 raeburn 4601: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4602: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4603: if ($nolink) {
4604: $line.=$title;
4605: } else {
4606: $line.='<a href="'.$url.'">'.$title.'</a>';
4607: }
1.682 raeburn 4608: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4609: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4610: my $editurl = $url;
4611: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4612: $line .= ' '.'<a href="'.$editurl.'">'.
4613: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4614: '</a>';
4615: }
4616: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4617: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4618: }
1.469 www 4619: } elsif ($url) {
1.685 raeburn 4620: if ($nolink) {
4621: $line.=$title;
4622: } elsif ($nomodal) {
1.621 raeburn 4623: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4624: $title.'</a>';
4625: } else {
4626: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4627: }
1.617 raeburn 4628: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4629: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4630: } else {
4631: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4632: }
1.633 raeburn 4633: if (($allowed) && ($curralias ne '')) {
4634: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4635: } else {
4636: $line .= $extresform;
4637: }
4638: $line .= '</td>';
1.478 raeburn 4639: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4640: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4641: if ($uploaded && $url && !$isfolder && !$ispage) {
4642: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4643: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4644: }
4645: }
1.682 raeburn 4646: if ($allowed) {
4647: my %lt=&Apache::lonlocal::texthash(
4648: 'hd' => 'Hidden',
4649: 'ec' => 'URL hidden');
4650: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4651: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4652: $hidtext = ' checked="checked"';
1.694 ! raeburn 4653: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 4654: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4655: }
4656: }
1.682 raeburn 4657: $formhidden = 'edit_hiddenresource_'.$orderidx;
4658: $line.=(<<ENDPARMS);
1.329 droeschl 4659: <td class="LC_docs_entry_parameter">
1.537 raeburn 4660: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4661: $form_param
1.478 raeburn 4662: $form_common
1.611 raeburn 4663: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4664: $form_end
1.682 raeburn 4665: ENDPARMS
4666: if ($folder =~/^supplemental/) {
4667: $line.= "\n <td>";
4668: } else {
4669: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4670: $enctext = ' checked="checked"';
4671: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4672: push(@{$filtersref->{'encrypturl'}},$orderidx);
4673: }
4674: }
4675: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4676: $line.=(<<ENDPARMS);
1.458 raeburn 4677: <br />
1.537 raeburn 4678: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4679: $form_param
1.478 raeburn 4680: $form_common
1.611 raeburn 4681: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4682: $form_end
4683: </td>
1.478 raeburn 4684: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4685: $rand_order_text</td>
1.329 droeschl 4686: ENDPARMS
1.682 raeburn 4687: }
1.329 droeschl 4688: }
1.379 bisitz 4689: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4690: return $line;
4691: }
4692:
1.538 raeburn 4693: sub action_restrictions {
4694: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4695: my %denied = (
4696: cut => 0,
4697: copy => 0,
4698: remove => 0,
4699: );
4700: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4701: # no copy for published maps
4702: $denied{'copy'} = 1;
1.597 raeburn 4703: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4704: unless ($1 eq 'simpleproblem') {
4705: $denied{'copy'} = 1;
4706: }
4707: $denied{'cut'} = 1;
1.538 raeburn 4708: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4709: if ($folderpath =~ /^default&[^\&]+$/) {
4710: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4711: $denied{'remove'} = 1;
4712: }
4713: $denied{'cut'} = 1;
4714: $denied{'copy'} = 1;
4715: }
4716: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4717: my $group = $1;
4718: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4719: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4720: $denied{'remove'} = 1;
4721: }
4722: }
4723: $denied{'cut'} = 1;
4724: $denied{'copy'} = 1;
4725: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4726: my $group = $1;
4727: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4728: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4729: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4730: if (keys(%groupsettings) > 0) {
4731: $denied{'remove'} = 1;
4732: }
4733: $denied{'cut'} = 1;
4734: $denied{'copy'} = 1;
4735: }
4736: }
4737: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4738: my $group = $1;
4739: if ($url =~ /group_boards_\Q$group\E/) {
4740: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4741: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4742: if (keys(%groupsettings) > 0) {
4743: if (ref($groupsettings{'functions'}) eq 'HASH') {
4744: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4745: $denied{'remove'} = 1;
4746: }
4747: }
4748: }
4749: $denied{'cut'} = 1;
4750: $denied{'copy'} = 1;
4751: }
4752: }
4753: }
4754: return %denied;
4755: }
4756:
1.533 raeburn 4757: sub new_timebased_suffix {
1.538 raeburn 4758: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4759: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4760: if ($type eq 'paste') {
4761: $prefix = $type;
4762: $namespace = 'courseeditor';
1.587 raeburn 4763: $idtype = 'addcode';
1.538 raeburn 4764: } elsif ($type eq 'map') {
1.533 raeburn 4765: $prefix = 'docs';
4766: if ($area eq 'supplemental') {
4767: $prefix = 'supp';
4768: }
4769: $prefix .= $container;
4770: $namespace = 'uploadedmaps';
4771: } else {
4772: $prefix = $type;
4773: $namespace = 'templated';
1.504 raeburn 4774: }
4775: my ($suffix,$freedlock,$error) =
1.587 raeburn 4776: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4777: if (!$suffix) {
1.538 raeburn 4778: if ($type eq 'paste') {
4779: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4780: } elsif ($type eq 'map') {
1.533 raeburn 4781: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4782: } elsif ($type eq 'smppg') {
4783: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4784: } elsif ($type eq 'exttool') {
4785: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4786: } else {
1.565 bisitz 4787: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4788: }
1.504 raeburn 4789: if ($error) {
4790: $errtext .= '<br />'.$error;
4791: }
4792: }
4793: if ($freedlock ne 'ok') {
1.630 raeburn 4794: $locknotfreed =
1.533 raeburn 4795: '<div class="LC_error">'.
4796: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4797: if ($type eq 'paste') {
1.591 raeburn 4798: if ($freedlock eq 'nolock') {
4799: $locknotfreed =
4800: '<div class="LC_error">'.
4801: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4802:
1.593 droeschl 4803: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4804: } else {
4805: $locknotfreed .=
4806: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4807: }
1.538 raeburn 4808: } elsif ($type eq 'map') {
1.591 raeburn 4809: $locknotfreed .=
4810: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4811: } elsif ($type eq 'smppg') {
4812: $locknotfreed .=
4813: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4814: } elsif ($type eq 'exttool') {
4815: $locknotfreed .=
4816: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4817: } else {
4818: $locknotfreed .=
1.565 bisitz 4819: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4820: }
1.538 raeburn 4821: unless ($type eq 'paste') {
4822: $locknotfreed .=
1.560 raeburn 4823: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4824: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4825: }
4826: $locknotfreed .= '</div>';
1.504 raeburn 4827: }
4828: return ($suffix,$errtext,$locknotfreed);
4829: }
4830:
1.329 droeschl 4831: =pod
4832:
4833: =item tiehash()
4834:
4835: tie the hash
4836:
4837: =cut
4838:
4839: sub tiehash {
4840: my ($mode)=@_;
4841: $hashtied=0;
4842: if ($env{'request.course.fn'}) {
4843: if ($mode eq 'write') {
4844: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4845: &GDBM_WRCREAT(),0640)) {
4846: $hashtied=2;
4847: }
4848: } else {
4849: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4850: &GDBM_READER(),0640)) {
4851: $hashtied=1;
4852: }
4853: }
1.364 bisitz 4854: }
1.329 droeschl 4855: }
4856:
4857: sub untiehash {
4858: if ($hashtied) { untie %hash; }
4859: $hashtied=0;
4860: return OK;
4861: }
4862:
4863:
4864:
4865:
4866: sub checkonthis {
1.637 raeburn 4867: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4868: $url=&unescape($url);
4869: $alreadyseen{$url}=1;
4870: $r->rflush();
4871: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4872: $r->print("\n<br />");
4873: if ($level==0) {
4874: $r->print("<br />");
4875: }
4876: for (my $i=0;$i<=$level*5;$i++) {
4877: $r->print(' ');
4878: }
4879: $r->print('<a href="'.$url.'" target="cat">'.
4880: ($title?$title:$url).'</a> ');
4881: if ($url=~/^\/res\//) {
1.637 raeburn 4882: my $updated;
4883: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4884: ($url !~ /\.\d+\.\w+$/)) {
4885: $updated = &Apache::lonnet::remove_stale_resfile($url);
4886: }
1.329 droeschl 4887: my $result=&Apache::lonnet::repcopy(
4888: &Apache::lonnet::filelocation('',$url));
4889: if ($result eq 'ok') {
4890: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4891: if ($updated) {
4892: $r->print('<br />');
4893: for (my $i=0;$i<=$level*5;$i++) {
4894: $r->print(' ');
4895: }
4896: $r->print('- '.&mt('Outdated copy removed'));
4897: }
1.329 droeschl 4898: $r->rflush();
4899: &Apache::lonnet::countacc($url);
4900: $url=~/\.(\w+)$/;
4901: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4902: $r->print('<br />');
4903: $r->rflush();
4904: for (my $i=0;$i<=$level*5;$i++) {
4905: $r->print(' ');
4906: }
4907: $r->print('- '.&mt('Rendering:').' ');
4908: my ($errorcount,$warningcount)=split(/:/,
4909: &Apache::lonnet::ssi_body($url,
4910: ('grade_target'=>'web',
4911: 'return_only_error_and_warning_counts' => 1)));
4912: if (($errorcount) ||
4913: ($warningcount)) {
4914: if ($errorcount) {
1.369 bisitz 4915: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4916: &mt('[quant,_1,error]',$errorcount).'</span>');
4917: }
4918: if ($warningcount) {
4919: $r->print('<span class="LC_warning">'.
4920: &mt('[quant,_1,warning]',$warningcount).'</span>');
4921: }
4922: } else {
4923: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4924: }
4925: $r->rflush();
4926: }
4927: my $dependencies=
4928: &Apache::lonnet::metadata($url,'dependencies');
4929: foreach my $dep (split(/\,/,$dependencies)) {
4930: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4931: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4932: }
4933: }
4934: } elsif ($result eq 'unavailable') {
4935: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4936: } elsif ($result eq 'not_found') {
4937: unless ($url=~/\$/) {
1.521 bisitz 4938: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4939: } else {
1.366 bisitz 4940: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4941: }
4942: } else {
4943: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4944: }
1.637 raeburn 4945: if (($updated) && ($result ne 'ok')) {
4946: $r->print('<br />'.&mt('Outdated copy removed'));
4947: }
1.329 droeschl 4948: }
4949: }
4950: }
4951:
4952:
4953:
4954: =pod
4955:
4956: =item list_symbs()
4957:
1.485 raeburn 4958: List Content Identifiers
1.329 droeschl 4959:
4960: =cut
4961:
4962: sub list_symbs {
4963: my ($r) = @_;
4964:
1.408 raeburn 4965: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4966: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4967: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4968: $r->print(&startContentScreen('tools'));
1.329 droeschl 4969: my $navmap = Apache::lonnavmaps::navmap->new();
4970: if (!defined($navmap)) {
4971: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4972: '<div class="LC_error">'.
4973: &mt('Unable to retrieve information about course contents').
4974: '</div>');
1.408 raeburn 4975: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4976: } else {
1.484 raeburn 4977: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4978: &Apache::loncommon::start_data_table().
4979: &Apache::loncommon::start_data_table_header_row().
4980: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4981: &Apache::loncommon::end_data_table_header_row()."\n");
4982: my $count;
1.329 droeschl 4983: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4984: $r->print(&Apache::loncommon::start_data_table_row().
4985: '<td>'.$res->compTitle().'</td>'.
4986: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4987: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4988: $count ++;
4989: }
4990: if (!$count) {
4991: $r->print(&Apache::loncommon::start_data_table_row().
4992: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4993: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4994: }
1.484 raeburn 4995: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4996: }
1.521 bisitz 4997: $r->print(&endContentScreen());
1.329 droeschl 4998: }
4999:
1.651 raeburn 5000: sub short_urls {
5001: my ($r,$canedit) = @_;
5002: my $crstype = &Apache::loncommon::course_type();
5003: my $formname = 'shortenurl';
5004: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5005: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5006: $r->print(&startContentScreen('tools'));
5007: my ($navmap,$errormsg) =
5008: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5009: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5010: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5011: my (%maps,%resources,%titles);
5012: if (!ref($navmap)) {
5013: $r->print($errormsg.
5014: &endContentScreen());
5015: return '';
5016: } else {
1.652 raeburn 5017: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5018: $r->rflush();
5019: my $readonly;
5020: if ($canedit) {
1.671 raeburn 5021: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5022: if ($numnew) {
5023: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5024: }
5025: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5026: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5027: foreach my $error (@{$errors}) {
5028: $r->print('<li>'.$error.'</li>');
5029: }
5030: $r->print('</ul><br />');
5031: }
5032: } else {
5033: $readonly = 1;
5034: }
5035: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5036: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5037: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5038: }
5039: $r->print(&endContentScreen());
5040: }
5041:
1.637 raeburn 5042: sub contentverifyform {
5043: my ($r) = @_;
5044: my $crstype = &Apache::loncommon::course_type();
5045: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5046: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5047: $r->print(&startContentScreen('tools'));
5048: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5049: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5050: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5051: ' <span class="LC_nobreak">'.
5052: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5053: &mt('No').'</label>'.(' 'x2).
5054: '<label><input type="radio" name="checkstale" value="1" />'.
5055: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5056: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5057: '<input type="hidden" value="1" name="tools" />'.
5058: '<input type="hidden" value="1" name="verify" /></p></form>');
5059: $r->print(&endContentScreen());
5060: return;
5061: }
1.329 droeschl 5062:
5063: sub verifycontent {
1.637 raeburn 5064: my ($r,$checkstale) = @_;
1.408 raeburn 5065: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5066: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5067: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5068: $r->print(&startContentScreen('tools'));
5069: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5070: $hashtied=0;
5071: undef %alreadyseen;
5072: %alreadyseen=();
5073: &tiehash();
1.484 raeburn 5074:
1.329 droeschl 5075: foreach my $key (keys(%hash)) {
5076: if ($hash{$key}=~/\.(page|sequence)$/) {
5077: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5078: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5079: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5080: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5081: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5082: }
5083: }
5084: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5085: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5086: }
5087: }
5088: &untiehash();
1.442 www 5089: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5090: $r->print(&endContentScreen());
1.329 droeschl 5091: }
5092:
5093: sub devalidateversioncache {
5094: my $src=shift;
5095: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5096: &Apache::lonnet::clutter($src));
5097: }
5098:
5099: sub checkversions {
1.611 raeburn 5100: my ($r,$canedit) = @_;
1.408 raeburn 5101: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5102: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5103: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5104: $r->print(&startContentScreen('tools'));
1.442 www 5105:
1.329 droeschl 5106: my $header='';
5107: my $startsel='';
5108: my $monthsel='';
5109: my $weeksel='';
5110: my $daysel='';
5111: my $allsel='';
5112: my %changes=();
5113: my $starttime=0;
5114: my $haschanged=0;
5115: my %setversions=&Apache::lonnet::dump('resourceversions',
5116: $env{'course.'.$env{'request.course.id'}.'.domain'},
5117: $env{'course.'.$env{'request.course.id'}.'.num'});
5118:
5119: $hashtied=0;
5120: &tiehash();
1.611 raeburn 5121: if ($canedit) {
5122: my %newsetversions=();
5123: if ($env{'form.setmostrecent'}) {
5124: $haschanged=1;
5125: foreach my $key (keys(%hash)) {
5126: if ($key=~/^ids\_(\/res\/.+)$/) {
5127: $newsetversions{$1}='mostrecent';
5128: &devalidateversioncache($1);
5129: }
5130: }
5131: } elsif ($env{'form.setcurrent'}) {
5132: $haschanged=1;
5133: foreach my $key (keys(%hash)) {
5134: if ($key=~/^ids\_(\/res\/.+)$/) {
5135: my $getvers=&Apache::lonnet::getversion($1);
5136: if ($getvers>0) {
5137: $newsetversions{$1}=$getvers;
5138: &devalidateversioncache($1);
5139: }
5140: }
1.329 droeschl 5141: }
1.611 raeburn 5142: } elsif ($env{'form.setversions'}) {
5143: $haschanged=1;
5144: foreach my $key (keys(%env)) {
5145: if ($key=~/^form\.set_version_(.+)$/) {
5146: my $src=$1;
5147: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5148: $newsetversions{$src}=$env{$key};
5149: &devalidateversioncache($src);
5150: }
5151: }
1.329 droeschl 5152: }
1.611 raeburn 5153: }
5154: if ($haschanged) {
5155: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5156: $env{'course.'.$env{'request.course.id'}.'.domain'},
5157: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5158: $r->print(&Apache::loncommon::confirmwrapper(
5159: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5160: } else {
5161: $r->print(&Apache::loncommon::confirmwrapper(
5162: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5163: }
1.611 raeburn 5164: &mark_hash_old();
5165: }
5166: &changewarning($r,'');
1.329 droeschl 5167: }
5168: if ($env{'form.timerange'} eq 'all') {
5169: # show all documents
1.549 raeburn 5170: $header=&mt('All content in '.$crstype);
1.521 bisitz 5171: $allsel=' selected="selected"';
1.329 droeschl 5172: foreach my $key (keys(%hash)) {
5173: if ($key=~/^ids\_(\/res\/.+)$/) {
5174: my $src=$1;
5175: $changes{$src}=1;
5176: }
5177: }
5178: } else {
5179: # show documents which changed
5180: %changes=&Apache::lonnet::dump
5181: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5182: $env{'course.'.$env{'request.course.id'}.'.num'});
5183: my $firstkey=(keys(%changes))[0];
5184: unless ($firstkey=~/^error\:/) {
5185: unless ($env{'form.timerange'}) {
5186: $env{'form.timerange'}=604800;
5187: }
5188: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5189: .&mt('seconds');
5190: if ($env{'form.timerange'}==-1) {
5191: $seltext='since start of course';
1.521 bisitz 5192: $startsel=' selected="selected"';
1.329 droeschl 5193: $env{'form.timerange'}=time;
5194: }
5195: $starttime=time-$env{'form.timerange'};
5196: if ($env{'form.timerange'}==2592000) {
5197: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5198: $monthsel=' selected="selected"';
1.329 droeschl 5199: } elsif ($env{'form.timerange'}==604800) {
5200: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5201: $weeksel=' selected="selected"';
1.329 droeschl 5202: } elsif ($env{'form.timerange'}==86400) {
5203: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5204: $daysel=' selected="selected"';
1.329 droeschl 5205: }
5206: $header=&mt('Content changed').' '.$seltext;
5207: } else {
5208: $header=&mt('No content modifications yet.');
5209: }
5210: }
5211: %setversions=&Apache::lonnet::dump('resourceversions',
5212: $env{'course.'.$env{'request.course.id'}.'.domain'},
5213: $env{'course.'.$env{'request.course.id'}.'.num'});
5214: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5215: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5216: 'lm' => 'Version changes since last Month',
5217: 'lw' => 'Version changes since last Week',
5218: 'sy' => 'Version changes since Yesterday',
5219: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5220: 'cd' => 'Change display',
1.329 droeschl 5221: 'sd' => 'Display',
5222: 'fi' => 'File',
5223: 'md' => 'Modification Date',
5224: 'mr' => 'Most recently published Version',
1.408 raeburn 5225: 've' => 'Version used in '.$crstype,
5226: 'vu' => 'Set Version to be used in '.$crstype,
5227: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5228: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5229: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5230: 'di' => 'Differences',
1.484 raeburn 5231: 'save' => 'Save changes',
5232: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5233: 'act' => 'Actions');
1.611 raeburn 5234: my ($disabled,$readonly);
5235: unless ($canedit) {
5236: $disabled = 'disabled="disabled"';
5237: $readonly = 1;
5238: }
1.329 droeschl 5239: $r->print(<<ENDHEADERS);
1.484 raeburn 5240: <h4 class="LC_info">$header</h4>
1.329 droeschl 5241: <form action="/adm/coursedocs" method="post">
5242: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5243: <div class="LC_left_float">
1.479 golterma 5244: <fieldset>
1.484 raeburn 5245: <legend>$lt{'cd'}</legend>
1.329 droeschl 5246: <select name="timerange">
1.521 bisitz 5247: <option value='all'$allsel>$lt{'al'}</option>
5248: <option value="-1"$startsel>$lt{'st'}</option>
5249: <option value="2592000"$monthsel>$lt{'lm'}</option>
5250: <option value="604800"$weeksel>$lt{'lw'}</option>
5251: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5252: </select>
5253: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5254: </fieldset>
5255: </div>
5256: <div class="LC_left_float">
5257: <fieldset>
5258: <legend>$lt{'act'}</legend>
1.611 raeburn 5259: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5260: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5261: </fieldset>
5262: </div>
5263: <br clear="all" />
5264: <hr />
5265: <h4>$lt{'vers'}</h4>
1.329 droeschl 5266: ENDHEADERS
1.479 golterma 5267: #number of columns for version history
1.571 raeburn 5268: my %changedbytime;
5269: foreach my $key (keys(%changes)) {
5270: #excludes not versionable problems from resource version history:
5271: next if ($key =~ /^\/res\/lib\/templates/);
5272: my $chg;
5273: if ($env{'form.timerange'} eq 'all') {
5274: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5275: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5276: } else {
5277: $chg = $changes{$key};
5278: next if ($chg < $starttime);
5279: }
5280: push(@{$changedbytime{$chg}},$key);
5281: }
5282: if (keys(%changedbytime) == 0) {
5283: &untiehash();
5284: $r->print(&mt('No content changes in imported content in specified time frame').
5285: &endContentScreen());
5286: return;
5287: }
1.479 golterma 5288: $r->print(
1.611 raeburn 5289: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5290: &Apache::loncommon::start_data_table().
5291: &Apache::loncommon::start_data_table_header_row().
5292: '<th>'.&mt('Resources').'</th>'.
5293: "<th>$lt{'mr'}</th>".
5294: "<th>$lt{'ve'}</th>".
5295: "<th>$lt{'vu'}</th>".
5296: '<th>'.&mt('History').'</th>'.
5297: &Apache::loncommon::end_data_table_header_row()
5298: );
1.571 raeburn 5299: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5300: foreach my $key (sort(@{$changedbytime{$chg}})) {
5301: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5302: my $currentversion=&Apache::lonnet::getversion($key);
5303: if ($currentversion<0) {
5304: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5305: }
5306: my $linkurl=&Apache::lonnet::clutter($key);
5307: $r->print(
5308: &Apache::loncommon::start_data_table_row().
5309: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5310: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5311: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5312: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5313: '<td align="right">'
5314: );
5315: # Used in course
5316: my $usedversion=$hash{'version_'.$linkurl};
5317: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5318: if ($usedversion != $currentversion) {
1.479 golterma 5319: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5320: } else {
1.479 golterma 5321: $r->print($usedversion);
5322: }
1.329 droeschl 5323: } else {
1.521 bisitz 5324: $r->print($currentversion);
1.329 droeschl 5325: }
1.571 raeburn 5326: $r->print('</td><td title="'.$lt{'vu'}.'">');
5327: # Set version
5328: $r->print(&Apache::loncommon::select_form(
5329: $setversions{$linkurl},
5330: 'set_version_'.$linkurl,
5331: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5332: '' => '',
5333: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5334: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5335: my $lastold=1;
5336: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5337: my $url=$root.'.'.$prevvers.'.'.$extension;
5338: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5339: $lastold=$prevvers;
5340: }
5341: }
5342: $r->print('</td>');
5343: # List all available versions
5344: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5345: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5346: my $url=$root.'.'.$prevvers.'.'.$extension;
5347: $r->print(
5348: '<span class="LC_nobreak">'
5349: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5350: .&mt('Version [_1]',$prevvers).'</a>'
5351: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5352: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5353: .')');
5354: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5355: $r->print(
5356: ' <a href="/adm/diff?filename='.
5357: &Apache::lonnet::clutter($root.'.'.$extension).
5358: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5359: '" target="diffs">'.&mt('Diffs').'</a>');
5360: }
5361: $r->print('</span><br />');
1.329 droeschl 5362: }
1.571 raeburn 5363: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5364: }
1.329 droeschl 5365: }
1.521 bisitz 5366: $r->print(
5367: &Apache::loncommon::end_data_table().
1.611 raeburn 5368: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5369: '</form>'
5370: );
1.329 droeschl 5371:
5372: &untiehash();
1.521 bisitz 5373: $r->print(&endContentScreen());
1.571 raeburn 5374: return;
1.329 droeschl 5375: }
5376:
5377: sub mark_hash_old {
5378: my $retie_hash=0;
5379: if ($hashtied) {
5380: $retie_hash=1;
5381: &untiehash();
5382: }
5383: &tiehash('write');
5384: $hash{'old'}=1;
5385: &untiehash();
5386: if ($retie_hash) { &tiehash(); }
5387: }
5388:
5389: sub is_hash_old {
5390: my $untie_hash=0;
5391: if (!$hashtied) {
5392: $untie_hash=1;
5393: &tiehash();
5394: }
5395: my $return=$hash{'old'};
5396: if ($untie_hash) { &untiehash(); }
5397: return $return;
5398: }
5399:
5400: sub changewarning {
5401: my ($r,$postexec,$message,$url)=@_;
5402: if (!&is_hash_old()) { return; }
5403: my $pathvar='folderpath';
5404: my $path=&escape($env{'form.folderpath'});
5405: if (!defined($url)) {
5406: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5407: }
5408: my $course_type = &Apache::loncommon::course_type();
5409: if (!defined($message)) {
5410: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5411: }
1.653 raeburn 5412: my $windowname = 'loncapaclient';
5413: if ($env{'request.lti.login'}) {
5414: $windowname .= 'lti';
5415: }
1.329 droeschl 5416: $r->print("\n\n".
1.372 bisitz 5417: '<script type="text/javascript">'."\n".
5418: '// <![CDATA['."\n".
5419: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5420: '// ]]>'."\n".
1.369 bisitz 5421: '</script>'."\n".
1.653 raeburn 5422: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5423: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5424: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5425: &mt($message,' <input type="hidden" name="'.
5426: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5427: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5428: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5429: }
5430:
5431:
5432: sub init_breadcrumbs {
1.571 raeburn 5433: my ($form,$text,$help)=@_;
1.329 droeschl 5434: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5435: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5436: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5437: faq=>273,
5438: bug=>'Instructor Interface',
1.571 raeburn 5439: help => $help});
1.329 droeschl 5440: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5441: text=>$text,
5442: faq=>273,
5443: bug=>'Instructor Interface'});
5444: }
5445:
1.441 www 5446: # subroutine to list form elements
5447: sub create_list_elements {
5448: my @formarr = @_;
5449: my $list = '';
1.501 raeburn 5450: foreach my $button (@formarr){
5451: foreach my $picture (keys(%{$button})) {
5452: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5453: }
5454: }
5455: return $list;
5456: }
1.329 droeschl 5457:
1.441 www 5458: # subroutine to create ul from list elements
5459: sub create_form_ul {
5460: my $list = shift;
5461: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5462: return $ul;
5463: }
1.329 droeschl 5464:
1.442 www 5465: #
5466: # Start tabs
5467: #
5468:
5469: sub startContentScreen {
1.484 raeburn 5470: my ($mode) = @_;
5471: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5472: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5473: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5474: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5475: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5476: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5477: } else {
1.549 raeburn 5478: $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 5479: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5480: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5481: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5482: }
5483: $output .= "\n".'</ul>'."\n";
5484: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5485: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5486: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5487: return $output;
1.442 www 5488: }
5489:
5490: #
5491: # End tabs
5492: #
5493:
5494: sub endContentScreen {
1.484 raeburn 5495: return '</div></div></div>';
1.442 www 5496: }
1.329 droeschl 5497:
1.446 www 5498: sub supplemental_base {
1.548 raeburn 5499: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5500: }
5501:
1.329 droeschl 5502: sub handler {
5503: my $r = shift;
5504: &Apache::loncommon::content_type($r,'text/html');
5505: $r->send_http_header;
5506: return OK if $r->header_only;
1.484 raeburn 5507:
5508: # get course data
1.408 raeburn 5509: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5510: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5511: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5512:
1.606 raeburn 5513: # get docroot
5514: my $londocroot = $r->dir_config('lonDocRoot');
5515:
1.484 raeburn 5516: # graphics settings
5517: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5518:
1.443 www 5519: #
1.329 droeschl 5520: # --------------------------------------------- Initialize help topics for this
5521: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5522: 'Adding_External_Resource','Adding_External_Tool',
5523: 'Navigate_Content','Adding_Folders','Docs_Overview',
5524: 'Load_Map','Supplemental','Score_Upload_Form',
5525: 'Adding_Pages','Importing_LON-CAPA_Resource',
5526: 'Importing_IMS_Course','Uploading_From_Harddrive',
5527: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5528: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5529: }
5530: # Composite help files
5531: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5532: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5533: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5534: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5535: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5536: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5537: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5538: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5539: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5540: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5541:
1.611 raeburn 5542: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5543: # does this user have privileges to modify content.
5544: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5545: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5546: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5547: $allowed = 1;
1.682 raeburn 5548: }
5549: $canedit = 1;
5550: $canview = 1;
5551: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5552: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5553: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5554: $allowed = 1;
5555: }
1.682 raeburn 5556: $canview = 1;
1.611 raeburn 5557: }
5558: unless ($canedit) {
5559: $disabled = ' disabled="disabled"';
1.472 raeburn 5560: }
1.582 raeburn 5561: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5562: if ($env{'form.inhibitmenu'}) {
5563: unless ($env{'form.inhibitmenu'} eq 'yes') {
5564: delete($env{'form.inhibitmenu'});
5565: }
5566: }
5567:
1.582 raeburn 5568: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5569: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5570: if (!$canedit) {
5571: &verifycontent($r);
5572: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5573: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5574: text=>'Results',
5575: faq=>273,
5576: bug=>'Instructor Interface'});
5577: &verifycontent($r,$env{'form.checkstale'});
5578: } else {
5579: &contentverifyform($r);
5580: }
1.329 droeschl 5581: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5582: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5583: &list_symbs($r);
1.651 raeburn 5584: } elsif ($allowed && $env{'form.shorturls'}) {
5585: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5586: &short_urls($r,$canedit);
1.329 droeschl 5587: } elsif ($allowed && $env{'form.docslog'}) {
5588: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5589: my $folder = $env{'form.folder'};
5590: if ($folder eq '') {
5591: $folder='default';
5592: }
1.611 raeburn 5593: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5594: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5595: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5596: &checkversions($r,$canedit);
5597: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5598: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5599: &dumpcourse($r);
1.611 raeburn 5600: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5601: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5602: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5603: } else {
1.611 raeburn 5604: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5605: $noendpage = 1;
5606: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5607: if ($redirect) {
5608: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5609: my $container = 'sequence';
5610: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5611: $is_random_order,$container) =
5612: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5613: my (@folders)=split('&',$env{'form.folderpath'});
5614: $env{'form.foldername'}=&unescape(pop(@folders));
5615: my $folder=pop(@folders);
5616: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5617: $folder.'.'.$container);
5618: my $warning;
5619: if ($fatal) {
5620: if ($container eq 'page') {
5621: $warning = &mt('An error occurred retrieving the contents of the current page.');
5622: } else {
5623: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5624: }
5625: } else {
5626: my $url = $redirect;
5627: my $srcfile = $londocroot.$url;
5628: $url =~ s{^/priv/}{/res/};
5629: my $targetfile = $londocroot.$url;
5630: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5631: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5632: $env{'form.folder'} = $folder;
5633: &snapshotbefore();
5634: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5635: my $ext = 'false';
5636: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5637: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5638: ':'.$ext.':normal:res';
5639: push(@LONCAPA::map::order,$newidx);
5640: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5641: 'string_yesno');
5642: &remember_parms($newidx,'hiddenresource','set','yes');
5643: ($errtext,$fatal) =
5644: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5645: &log_differences($plain);
5646: &mark_hash_old();
5647: $r->internal_redirect($redirect);
5648: return OK;
5649: }
1.654 raeburn 5650: } else {
5651: $r->internal_redirect($redirect);
1.606 raeburn 5652: }
5653: }
5654: }
1.445 www 5655: #
5656: # Done catching special calls
1.484 raeburn 5657: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5658: # Get the parameters that may be needed
5659: #
5660: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5661: ['folderpath','title',
1.519 raeburn 5662: 'forcesupplement','forcestandard',
1.510 raeburn 5663: 'tools','symb','command','supppath']);
1.445 www 5664:
1.635 raeburn 5665: foreach my $item ('forcesupplement','forcestandard','tools') {
5666: next if ($env{'form.'.$item} eq '');
5667: unless ($env{'form.'.$item} eq '1') {
5668: delete($env{'form.'.$item});
5669: }
5670: }
5671:
5672: if ($env{'form.command'}) {
5673: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5674: delete($env{'form.command'});
5675: }
5676: }
5677:
5678: if ($env{'form.symb'}) {
5679: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5680: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5681: delete($env{'form.symb'});
5682: }
5683: }
5684:
1.445 www 5685: # standard=1: this is a "new-style" course with an uploaded map as top level
5686: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5687:
5688: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5689:
1.484 raeburn 5690: # Decide whether this should display supplemental or main content or utilities
1.445 www 5691: # supplementalflag=1: show supplemental documents
5692: # supplementalflag=0: show standard documents
1.484 raeburn 5693: # toolsflag=1: show utilities
1.445 www 5694:
1.561 raeburn 5695: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5696: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5697: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5698: $supplementalflag=0;
5699: }
5700: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5701: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5702: unless ($allowed) { $supplementalflag=1; }
5703: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5704: my $toolsflag=0;
5705: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5706:
1.635 raeburn 5707: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5708: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5709: }
5710:
1.685 raeburn 5711: my $backto_supppath;
1.635 raeburn 5712: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5713: if ($supplementalflag && $allowed) {
5714: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5715: }
1.635 raeburn 5716: }
5717:
1.329 droeschl 5718: my $script='';
5719: my $showdoc=0;
1.457 raeburn 5720: my $addentries = {};
1.475 raeburn 5721: my $container;
1.329 droeschl 5722: my $containertag;
1.508 raeburn 5723: my $pathitem;
1.598 raeburn 5724: my %ltitools;
1.617 raeburn 5725: my $hiddentop;
1.615 raeburn 5726: my $navmap;
1.617 raeburn 5727: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5728:
1.464 www 5729: # Do we directly jump somewhere?
1.525 raeburn 5730: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5731: if ($env{'form.symb'} ne '') {
1.522 raeburn 5732: $env{'form.folderpath'}=
1.617 raeburn 5733: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5734: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5735: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5736: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5737: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5738: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5739: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5740: }
1.472 raeburn 5741: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5742: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5743: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5744: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5745: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5746: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5747: } elsif ($env{'form.command'} eq 'contents') {
5748: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5749: } elsif ($env{'form.command'} eq 'home') {
5750: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5751: }
5752:
1.525 raeburn 5753:
1.445 www 5754: # Where do we store these for when we come back?
5755: my $stored_folderpath='docs_folderpath';
5756: if ($supplementalflag) {
5757: $stored_folderpath='docs_sup_folderpath';
5758: }
1.464 www 5759:
1.519 raeburn 5760: # No folderpath, and in edit mode, see if we have something stored
5761: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5762: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5763: {'folderpath' => 'scalar'});
1.615 raeburn 5764:
5765: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5766: if ($supplementalflag) {
5767: undef($env{'form.folderpath'}) if ($1 eq 'default');
5768: } else {
5769: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5770: }
5771: } else {
1.523 raeburn 5772: undef($env{'form.folderpath'});
5773: }
1.677 raeburn 5774: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5775: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5776: }
1.329 droeschl 5777: }
1.446 www 5778:
5779: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5780: if (!$allowed) {
1.446 www 5781: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5782: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5783: }
5784: }
1.446 www 5785: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5786: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5787: $env{'form.folderpath'} = &supplemental_base()
5788: .'&'.
1.329 droeschl 5789: $env{'form.folderpath'};
5790: }
1.685 raeburn 5791: # If allowed and user's role is not advanced check folderpath is not hidden
5792: my $hidden_and_empty;
1.687 raeburn 5793: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5794: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5795: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5796: my $folder = $pathitems[-2];
5797: if ($folder eq '') {
5798: undef($env{'form.folderpath'});
5799: } else {
5800: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5801: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5802: $folderurl .= '.page';
5803: } else {
5804: $folderurl .= '.sequence';
5805: }
1.685 raeburn 5806: if ($supplementalflag) {
5807: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5808: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5809: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5810: if (ref($supplemental) eq 'HASH') {
5811: my ($suppmap,$suppmapnum);
5812: if ($folder eq 'supplemental') {
5813: $suppmap = 'default';
5814: $suppmapnum = 0;
5815: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5816: $suppmap = $1;
5817: $suppmapnum = $suppmap;
5818: }
5819: if ($hiddenfolder) {
5820: my $hascontent;
5821: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5822: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5823: $hascontent = 1;
5824: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5825: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5826: if ($id =~ /^$suppmapnum\:/) {
5827: $hascontent = 1;
5828: last;
5829: }
5830: }
5831: }
5832: last if ($hascontent);
5833: }
5834: unless ($hascontent) {
5835: if ($foldername ne '') {
5836: $hidden_and_empty = $foldername;
5837: } else {
5838: $hidden_and_empty = $folder;
5839: }
5840: }
5841: }
5842: }
5843: } else {
5844: unless (ref($navmap)) {
5845: $navmap = Apache::lonnavmaps::navmap->new();
5846: }
5847: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5848: $foldername = &HTML::Entities::decode(&unescape($foldername));
5849: if (ref($navmap)) {
5850: if ($hiddenfolder ||
5851: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5852: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5853: unless (@resources) {
5854: if ($foldername ne '') {
5855: $hidden_and_empty = $foldername;
5856: } else {
5857: $hidden_and_empty = $folder;
5858: }
5859: }
5860: }
5861: }
1.617 raeburn 5862: }
1.685 raeburn 5863: if ($hidden_and_empty ne '') {
5864: splice(@pathitems,-2);
5865: if (@pathitems) {
5866: $env{'form.folderpath'} = join('&',@pathitems);
5867: } else {
5868: undef($env{'form.folderpath'});
1.615 raeburn 5869: }
5870: }
5871: }
5872: }
5873:
1.446 www 5874: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5875: unless ($env{'form.folderpath'}) {
1.446 www 5876: if ($supplementalflag) {
5877: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5878: } elsif ($allowed) {
5879: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5880: }
1.472 raeburn 5881: }
1.446 www 5882:
1.445 www 5883: # Store this
1.484 raeburn 5884: unless ($toolsflag) {
1.615 raeburn 5885: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5886: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5887: {'folderpath' => 'scalar'});
1.510 raeburn 5888: }
1.519 raeburn 5889: my $folderpath;
1.484 raeburn 5890: if ($env{'form.folderpath'}) {
1.519 raeburn 5891: $folderpath = $env{'form.folderpath'};
5892: my (@folders)=split('&',$env{'form.folderpath'});
5893: $env{'form.foldername'}=&unescape(pop(@folders));
5894: if ($env{'form.foldername'} =~ /\:1$/) {
5895: $container = 'page';
5896: } else {
5897: $container = 'sequence';
5898: }
5899: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5900: } else {
1.519 raeburn 5901: if ($env{'form.folder'} eq '' ||
5902: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5903: if ($env{'form.folder'} eq 'supplemental') {
5904: $folderpath=&supplemental_base();
5905: } elsif (!$hiddentop) {
5906: $folderpath='default&'.
5907: &escape(&mt('Main Content').':::::');
5908: }
1.484 raeburn 5909: }
5910: }
1.519 raeburn 5911: $containertag = '<input type="hidden" name="folderpath" value="" />';
5912: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5913: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5914: $showdoc='/'.$1;
5915: }
5916: if ($showdoc) { # got called in sequence from course
5917: $allowed=0;
5918: } else {
1.611 raeburn 5919: if ($canedit) {
1.484 raeburn 5920: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5921: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5922: }
5923: }
1.329 droeschl 5924: }
5925:
1.344 bisitz 5926: # get personal data
1.329 droeschl 5927: my $uname=$env{'user.name'};
5928: my $udom=$env{'user.domain'};
5929: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5930:
5931: if ($allowed) {
1.484 raeburn 5932: if ($toolsflag) {
5933: $script .= &inject_data_js();
5934: my ($home,$other,%outhash)=&authorhosts();
5935: if (!$home && $other) {
5936: my @hosts;
5937: foreach my $aurole (keys(%outhash)) {
5938: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5939: push(@hosts,$outhash{$aurole});
5940: }
5941: }
5942: $script .= &dump_switchserver_js(@hosts);
5943: }
1.458 raeburn 5944: } else {
1.570 raeburn 5945: my $tid = 1;
1.484 raeburn 5946: my @tabids;
5947: if ($supplementalflag) {
1.655 raeburn 5948: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5949: $tid = 2;
1.484 raeburn 5950: } else {
5951: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5952: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5953: unshift(@tabids,'001');
5954: push(@tabids,('dd1','ee1'));
5955: }
1.458 raeburn 5956: }
1.484 raeburn 5957: my $tabidstr = join("','",@tabids);
1.644 raeburn 5958: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5959: my $posslti = keys(%ltitools);
1.622 raeburn 5960: my $hostname = $r->hostname();
1.606 raeburn 5961: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5962: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5963: &history_tab_js().
5964: &inject_data_js().
1.570 raeburn 5965: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5966: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 5967: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5968: if ($hidden_and_empty ne '') {
5969: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5970: $hidden_and_empty);
5971: $onload .= "javascript:alert('".&js_escape($alert)."');";
5972: }
1.484 raeburn 5973: $addentries = {
1.685 raeburn 5974: onload => $onload,
1.484 raeburn 5975: };
1.458 raeburn 5976: }
1.538 raeburn 5977: $script .= &paste_popup_js();
1.501 raeburn 5978: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5979: &mt('Switch server?');
5980:
5981:
1.329 droeschl 5982: }
5983: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5984: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5985: .'// <![CDATA['."\n"
5986: .$script."\n"
5987: .'// ]]>'."\n"
1.595 musolffc 5988: .'</script>'."\n"
5989: .'<script type="text/javascript"
5990: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5991:
5992: # Breadcrumbs
5993: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5994:
5995: if ($showdoc) {
1.682 raeburn 5996: my $args;
5997: if ($supplementalflag) {
1.687 raeburn 5998: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
5999: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 6000: $args = {'bread_crumbs' => $brcrum};
6001: } else {
6002: $args = {'force_register' => $showdoc};
6003: }
6004: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6005: } elsif ($toolsflag) {
1.611 raeburn 6006: my ($breadtext,$breadtitle);
1.617 raeburn 6007: $breadtext = "$crstype Editor";
1.611 raeburn 6008: if ($canedit) {
6009: $breadtitle = 'Editing '.$crstype.' Contents';
6010: } else {
6011: $breadtext .= ' (View-only mode)';
6012: $breadtitle = 'Viewing '.$crstype.' Contents';
6013: }
1.571 raeburn 6014: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6015: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6016: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6017: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6018: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6019: $breadtitle)
1.571 raeburn 6020: );
1.510 raeburn 6021: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6022: unless ($env{'request.role.adv'}) {
6023: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6024: $r->internal_redirect('/adm/navmaps');
6025: return OK;
6026: }
6027: }
1.510 raeburn 6028: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6029: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6030: {'bread_crumbs' => $brcrum,}));
6031: } else {
1.611 raeburn 6032: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6033: $breadtext = "$crstype Editor";
1.611 raeburn 6034: if ($canedit) {
6035: $breadtitle = 'Editing '.$crstype.' Contents';
6036: $helpitem = 'Docs_Adding_Course_Doc';
6037: } else {
6038: $breadtext .= ' (View-only mode)';
6039: $breadtitle = 'Viewing '.$crstype.' Contents';
6040: $helpitem = 'Docs_Viewing_Course_Doc';
6041: }
1.392 raeburn 6042: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6043: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6044: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6045: {'add_entries' => $addentries}
6046: )
1.392 raeburn 6047: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6048: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6049: $breadtitle,
6050: $helpitem)
1.392 raeburn 6051: );
6052: }
1.364 bisitz 6053:
1.329 droeschl 6054: my %allfiles = ();
6055: my %codebase = ();
1.440 raeburn 6056: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6057: if ($canedit) {
1.684 raeburn 6058: undef($suppchanges);
1.329 droeschl 6059: if (($env{'form.uploaddoc.filename'}) &&
6060: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6061: my $context = $1;
6062: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6063: undef($hadchanges);
1.440 raeburn 6064: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6065: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6066: undef($navmap);
1.329 droeschl 6067: if ($hadchanges) {
6068: &mark_hash_old();
6069: }
1.684 raeburn 6070: if ($suppchanges) {
6071: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6072: undef($suppchanges);
6073: }
1.440 raeburn 6074: $r->print($upload_output);
6075: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6076: # Process file upload - phase two - upload embedded objects
6077: $uploadphase = 'check_embedded';
6078: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6079: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6080: $env{'form.newidx'});
6081: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6082: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6083: my ($destination,$dir_root) = &embedded_destination();
6084: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6085: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6086: my ($result,$flag) =
1.440 raeburn 6087: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6088: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6089: $actionurl);
6090: $r->print($result.&return_to_editor());
6091: } elsif ($env{'form.phase'} eq 'check_embedded') {
6092: # Process file upload - phase three - modify references in HTML file
6093: $uploadphase = 'modified_orightml';
6094: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6095: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6096: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6097: my $result =
1.482 raeburn 6098: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6099: $docuname,$docudom,undef,
6100: $dir_root);
1.630 raeburn 6101: $r->print($result.&return_to_editor());
1.476 raeburn 6102: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6103: $uploadphase = 'decompress_phase_one';
6104: $r->print(&decompression_phase_one().
6105: &return_to_editor());
6106: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6107: $uploadphase = 'decompress_phase_two';
6108: $r->print(&decompression_phase_two().
6109: &return_to_editor());
1.329 droeschl 6110: }
6111: }
6112:
1.484 raeburn 6113: if ($allowed && $toolsflag) {
6114: $r->print(&startContentScreen('tools'));
1.611 raeburn 6115: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6116: $r->print(&endContentScreen());
6117: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6118: # -----------------------------------------------------------------------------
6119: my %lt=&Apache::lonlocal::texthash(
6120: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6121: 'upfi' => 'Upload File',
1.553 raeburn 6122: 'upld' => 'Upload Content',
1.329 droeschl 6123: 'srch' => 'Search',
6124: 'impo' => 'Import',
1.487 raeburn 6125: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6126: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6127: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6128: 'extr' => 'External Resource',
6129: 'extt' => 'External Tool',
1.329 droeschl 6130: 'selm' => 'Select Map',
6131: 'load' => 'Load Map',
6132: 'newf' => 'New Folder',
6133: 'newp' => 'New Composite Page',
6134: 'syll' => 'Syllabus',
1.425 raeburn 6135: 'navc' => 'Table of Contents',
1.343 biermanm 6136: 'sipa' => 'Simple Course Page',
1.329 droeschl 6137: 'sipr' => 'Simple Problem',
1.630 raeburn 6138: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6139: 'stpr' => 'Standard Problem',
6140: 'news' => 'New sub-directory',
6141: 'crpr' => 'Create Problem',
1.689 raeburn 6142: 'swit' => 'Switch Server',
1.329 droeschl 6143: 'drbx' => 'Drop Box',
1.451 www 6144: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6145: 'bull' => 'Discussion Board',
1.347 weissno 6146: 'mypi' => 'My Personal Information Page',
1.353 weissno 6147: 'grpo' => 'Group Portfolio',
1.329 droeschl 6148: 'rost' => 'Course Roster',
1.528 raeburn 6149: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6150: 'imsf' => 'IMS Upload',
6151: 'imsl' => 'Upload IMS package',
1.501 raeburn 6152: 'cms' => 'Origin of IMS package',
6153: 'se' => 'Select',
1.329 droeschl 6154: 'file' => 'File',
6155: 'title' => 'Title',
1.606 raeburn 6156: 'addp' => 'Add Placeholder to course?',
6157: 'uste' => 'Use Template?',
6158: 'fnam' => 'File Name:',
6159: 'loca' => 'Location:',
6160: 'dire' => 'Directory:',
6161: 'cate' => 'Category:',
6162: 'tmpl' => 'Template:',
1.329 droeschl 6163: 'comment' => 'Comment',
1.403 raeburn 6164: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6165: 'bb5' => 'Blackboard 5',
6166: 'bb6' => 'Blackboard 6',
6167: 'angel5' => 'ANGEL 5.5',
6168: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6169: 'yes' => 'Yes',
6170: 'no' => 'No',
1.618 raeburn 6171: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6172: );
1.329 droeschl 6173: # -----------------------------------------------------------------------------
1.595 musolffc 6174:
6175: # Calculate free quota space for a user or course. A javascript function checks
6176: # file size to determine if upload should be allowed.
6177: my $quotatype = 'unofficial';
6178: if ($crstype eq 'Community') {
1.601 raeburn 6179: $quotatype = 'community';
6180: } elsif ($crstype eq 'Placement') {
6181: $quotatype = 'placement';
1.595 musolffc 6182: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6183: $quotatype = 'official';
6184: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6185: $quotatype = 'textbook';
6186: }
6187: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6188: 'course',$quotatype); # expressed in MB
6189: my $current_disk_usage = 0;
6190: foreach my $subdir ('docs','supplemental') {
6191: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6192: "userfiles/$subdir",1); # expressed in kB
6193: }
6194: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6195: my $usage = $current_disk_usage/1024; # in MB
6196: my $quota = $disk_quota;
6197: my $percent;
6198: if ($disk_quota == 0) {
6199: $percent = 100.0;
6200: } else {
1.619 raeburn 6201: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6202: }
6203: $usage = sprintf("%.2f",$usage);
6204: $quota = sprintf("%.2f",$quota);
6205: $percent = sprintf("%.0f",$percent);
6206: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6207: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6208:
1.329 droeschl 6209: my $fileupload=(<<FIUP);
1.605 raeburn 6210: $quotainfo
1.329 droeschl 6211: $lt{'file'}:<br />
1.662 raeburn 6212: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6213: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6214: FIUP
6215:
6216: my $checkbox=(<<CHBO);
6217: <!-- <label>$lt{'parse'}?
6218: <input type="checkbox" name="parserflag" />
6219: </label> -->
6220: <label>
1.611 raeburn 6221: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6222: </label>
6223: CHBO
1.501 raeburn 6224: my $imsfolder = $env{'form.folder'};
6225: if ($imsfolder eq '') {
6226: $imsfolder = 'default';
6227: }
6228: my $imspform=(<<IMSFORM);
6229: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6230: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6231: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6232: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6233: <legend>$lt{'imsf'}</legend>
6234: $fileupload
6235: <br />
6236: <p>
6237: $lt{'cms'}:
1.611 raeburn 6238: <select name="source" $disabled>
1.501 raeburn 6239: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6240: <option value="bb5">$lt{'bb5'}</option>
6241: <option value="bb6">$lt{'bb6'}</option>
6242: <option value="angel5">$lt{'angel5'}</option>
6243: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6244: </select>
6245: <input type="hidden" name="folder" value="$imsfolder" />
6246: </p>
6247: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6248: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6249: </fieldset>
6250: </form>
6251: IMSFORM
1.329 droeschl 6252:
6253: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6254: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6255: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6256: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6257: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6258: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6259: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6260: $fileupload
1.329 droeschl 6261: <br />
6262: $lt{'title'}:<br />
1.611 raeburn 6263: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6264: $pathitem
1.329 droeschl 6265: <input type="hidden" name="cmd" value="upload_default" />
6266: <br />
1.458 raeburn 6267: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6268: $checkbox
6269: </span>
1.501 raeburn 6270: <br clear="all" />
1.611 raeburn 6271: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6272: </fieldset>
6273: </form>
1.383 tempelho 6274: FUFORM
1.329 droeschl 6275:
1.611 raeburn 6276: my $mapimportjs;
6277: if ($canedit) {
6278: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6279: } else {
6280: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6281: }
1.502 raeburn 6282: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6283: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6284: $lt{'impm'}</a>$help{'Load_Map'}
6285: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6286: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6287: <legend>$lt{'impm'}</legend>
1.371 tempelho 6288: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6289: $lt{'copm'}<br />
6290: <span class="LC_nobreak">
6291: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6292: onfocus="this.blur();$mapimportjs" $disabled />
6293: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6294: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6295: </fieldset>
6296: </form>
6297:
1.383 tempelho 6298: SEDFFORM
1.606 raeburn 6299: my $importcrsresform;
1.608 raeburn 6300: my ($numdirs,$pickfile) =
1.690 raeburn 6301: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6302: "resize_scrollbox('contentscroll','1','0');",
6303: undef,'res');
1.606 raeburn 6304: if ($pickfile) {
6305: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6306: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6307: $lt{'imcr'}</a>$help{'Course_Resources'}
6308: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6309: <fieldset id="importcrsresform" style="display: none;">
6310: <legend>$lt{'imcr'}</legend>
6311: <input type="hidden" name="active" value="bb" />
6312: $pickfile
6313: <p>
1.611 raeburn 6314: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6315: </p>
6316: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6317: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.606 raeburn 6318: </fieldset>
6319: </form>
6320: CRSFORM
6321: }
6322:
1.611 raeburn 6323: my $fromstoredjs;
6324: if ($canedit) {
6325: $fromstoredjs = 'open_StoredLinks_Import()';
6326: } else {
6327: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6328: }
6329:
1.502 raeburn 6330: my @importpubforma = (
1.508 raeburn 6331: { '<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 6332: { '<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 6333: { '<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 6334: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6335: );
6336: if ($pickfile) {
1.690 raeburn 6337: 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 6338: }
1.502 raeburn 6339: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6340: my $extresourcesform =
6341: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6342: $help{'Adding_External_Resource'},
6343: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6344: my $exttoolform =
6345: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6346: $help{'Adding_External_Tool'},undef,
6347: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6348: \%ltitools,$disabled);
1.329 droeschl 6349: if ($allowed) {
1.492 raeburn 6350: my $folder = $env{'form.folder'};
6351: if ($folder eq '') {
6352: $folder='default';
6353: }
1.615 raeburn 6354: if ($canedit) {
6355: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6356: if ($output) {
6357: $r->print($output);
6358: }
1.538 raeburn 6359: }
1.337 ehlerst 6360: $r->print(<<HIDDENFORM);
6361: <form name="renameform" method="post" action="/adm/coursedocs">
6362: <input type="hidden" name="title" />
6363: <input type="hidden" name="cmd" />
6364: <input type="hidden" name="markcopy" />
6365: <input type="hidden" name="copyfolder" />
6366: $containertag
6367: </form>
1.633 raeburn 6368: <form name="aliasform" method="post" action="/adm/coursedocs">
6369: <input type="hidden" name="alias" />
6370: <input type="hidden" name="cmd" />
6371: $containertag
6372: </form>
1.484 raeburn 6373:
1.337 ehlerst 6374: HIDDENFORM
1.508 raeburn 6375: $r->print(&makesimpleeditform($pathitem)."\n".
6376: &makedocslogform($pathitem."\n".
1.484 raeburn 6377: '<input type="hidden" name="folder" value="'.
6378: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6379: }
1.442 www 6380:
6381: # Generate the tabs
1.510 raeburn 6382: my ($mode,$needs_end);
1.472 raeburn 6383: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6384: my @folders = split('&',$env{'form.folderpath'});
6385: unless (@folders > 2) {
6386: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6387: $needs_end = 1;
6388: }
1.472 raeburn 6389: } else {
1.484 raeburn 6390: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6391: $needs_end = 1;
1.472 raeburn 6392: }
1.443 www 6393:
1.442 www 6394: #
1.622 raeburn 6395: my $hostname = $r->hostname();
1.442 www 6396: my $savefolderpath;
6397:
1.395 raeburn 6398: if ($allowed) {
1.329 droeschl 6399: my $folder=$env{'form.folder'};
1.615 raeburn 6400: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6401: $folder='default';
1.356 tempelho 6402: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6403: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6404: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6405: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6406: }
6407: my $postexec='';
6408: if ($folder eq 'default') {
1.653 raeburn 6409: my $windowname = 'loncapaclient';
6410: if ($env{'request.lti.login'}) {
6411: $windowname .= 'lti';
6412: }
1.372 bisitz 6413: $r->print('<script type="text/javascript">'."\n"
6414: .'// <![CDATA['."\n"
1.653 raeburn 6415: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6416: .'// ]]>'."\n"
6417: .'</script>'."\n"
1.369 bisitz 6418: );
1.329 droeschl 6419: } else {
6420: #$postexec='self.close();';
6421: }
1.504 raeburn 6422: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6423: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6424: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6425:
6426: my $newnavform=(<<NNFORM);
6427: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6428: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6429: $pathitem
1.329 droeschl 6430: <input type="hidden" name="importdetail"
6431: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6432: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6433: $help{'Navigate_Content'}
6434: </form>
6435: NNFORM
6436: my $newsmppageform=(<<NSPFORM);
6437: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6438: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6439: $pathitem
1.329 droeschl 6440: <input type="hidden" name="importdetail" value="" />
1.423 onken 6441: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6442: $help{'Simple Page'}
1.329 droeschl 6443: </form>
6444: NSPFORM
6445:
6446: my $newsmpproblemform=(<<NSPROBFORM);
6447: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6448: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6449: $pathitem
1.329 droeschl 6450: <input type="hidden" name="importdetail" value="" />
1.423 onken 6451: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6452: $help{'Simple_Problem'}
1.329 droeschl 6453: </form>
6454:
6455: NSPROBFORM
6456:
6457: my $newdropboxform=(<<NDBFORM);
6458: <form action="/adm/coursedocs" method="post" name="newdropbox">
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:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6463: $help{'Dropbox'}
1.344 bisitz 6464: </form>
1.329 droeschl 6465: NDBFORM
6466:
6467: my $newexuploadform=(<<NEXUFORM);
6468: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6469: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6470: $pathitem
1.329 droeschl 6471: <input type="hidden" name="importdetail" value="" />
1.423 onken 6472: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6473: $help{'Score_Upload_Form'}
6474: </form>
6475: NEXUFORM
6476:
6477: my $newbulform=(<<NBFORM);
6478: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6479: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6480: $pathitem
1.329 droeschl 6481: <input type="hidden" name="importdetail" value="" />
1.423 onken 6482: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6483: $help{'Bulletin Board'}
6484: </form>
6485: NBFORM
6486:
6487: my $newaboutmeform=(<<NAMFORM);
6488: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6489: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6490: $pathitem
1.329 droeschl 6491: <input type="hidden" name="importdetail"
6492: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6493: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6494: $help{'My Personal Information Page'}
1.329 droeschl 6495: </form>
6496: NAMFORM
6497:
6498: my $newaboutsomeoneform=(<<NASOFORM);
6499: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
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" value="" />
1.423 onken 6503: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6504: </form>
6505: NASOFORM
6506:
6507: my $newrosterform=(<<NROSTFORM);
6508: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6509: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6510: $pathitem
1.329 droeschl 6511: <input type="hidden" name="importdetail"
6512: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6513: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6514: $help{'Course_Roster'}
1.329 droeschl 6515: </form>
6516: NROSTFORM
6517:
1.534 raeburn 6518: my $newwebpage;
6519: if ($folder =~ /^default_?(\d*)$/) {
6520: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6521: if ($1) {
6522: $newwebpage .= $1;
6523: } else {
6524: $newwebpage .= 'default';
6525: }
6526: $newwebpage .= '/new.html';
6527: }
6528: my $newwebpageform =(<<NWEBFORM);
6529: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6530: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6531: $pathitem
6532: <input type="hidden" name="importdetail" value="$newwebpage" />
6533: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6534: $help{'Web_Page'}
1.534 raeburn 6535: </form>
6536: NWEBFORM
1.604 raeburn 6537:
1.606 raeburn 6538: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6539: my $machines_str = "'".join("','",@ids)."'";
6540: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6541: if ($env{'user.author'}) {
6542: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6543: $is_home{'author'} = 1;
1.606 raeburn 6544: }
1.691 raeburn 6545: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6546: }
6547: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6548: ['active'],['ca','aa']);
1.691 raeburn 6549: my %by_roletype;
1.606 raeburn 6550: if (keys(%roleshash)) {
6551: foreach my $entry (keys(%roleshash)) {
6552: my ($auname,$audom,$roletype) = split(/:/,$entry);
6553: my $key = $entry;
6554: $key =~ s/:/___/g;
1.691 raeburn 6555: my $author = $auname.'___'.$audom;
6556: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6557: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6558: $toppath{$author} = "/priv/$audom/$auname";
6559: if (grep(/^\Q$rolehome\E$/,@ids)) {
6560: $is_home{$author} = 1;
1.606 raeburn 6561: }
1.691 raeburn 6562: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6563: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6564: }
1.691 raeburn 6565: }
6566: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6567: if (grep(/^\Q$crshome\E$/,@ids)) {
6568: $is_home{'course'} = 1;
6569: }
6570: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6571: my $pickdir = $lt{'loca'}.
6572: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6573: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6574: if ($env{'user.author'}) {
6575: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6576: }
6577: if (keys(%by_roletype)) {
6578: foreach my $possrole ('ca','aa') {
6579: if (ref($by_roletype{$possrole}) eq 'HASH') {
6580: my $roletitle = &Apache::lonnet::plaintext($possrole);
6581: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6582: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6583: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6584: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6585: }
6586: }
6587: }
6588: }
1.691 raeburn 6589: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6590: '</select><br />'."\n".
6591: $lt{'dire'}.
6592: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6593: '<option value=""></option>'.
6594: '</select><br />'."\n";
1.606 raeburn 6595:
6596: my %seltemplate_menus;
6597: my @files = &Apache::lonhomework::get_template_list('problem');
6598: my @noexamplelink = ('blank.problem','blank.library','script.library');
6599: my $currentcategory = '';
6600: my @ordered = ('');
6601: my %templatehelp;
6602: my $defcategory = '';
6603: my @catorder = ($defcategory);
6604: $seltemplate_menus{$defcategory}->{'order'} = [''];
6605: $seltemplate_menus{$defcategory}->{'text'} = '';
6606: foreach my $file (@files) {
6607: if (ref($file) eq 'ARRAY') {
6608: my ($path,$title,$category,$help) = @{$file};
6609: next if ($title !~ /\S/);
6610: if (&js_escape($category) ne $currentcategory) {
6611: $currentcategory = &js_escape($category);
6612: push(@catorder,&js_escape($currentcategory));
6613: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6614: $seltemplate_menus{$currentcategory}->{'default'} = '';
6615: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6616: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6617: }
6618: if ($path) {
6619: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6620: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6621: if ($help) {
6622: $templatehelp{$path} = $help;
6623: }
6624: }
6625: }
6626: }
6627:
6628: my $templates = $lt{'cate'}.' '.
6629: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6630: $defcategory,'tempcategory','template',
6631: \%seltemplate_menus,\@catorder,
6632: "resize_scrollbox('contentscroll','1','0');",
6633: "toggleExampleText();",'template').'<br />';
6634: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6635: '<span id="newresexample">'.&mt('Example').'<span></a>';
6636: my $crsresform=(<<RESFORM);
1.691 raeburn 6637: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 6638: $lt{'stpr'}</a>$help{'Course_Resource'}
6639: <form action="/adm/coursedocs" method="post" name="courseresform">
6640: <fieldset id="crsresform" style="display:none;">
6641: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6642: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6643: <p>
6644: $pickdir
1.691 raeburn 6645: <div id="newstdproblem" style="display:none;">
1.606 raeburn 6646: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6647: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6648:
1.611 raeburn 6649: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6650: </span><span id="newsubdir"></span>
6651: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6652: </p>
6653: $lt{'fnam'}
1.611 raeburn 6654: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6655: <p>
1.691 raeburn 6656: <div id="newresource" style="display:none">
1.606 raeburn 6657: $lt{'addp'}
1.611 raeburn 6658: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6659: $lt{'no'}</label>
1.611 raeburn 6660: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6661: $lt{'yes'}</label>
6662: <span id="newrestitle"></span>
1.611 raeburn 6663: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6664: </div>
6665: </p>
6666: <p>
6667: $lt{'uste'}
1.611 raeburn 6668: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6669: $lt{'no'}</label>
1.611 raeburn 6670: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6671: $lt{'yes'}</label>
6672: <div id="newrestemplate" style="display:none">
6673: $templates
6674: $templatepreview
6675: </div>
6676: </p>
6677: <span class="LC_nobreak">
6678: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6679: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6680: </span>
1.689 raeburn 6681: </div>
1.691 raeburn 6682: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 6683: $rolehomes
6684: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6685: </div>
1.606 raeburn 6686: </fieldset>
6687: </form>
6688:
6689: RESFORM
1.534 raeburn 6690:
1.342 ehlerst 6691: my $specialdocumentsform;
1.383 tempelho 6692: my @specialdocumentsforma;
1.451 www 6693: my $gradingform;
6694: my @gradingforma;
6695: my $communityform;
6696: my @communityforma;
1.351 ehlerst 6697: my $newfolderform;
1.390 tempelho 6698: my $newfolderb;
1.342 ehlerst 6699:
1.451 www 6700: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6701:
1.329 droeschl 6702: my $newpageform=(<<NPFORM);
6703: <form action="/adm/coursedocs" method="post" name="newpage">
6704: <input type="hidden" name="folderpath" value="$path" />
6705: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6706: <input type="hidden" name="active" value="ee" />
1.423 onken 6707: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6708: $help{'Adding_Pages'}
1.329 droeschl 6709: </form>
6710: NPFORM
1.390 tempelho 6711:
6712:
1.351 ehlerst 6713: $newfolderform=(<<NFFORM);
1.329 droeschl 6714: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6715: $pathitem
1.329 droeschl 6716: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6717: <input type="hidden" name="active" value="" />
1.422 onken 6718: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6719: </form>
6720: NFFORM
6721:
6722: my $newsylform=(<<NSYLFORM);
6723: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6724: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6725: $pathitem
1.329 droeschl 6726: <input type="hidden" name="importdetail"
6727: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6728: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6729: $help{'Syllabus'}
1.383 tempelho 6730:
1.329 droeschl 6731: </form>
6732: NSYLFORM
1.364 bisitz 6733:
1.329 droeschl 6734: my $newgroupfileform=(<<NGFFORM);
6735: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6736: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6737: $pathitem
1.329 droeschl 6738: <input type="hidden" name="importdetail"
6739: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6740: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6741: $help{'Group Portfolio'}
1.329 droeschl 6742: </form>
6743: NGFFORM
1.672 raeburn 6744: if ($container eq 'page') {
6745: @specialdocumentsforma=(
6746: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6747: );
6748: } else {
6749: @specialdocumentsforma=(
1.421 onken 6750: {'<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 6751: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6752: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6753: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6754: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6755: );
6756: }
1.451 www 6757: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6758:
1.655 raeburn 6759: my @external = (
6760: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6761: );
1.598 raeburn 6762: if (keys(%ltitools)) {
1.655 raeburn 6763: push(@external,
6764: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6765: );
1.598 raeburn 6766: }
1.655 raeburn 6767: my $externalform = &create_form_ul(&create_list_elements(@external));
6768:
6769: my @importdoc = ();
1.519 raeburn 6770: unless ($container eq 'page') {
6771: push(@importdoc,
6772: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6773: );
6774: }
6775: push(@importdoc,
1.558 raeburn 6776: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6777: );
1.501 raeburn 6778: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6779:
1.451 www 6780: @gradingforma=(
6781: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6782: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6783: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 6784: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 6785: );
6786: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6787:
6788: @communityforma=(
6789: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6790: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6791: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6792: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6794: );
6795: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6796:
1.330 tempelho 6797: my %orderhash = (
1.553 raeburn 6798: 'aa' => ['Upload',$fileuploadform],
6799: 'bb' => ['Import',$importpubform],
1.655 raeburn 6800: 'cc' => ['External',$externalform],
6801: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6802: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6803: );
1.519 raeburn 6804: unless ($container eq 'page') {
1.434 raeburn 6805: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6806: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6807: }
6808:
1.341 ehlerst 6809: $hadchanges=0;
1.484 raeburn 6810: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6811: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6812: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6813: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6814: undef($navmap);
1.443 www 6815: if ($error) {
6816: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6817: }
1.639 raeburn 6818: if ($hadchanges) {
6819: unless (&is_hash_old()) {
1.638 raeburn 6820: &mark_hash_old();
6821: }
6822: }
1.341 ehlerst 6823:
1.443 www 6824: &changewarning($r,'');
6825: }
1.458 raeburn 6826: }
1.442 www 6827:
1.443 www 6828: # Supplemental documents start here
6829:
1.329 droeschl 6830: my $folder=$env{'form.folder'};
1.443 www 6831: unless ($supplementalflag) {
1.329 droeschl 6832: $folder='supplemental';
6833: }
1.685 raeburn 6834: if (($folder eq 'supplemental') &&
1.329 droeschl 6835: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6836: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6837: } elsif ($allowed) {
1.356 tempelho 6838: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6839: }
1.508 raeburn 6840: $pathitem = '<input type="hidden" name="folderpath" value="'.
6841: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6842: if ($allowed) {
6843: my $folderseq=
1.504 raeburn 6844: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6845:
6846: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6847: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6848: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6849: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6850: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6851: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6852: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6853: $fileupload
6854: <br />
6855: <br />
6856: <span class="LC_nobreak">
6857: $checkbox
6858: </span>
6859: <br /><br />
6860: $lt{'comment'}:<br />
1.383 tempelho 6861: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6862: <br />
1.508 raeburn 6863: $pathitem
1.329 droeschl 6864: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6865: <input type='submit' value="$lt{'upld'}" />
6866: </form>
1.329 droeschl 6867: SUPDOCFORM
6868:
6869: my $supnewfolderform=(<<SNFFORM);
6870: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6871: <input type="hidden" name="active" value="" />
1.508 raeburn 6872: $pathitem
1.329 droeschl 6873: <input type="hidden" name="importdetail" value="" />
1.423 onken 6874: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6875: $help{'Adding_Folders'}
1.329 droeschl 6876: </form>
6877: SNFFORM
1.383 tempelho 6878:
1.510 raeburn 6879: my $supextform =
6880: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6881: $help{'Adding_External_Resource'},
6882: undef,undef,undef,undef,undef,undef,
6883: $disabled);
1.329 droeschl 6884:
1.598 raeburn 6885: my $supexttoolform =
6886: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6887: $help{'Adding_External_Tool'},
6888: undef,undef,'tool',$coursedom,
1.611 raeburn 6889: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6890:
1.329 droeschl 6891: my $supnewsylform=(<<SNSFORM);
6892: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6893: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6894: $pathitem
1.329 droeschl 6895: <input type="hidden" name="importdetail"
6896: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6897: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6898: $help{'Syllabus'}
6899: </form>
6900: SNSFORM
6901:
6902: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6903: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
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="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6908: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6909: $help{'My Personal Information Page'}
1.329 droeschl 6910: </form>
6911: SNAMFORM
6912:
1.534 raeburn 6913: my $supwebpage;
6914: if ($folder =~ /^supplemental_?(\d*)$/) {
6915: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6916: if ($1) {
6917: $supwebpage .= $1;
6918: } else {
6919: $supwebpage .= 'default';
6920: }
6921: $supwebpage .= '/new.html';
6922: }
6923: my $supwebpageform =(<<SWEBFORM);
6924: <form action="/adm/coursedocs" method="post" name="supwebpage">
6925: <input type="hidden" name="active" value="cc" />
6926: $pathitem
6927: <input type="hidden" name="importdetail" value="$supwebpage" />
6928: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6929: $help{'Web_Page'}
1.534 raeburn 6930: </form>
6931: SWEBFORM
6932:
1.333 muellerd 6933:
1.383 tempelho 6934: my @specialdocs = (
1.618 raeburn 6935: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6936: =>$supnewsylform},
1.611 raeburn 6937: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6938: =>$supnewaboutmeform},
1.534 raeburn 6939: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6940:
1.383 tempelho 6941: );
1.655 raeburn 6942: my @supexternal = (
6943: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6944: =>$supextform});
1.598 raeburn 6945: if (keys(%ltitools)) {
1.655 raeburn 6946: push(@supexternal,
6947: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6948: =>$supexttoolform});
6949: }
1.655 raeburn 6950: my @supimportdoc = (
1.598 raeburn 6951: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6952: =>$supupdocform},
1.598 raeburn 6953: );
1.501 raeburn 6954:
6955: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6956: my %suporderhash = (
1.390 tempelho 6957: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6958: 'dd' => ['Upload',$supupdocform],
6959: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6960: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6961: );
1.443 www 6962: if ($supplementalflag) {
1.682 raeburn 6963: $suppchanges = 0;
6964: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6965: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6966: \%ltitools,$canedit,$hostname);
6967: if ($error) {
6968: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6969: }
6970: if ($suppchanges) {
1.684 raeburn 6971: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 6972: undef($suppchanges);
6973: }
1.393 raeburn 6974: }
1.443 www 6975: } elsif ($supplementalflag) {
1.458 raeburn 6976: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 6977: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6978: $hostname);
1.393 raeburn 6979: if ($error) {
6980: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6981: }
1.393 raeburn 6982: }
1.389 tempelho 6983:
1.510 raeburn 6984: if ($needs_end) {
6985: $r->print(&endContentScreen());
6986: }
1.383 tempelho 6987:
1.329 droeschl 6988: if ($allowed) {
6989: $r->print('
6990: <form method="post" name="extimport" action="/adm/coursedocs">
6991: <input type="hidden" name="title" />
6992: <input type="hidden" name="url" />
6993: <input type="hidden" name="useform" />
6994: <input type="hidden" name="residx" />
6995: </form>');
6996: }
1.484 raeburn 6997: } elsif ($showdoc) {
1.329 droeschl 6998: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6999: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7000: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7001: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7002: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7003: }
7004: }
1.630 raeburn 7005: unless ($noendpage) {
1.606 raeburn 7006: $r->print(&Apache::loncommon::end_page());
7007: }
1.329 droeschl 7008: return OK;
1.364 bisitz 7009: }
1.329 droeschl 7010:
1.440 raeburn 7011: sub embedded_form_elems {
7012: my ($phase,$primaryurl,$newidx) = @_;
7013: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7014: $newidx =~s /\D+//g;
1.440 raeburn 7015: return <<STATE;
7016: <input type="hidden" name="folderpath" value="$folderpath" />
7017: <input type="hidden" name="cmd" value="upload_embedded" />
7018: <input type="hidden" name="newidx" value="$newidx" />
7019: <input type="hidden" name="phase" value="$phase" />
7020: <input type="hidden" name="primaryurl" value="$primaryurl" />
7021: STATE
7022: }
7023:
7024: sub embedded_destination {
7025: my $folder=$env{'form.folder'};
7026: my $destination = 'docs/';
7027: if ($folder =~ /^supplemental/) {
7028: $destination = 'supplemental/';
7029: }
7030: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7031: $destination .= 'default/';
7032: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7033: $destination .= $2.'/';
7034: }
1.634 raeburn 7035: my $newidx = $env{'form.newidx'};
7036: $newidx =~s /\D+//g;
7037: if ($newidx) {
7038: $destination .= $newidx;
7039: }
1.440 raeburn 7040: my $dir_root = '/userfiles';
7041: return ($destination,$dir_root);
7042: }
7043:
7044: sub return_to_editor {
7045: my $actionurl = '/adm/coursedocs';
7046: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7047: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7048: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7049: '</a></p>';
7050: }
7051:
1.476 raeburn 7052: sub decompression_info {
7053: my ($destination,$dir_root) = &embedded_destination();
7054: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7055: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7056: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7057: my $container='sequence';
1.480 raeburn 7058: my ($pathitem,$hiddenelem);
1.583 raeburn 7059: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7060: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7061: $container='page';
7062: }
1.480 raeburn 7063: unshift(@hiddens,$pathitem);
7064: foreach my $item (@hiddens) {
1.634 raeburn 7065: if ($item eq 'newidx') {
7066: next if ($env{'form.'.$item} =~ /\D/);
7067: }
1.480 raeburn 7068: if ($env{'form.'.$item}) {
7069: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7070: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7071: }
1.477 raeburn 7072: }
1.476 raeburn 7073: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7074: $hiddenelem);
7075: }
7076:
7077: sub decompression_phase_one {
7078: my ($dir,$file,$warning,$error,$output);
7079: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7080: &decompression_info();
1.490 raeburn 7081: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7082: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7083: } else {
7084: my $file = $1;
1.630 raeburn 7085: $output =
1.481 raeburn 7086: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7087: $destination,$dir_root,
7088: $hiddenelem);
7089: if ($env{'form.autoextract_camtasia'}) {
7090: $output .= &remove_archive($docudom,$docuname,$container);
7091: }
1.476 raeburn 7092: }
7093: if ($error) {
7094: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7095: $error.'</p>'."\n";
7096: }
7097: if ($warning) {
7098: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7099: }
7100: return $output;
7101: }
7102:
7103: sub decompression_phase_two {
7104: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7105: &decompression_info();
1.481 raeburn 7106: my $output;
1.480 raeburn 7107: if ($env{'form.archivedelete'}) {
1.481 raeburn 7108: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7109: }
7110: $output .=
1.481 raeburn 7111: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7112: $destination,$dir_root,$hiddenelem);
7113: return $output;
7114: }
7115:
1.480 raeburn 7116: sub remove_archive {
7117: my ($docudom,$docuname,$container) = @_;
7118: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7119: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7120: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7121: if ($fatal) {
7122: if ($container eq 'page') {
7123: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7124: } else {
7125: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7126: }
1.583 raeburn 7127: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7128: } else {
7129: my $currcmd = $env{'form.cmd'};
7130: my $position = $env{'form.position'};
1.583 raeburn 7131: my $archiveidx = $position;
1.563 raeburn 7132: if ($position > 0) {
1.583 raeburn 7133: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7134: $archiveidx = $position-1;
7135: }
7136: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7137: my ($title,$url,@rrest) =
1.583 raeburn 7138: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7139: if ($url eq $env{'form.archiveurl'}) {
7140: if (&handle_edit_cmd($docuname,$docudom)) {
7141: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7142: if ($suppchanges) {
7143: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7144: undef($suppchanges);
7145: }
1.583 raeburn 7146: if ($fatal) {
7147: if ($container eq 'page') {
7148: $delwarning = &mt('An error occurred updating the contents of the current page.');
7149: } else {
7150: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7151: }
1.480 raeburn 7152: } else {
1.583 raeburn 7153: $delresult = &mt('Archive file removed.');
1.480 raeburn 7154: }
7155: }
1.583 raeburn 7156: } else {
7157: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7158: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7159: }
7160: }
7161: $env{'form.cmd'} = $currcmd;
7162: }
7163: if ($delwarning) {
7164: $output = '<p class="LC_warning">'.
7165: $delwarning.
7166: '</p>';
7167: }
7168: if ($delresult) {
7169: $output .= '<p class="LC_info">'.
7170: $delresult.
7171: '</p>';
7172: }
1.481 raeburn 7173: return $output;
1.480 raeburn 7174: }
7175:
1.484 raeburn 7176: sub generate_admin_menu {
1.611 raeburn 7177: my ($crstype,$canedit) = @_;
1.484 raeburn 7178: my $lc_crstype = lc($crstype);
7179: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7180: my %lt= ( # do not translate here
1.484 raeburn 7181: 'vc' => 'Verify Content',
7182: 'cv' => 'Check/Set Resource Versions',
7183: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7184: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7185: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7186: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7187: );
1.484 raeburn 7188: my ($candump,$dumpurl);
7189: if ($home + $other > 0) {
7190: $candump = 'F';
7191: if ($home) {
7192: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7193: } else {
7194: my @hosts;
7195: foreach my $aurole (keys(%outhash)) {
7196: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7197: push(@hosts,$outhash{$aurole});
1.538 raeburn 7198: }
1.484 raeburn 7199: }
7200: if (@hosts == 1) {
7201: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7202: '&role='.
7203: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7204: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7205: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7206: } else {
7207: $dumpurl = "javascript:choose_switchserver_window()";
7208: }
7209: }
7210: }
7211: my @menu=
7212: ({ categorytitle=>'Administration',
7213: items =>[
7214: { linktext => $lt{'vc'},
7215: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7216: permission => 'F',
1.571 raeburn 7217: help => 'Docs_Verify_Content',
1.484 raeburn 7218: icon => 'verify.png',
7219: linktitle => 'Verify contents can be retrieved/rendered',
7220: },
7221: { linktext => $lt{'cv'},
7222: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7223: permission => 'F',
1.571 raeburn 7224: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7225: icon => 'resversion.png',
7226: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7227: },
7228: { linktext => $lt{'ls'},
7229: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7230: permission => 'F',
7231: #help => '',
7232: icon => 'symbs.png',
7233: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7234: },
1.651 raeburn 7235: { linktext => $lt{'ct'},
7236: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7237: permission => 'F',
7238: help => 'Docs_Short_URLs',
7239: icon => 'shorturls.png',
7240: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7241: },
1.484 raeburn 7242: ]
1.611 raeburn 7243: });
7244: if ($canedit) {
7245: push(@menu,
1.484 raeburn 7246: { categorytitle=>'Export',
7247: items =>[
7248: { linktext => $lt{'imse'},
7249: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7250: permission => 'F',
7251: help => 'Docs_Export_Course_Docs',
7252: icon => 'imsexport.png',
7253: linktitle => $lt{'imse'},
7254: },
7255: { linktext => $lt{'dcd'},
7256: url => $dumpurl,
7257: permission => $candump,
1.571 raeburn 7258: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7259: icon => 'dump.png',
7260: linktitle => $lt{'dcd'},
7261: },
7262: ]
7263: });
1.611 raeburn 7264: }
1.484 raeburn 7265: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7266: '<input type="hidden" id="dummy" />'."\n".
7267: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7268: '</form>';
1.329 droeschl 7269: }
7270:
7271: sub generate_edit_table {
1.538 raeburn 7272: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7273: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7274: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7275: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7276: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7277: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7278: $activetab = $env{'form.active'};
7279: }
1.611 raeburn 7280: unless ($canedit) {
7281: $disabled = ' disabled="disabled"';
7282: }
1.472 raeburn 7283: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7284: my $backtext = &mt('Exit Editor');
1.458 raeburn 7285: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7286: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7287: '<li class="goback">'.
1.546 raeburn 7288: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7289: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7290: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7291: '<li>'.
7292: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7293: &mt('Undo Delete').'</a></li>'."\n";
7294: if ($env{'form.docslog'}) {
7295: $form .= '<li class="active">';
7296: } else {
7297: $form .= '<li>';
7298: }
7299: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7300: &mt('History').'</a></li>'."\n";
7301: if ($env{'form.docslog'}) {
7302: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7303: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7304: }
1.458 raeburn 7305: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7306: if($name ne '00'){
1.371 tempelho 7307: if($activetab eq '' || $activetab ne $name){
7308: $active = '';
7309: }elsif($activetab eq $name){
7310: $active = 'class="active"';
7311: }
1.458 raeburn 7312: $form .= '<li style="float:right" '.$active
1.484 raeburn 7313: .' 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 7314: } else {
1.570 raeburn 7315: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7316:
7317: }
1.329 droeschl 7318: }
1.484 raeburn 7319: $form .= '</ul>'."\n";
7320: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7321:
7322: if ($to_show ne '') {
1.538 raeburn 7323: my $saveform;
7324: if ($need_save) {
7325: my $button = &mt('Make changes');
7326: my $path;
7327: if ($env{'form.folderpath'}) {
7328: $path =
7329: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7330: }
7331: $saveform = <<"END";
7332: <div id="multisave" style="display:none; clear:both;" >
7333: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7334: <input type="hidden" name="folderpath" value="$path" />
7335: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7336: <input type="hidden" name="allhiddenresource" value="" />
7337: <input type="hidden" name="allencrypturl" value="" />
7338: <input type="hidden" name="allrandompick" value="" />
7339: <input type="hidden" name="allrandomorder" value="" />
7340: <input type="hidden" name="changeparms" value="" />
7341: <input type="hidden" name="multiremove" value="" />
7342: <input type="hidden" name="multicut" value="" />
7343: <input type="hidden" name="multicopy" value="" />
7344: <input type="hidden" name="multichange" value="" />
7345: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7346: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7347: </form>
7348: </div>
7349: END
7350: }
7351: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7352: }
1.363 ehlerst 7353: foreach my $field (keys(%orderhash)){
1.390 tempelho 7354: if($field ne '00'){
1.422 onken 7355: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7356: $active = 'style="display: none;float:left"';
1.422 onken 7357: }elsif($activetab eq $field){
1.458 raeburn 7358: $active = 'style="display:block;float:left"';
1.422 onken 7359: }
7360: $form .= '<div id="'.$field.$tid.'"'
7361: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7362: .'</div>'."\n";
1.363 ehlerst 7363: }
7364: }
1.484 raeburn 7365: unless ($env{'form.docslog'}) {
7366: $form .= '</div></div>'."\n";
7367: }
1.329 droeschl 7368: return $form;
7369: }
7370:
7371: sub editing_js {
1.622 raeburn 7372: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7373: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7374: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7375: p_mnf => 'Name of New Folder',
7376: t_mnf => 'New Folder',
7377: p_mnp => 'Name of New Page',
7378: t_mnp => 'New Page',
1.451 www 7379: p_mxu => 'Title for the External Score',
1.349 biermanm 7380: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7381: p_msb => 'Title for the Problem',
7382: p_mdb => 'Title for the Drop Box',
1.336 schafran 7383: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7384: p_mwp => 'Title for Web Page',
1.606 raeburn 7385: p_mnr => 'Title for the Resource',
1.348 weissno 7386: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7387: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7388: p_mab_alrt1 => 'Not a valid user:domain',
7389: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7390: p_chn => 'New Title',
7391: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7392: p_rmr2a => 'Remove',
7393: p_rmr2b => '?',
7394: p_rmr3a => 'Remove those',
7395: p_rmr3b => 'items?',
7396: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7397: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7398: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7399: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7400: p_ctr2a => 'Cut',
7401: p_ctr2b => '?',
7402: p_ctr3a => 'Cut those',
7403: p_ctr3b => 'items?',
1.633 raeburn 7404: setal => 'Enter a (unique) alias',
7405: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7406: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7407: imsfile => 'You must choose an IMS package for import',
7408: imscms => 'You must select which Course Management System was the source of the IMS package',
7409: invurl => 'Invalid URL',
7410: titbl => 'Title is blank',
1.538 raeburn 7411: more => '(More ...)',
7412: less => '(Less ...)',
1.543 raeburn 7413: noor => 'No actions selected or changes to settings specified.',
7414: noch => 'No changes to settings specified.',
7415: noac => 'No actions selected.',
1.606 raeburn 7416: nofi => 'No file selected',
7417: tinc => 'Title in course',
7418: sunm => 'Sub-directory name',
1.618 raeburn 7419: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7420: sele => 'Select',
7421: swit => 'Switch server required',
1.329 droeschl 7422: );
1.594 damieng 7423: &js_escape(\%js_lt);
1.433 raeburn 7424: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7425: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7426: my $main_container_page;
1.519 raeburn 7427: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7428: $main_container_page = 1;
1.434 raeburn 7429: }
1.617 raeburn 7430: my $backtourl;
7431: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7432: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7433: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7434: my @ids=&Apache::lonnet::current_machine_ids();
7435: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7436: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7437: my $caller = $1;
1.525 raeburn 7438: if ($caller =~ /^supplemental/) {
7439: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7440: } else {
7441: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7442: $res = &Apache::lonnet::clutter($res);
7443: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7444: my ($url,$anchor);
7445: if ($res =~ /^([^#]+)#([^#]+)$/) {
7446: $url = $1;
7447: $anchor = $2;
7448: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7449: $caller = $1.&escape('#').$anchor;
7450: }
1.614 raeburn 7451: } else {
7452: $url = $res;
1.609 raeburn 7453: }
1.640 raeburn 7454: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7455: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7456: $backtourl .= '?navmap=1';
7457: } else {
7458: $backtourl .= '?symb='.
7459: &HTML::Entities::encode($caller,'<>&"');
7460: }
1.622 raeburn 7461: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7462: if (($ENV{'SERVER_PORT'} == 443) &&
7463: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7464: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7465: if ($hostname ne '') {
7466: $backtourl = 'http://'.$hostname.$backtourl;
7467: }
7468: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7469: }
7470: }
1.623 raeburn 7471: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7472: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7473: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7474: if ($hostname ne '') {
7475: $backtourl = 'http://'.$hostname.$backtourl;
7476: }
7477: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7478: }
1.623 raeburn 7479: }
1.622 raeburn 7480: }
1.609 raeburn 7481: if ($anchor ne '') {
7482: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7483: }
1.590 raeburn 7484: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7485: } else {
7486: $backtourl = '/adm/navmaps';
1.525 raeburn 7487: }
7488: }
7489: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7490: $backtourl = '/adm/menu';
7491: } elsif ($supplementalflag) {
1.682 raeburn 7492: if (($env{'request.role.adv'}) ||
7493: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7494: $backtourl = '/adm/supplemental';
7495: } else {
7496: $backtourl = '/adm/navmaps';
7497: }
1.525 raeburn 7498: } else {
7499: $backtourl = '/adm/navmaps';
1.472 raeburn 7500: }
7501:
1.655 raeburn 7502: my $fieldsets = "'doc'";
1.519 raeburn 7503: unless ($main_container_page) {
7504: $fieldsets .=",'ims'";
7505: }
1.655 raeburn 7506: my $extfieldsets = "'ext'";
7507: if ($posslti) {
7508: $extfieldsets .= ",'tool'";
7509: }
1.501 raeburn 7510: if ($supplementalflag) {
1.655 raeburn 7511: $fieldsets = "'suppdoc'";
7512: $extfieldsets = "'suppext'";
1.600 raeburn 7513: if ($posslti) {
1.655 raeburn 7514: $extfieldsets .= ",'supptool'";
1.600 raeburn 7515: }
1.501 raeburn 7516: }
1.655 raeburn 7517:
1.611 raeburn 7518: my $jsmakefunctions;
7519: if ($canedit) {
7520: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7521: function makenewfolder(targetform,folderseq) {
1.594 damieng 7522: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7523: if (foldername) {
1.676 raeburn 7524: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7525: targetform.submit();
7526: }
7527: }
7528:
7529: function makenewpage(targetform,folderseq) {
1.594 damieng 7530: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7531: if (pagename) {
1.676 raeburn 7532: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7533: targetform.submit();
7534: }
7535: }
7536:
7537: function makeexamupload() {
1.594 damieng 7538: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7539: if (title) {
1.329 droeschl 7540: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7541: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7542: this.document.forms.newexamupload.submit();
7543: }
7544: }
7545:
7546: function makesmppage() {
1.594 damieng 7547: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7548: if (title) {
1.329 droeschl 7549: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7550: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7551: this.document.forms.newsmppg.submit();
7552: }
7553: }
7554:
1.534 raeburn 7555: function makewebpage(type) {
1.594 damieng 7556: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7557: var formname;
7558: if (type == 'supp') {
7559: formname = this.document.forms.supwebpage;
7560: } else {
7561: formname = this.document.forms.newwebpage;
7562: }
7563: if (title) {
7564: var webpage = formname.importdetail.value;
1.675 raeburn 7565: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7566: formname.submit();
7567: }
7568: }
7569:
1.329 droeschl 7570: function makesmpproblem() {
1.594 damieng 7571: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7572: if (title) {
1.329 droeschl 7573: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7574: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7575: this.document.forms.newsmpproblem.submit();
7576: }
7577: }
7578:
7579: function makedropbox() {
1.594 damieng 7580: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7581: if (title) {
1.329 droeschl 7582: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7583: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7584: this.document.forms.newdropbox.submit();
7585: }
7586: }
7587:
7588: function makebulboard() {
1.594 damieng 7589: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7590: if (title) {
7591: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7592: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7593: this.document.forms.newbul.submit();
7594: }
7595: }
7596:
7597: function makeabout() {
1.594 damieng 7598: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7599: if (user) {
7600: var comp=new Array();
7601: comp=user.split(':');
7602: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7603: if ((comp[0]) && (comp[1])) {
7604: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7605: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7606: this.document.forms.newaboutsomeone.submit();
7607: } else {
7608: alert("$js_lt{'p_mab_alrt1'}");
7609: }
7610: } else {
7611: alert("$js_lt{'p_mab_alrt2'}");
7612: }
7613: }
7614: }
7615:
7616: function makenew(targetform) {
7617: targetform.submit();
7618: }
7619:
7620: function changename(folderpath,index,oldtitle) {
7621: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7622: if (title) {
7623: this.document.forms.renameform.markcopy.value='';
7624: this.document.forms.renameform.title.value=title;
7625: this.document.forms.renameform.cmd.value='rename_'+index;
7626: this.document.forms.renameform.folderpath.value=folderpath;
7627: this.document.forms.renameform.submit();
7628: }
7629: }
7630:
1.633 raeburn 7631: function setalias(folderpath,index) {
7632: var alias = prompt('$js_lt{"setal"}');
7633: if ((alias != null) && (alias != '')) {
7634: this.document.forms.aliasform.alias.value=alias;
7635: this.document.forms.aliasform.cmd.value='setalias_'+index;
7636: this.document.forms.aliasform.folderpath.value=folderpath;
7637: this.document.forms.aliasform.submit();
7638: }
7639: }
7640:
7641: function delalias(folderpath,index) {
7642: if (confirm('$js_lt{"delal"}')) {
7643: this.document.forms.aliasform.cmd.value='delalias_'+index;
7644: this.document.forms.aliasform.folderpath.value=folderpath;
7645: this.document.forms.aliasform.submit();
7646: }
7647: }
7648:
1.611 raeburn 7649: ENDNEWSCRIPT
7650: } else {
7651: $jsmakefunctions = <<ENDNEWSCRIPT;
7652:
7653: function makenewfolder() {
7654: alert("$js_lt{'edri'}");
7655: }
7656:
7657: function makenewpage() {
7658: alert("$js_lt{'edri'}");
7659: }
7660:
7661: function makeexamupload() {
7662: alert("$js_lt{'edri'}");
7663: }
7664:
7665: function makesmppage() {
7666: alert("$js_lt{'edri'}");
7667: }
7668:
7669: function makewebpage(type) {
7670: alert("$js_lt{'edri'}");
7671: }
7672:
7673: function makesmpproblem() {
7674: alert("$js_lt{'edri'}");
7675: }
7676:
7677: function makedropbox() {
7678: alert("$js_lt{'edri'}");
7679: }
7680:
7681: function makebulboard() {
7682: alert("$js_lt{'edri'}");
7683: }
7684:
7685: function makeabout() {
7686: alert("$js_lt{'edri'}");
7687: }
7688:
7689: function changename() {
7690: alert("$js_lt{'edri'}");
7691: }
7692:
1.633 raeburn 7693: function setalias() {
7694: alert("$js_lt{'edri'}");
7695: }
7696:
7697: function delalias() {
7698: alert("$js_lt{'edri'}");
7699: }
7700:
1.611 raeburn 7701: function makenew() {
7702: alert("$js_lt{'edri'}");
7703: }
7704:
7705: function groupimport() {
7706: alert("$js_lt{'edri'}");
1.335 ehlerst 7707: }
1.611 raeburn 7708:
7709: function groupsearch() {
7710: alert("$js_lt{'edri'}");
1.335 ehlerst 7711: }
1.611 raeburn 7712:
7713: function groupopen(url,recover) {
7714: var options="scrollbars=1,resizable=1,menubar=0";
7715: idxflag=1;
7716: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7717: idx.focus();
1.329 droeschl 7718: }
7719:
1.611 raeburn 7720: ENDNEWSCRIPT
7721:
7722: }
7723: return <<ENDSCRIPT;
7724:
7725: $jsmakefunctions
7726:
1.501 raeburn 7727: function toggleUpload(caller) {
7728: var blocks = Array($fieldsets);
7729: for (var i=0; i<blocks.length; i++) {
7730: var disp = 'none';
7731: if (caller == blocks[i]) {
7732: var curr = document.getElementById('upload'+caller+'form').style.display;
7733: if (curr == 'none') {
7734: disp='block';
7735: }
7736: }
7737: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7738: }
7739: resize_scrollbox('contentscroll','1','1');
7740: return;
7741: }
7742:
7743: function toggleExternal(caller) {
7744: var blocks = Array($extfieldsets);
7745: for (var i=0; i<blocks.length; i++) {
7746: var disp = 'none';
7747: if (caller == blocks[i]) {
7748: var curr = document.getElementById('external'+caller+'form').style.display;
7749: if (curr == 'none') {
7750: disp='block';
7751: }
7752: }
7753: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7754: if ((caller == 'tool') || (caller == 'supptool')) {
7755: if (disp == 'block') {
1.655 raeburn 7756: if (document.getElementById('LC_exttoolid')) {
7757: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7758: var suppflag = 0;
7759: if (caller == 'supptool') {
7760: suppflag = 1;
7761: }
7762: currForm = document.getElementById('new'+caller);
1.655 raeburn 7763: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7764: }
7765: }
7766: }
1.501 raeburn 7767: }
1.502 raeburn 7768: resize_scrollbox('contentscroll','1','1');
7769: return;
7770: }
7771:
1.514 raeburn 7772: function toggleMap(caller) {
1.502 raeburn 7773: var disp = 'none';
1.510 raeburn 7774: if (document.getElementById('importmapform')) {
1.514 raeburn 7775: if (caller == 'map') {
7776: var curr = document.getElementById('importmapform').style.display;
7777: if (curr == 'none') {
7778: disp='block';
7779: }
1.510 raeburn 7780: }
7781: document.getElementById('importmapform').style.display=disp;
7782: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7783: }
1.501 raeburn 7784: return;
1.329 droeschl 7785: }
7786:
1.691 raeburn 7787: function toggleCrsRes(caller) {
1.606 raeburn 7788: var disp = 'none';
7789: if (document.getElementById('crsresform')) {
7790: if (caller == 'res') {
1.691 raeburn 7791: var form = document.getElementById('crsresform');
7792: var curr = form.style.display;
1.606 raeburn 7793: if (curr == 'none') {
7794: disp='block';
1.691 raeburn 7795: document.courseresform.authorrole.selectedIndex = 0;
7796: document.courseresform.authorpath.selectedIndex = 0;
7797: document.courseresform.newresourceadd.selectedIndex = 0;
7798: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7799: toggleNewInCourse(document.courseresform);
7800: if (document.getElementById('newresource')) {
7801: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 7802: }
7803: if (document.courseresform.newresusetemp.length) {
7804: document.courseresform.newresusetemp[0].checked = true;
7805: toggleWithTemplate(document.courseresform);
7806: }
7807: document.courseresform.newresourcename.value = '';
7808: }
7809: }
7810: if (document.courseresform.newsubdir.length) {
7811: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7812: if (document.courseresform.newsubdir[j].value == 0) {
7813: document.courseresform.newsubdir[j].checked = true;
7814: }
7815: break;
7816: }
7817: if (document.getElementById('newsubdirname')) {
7818: document.getElementById('newsubdirname').type = "hidden";
7819: document.getElementById('newsubdirname').value = "";
7820: }
7821: if (document.getElementById('newsubdir')) {
7822: document.getElementById('newsubdir').innerHTML = "";
7823: }
7824: }
7825: document.getElementById('crsresform').style.display=disp;
7826: resize_scrollbox('contentscroll','1','0');
7827: }
7828: return;
7829: }
7830:
7831: function toggleNewsubdir(form) {
7832: if (form.newsubdir.length) {
7833: for (var j=0; j<form.newsubdir.length; j++) {
7834: if (form.newsubdir[j].checked) {
7835: if (document.getElementById('newsubdirname')) {
7836: if (form.newsubdir[j].value == '1') {
7837: document.getElementById('newsubdirname').type = "text";
7838: if (document.getElementById('newsubdir')) {
7839: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7840: }
7841: } else {
7842: document.getElementById('newsubdirname').type = "hidden";
7843: document.getElementById('newsubdirname').value = "";
7844: document.getElementById('newsubdir').innerHTML = "";
7845: }
7846: }
7847: break;
7848: }
7849: }
7850: }
7851: }
7852:
7853: function toggleCrsResTitle() {
7854: if (document.getElementById('newresource')) {
1.691 raeburn 7855: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7856: if (selloc == 'course') {
1.606 raeburn 7857: document.getElementById('newresource').style.display = 'inline';
7858: document.courseresform.newresourceadd[0].checked = true;
7859: toggleNewInCourse(document.courseresform);
7860: } else {
7861: document.getElementById('newresource').style.display = 'none';
7862: }
1.689 raeburn 7863: }
7864: if (document.getElementById('newstdproblem')) {
7865: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7866: document.getElementById('newstdproblem').style.display = 'none';
7867: if (document.getElementById('stdprobswitch')) {
7868: document.getElementById('stdprobswitch').style.display = 'block';
7869: }
7870: } else {
7871: document.getElementById('newstdproblem').style.display = 'block';
7872: if (document.getElementById('stdprobswitch')) {
7873: document.getElementById('stdprobswitch').style.display = 'none';
7874: }
7875: }
7876: }
1.606 raeburn 7877: }
7878:
7879: function toggleNewInCourse(form) {
7880: if (form.newresourceadd.length) {
7881: for (var i=0; i<form.newresourceadd.length; i++) {
7882: if (form.newresourceadd[i].checked) {
7883: if (document.getElementById('newresourcetitle')) {
7884: if (form.newresourceadd[i].value == '1') {
7885: document.getElementById('newresourcetitle').type = 'text';
7886: if (document.getElementById('newrestitle')) {
7887: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7888: }
7889: } else {
7890: document.getElementById('newresourcetitle').type = 'hidden';
7891: document.getElementById('newresourcetitle').value = '';
7892: if (document.getElementById('newrestitle')) {
7893: document.getElementById('newrestitle').innerHTML = '';
7894: }
7895: }
7896: }
7897: break;
7898: }
7899: }
7900: }
7901: }
7902:
7903: function toggleWithTemplate(form) {
7904: if (form.newresusetemp.length) {
7905: for (var i=0; i<form.newresusetemp.length; i++) {
7906: if (form.newresusetemp[i].checked) {
7907: if (document.getElementById('newrestemplate')) {
7908: if (form.newresusetemp[i].value == '1') {
7909: document.getElementById('newrestemplate').style.display = 'inline';
7910: toggleExampleText();
7911: } else {
7912: form.tempcategory.selectedIndex = 0;
7913: select1template_changed();
7914: document.getElementById('newrestemplate').style.display = 'none';
7915: }
7916: }
7917: }
7918: }
7919: }
7920: }
7921:
7922: function toggleExampleText() {
7923: if (document.getElementById('newresexample')) {
7924: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7925: if (url == '') {
7926: document.getElementById('newresexample').style.fontWeight = 'normal';
7927: } else {
7928: document.getElementById('newresexample').style.fontWeight = 'bold';
7929: }
7930: }
7931: }
7932:
7933: function getExample(width,height,scrolling,transparency) {
7934: var url;
7935: if (document.courseresform.newresusetemp.length) {
7936: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7937: if (document.courseresform.newresusetemp[i].checked) {
7938: if (document.courseresform.newresusetemp[i].value == '1') {
7939: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7940: if (url == '') {
7941: alert('Pick a category and template');
7942: } else {
7943: url = url.replace("$londocroot","");
7944: url += '?inhibitmenu=yes';
7945: }
7946: }
7947: break;
7948: }
7949: }
7950: }
7951: if (url != '') {
7952: openMyModal(url,width,height,scrolling,transparency,'');
7953: }
7954: }
7955:
1.690 raeburn 7956: function toggleImportCrsres(caller) {
1.606 raeburn 7957: var disp = 'none';
7958: if (document.getElementById('importcrsresform')) {
7959: if (caller == 'res') {
7960: var curr = document.getElementById('importcrsresform').style.display;
7961: if (curr == 'none') {
7962: disp='block';
1.690 raeburn 7963: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1);
1.606 raeburn 7964: }
7965: }
7966: document.getElementById('importcrsresform').style.display=disp;
7967: resize_scrollbox('contentscroll','1','0');
7968: }
7969: return;
7970: }
7971:
1.690 raeburn 7972: $showfile_js
7973:
1.691 raeburn 7974: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
7975: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
7976: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
7977: var selelem = form.elements[dirsel];
7978: var i, numfiles = selelem.options.length -1;
7979: if (numfiles >=0) {
7980: for (i = numfiles; i >= 0; i--) {
7981: selelem.remove(i);
7982: }
7983: }
7984: if ((location == '') || (location == null) || (location == 'undefined')) {
7985: if (selelem.options.length == 0) {
7986: selelem.options[selelem.options.length] = new Option('','');
7987: selelem.selectedIndex = 0;
7988: }
7989: if (document.getElementById('newstdproblem')) {
7990: document.getElementById('newstdproblem').style.display = 'none';
7991: }
7992: return;
7993: }
7994: var machineIds = new Array($machines_str);
7995: var athome = 0;
7996: var role = location;
7997: if ((location == 'author') || (location == 'course')) {
7998: if (document.getElementById('rolehome_'+location)) {
7999: var currhome = document.getElementById('rolehome_'+location).value;
8000: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8001: if (machineIds.includes(currhome)) {
8002: athome = 1;
8003: }
8004: }
8005: }
8006: } else {
8007: const roleinfo = location.split('___');
8008: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8009: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8010: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8011: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8012: if (machineIds.includes(currhome)) {
8013: athome = 1;
8014: }
8015: }
8016: }
8017: }
8018: if (athome) {
8019: if (document.getElementById('stdprobswitch')) {
8020: document.getElementById('stdprobswitch').style.display = 'none';
8021: }
8022: if (document.getElementById('newstdproblem')) {
8023: document.getElementById('newstdproblem').style.display = 'none';
8024: }
8025: var http = new XMLHttpRequest();
8026: var url = "/adm/courseauthor";
8027: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir;
8028: http.open("POST", url, true);
8029: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8030: http.onreadystatechange = function() {
8031: if (http.readyState == 4 && http.status == 200) {
8032: var data = JSON.parse(http.responseText);
8033: if (Array.isArray(data.dirs)) {
8034: var len = data.dirs.length;
8035: if (len) {
8036: if (len > 1) {
8037: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8038: }
8039: }
8040: if (len) {
8041: var j;
8042: for (j = 0; j < len; j++) {
8043: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8044: }
8045: selelem.selectedIndex = 0;
8046: }
8047: }
8048: }
8049: }
8050: http.send(params);
8051: } else {
8052: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8053: selelem.selectedIndex = 0;
8054: if (document.getElementById('stdprobswitch')) {
8055: document.getElementById('stdprobswitch').style.display = 'block';
8056: }
8057: if (document.getElementById('newstdproblem')) {
8058: document.getElementById('newstdproblem').style.display = 'none';
8059: }
8060: }
8061: }
8062: return;
8063: }
8064:
1.689 raeburn 8065: function switchForProb() {
8066: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8067: var url = '/adm/switchserver?otherserver=';
8068: var newhostid = '';
8069: var role = '';
8070: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8071: if (selloc == 'author') {
8072: newhostid = document.courseresform.rolehome_author.value;
8073: role = "au./&js_escape($env{'user.domain'})/";
8074: } else if (selloc == 'course') {
8075: newhostid = document.courseresform.rolehome_course.value;
8076: role = "&js_escape($env{'request.role'})";
8077: } else {
8078: var items = new Array();
8079: items = selloc.split('___');
8080: var len = document.courseresform.rolehome_coauthor.length;
8081: if (null == len) {
8082: var currval = document.courseresform.rolehome_coauthor.value;
8083: if (null != currval) {
8084: var info = new Array();
8085: info = currval.split('=');
8086: newhostid = info[2];
8087: role = info[0]+'./'+info[1];
8088: }
8089: } else {
8090: for (var i=0; i<len; i++) {
8091: var currval = document.courseresform.rolehome_coauthor[i].value;
8092: if (null != currval) {
8093: var info = new Array();
8094: info = currval.split('=');
8095: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8096: newhostid = info[2];
8097: role = info[0]+'./'+info[1];
8098: break;
8099: }
8100: }
8101: }
8102: }
8103: }
8104: if (newhostid != '') {
8105: url += newhostid;
8106: if (role != '') {
8107: url += '&role='+role;
8108: }
8109: document.location.href = url;
8110: }
8111: }
8112: return;
8113: }
8114:
1.501 raeburn 8115: function makeims(imsform) {
8116: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8117: alert("$js_lt{'imsfile'}");
1.501 raeburn 8118: return;
8119: }
8120: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8121: alert("$js_lt{'imscms'}");
1.501 raeburn 8122: return;
8123: }
8124: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8125: imsform.submit();
8126: }
8127:
1.478 raeburn 8128: function updatePick(targetform,index,caller) {
1.537 raeburn 8129: var pickitem;
8130: var picknumitem;
8131: var picknumtext;
8132: if (index == 'all') {
8133: pickitem = document.getElementById('randompickall');
8134: picknumitem = document.getElementById('rpicknumall');
8135: picknumtext = document.getElementById('rpicktextall');
8136: } else {
8137: pickitem = document.getElementById('randompick_'+index);
8138: picknumitem = document.getElementById('rpicknum_'+index);
8139: picknumtext = document.getElementById('randompicknum_'+index);
8140: }
1.478 raeburn 8141: if (pickitem.checked) {
1.594 damieng 8142: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8143: if (picknum == '' || picknum == null) {
8144: if (caller == 'check') {
8145: pickitem.checked=false;
1.537 raeburn 8146: if (index == 'all') {
8147: picknumtext.innerHTML = '';
8148: if (caller == 'link') {
8149: propagateState(targetform,'rpicknum');
8150: }
8151: } else {
1.538 raeburn 8152: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8153: }
1.478 raeburn 8154: }
8155: } else {
8156: picknum.toString();
8157: var regexdigit=/^\\d+\$/;
8158: if (regexdigit.test(picknum)) {
8159: picknumitem.value = picknum;
1.537 raeburn 8160: if (index == 'all') {
1.538 raeburn 8161: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8162: if (caller == 'link') {
8163: propagateState(targetform,'rpicknum');
8164: }
8165: } else {
8166: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8167: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8168: }
1.478 raeburn 8169: } else {
8170: if (caller == 'check') {
1.537 raeburn 8171: if (index == 'all') {
8172: picknumtext.innerHTML = '';
8173: if (caller == 'link') {
8174: propagateState(targetform,'rpicknum');
8175: }
8176: } else {
8177: pickitem.checked=false;
1.538 raeburn 8178: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8179: }
1.478 raeburn 8180: }
8181: return;
8182: }
8183: }
8184: } else {
1.537 raeburn 8185: picknumitem.value = '';
8186: picknumtext.innerHTML = '';
8187: if (index == 'all') {
8188: if (caller == 'link') {
8189: propagateState(targetform,'rpicknum');
8190: }
8191: } else {
1.538 raeburn 8192: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8193: }
8194: }
8195: }
8196:
8197: function propagateState(form,param) {
8198: if (document.getElementById(param+'all')) {
8199: var setcheck = 0;
8200: var rpick = 0;
8201: if (param == 'rpicknum') {
8202: if (document.getElementById('randompickall')) {
8203: if (document.getElementById('randompickall').checked) {
8204: if (document.getElementById('rpicknumall')) {
8205: rpick = document.getElementById('rpicknumall').value;
8206: }
8207: }
8208: }
8209: } else {
8210: if (document.getElementById(param+'all').checked) {
8211: setcheck = 1;
8212: }
8213: }
1.538 raeburn 8214: var allidxlist;
8215: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8216: if (document.getElementById('all'+param+'idx')) {
8217: allidxlist = document.getElementById('all'+param+'idx').value;
8218: }
8219: var actions = new Array ('remove','cut','copy');
8220: for (var i=0; i<actions.length; i++) {
8221: if (actions[i] != param) {
8222: if (document.getElementById(actions[i]+'all')) {
8223: document.getElementById(actions[i]+'all').checked = false;
8224: }
8225: }
8226: }
8227: }
1.537 raeburn 8228: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8229: allidxlist = form.allidx.value;
8230: }
8231: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8232: allidxlist = form.allmapidx.value;
8233: }
8234: if ((allidxlist != '') && (allidxlist != null)) {
8235: var allidxs = allidxlist.split(',');
8236: if (allidxs.length > 1) {
8237: for (var i=0; i<allidxs.length; i++) {
8238: if (document.getElementById(param+'_'+allidxs[i])) {
8239: if (param == 'rpicknum') {
8240: if (document.getElementById('randompick_'+allidxs[i])) {
8241: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8242: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8243: if (rpick > 0) {
8244: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8245: } else {
8246: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8247: }
8248: }
8249: }
8250: } else {
1.537 raeburn 8251: if (setcheck == 1) {
8252: document.getElementById(param+'_'+allidxs[i]).checked = true;
8253: } else {
8254: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8255: if (param == 'randompick') {
8256: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8257: }
1.537 raeburn 8258: }
8259: }
8260: }
8261: }
1.538 raeburn 8262: if (setcheck == 1) {
8263: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8264: var actions = new Array('copy','cut','remove');
8265: for (var i=0; i<actions.length; i++) {
8266: var otheractions;
8267: var otheridxs;
8268: if (actions[i] === param) {
8269: continue;
8270: } else {
8271: if (document.getElementById('all'+actions[i]+'idx')) {
8272: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8273: otheridxs = otheractions.split(',');
8274: if (otheridxs.length > 1) {
8275: for (var j=0; j<otheridxs.length; j++) {
8276: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8277: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8278: }
1.537 raeburn 8279: }
8280: }
8281: }
1.538 raeburn 8282: }
8283: }
8284: }
8285: }
8286: }
8287: }
8288: }
8289: return;
8290: }
8291:
1.603 raeburn 8292: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8293: var canedit = '$canedit';
8294: if (canedit == '') {
8295: alert("$js_lt{'edri'}");
8296: return;
8297: }
1.539 raeburn 8298: var dosettings;
8299: var doaction;
1.538 raeburn 8300: var control = document.togglemultsettings;
8301: if (context == 'actions') {
8302: control = document.togglemultactions;
1.539 raeburn 8303: doaction = 1;
8304: } else {
8305: dosettings = 1;
1.538 raeburn 8306: }
1.539 raeburn 8307: if (control) {
8308: if (control.showmultpick.length) {
8309: for (var i=0; i<control.showmultpick.length; i++) {
8310: if (control.showmultpick[i].checked) {
8311: if (control.showmultpick[i].value == 1) {
8312: if (context == 'settings') {
8313: dosettings = 0;
8314: } else {
8315: doaction = 0;
1.538 raeburn 8316: }
8317: }
8318: }
1.537 raeburn 8319: }
8320: }
1.539 raeburn 8321: }
8322: if (context == 'settings') {
8323: if (dosettings == 1) {
1.538 raeburn 8324: targetform.changeparms.value=param;
8325: targetform.submit();
8326: }
1.537 raeburn 8327: }
1.539 raeburn 8328: if (context == 'actions') {
8329: if (doaction == 1) {
8330: targetform.cmd.value=param+'_'+index;
8331: targetform.folderpath.value=folderpath;
8332: targetform.markcopy.value=idx+':'+param;
8333: targetform.copyfolder.value=folder+'.'+container;
8334: if (param == 'remove') {
1.603 raeburn 8335: var doremove = 0;
8336: if (skip_confirm) {
8337: if (confirm_removal) {
8338: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8339: doremove = 1;
8340: }
8341: } else {
8342: doremove = 1;
8343: }
8344: } else {
8345: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8346: doremove = 1;
8347: }
8348: }
8349: if (doremove) {
1.539 raeburn 8350: targetform.markcopy.value='';
8351: targetform.copyfolder.value='';
8352: targetform.submit();
8353: }
8354: }
8355: if (param == 'cut') {
1.594 damieng 8356: 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 8357: targetform.submit();
8358: return;
8359: }
8360: }
8361: if (param == 'copy') {
8362: targetform.submit();
8363: return;
8364: }
8365: targetform.markcopy.value='';
8366: targetform.copyfolder.value='';
8367: targetform.cmd.value='';
8368: targetform.folderpath.value='';
8369: return;
8370: } else {
8371: if (document.getElementById(param+'_'+idx)) {
8372: item = document.getElementById(param+'_'+idx);
8373: if (item.type == 'checkbox') {
8374: if (item.checked) {
8375: item.checked = false;
8376: } else {
8377: item.checked = true;
8378: singleCheck(item,idx,param);
8379: }
8380: }
8381: }
8382: }
8383: }
1.537 raeburn 8384: return;
8385: }
8386:
1.538 raeburn 8387: function singleCheck(caller,idx,action) {
8388: actions = new Array('cut','copy','remove');
8389: if (caller.checked) {
8390: for (var i=0; i<actions.length; i++) {
8391: if (actions[i] != action) {
8392: if (document.getElementById(actions[i]+'_'+idx)) {
8393: if (document.getElementById(actions[i]+'_'+idx).checked) {
8394: document.getElementById(actions[i]+'_'+idx).checked = false;
8395: }
1.537 raeburn 8396: }
8397: }
8398: }
1.478 raeburn 8399: }
1.537 raeburn 8400: return;
1.478 raeburn 8401: }
8402:
1.334 muellerd 8403: function unselectInactive(nav) {
1.335 ehlerst 8404: currentNav = document.getElementById(nav);
8405: currentLis = currentNav.getElementsByTagName('LI');
8406: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8407: if (currentLis[i].className == 'goback') {
8408: currentLis[i].className = 'goback';
8409: } else {
8410: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8411: currentLis[i].className = 'right';
1.472 raeburn 8412: } else {
1.374 tempelho 8413: currentLis[i].className = 'i';
1.472 raeburn 8414: }
8415: }
1.335 ehlerst 8416: }
1.332 tempelho 8417: }
8418:
1.334 muellerd 8419: function hideAll(current, nav, data) {
1.335 ehlerst 8420: unselectInactive(nav);
1.570 raeburn 8421: if (current) {
8422: if (current.className == 'right'){
8423: current.className = 'right active'
8424: } else {
8425: current.className = 'active';
8426: }
1.374 tempelho 8427: }
1.335 ehlerst 8428: currentData = document.getElementById(data);
8429: currentDivs = currentData.getElementsByTagName('DIV');
8430: for (i = 0; i < currentDivs.length; i++) {
8431: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8432: currentDivs[i].style.display = 'none';
1.330 tempelho 8433: }
8434: }
1.335 ehlerst 8435: }
1.330 tempelho 8436:
1.374 tempelho 8437: function openTabs(pageId) {
8438: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8439: if(tabnav.length > 2 ){
1.389 tempelho 8440: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8441: currentLis = currentNav.getElementsByTagName('LI');
8442: for(i = 0; i< currentLis.length; i++){
8443: if(currentLis[i].className == 'active') {
1.375 tempelho 8444: funcString = currentLis[i].onclick.toString();
8445: tab = funcString.split('"');
1.420 onken 8446: if(tab.length < 2) {
8447: tab = funcString.split("'");
8448: }
1.375 tempelho 8449: currentData = document.getElementById(tab[1]);
8450: currentData.style.display = 'block';
1.374 tempelho 8451: }
8452: }
8453: }
8454: }
8455:
1.334 muellerd 8456: function showPage(current, pageId, nav, data) {
1.570 raeburn 8457: currstate = current.className;
1.334 muellerd 8458: hideAll(current, nav, data);
1.375 tempelho 8459: openTabs(pageId);
1.334 muellerd 8460: unselectInactive(nav);
1.570 raeburn 8461: if ((currstate == 'active') || (currstate == 'right active')) {
8462: if (currstate == 'active') {
8463: current.className = '';
8464: } else {
8465: current.className = 'right';
8466: }
8467: activeTab = '';
1.656 raeburn 8468: toggleExternal();
1.570 raeburn 8469: toggleUpload();
8470: toggleMap();
1.606 raeburn 8471: toggleCrsRes();
8472: toggleImportCrsres();
1.570 raeburn 8473: resize_scrollbox('contentscroll','1','0');
8474: return;
8475: } else {
8476: current.className = 'active';
8477: }
1.330 tempelho 8478: currentData = document.getElementById(pageId);
8479: currentData.style.display = 'block';
1.458 raeburn 8480: activeTab = pageId;
1.656 raeburn 8481: toggleExternal();
1.501 raeburn 8482: toggleUpload();
1.503 raeburn 8483: toggleMap();
1.606 raeburn 8484: toggleCrsRes();
8485: toggleImportCrsres();
1.433 raeburn 8486: if (nav == 'mainnav') {
8487: var storedpath = "$docs_folderpath";
1.434 raeburn 8488: var storedpage = "$main_container_page";
1.433 raeburn 8489: var reg = new RegExp("^supplemental");
8490: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8491: if (storedpage == 1) {
8492: document.simpleedit.folderpath.value = '';
8493: document.uploaddocument.folderpath.value = '';
8494: } else {
8495: if (reg.test(storedpath)) {
8496: document.simpleedit.folderpath.value = '$toplevelmain';
8497: document.uploaddocument.folderpath.value = '$toplevelmain';
8498: document.newext.folderpath.value = '$toplevelmain';
8499: } else {
8500: document.simpleedit.folderpath.value = storedpath;
8501: document.uploaddocument.folderpath.value = storedpath;
8502: document.newext.folderpath.value = storedpath;
8503: }
1.433 raeburn 8504: }
8505: } else {
1.434 raeburn 8506: if (reg.test(storedpath)) {
8507: document.simpleedit.folderpath.value = storedpath;
8508: document.supuploaddocument.folderpath.value = storedpath;
8509: document.supnewext.folderpath.value = storedpath;
8510: } else {
1.433 raeburn 8511: document.simpleedit.folderpath.value = '$toplevelsupp';
8512: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8513: document.supnewext.folderpath.value = '$toplevelsupp';
8514: }
8515: }
8516: }
1.485 raeburn 8517: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8518: return false;
8519: }
1.329 droeschl 8520:
1.472 raeburn 8521: function toContents(jumpto) {
8522: var newurl = '$backtourl';
1.525 raeburn 8523: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8524: newurl = newurl+'?postdata='+jumpto;
8525: }
8526: location.href=newurl;
8527: }
8528:
1.538 raeburn 8529: function togglePick(caller,value) {
8530: var disp = 'none';
8531: if (document.getElementById('multi'+caller)) {
8532: var curr = document.getElementById('multi'+caller).style.display;
8533: if (value == 1) {
8534: disp='block';
8535: }
8536: if (curr == disp) {
8537: return;
8538: }
8539: document.getElementById('multi'+caller).style.display=disp;
8540: if (value == 1) {
1.594 damieng 8541: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8542: } else {
8543: document.getElementById('more'+caller).innerHTML = '';
8544: }
8545: if (caller == 'actions') {
8546: setClass(value);
8547: setBoxes(value);
8548: }
8549: }
8550: var showButton = multiSettings();
8551: if (showButton != 1) {
8552: showButton = multiActions();
8553: }
8554: if (document.getElementById('multisave')) {
8555: if (showButton == 1) {
8556: document.getElementById('multisave').style.display='block';
8557: } else {
8558: document.getElementById('multisave').style.display='none';
8559: }
8560: }
8561: resize_scrollbox('contentscroll','1','1');
8562: return;
8563: }
8564:
8565: function toggleCheckUncheck(caller,more) {
8566: if (more == 1) {
1.594 damieng 8567: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8568: document.getElementById('allfields'+caller).style.display='block';
8569: } else {
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: document.getElementById('allfields'+caller).style.display='none';
8572: }
8573: resize_scrollbox('contentscroll','1','1');
8574: }
8575:
8576: function multiSettings() {
8577: var inuse = 0;
8578: var settingsform = document.togglemultsettings;
8579: if (settingsform.showmultpick.length > 1) {
8580: for (var i=0; i<settingsform.showmultpick.length; i++) {
8581: if (settingsform.showmultpick[i].checked) {
8582: if (settingsform.showmultpick[i].value == 1) {
8583: inuse = 1;
8584: }
8585: }
8586: }
8587: }
8588: return inuse;
8589: }
8590:
8591: function multiActions() {
8592: var inuse = 0;
8593: var actionsform = document.togglemultactions;
8594: if (actionsform.showmultpick.length > 1) {
8595: for (var i=0; i<actionsform.showmultpick.length; i++) {
8596: if (actionsform.showmultpick[i].checked) {
8597: if (actionsform.showmultpick[i].value == 1) {
8598: inuse = 1;
8599: }
8600: }
8601: }
8602: }
8603: return inuse;
8604: }
8605:
8606: function checkSubmits() {
8607: var numchanges = 0;
8608: var form = document.saveactions;
8609: var doactions = multiActions();
1.542 raeburn 8610: var cutwarnings = 0;
8611: var remwarnings = 0;
1.603 raeburn 8612: var removalinfo = 0;
1.538 raeburn 8613: if (doactions == 1) {
8614: var remidxlist = document.cumulativeactions.allremoveidx.value;
8615: if ((remidxlist != '') && (remidxlist != null)) {
8616: var remidxs = remidxlist.split(',');
8617: for (var i=0; i<remidxs.length; i++) {
8618: if (document.getElementById('remove_'+remidxs[i])) {
8619: if (document.getElementById('remove_'+remidxs[i]).checked) {
8620: form.multiremove.value += remidxs[i]+',';
8621: numchanges ++;
1.542 raeburn 8622: if (document.getElementById('skip_remove_'+remidxs[i])) {
8623: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8624: remwarnings ++;
8625: }
8626: }
1.603 raeburn 8627: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8628: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8629: removalinfo ++;
8630: }
8631: }
1.537 raeburn 8632: }
8633: }
1.538 raeburn 8634: }
8635: }
8636: var cutidxlist = document.cumulativeactions.allcutidx.value;
8637: if ((cutidxlist != '') && (cutidxlist != null)) {
8638: var cutidxs = cutidxlist.split(',');
8639: for (var i=0; i<cutidxs.length; i++) {
8640: if (document.getElementById('cut_'+cutidxs[i])) {
8641: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8642: form.multicut.value += cutidxs[i]+',';
8643: numchanges ++;
1.542 raeburn 8644: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8645: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8646: cutwarnings ++;
8647: }
8648: }
1.537 raeburn 8649: }
8650: }
8651: }
8652: }
1.538 raeburn 8653: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8654: if ((copyidxlist != '') && (copyidxlist != null)) {
8655: var copyidxs = copyidxlist.split(',');
8656: for (var i=0; i<copyidxs.length; i++) {
8657: if (document.getElementById('copy_'+copyidxs[i])) {
8658: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8659: form.multicopy.value += copyidxs[i]+',';
8660: numchanges ++;
8661: }
8662: }
8663: }
8664: }
8665: if (numchanges > 0) {
8666: form.multichange.value = numchanges;
8667: }
1.537 raeburn 8668: }
1.538 raeburn 8669: var dosettings = multiSettings();
1.543 raeburn 8670: var haschanges = 0;
1.538 raeburn 8671: if (dosettings == 1) {
8672: form.allencrypturl.value = '';
8673: form.allhiddenresource.value = '';
1.543 raeburn 8674: form.changeparms.value = 'all';
8675: var patt=new RegExp(",\$");
1.538 raeburn 8676: var allidxlist = document.cumulativesettings.allidx.value;
8677: if ((allidxlist != '') && (allidxlist != null)) {
8678: var allidxs = allidxlist.split(',');
8679: if (allidxs.length > 1) {
8680: for (var i=0; i<allidxs.length; i++) {
8681: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8682: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8683: form.allhiddenresource.value += allidxs[i]+',';
8684: }
8685: }
8686: if (document.getElementById('encrypturl_'+allidxs[i])) {
8687: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8688: form.allencrypturl.value += allidxs[i]+',';
8689: }
8690: }
8691: }
1.543 raeburn 8692: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8693: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8694: }
1.538 raeburn 8695: }
8696: form.allrandompick.value = '';
8697: form.allrandomorder.value = '';
8698: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8699: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8700: var allmapidxs = allmapidxlist.split(',');
8701: for (var i=0; i<allmapidxs.length; i++) {
8702: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8703: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8704: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8705: if ((randompick.checked) && (rpicknum.value != '')) {
8706: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8707: }
8708: if (randorder.checked) {
8709: form.allrandomorder.value += allmapidxs[i]+',';
8710: }
1.537 raeburn 8711: }
1.543 raeburn 8712: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8713: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8714: }
8715: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8716: haschanges = 1;
8717: }
8718: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8719: haschanges = 1;
8720: }
8721: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8722: haschanges = 1;
8723: }
8724: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8725: haschanges = 1;
1.537 raeburn 8726: }
8727: }
1.543 raeburn 8728: if (doactions == 1) {
1.542 raeburn 8729: if (numchanges > 0) {
1.603 raeburn 8730: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8731: if (remwarnings > 0) {
1.594 damieng 8732: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8733: return false;
8734: }
8735: }
1.603 raeburn 8736: if (removalinfo > 0) {
8737: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8738: return false;
8739: }
8740: }
1.542 raeburn 8741: if (cutwarnings > 0) {
1.594 damieng 8742: 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 8743: return false;
8744: }
8745: }
8746: }
8747: form.submit();
8748: return true;
1.543 raeburn 8749: }
8750: }
8751: if (dosettings == 1) {
8752: if (haschanges == 1) {
1.542 raeburn 8753: form.submit();
8754: return true;
8755: }
1.543 raeburn 8756: }
8757: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8758: alert("$js_lt{'noor'}");
1.543 raeburn 8759: } else {
8760: if (dosettings == 1) {
1.594 damieng 8761: alert("$js_lt{'noch'}");
1.543 raeburn 8762: } else {
1.594 damieng 8763: alert("$js_lt{'noac'}");
1.543 raeburn 8764: }
8765: }
1.538 raeburn 8766: return false;
8767: }
8768:
8769: function setClass(value) {
8770: var cutclass = 'LC_docs_cut';
8771: var copyclass = 'LC_docs_copy';
8772: var removeclass = 'LC_docs_remove';
8773: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8774: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8775: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8776: var links = document.getElementsByTagName('a');
8777: for (var i=0; i<links.length; i++) {
8778: var classes = links[i].className;
8779: if (cutreg.test(classes)) {
8780: links[i].className = cutclass;
8781: if (value == 1) {
8782: links[i].className += " LC_menubuttons_link";
8783: }
8784: } else {
8785: if (copyreg.test(classes)) {
8786: links[i].className = copyclass;
8787: if (value == 1) {
8788: links[i].className += " LC_menubuttons_link";
8789: }
8790: } else {
8791: if (removereg.test(classes)) {
8792: links[i].className = removeclass;
8793: if (value == 1) {
8794: links[i].className += " LC_menubuttons_link";
8795: }
8796: }
8797: }
8798: }
8799: }
8800: return;
1.537 raeburn 8801: }
8802:
1.538 raeburn 8803: function setBoxes(value) {
8804: var remidxlist = document.cumulativeactions.allremoveidx.value;
8805: if ((remidxlist != '') && (remidxlist != null)) {
8806: var remidxs = remidxlist.split(',');
8807: for (var i=0; i<remidxs.length; i++) {
8808: if (document.getElementById('remove_'+remidxs[i])) {
8809: var item = document.getElementById('remove_'+remidxs[i]);
8810: if (value == 1) {
8811: item.className = 'LC_docs_remove';
8812: } else {
8813: item.className = 'LC_hidden';
8814: }
8815: }
8816: }
8817: }
8818: var cutidxlist = document.cumulativeactions.allcutidx.value;
8819: if ((cutidxlist != '') && (cutidxlist != null)) {
8820: var cutidxs = cutidxlist.split(',');
8821: for (var i=0; i<cutidxs.length; i++) {
8822: if (document.getElementById('cut_'+cutidxs[i])) {
8823: var item = document.getElementById('cut_'+cutidxs[i]);
8824: if (value == 1) {
8825: item.className = 'LC_docs_cut';
8826: } else {
8827: item.className = 'LC_hidden';
8828: }
8829: }
1.537 raeburn 8830: }
8831: }
1.538 raeburn 8832: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8833: if ((copyidxlist != '') && (copyidxlist != null)) {
8834: var copyidxs = copyidxlist.split(',');
8835: for (var i=0; i<copyidxs.length; i++) {
8836: if (document.getElementById('copy_'+copyidxs[i])) {
8837: var item = document.getElementById('copy_'+copyidxs[i]);
8838: if (value == 1) {
8839: item.className = 'LC_docs_copy';
8840: } else {
8841: item.className = 'LC_hidden';
8842: }
8843: }
1.537 raeburn 8844: }
8845: }
8846: return;
8847: }
8848:
1.606 raeburn 8849: function validImportCrsRes() {
8850: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8851: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8852: if ((fname == '') || (fname == null)) {
8853: alert("$js_lt{'nofi'}");
8854: return false;
8855: }
8856: var url = '/res/$coursedom/$coursenum/';
8857: if (path && path != '/') {
8858: url += path+'/';
8859: }
8860: if (fname != '') {
8861: url += fname;
8862: }
8863: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8864: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8865: return true;
8866: }
8867:
8868: function validateNewRes(caller) {
8869: if (caller == 'single') {
8870: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8871: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8872: var resname = document.courseresform.newresourcename.value;
8873: }
8874: }
8875:
1.611 raeburn 8876: ENDSCRIPT
1.329 droeschl 8877: }
1.457 raeburn 8878:
1.483 raeburn 8879: sub history_tab_js {
8880: return <<"ENDHIST";
8881: function toggleHistoryDisp(choice) {
8882: document.docslogform.docslog.value = choice;
8883: document.docslogform.submit();
8884: return;
8885: }
8886:
8887: ENDHIST
8888: }
8889:
1.484 raeburn 8890: sub inject_data_js {
8891: return <<ENDINJECT;
8892:
8893: function injectData(current, hiddenField, name, value) {
8894: currentElement = document.getElementById(hiddenField);
8895: currentElement.name = name;
8896: currentElement.value = value;
8897: current.submit();
8898: }
8899:
8900: ENDINJECT
8901: }
8902:
8903: sub dump_switchserver_js {
8904: my @hosts = @_;
1.594 damieng 8905: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8906: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8907: swit => 'Switch server?',
1.594 damieng 8908: );
8909: my %html_js_lt = &Apache::lonlocal::texthash(
8910: swit => 'Switch server?',
1.568 raeburn 8911: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8912: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8913: chos => 'Choose server',
8914: );
1.594 damieng 8915: &js_escape(\%js_lt);
8916: &html_escape(\%html_js_lt);
8917: &js_escape(\%html_js_lt);
1.484 raeburn 8918: my $role = $env{'request.role'};
8919: my $js = <<"ENDSWJS";
8920: <script type="text/javascript">
8921: function write_switchserver() {
8922: var server;
8923: if (document.setserver.posshosts.length > 0) {
8924: for (var i=0; i<document.setserver.posshosts.length; i++) {
8925: if (document.setserver.posshosts[i].checked) {
8926: server = document.setserver.posshosts[i].value;
8927: }
8928: }
8929: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8930: }
8931: window.close();
8932: }
8933: </script>
8934:
8935: ENDSWJS
8936:
8937: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8938: {'only_body' => 1,
8939: 'js_ready' => 1,});
8940: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8941:
8942: my $hostpicker;
8943: my $count = 0;
8944: foreach my $host (sort(@hosts)) {
8945: my $checked;
8946: if ($count == 0) {
8947: $checked = ' checked="checked"';
8948: }
8949: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8950: $host.'"'.$checked.' />'.$host.'</label> ';
8951: $count++;
8952: }
8953:
8954: return <<"ENDSWITCHJS";
8955:
8956: function dump_needs_switchserver(url) {
8957: if (url!='' && url!= null) {
1.594 damieng 8958: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8959: go(url);
8960: }
8961: }
8962: return;
8963: }
8964:
8965: function choose_switchserver_window() {
8966: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8967: newWindow.document.open();
8968: newWindow.document.writeln('$startpage');
1.594 damieng 8969: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8970: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8971: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8972: '<form name="setserver" method="post" action="" \\/>\\n'+
8973: '$hostpicker\\n'+
8974: '<br \\/><br \\/>\\n'+
1.594 damieng 8975: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8976: 'onclick="write_switchserver();" \\/>\\n'+
8977: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8978: newWindow.document.writeln('$endpage');
8979: newWindow.document.close();
8980: newWindow.focus();
8981: }
8982:
8983: ENDSWITCHJS
8984: }
8985:
8986: sub makedocslogform {
8987: my ($formelems,$docslog) = @_;
8988: return <<"LOGSFORM";
8989: <form action="/adm/coursedocs" method="post" name="docslogform">
8990: <input type="hidden" name="docslog" value="$docslog" />
8991: $formelems
8992: </form>
8993: LOGSFORM
8994: }
8995:
8996: sub makesimpleeditform {
8997: my ($formelems) = @_;
8998: return <<"SIMPFORM";
8999: <form name="simpleedit" method="post" action="/adm/coursedocs">
9000: <input type="hidden" name="importdetail" value="" />
9001: $formelems
9002: </form>
9003: SIMPFORM
9004: }
9005:
1.606 raeburn 9006: sub makenewproblem {
9007: my ($r,$coursedom,$coursenum) = @_;
9008: # Creating a new problem
9009: my ($redirect,$error);
9010: if ($env{'form.authorrole'}) {
9011: my ($newsubdir,$filename);
9012: if ($env{'form.newsubdir'}) {
9013: if ($env{'form.newsubdirname'} ne '') {
9014: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9015: }
1.606 raeburn 9016: }
9017: if ($env{'form.newresourcename'}) {
9018: $filename = $env{'form.newresourcename'};
9019: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9020: $filename =~ s/`//g;
9021: $filename =~ s{/\.\./}{_}g;
9022: $filename =~ s/\.+/./g;
9023: $filename =~ s{/+}{_}g;
9024: if ($filename ne '') {
9025: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9026: if (($ext) && ($ext ne '.problem')) {
9027: $filename = $name.'.problem';
9028: } elsif ($ext eq '') {
9029: $filename .= '.problem';
9030: }
9031: my $docroot = $r->dir_config('lonDocRoot');
9032: my @ids=&Apache::lonnet::current_machine_ids();
9033: if ($env{'form.authorrole'} eq 'author') {
9034: if ($env{'user.author'}) {
9035: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9036: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9037: my $path = $docroot.$url;
9038: my $subdir = $env{'form.authorpath'};
9039: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9040: }
9041: }
9042: } elsif ($env{'form.authorrole'} eq 'course') {
9043: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9044: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9045: my $url = "/priv/$coursedom/$coursenum";
9046: my $path=$docroot.$url;
9047: my $subdir = $env{'form.authorpath'};
9048: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9049: if ($redirect) {
9050: my $rightsfile = 'default.rights';
9051: my $sourcerights = "$path/$rightsfile";
9052: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9053: my $now = time;
9054: if (!-e $sourcerights) {
9055: my $cid = $coursedom.'_'.$coursenum;
9056: if (open(my $fh,">$sourcerights")) {
9057: print $fh <<END;
9058: <accessrule effect="deny" realm="" type="course" role="" />
9059: <accessrule effect="allow" realm="$cid" type="course" role="" />
9060: END
9061: close($fh);
9062: }
9063: }
9064: if (!-e "$sourcerights.meta") {
9065: if (open(my $fh,">$sourcerights.meta")) {
9066: my $author=$env{'environment.firstname'}.' '.
9067: $env{'environment.middlename'}.' '.
9068: $env{'environment.lastname'}.' '.
9069: $env{'environment.generation'};
9070: $author =~ s/\s+$//;
9071: print $fh <<"END";
9072:
9073: <abstract></abstract>
9074: <author>$author</author>
9075: <authorspace>$coursenum:$coursedom</authorspace>
9076: <copyright>private</copyright>
9077: <creationdate>$now</creationdate>
9078: <customdistributionfile></customdistributionfile>
9079: <dependencies></dependencies>
9080: <domain>$coursedom</domain>
9081: <highestgradelevel>0</highestgradelevel>
9082: <keywords></keywords>
9083: <language>notset </language>
9084: <lastrevisiondate>$now</lastrevisiondate>
9085: <lowestgradelevel>0</lowestgradelevel>
9086: <mime>rights</mime>
9087: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9088: <notes></notes>
9089: <obsolete></obsolete>
9090: <obsoletereplacement></obsoletereplacement>
9091: <owner>$coursenum:$coursedom</owner>
9092: <rule>deny:::course,allow:$cid::course</rule>
9093: <sourceavail></sourceavail>
9094: <standards></standards>
9095: <subject></subject>
9096: <title></title>
9097: END
1.654 raeburn 9098: close($fh);
9099: }
9100: }
9101: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9102: if (!-e "$docroot/res/$coursedom") {
9103: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9104: }
1.654 raeburn 9105: if (!-e "$docroot/res/$coursedom/$coursenum") {
9106: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9107: }
9108: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9109: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9110: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9111: }
9112: }
1.654 raeburn 9113: my $source = $docroot.$redirect;
9114: if (!-e "$source.meta") {
9115: my $cid = $coursedom.'_'.$coursenum;
9116: my $now = time;
9117: if (open(my $fh,">$source.meta")) {
9118: my $author=$env{'environment.firstname'}.' '.
9119: $env{'environment.middlename'}.' '.
9120: $env{'environment.lastname'}.' '.
9121: $env{'environment.generation'};
9122: $author =~ s/\s+$//;
9123: my $title = $env{'form.newresourcetitle'};
9124: $title =~ s/^\s+|\s+$//g;
9125: print $fh <<END;
1.606 raeburn 9126:
9127: <abstract></abstract>
9128: <author>$author</author>
9129: <authorspace>$coursenum:$coursedom</authorspace>
9130: <copyright>custom</copyright>
9131: <creationdate>$now</creationdate>
9132: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9133: <dependencies></dependencies>
9134: <domain>$coursedom</domain>
9135: <highestgradelevel>0</highestgradelevel>
9136: <keywords></keywords>
9137: <language>notset </language>
9138: <lastrevisiondate>$now</lastrevisiondate>
9139: <lowestgradelevel>0</lowestgradelevel>
9140: <mime>problem</mime>
9141: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9142: <notes></notes>
9143: <obsolete></obsolete>
9144: <obsoletereplacement></obsoletereplacement>
9145: <owner>$coursenum:$coursedom</owner>
9146: <sourceavail></sourceavail>
9147: <standards></standards>
9148: <subject></subject>
9149: <title>$title</title>
9150: END
1.654 raeburn 9151: close($fh);
1.606 raeburn 9152: }
9153: }
9154: }
9155: }
9156: } else {
9157: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9158: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9159: if (grep(/^\Q$rolehome\E$/,@ids)) {
9160: my $now = time;
9161: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9162: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9163: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9164: my $url = "/priv/$audom/$auname";
9165: my $path = $r->dir_config('lonDocRoot').$url;
9166: my $subdir = $env{'form.authorpath'};
9167: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9168: }
9169: }
9170: }
9171: }
9172: }
9173: }
9174: }
9175: return ($redirect,$error);
9176: }
9177:
9178: sub finishnewprob {
1.654 raeburn 9179: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9180: unless (-d $path) {
9181: unless (mkdir($path,02770)) {
9182: return;
9183: }
9184: }
1.606 raeburn 9185: my $redirect;
9186: if ($subdir ne '/') {
9187: $subdir = &cleandir($subdir);
9188: if (($subdir ne '') && (-d "$path/$subdir")) {
9189: $path .= "/$subdir";
9190: $url .= "/$subdir";
9191: }
9192: }
9193: my $dest;
9194: if ($newsubdir ne '') {
9195: $newsubdir = &cleandir($newsubdir);
9196: }
9197: if ($newsubdir ne '') {
9198: if (-d "$path/$newsubdir") {
9199: $dest = "$path/$newsubdir/$filename";
9200: } else {
9201: my $dirok;
9202: unless (-e "$path/$newsubdir") {
9203: if (mkdir("$path/$newsubdir",02770)) {
9204: if (chmod(02770,"$path/$newsubdir")) {
9205: $dirok = 1;
9206: }
9207: }
9208: }
9209: if ($dirok) {
9210: $dest = "$path/$newsubdir/$filename";
9211: }
9212: }
9213: if (($dest ne '') && (!-e $dest)) {
9214: $redirect = "$url/$newsubdir/$filename";
9215: }
9216: } else {
9217: $dest = "$path/$filename";
9218: if (($dest ne '') && (!-e $dest)) {
9219: $redirect = "$url/$filename";
9220: }
9221: }
1.654 raeburn 9222: if ((!-e $dest) && ($context ne 'upload')) {
9223: my $template = $env{'form.template'};
9224: my $copyfrom;
9225: if ($template ne '') {
9226: my %templates;
9227: my @files = &Apache::lonhomework::get_template_list('problem');
9228: foreach my $poss (@files) {
9229: if (ref($poss) eq 'ARRAY') {
9230: if ($template eq $poss->[0]) {
9231: $templates{$template} = 1;
9232: last;
9233: }
9234: }
9235: }
9236: if ($templates{$template}) {
9237: $copyfrom = $template;
9238: }
9239: }
9240: if ($filename =~ /\.problem$/) {
9241: unless ($copyfrom) {
9242: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9243: }
9244: &File::Copy::copy($copyfrom,$dest);
9245: }
9246: }
1.606 raeburn 9247: return $redirect;
9248: }
9249:
9250: sub cleandir {
9251: my ($dir) = @_;
9252: $dir =~ s/^\s+//;
9253: $dir =~ s/\s+$//;
9254: $dir =~ s/\.+//g;
9255: $dir =~ s/[\#\?&%\":]//g;
9256: return $dir;
9257: }
9258:
1.329 droeschl 9259: 1;
9260: __END__
9261:
9262:
9263: =head1 NAME
9264:
9265: Apache::londocs.pm
9266:
9267: =head1 SYNOPSIS
9268:
9269: This is part of the LearningOnline Network with CAPA project
9270: described at http://www.lon-capa.org.
9271:
9272: =head1 SUBROUTINES
9273:
9274: =over
9275:
9276: =item %help=()
9277:
9278: Available help topics
9279:
9280: =item mapread()
9281:
1.344 bisitz 9282: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9283: @order and @resources, determines status
9284: sets @order - pointer to resources in right order
9285: sets @resources - array with the resources with correct idx
9286:
9287: =item authorhosts()
9288:
9289: Return hash with valid author names
9290:
9291: =item clean()
9292:
9293: =item dumpcourse()
9294:
9295: Actually dump course
9296:
9297: =item group_import()
9298:
9299: Imports the given (name, url) resources into the course
9300: coursenum, coursedom, and folder must precede the list
9301:
9302: =item breadcrumbs()
9303:
9304: =item log_docs()
9305:
9306: =item docs_change_log()
9307:
9308: =item update_paste_buffer()
9309:
9310: =item print_paste_buffer()
9311:
9312: =item do_paste_from_buffer()
9313:
1.538 raeburn 9314: =item do_buffer_empty()
9315:
9316: =item clear_from_buffer()
9317:
1.492 raeburn 9318: =item get_newmap_url()
9319:
9320: =item dbcopy()
9321:
9322: =item uniqueness_check()
9323:
9324: =item contained_map_check()
9325:
9326: =item url_paste_fixups()
9327:
9328: =item apply_fixups()
9329:
9330: =item copy_dependencies()
9331:
1.329 droeschl 9332: =item update_parameter()
9333:
9334: =item handle_edit_cmd()
9335:
9336: =item editor()
9337:
9338: =item process_file_upload()
9339:
9340: =item process_secondary_uploads()
9341:
9342: =item is_supplemental_title()
9343:
9344: =item entryline()
9345:
9346: =item tiehash()
9347:
9348: =item untiehash()
9349:
9350: =item checkonthis()
9351:
9352: check on this
9353:
9354: =item verifycontent()
9355:
9356: Verify Content
9357:
1.636 raeburn 9358: =item devalidateversioncache()
9359:
9360: =item checkversions()
1.329 droeschl 9361:
9362: Check Versions
9363:
9364: =item mark_hash_old()
9365:
9366: =item is_hash_old()
9367:
9368: =item changewarning()
9369:
9370: =item init_breadcrumbs()
9371:
9372: Breadcrumbs for special functions
9373:
1.484 raeburn 9374: =item create_list_elements()
9375:
9376: =item create_form_ul()
9377:
9378: =item startContentScreen()
9379:
9380: =item endContentScreen()
9381:
9382: =item supplemental_base()
9383:
9384: =item embedded_form_elems()
9385:
9386: =item embedded_destination()
9387:
9388: =item return_to_editor()
9389:
9390: =item decompression_info()
9391:
9392: =item decompression_phase_one()
9393:
9394: =item decompression_phase_two()
9395:
9396: =item remove_archive()
9397:
9398: =item generate_admin_menu()
9399:
9400: =item generate_edit_table()
9401:
9402: =item editing_js()
9403:
9404: =item history_tab_js()
9405:
9406: =item inject_data_js()
9407:
9408: =item dump_switchserver_js()
9409:
1.485 raeburn 9410: =item resize_scrollbox_js()
1.484 raeburn 9411:
9412: =item makedocslogform()
9413:
1.485 raeburn 9414: =item makesimpleeditform()
9415:
1.329 droeschl 9416: =back
9417:
9418: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>