File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.624:
download - view:
text,
annotated -
select for diffs
Tue Apr 25 22:18:59 2017 UTC (7 years, 4 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6754. Make LON-CAPA an LTI Tool Consumer (LTI 1.1).
When LTI Tool set to be accessed via link to open new tab,
domain configuration for each Tool includes:
(a) default link text
(b) default text block
(c) whether link text and/or text block content configurable in course.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.624 2017/04/25 22:18:59 raeburn Exp $
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;
36: use Apache::lonhtmlcommon;
37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
42: use Apache::lonnavdisplay();
43: use Apache::lonextresedit();
44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
46: use Apache::lonhomework();
47: use Apache::lonpublisher();
48: use HTML::Entities;
49: use HTML::TokeParser;
50: use GDBM_File;
51: use File::MMagic;
52: use File::Copy;
53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
65: my $suppchanges;
66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
86: $map,1,$report);
87: if ($errtext) { return ($errtext,2); }
88:
89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
126: if ($allowed) {
127: $home++;
128: $outhash{'home_'.$ca.':'.$cd}=1;
129: } else {
130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
142: return $title;
143: }
144:
145: sub default_folderpath {
146: my ($coursenum,$coursedom,$navmapref) = @_;
147: return unless ($coursenum && $coursedom && ref($navmapref));
148: # Check if entire course is hidden and/or encrypted
149: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
150: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
151: unless (ref($$navmapref)) {
152: $$navmapref = Apache::lonnavmaps::navmap->new();
153: }
154: if (ref($$navmapref)) {
155: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
156: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
157: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
158: unless (@resources) {
159: $hiddenmap = 1;
160: unless ($env{'request.role.adv'}) {
161: $hiddentop = 1;
162: if ($env{'form.folder'}) {
163: undef($env{'form.folder'});
164: }
165: }
166: }
167: }
168: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
169: $encryptmap = 1;
170: }
171: }
172: unless ($hiddentop) {
173: $folderpath='default&'.&escape(&mt('Main Content')).
174: '::'.$hiddenmap.':'.$encryptmap.'::';
175: }
176: if (wantarray) {
177: return ($folderpath,$hiddentop);
178: } else {
179: return $folderpath;
180: }
181: }
182:
183: sub dumpcourse {
184: my ($r) = @_;
185: my $crstype = &Apache::loncommon::course_type();
186: my ($starthash,$js);
187: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
188: $js = <<"ENDJS";
189: <script type="text/javascript">
190: // <![CDATA[
191:
192: function hide_searching() {
193: if (document.getElementById('searching')) {
194: document.getElementById('searching').style.display = 'none';
195: }
196: return;
197: }
198:
199: // ]]>
200: </script>
201: ENDJS
202: $starthash = {
203: add_entries => {'onload' => "hide_searching();"},
204: };
205: }
206: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
207: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
208: $r->print(&startContentScreen('tools'));
209: my ($home,$other,%outhash)=&authorhosts();
210: unless ($home) {
211: $r->print(&endContentScreen());
212: return '';
213: }
214: my $origcrsid=$env{'request.course.id'};
215: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
216: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
217: # Do the dumping
218: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
219: $r->print(&endContentScreen());
220: return '';
221: }
222: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
223: $r->print('<h3>'.&mt('Copying Files').'</h3>');
224: my $title=$env{'form.authorfolder'};
225: $title=&clean($title);
226: my ($navmap,$errormsg) =
227: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
230: my (%maps,%resources,%titles);
231: if (!ref($navmap)) {
232: $r->print($errormsg.
233: &endContentScreen());
234: return '';
235: } else {
236: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
237: 'dumpdocs',$cdom,$cnum);
238: }
239: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
240: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
241: %newcontent,%has_simpleprobs);
242: foreach my $item (sort {$a <=> $b} (@todump)) {
243: my $name = $env{'form.namefor_'.$item};
244: if ($resources{$item}) {
245: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
246: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
247: $tocopy{$1} = $name;
248: $display{$item} = $1;
249: $lookup{$1} = $item;
250: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
251: $simpleproblems{$item} = {
252: symb => $resources{$item},
253: name => $name,
254: };
255: $display{$item} = 'simpleproblem_'.$name;
256: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
257: $has_simpleprobs{$1}{$id} = $item;
258: }
259: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
260: my $marker = $1;
261: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
262: $simplepages{$item} = {
263: res => $res,
264: title => $titles{$item},
265: db => $db_name,
266: marker => $marker,
267: symb => $resources{$item},
268: name => $name,
269: };
270: $display{$item} = '/'.$res;
271: }
272: } elsif ($maps{$item}) {
273: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
274: $tocopy{$1} = $name;
275: $display{$item} = $1;
276: $lookup{$1} = $item;
277: }
278: } else {
279: next;
280: }
281: }
282: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
283: $crs=~s/\_/\//g;
284: my $mm = new File::MMagic;
285: my $prefix = "/uploaded/$cdom/$cnum/";
286: %replacehash = %tocopy;
287: foreach my $item (sort(keys(%simpleproblems))) {
288: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
289: $newcontent{$display{$item}} = $content;
290: }
291: my $gateway = Apache::lonhtmlgateway->new('web');
292: foreach my $item (sort(keys(%simplepages))) {
293: if (ref($simplepages{$item}) eq 'HASH') {
294: my $pagetitle = $simplepages{$item}{'title'};
295: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
296: my %contents;
297: foreach my $field (keys(%fields)) {
298: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
299: my $name = $1;
300: my $msg = $fields{$field};
301: if ($name eq 'webreferences') {
302: if ($msg =~ m{^https?://}) {
303: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
304: }
305: } else {
306: $msg = &Encode::decode('utf8',$msg);
307: $msg = $gateway->process_outgoing_html($msg,1);
308: $contents{$name} = $msg;
309: }
310: } elsif ($field eq 'uploaded.photourl') {
311: my $marker = $simplepages{$item}{marker};
312: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
313: my $filepath = $1;
314: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
315: if ($fname ne '') {
316: $fname=~s/\.(\w+)$//;
317: my $ext=$1;
318: $fname = &clean($fname);
319: $fname.='.'.$ext;
320: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
321: $replacehash{$filepath} = $relpath.$fname;
322: $deps{$item}{$filepath} = 1;
323: }
324: }
325: }
326: }
327: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
328: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
329: my $content = '
330: <html>
331: <head>
332: <title>'.$pagetitle.'</title>
333: </head>
334: <body bgcolor="#ffffff">';
335: if ($contents{title}) {
336: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
337: }
338: if ($contents{image}) {
339: $content .= "\n".$contents{image};
340: }
341: if ($contents{content}) {
342: $content .= '
343: <div class="LC_Box">
344: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
345: $contents{content}.'
346: </div>';
347: }
348: if ($contents{webreferences}) {
349: $content .= '
350: <div class="LC_Box">
351: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
352: $contents{webreferences}.'
353: </div>';
354: }
355: $content .= '
356: </body>
357: </html>
358: ';
359: $newcontent{'/'.$simplepages{$item}{res}} = $content;
360: }
361: }
362: foreach my $item (keys(%tocopy)) {
363: unless ($item=~/\.(sequence|page)$/) {
364: my $currurlpath = $prefix.$item;
365: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
366: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
367: }
368: }
369: foreach my $num (sort {$a <=> $b} (@todump)) {
370: my $src = $display{$num};
371: next if ($src eq '');
372: my @needcopy = ();
373: if ($replacehash{$src}) {
374: push(@needcopy,$src);
375: if (ref($deps{$num}) eq 'HASH') {
376: foreach my $dep (sort(keys(%{$deps{$num}}))) {
377: if ($replacehash{$dep}) {
378: push(@needcopy,$dep);
379: }
380: }
381: }
382: } elsif ($src =~ /^simpleproblem_/) {
383: push(@needcopy,$src);
384: }
385: next if (@needcopy == 0);
386: my ($result,$depresult);
387: for (my $i=0; $i<@needcopy; $i++) {
388: my $item = $needcopy[$i];
389: my $newfilename;
390: if ($simpleproblems{$num}) {
391: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
392: } else {
393: $newfilename=$title.'/'.$replacehash{$item};
394: }
395: $newfilename=~s/\.(\w+)$//;
396: my $ext=$1;
397: $newfilename=&clean($newfilename);
398: $newfilename.='.'.$ext;
399: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
400: if ($newrelpath ne $replacehash{$item}) {
401: $replacehash{$item} = $newrelpath;
402: }
403: my @dirs=split(/\//,$newfilename);
404: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
405: my $makepath=$path;
406: my $fail;
407: my $origin;
408: for (my $i=0;$i<$#dirs;$i++) {
409: $makepath.='/'.$dirs[$i];
410: unless (-e $makepath) {
411: unless(mkdir($makepath,0755)) {
412: $fail = &mt('Directory creation failed.');
413: }
414: }
415: }
416: if ($i == 0) {
417: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
418: } else {
419: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
420: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
421: &mt('(dependency)').'</span>: ';
422: }
423: if (-e $path.'/'.$newfilename) {
424: $fail = &mt('Destination already exists -- not overwriting.');
425: } else {
426: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
427: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
428: ($item =~ /^simpleproblem_/)) {
429: print $fh $newcontent{$item};
430: } else {
431: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
432: if (-e $fileloc) {
433: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
434: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
435: (ref($has_simpleprobs{$item}) eq 'HASH')) {
436: my %changes = %{$has_simpleprobs{$item}};
437: my $content = &Apache::lonclonecourse::rewritefile(
438: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
439: (%replacehash,$crs => '')
440: );
441: my $updatedcontent = '';
442: my $parser = HTML::TokeParser->new(\$content);
443: $parser->attr_encoded(1);
444: while (my $token = $parser->get_token) {
445: if ($token->[0] eq 'S') {
446: if (($token->[1] eq 'resource') &&
447: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
448: ($changes{$token->[2]->{'id'}})) {
449: my $id = $token->[2]->{'id'};
450: $updatedcontent .= '<'.$token->[1];
451: foreach my $attrib (@{$token->[3]}) {
452: next unless ($attrib =~ /^(src|type|title|id)$/);
453: if ($attrib eq 'src') {
454: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
455: if ($file) {
456: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: }
464: $updatedcontent .= ' />'."\n";
465: } else {
466: $updatedcontent .= $token->[4]."\n";
467: }
468: } else {
469: $updatedcontent .= $token->[2];
470: }
471: }
472: print $fh $updatedcontent;
473: } else {
474: print $fh &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: }
479: } else {
480: print $fh
481: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
482: }
483: } else {
484: $fail = &mt('Source does not exist.');
485: }
486: }
487: $fh->close();
488: } else {
489: $fail = &mt('Could not write to destination.');
490: }
491: }
492: my $text;
493: if ($fail) {
494: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
495: } else {
496: $text = '<span class="LC_success">'.&mt('ok').'</span>';
497: }
498: if ($i == 0) {
499: $result .= $text;
500: } else {
501: $depresult .= $text.'</li>';
502: }
503: }
504: $r->print($result);
505: if ($depresult) {
506: $r->print('<ul>'.$depresult.'</ul>');
507: }
508: }
509: } else {
510: my ($navmap,$errormsg) =
511: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
512: if (!ref($navmap)) {
513: $r->print($errormsg);
514: } else {
515: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
516: $r->rflush();
517: my ($preamble,$formname);
518: $formname = 'dumpdoc';
519: unless ($home==1) {
520: $preamble = '<div class="LC_left_float">'.
521: '<fieldset><legend>'.
522: &mt('Select the Authoring Space').
523: '</legend><select name="authorspace">';
524: }
525: my @orderspaces = ();
526: foreach my $key (sort(keys(%outhash))) {
527: if ($key=~/^home_(.+)$/) {
528: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
529: unshift(@orderspaces,$1);
530: } else {
531: push(@orderspaces,$1);
532: }
533: }
534: }
535: if ($home>1) {
536: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
537: }
538: foreach my $user (@orderspaces) {
539: if ($home==1) {
540: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
541: } else {
542: $preamble .= '<option value="'.$user.'">'.$user.' - '.
543: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
544: }
545: }
546: unless ($home==1) {
547: $preamble .= '</select></fieldset></div>'."\n";
548: }
549: my $title=$origcrsdata{'description'};
550: $title=~s/[\/\s]+/\_/gs;
551: $title=&clean($title);
552: $preamble .= '<div class="LC_left_float">'.
553: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
554: '<input type="text" size="50" name="authorfolder" value="'.
555: $title.'" />'.
556: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
557: my %uploadedfiles;
558: &tiehash();
559: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
560: my ($ext)=($file=~/\.(\w+)$/);
561: # FIXME Check supplemental here
562: my $title=$hash{'title_'.$hash{
563: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
564: if (!$title) {
565: $title=$file;
566: } else {
567: $title=~s|/|_|g;
568: }
569: $title=~s/\.(\w+)$//;
570: $title=&clean($title);
571: $title.='.'.$ext;
572: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
573: $uploadedfiles{$file} = $title;
574: }
575: &untiehash();
576: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
577: undef,undef,$preamble,$home,\%uploadedfiles));
578: }
579: }
580: $r->print(&endContentScreen());
581: }
582:
583: sub recurse_html {
584: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
585: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
586: my (%allfiles,%codebase);
587: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
588: if (keys(%allfiles)) {
589: foreach my $dependency (keys(%allfiles)) {
590: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
591: my ($depurl,$relfile,$newcontainer);
592: if ($dependency =~ m{^/}) {
593: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
594: $relfile = $1;
595: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
596: $newcontainer = $1;
597: next if ($replacehash->{$newcontainer});
598: }
599: $depurl = $dependency;
600: } else {
601: next;
602: }
603: } else {
604: $relfile = $dependency;
605: $depurl = $currurlpath;
606: $depurl =~ s{[^/]+$}{};
607: $depurl .= $dependency;
608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
609: }
610: next if ($relfile eq '');
611: my $newname = $replacehash->{$container};
612: $newname =~ s{[^/]+$}{};
613: $replacehash->{$newcontainer} = $newname.$relfile;
614: $deps->{$item}{$newcontainer} = 1;
615: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
616: my $depfile = &Apache::lonnet::filelocation('',$depurl);
617: my $type = $mm->checktype_filename($depfile);
618: if ($type eq 'text/html') {
619: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
620: }
621: }
622: }
623: }
624: return;
625: }
626:
627: sub group_import {
628: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
629: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
630: %removeparam,$importuploaded,$fixuperrors);
631: $allmaps = {};
632: while (@files) {
633: my ($name, $url, $residx) = @{ shift(@files) };
634: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
635: && ($caller eq 'londocs')
636: && (!&Apache::lonnet::stat_file($url))) {
637:
638: my $errtext = '';
639: my $fatal = 0;
640: my $newmapstr = '<map>'."\n".
641: '<resource id="1" src="" type="start"></resource>'."\n".
642: '<link from="1" to="2" index="1"></link>'."\n".
643: '<resource id="2" src="" type="finish"></resource>'."\n".
644: '</map>';
645: $env{'form.output'}=$newmapstr;
646: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
647: 'output',$1.$2);
648: if ($result !~ m{^/uploaded/}) {
649: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
650: $fatal = 2;
651: }
652: if ($fatal) {
653: return ($errtext,$fatal);
654: }
655: }
656: if ($url) {
657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
661: my ($toolid,%toolhash,%toolsettings);
662: my @extras = ('linktext','explanation','crslabel','crstitle');
663: my @toolinfo = split(/:/,$info);
664: if ($residx) {
665: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
666: $toolid = $toolsettings{'id'};
667: } else {
668: $toolid = shift(@toolinfo);
669: }
670: $toolid =~ s/\D//g;
671: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
672: $toolhash{'linktext'},$toolhash{'explanation'},
673: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
674: foreach my $item (@extras) {
675: $toolhash{$item} = &unescape($toolhash{$item});
676: }
677: if (ref($ltitoolsref) eq 'HASH') {
678: my @deleted;
679: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
680: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
681: $url =~ s/exttool$/exttools/;
682: }
683: $toolhash{'id'} = $toolid;
684: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
685: if ($toolhash{'target'} eq 'window') {
686: foreach my $item ('width','height') {
687: $toolhash{$item} =~ s/^\s+//;
688: $toolhash{$item} =~ s/\s+$//;
689: if ($toolhash{$item} =~ /\D/) {
690: delete($toolhash{$item});
691: if ($residx) {
692: if ($toolsettings{$item}) {
693: push(@deleted,$item);
694: }
695: }
696: }
697: }
698: }
699: } elsif ($residx) {
700: $toolhash{'target'} = $toolsettings{'target'};
701: if ($toolhash{'target'} eq 'window') {
702: foreach my $item ('width','height') {
703: $toolhash{$item} = $toolsettings{$item};
704: }
705: }
706: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
707: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
708: if ($toolhash{'target'} eq 'window') {
709: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
710: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
711: }
712: }
713: if ($toolhash{'target'} eq 'iframe') {
714: foreach my $item ('width','height','linktext','explanation') {
715: delete($toolhash{$item});
716: if ($residx) {
717: if ($toolsettings{$item}) {
718: push(@deleted,$item);
719: }
720: }
721: }
722: }
723: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
724: foreach my $item ('label','title','linktext','explanation') {
725: my $crsitem;
726: if (($item eq 'label') || ($item eq 'title')) {
727: $crsitem = 'crs'.$item;
728: } else {
729: $crsitem = $item;
730: }
731: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
732: $toolhash{$crsitem} =~ s/^\s+//;
733: $toolhash{$crsitem} =~ s/\s+$//;
734: if ($toolhash{$crsitem} eq '') {
735: delete($toolhash{$crsitem});
736: }
737: } else {
738: delete($toolhash{$crsitem});
739: }
740: if (($residx) && (exists($toolsettings{$crsitem}))) {
741: unless (exists($toolhash{$crsitem})) {
742: push(@deleted,$crsitem);
743: }
744: }
745: }
746: }
747: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
748: if ($putres eq 'ok') {
749: if (@deleted) {
750: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
751: }
752: }
753: }
754: }
755: }
756: if (($caller eq 'londocs') &&
757: ($folder =~ /^default/)) {
758: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
759: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
760: my $cid = $coursedom.'_'.$coursenum;
761: $allmaps =
762: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
763: $chome,$cid);
764: $donechk = 1;
765: }
766: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
767: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
768: \%addedmaps,\%hierarchy,\%titles,$allmaps);
769: $importuploaded = 1;
770: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
771: next if ($allmaps->{$url});
772: }
773: }
774: if (!$residx
775: || defined($LONCAPA::map::zombies[$residx])) {
776: $residx = &LONCAPA::map::getresidx($url,$residx);
777: push(@LONCAPA::map::order, $residx);
778: }
779: my $ext = 'false';
780: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
781: $name = &LONCAPA::map::qtunescape($name);
782: if ($name eq '') {
783: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
784: }
785: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
786: my $filepath = $1;
787: my $fname = $name;
788: if ($fname =~ /^\W+$/) {
789: $fname = 'web';
790: } else {
791: $fname =~ s/\W/_/g;
792: }
793: if (length($fname) > 15) {
794: $fname = substr($fname,0,14);
795: }
796: my $initialtext = &mt('Replace with your own content.');
797: my $newhtml = <<END;
798: <html>
799: <head>
800: <title>$name</title>
801: </head>
802: <body bgcolor="#ffffff">
803: $initialtext
804: </body>
805: </html>
806: END
807: $env{'form.output'}=$newhtml;
808: my $result =
809: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
810: 'output',
811: "$filepath/$residx/$fname.html");
812: if ($result =~ m{^/uploaded/}) {
813: $url = $result;
814: if ($filepath =~ /^supplemental/) {
815: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
816: $env{'user.domain'}.'___&&&___'.$name;
817: }
818: } else {
819: return (&mt('Failed to save new web page.'),1);
820: }
821: }
822: $url = &LONCAPA::map::qtunescape($url);
823: $LONCAPA::map::resources[$residx] =
824: join(':', ($name, $url, $ext, 'normal', 'res'));
825: }
826: }
827: if ($importuploaded) {
828: my %import_errors;
829: my %updated = (
830: removefrommap => \%removefrommap,
831: removeparam => \%removeparam,
832: );
833: my ($result,$msgsarray,$lockerror) =
834: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
835: if (keys(%import_errors) > 0) {
836: $fixuperrors =
837: '<p span class="LC_warning">'."\n".
838: &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".
839: '<ul>'."\n";
840: foreach my $key (sort(keys(%import_errors))) {
841: $fixuperrors .= '<li>'.$key.'</li>'."\n";
842: }
843: $fixuperrors .= '</ul></p>'."\n";
844: }
845: if (ref($msgsarray) eq 'ARRAY') {
846: if (@{$msgsarray} > 0) {
847: $fixuperrors .= '<p class="LC_info">'.
848: join('<br />',@{$msgsarray}).
849: '</p>';
850: }
851: }
852: if ($lockerror) {
853: $fixuperrors .= '<p class="LC_error">'.
854: $lockerror.
855: '</p>';
856: }
857: }
858: my ($errtext,$fatal) =
859: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
860: unless ($fatal) {
861: if ($folder =~ /^supplemental/) {
862: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
863: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
864: $folder.'.'.$container);
865: }
866: }
867: return ($errtext,$fatal,$fixuperrors);
868: }
869:
870: sub log_docs {
871: return &Apache::lonnet::write_log('course','docslog',@_);
872: }
873:
874: {
875: my @oldresources=();
876: my @oldorder=();
877: my $parmidx;
878: my %parmaction=();
879: my %parmvalue=();
880: my $changedflag;
881:
882: sub snapshotbefore {
883: @oldresources=@LONCAPA::map::resources;
884: @oldorder=@LONCAPA::map::order;
885: $parmidx=undef;
886: %parmaction=();
887: %parmvalue=();
888: $changedflag=0;
889: }
890:
891: sub remember_parms {
892: my ($idx,$parameter,$action,$value)=@_;
893: $parmidx=$idx;
894: $parmaction{$parameter}=$action;
895: $parmvalue{$parameter}=$value;
896: $changedflag=1;
897: }
898:
899: sub log_differences {
900: my ($plain)=@_;
901: my %storehash=('folder' => $plain,
902: 'currentfolder' => $env{'form.folder'});
903: if ($parmidx) {
904: $storehash{'parameter_res'}=$oldresources[$parmidx];
905: foreach my $parm (keys(%parmaction)) {
906: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
907: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
908: }
909: }
910: my $maxidx=$#oldresources;
911: if ($#LONCAPA::map::resources>$#oldresources) {
912: $maxidx=$#LONCAPA::map::resources;
913: }
914: for (my $idx=0; $idx<=$maxidx; $idx++) {
915: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
916: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
917: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
918: $changedflag=1;
919: }
920: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
921: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
922: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
923: $changedflag=1;
924: }
925: }
926: $storehash{'maxidx'}=$maxidx;
927: if ($changedflag) { &log_docs(\%storehash); }
928: }
929: }
930:
931: sub docs_change_log {
932: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
933: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
934: my $navmap;
935: my $js = '<script type="text/javascript">'."\n".
936: '// <![CDATA['."\n".
937: &Apache::loncommon::display_filter_js('docslog')."\n".
938: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
939: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
940: &history_tab_js()."\n".
941: &Apache::lonratedt::editscript('simple')."\n".
942: '// ]]>'."\n".
943: '</script>'."\n";
944: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
945: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
946: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
947: my %orderhash;
948: my $container='sequence';
949: my $pathitem;
950: if ($env{'form.folderpath'} =~ /\:1$/) {
951: $container='page';
952: }
953: my $folderpath=$env{'form.folderpath'};
954: if ($folderpath eq '') {
955: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
956: }
957: undef($navmap);
958: $pathitem = '<input type="hidden" name="folderpath" value="'.
959: &HTML::Entities::encode($folderpath,'<>&"').'" />';
960: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
961: my $jumpto = $readfile;
962: $jumpto =~ s{^/}{};
963: my $tid = 1;
964: if ($supplementalflag) {
965: $tid = 2;
966: }
967: my ($breadcrumbtrail) =
968: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
969: $r->print($breadcrumbtrail.
970: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
971: $readfile));
972: my %docslog=&Apache::lonnet::dump('nohist_docslog',
973: $env{'course.'.$env{'request.course.id'}.'.domain'},
974: $env{'course.'.$env{'request.course.id'}.'.num'});
975:
976: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
977:
978: my %saveable_parameters = ('show' => 'scalar',);
979: &Apache::loncommon::store_course_settings('docs_log',
980: \%saveable_parameters);
981: &Apache::loncommon::restore_course_settings('docs_log',
982: \%saveable_parameters);
983: if (!$env{'form.show'}) { $env{'form.show'}=10; }
984: # FIXME: internationalization seems wrong here
985: my %lt=('hiddenresource' => 'Resources hidden',
986: 'encrypturl' => 'URL hidden',
987: 'randompick' => 'Randomly pick',
988: 'randomorder' => 'Randomly ordered',
989: 'set' => 'set to',
990: 'del' => 'deleted');
991: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
992: $pathitem."\n".
993: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
994: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
995: $r->print('<div class="LC_left_float">'.
996: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
997: &makedocslogform($filter,1).
998: '</fieldset></div><br clear="all" />');
999: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1000: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1001: &mt('After').'</th>'.
1002: &Apache::loncommon::end_data_table_header_row());
1003: my $shown=0;
1004: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1005: if ($env{'form.displayfilter'} eq 'currentfolder') {
1006: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1007: }
1008: my @changes=keys(%{$docslog{$id}{'logentry'}});
1009: if ($env{'form.displayfilter'} eq 'containing') {
1010: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1011: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1012: foreach my $key (@changes) {
1013: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1014: }
1015: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1016: }
1017: my $count = 0;
1018: my $time =
1019: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1020: my $plainname =
1021: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1022: $docslog{$id}{'exe_udom'});
1023: my $about_me_link =
1024: &Apache::loncommon::aboutmewrapper($plainname,
1025: $docslog{$id}{'exe_uname'},
1026: $docslog{$id}{'exe_udom'});
1027: my $send_msg_link='';
1028: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1029: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1030: $send_msg_link ='<br />'.
1031: &Apache::loncommon::messagewrapper(&mt('Send message'),
1032: $docslog{$id}{'exe_uname'},
1033: $docslog{$id}{'exe_udom'});
1034: }
1035: $r->print(&Apache::loncommon::start_data_table_row());
1036: $r->print('<td>'.$time.'</td>
1037: <td>'.$about_me_link.
1038: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1039: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1040: $send_msg_link.'</td><td>'.
1041: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1042: my $is_supp = 0;
1043: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1044: $is_supp = 1;
1045: }
1046: # Before
1047: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1048: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1049: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1050: if ($oldname ne $newname) {
1051: my $shown = &LONCAPA::map::qtescape($oldname);
1052: if ($is_supp) {
1053: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1054: }
1055: $r->print($shown);
1056: }
1057: }
1058: $r->print('<ul>');
1059: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1060: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1061: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1062: if ($is_supp) {
1063: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1064: }
1065: $r->print('<li>'.$shown.'</li>');
1066: }
1067: }
1068: $r->print('</ul>');
1069: # After
1070: $r->print('</td><td>');
1071:
1072: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1073: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1074: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1075: if ($oldname ne '' && $oldname ne $newname) {
1076: my $shown = &LONCAPA::map::qtescape($newname);
1077: if ($is_supp) {
1078: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1079: }
1080: $r->print($shown);
1081: }
1082: }
1083: $r->print('<ul>');
1084: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1085: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1086: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1087: if ($is_supp) {
1088: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1089: }
1090: $r->print('<li>'.$shown.'</li>');
1091: }
1092: }
1093: $r->print('</ul>');
1094: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1095: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1096: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1097: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1098: # FIXME: internationalization seems wrong here
1099: $r->print('<li>'.
1100: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1101: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1102: .'</li>');
1103: }
1104: }
1105: $r->print('</ul>');
1106: }
1107: # End
1108: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1109: $shown++;
1110: if (!($env{'form.show'} eq &mt('all')
1111: || $shown<=$env{'form.show'})) { last; }
1112: }
1113: $r->print(&Apache::loncommon::end_data_table()."\n".
1114: &makesimpleeditform($pathitem)."\n".
1115: '</div></div>');
1116: $r->print(&endContentScreen());
1117: }
1118:
1119: sub update_paste_buffer {
1120: my ($coursenum,$coursedom,$folder) = @_;
1121: my (@possibles,%removals,%cuts,$output);
1122: if ($env{'form.multiremove'}) {
1123: $env{'form.multiremove'} =~ s/,$//;
1124: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1125: }
1126: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1127: if ($env{'form.multicut'}) {
1128: $env{'form.multicut'} =~ s/,$//;
1129: foreach my $item (split(/,/,$env{'form.multicut'})) {
1130: unless ($removals{$item}) {
1131: $cuts{$item} = 1;
1132: push(@possibles,$item.':cut');
1133: }
1134: }
1135: }
1136: if ($env{'form.multicopy'}) {
1137: $env{'form.multicopy'} =~ s/,$//;
1138: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1139: unless ($removals{$item} || $cuts{$item}) {
1140: push(@possibles,$item.':copy');
1141: }
1142: }
1143: }
1144: } elsif ($env{'form.markcopy'}) {
1145: @possibles = split(/,/,$env{'form.markcopy'});
1146: }
1147:
1148: return if (@possibles == 0);
1149: return if (!defined($env{'form.copyfolder'}));
1150:
1151: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1152: $env{'form.copyfolder'});
1153: return if ($fatal);
1154:
1155: my %curr_groups = &Apache::longroup::coursegroups();
1156:
1157: # Retrieve current paste buffer suffixes.
1158: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1159: my (%pasteurls,@newpaste);
1160:
1161: # Construct identifiers for current contents of user's paste buffer
1162: if (@currpaste) {
1163: foreach my $suffix (@currpaste) {
1164: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1165: my $url = $env{'docs.markedcopy_url_'.$suffix};
1166: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1167: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1168: ($url ne '')) {
1169: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1170: }
1171: }
1172: }
1173:
1174: # Mark items for copying (skip any items already in user's paste buffer)
1175: my %addtoenv;
1176:
1177: my @pathitems = split(/\&/,$env{'form.folderpath'});
1178: my @folderconf = split(/\:/,$pathitems[-1]);
1179: my $ispage = $folderconf[4];
1180:
1181: foreach my $item (@possibles) {
1182: my ($orderidx,$cmd) = split(/:/,$item);
1183: next if ($orderidx =~ /\D/);
1184: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1185: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1186: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1187: my %denied = &action_restrictions($coursenum,$coursedom,
1188: &LONCAPA::map::qtescape($url),
1189: $env{'form.folderpath'},\%curr_groups);
1190: next if ($denied{'copy'});
1191: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1192: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1193: my ($suffix,$errortxt,$locknotfreed) =
1194: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1195: if ($suffix ne '') {
1196: push(@newpaste,$suffix);
1197: } else {
1198: if ($locknotfreed) {
1199: return $locknotfreed;
1200: }
1201: }
1202: if (&is_supplemental_title($title)) {
1203: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1204: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1205: }
1206:
1207: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1208: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1209: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1210: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1211: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1212: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1213: my $prefix = $1;
1214: my $subdir =$2;
1215: if ($subdir eq '') {
1216: $subdir = $prefix;
1217: }
1218: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1219: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1220: \%hierarchy,\%titles,\%allmaps);
1221: if (ref($hierarchy{$url}) eq 'HASH') {
1222: my ($nested,$nestednames);
1223: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1224: $nested =~ s/\&$//;
1225: $nestednames =~ s/\Q___&&&___\E$//;
1226: if ($nested ne '') {
1227: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1228: }
1229: if ($nestednames ne '') {
1230: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1231: }
1232: }
1233: }
1234: if ($locknotfreed) {
1235: $output = $locknotfreed;
1236: last;
1237: }
1238: }
1239: if (@newpaste) {
1240: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1241: }
1242: &Apache::lonnet::appenv(\%addtoenv);
1243: delete($env{'form.markcopy'});
1244: return $output;
1245: }
1246:
1247: sub recurse_uploaded_maps {
1248: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1249: if (ref($hierarchy->{$url}) eq 'HASH') {
1250: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1251: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1252: my (@uploaded,@names,%shorter);
1253: for (my $i=0; $i<@maps; $i++) {
1254: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1255: if ($inner ne '') {
1256: push(@uploaded,$inner);
1257: push(@names,&escape($titles[$i]));
1258: $shorter{$maps[$i]} = $inner;
1259: }
1260: }
1261: $$nestref .= "$dir:".join(',',@uploaded).'&';
1262: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1263: foreach my $map (@maps) {
1264: if ($shorter{$map} ne '') {
1265: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1266: }
1267: }
1268: }
1269: return;
1270: }
1271:
1272: sub print_paste_buffer {
1273: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1274: return if (!defined($env{'docs.markedcopies'}));
1275:
1276: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1277: return if ($env{'docs.markedcopies'} eq '');
1278: }
1279:
1280: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1281: my ($pasteitems,@pasteable);
1282: my $clipboardcount = 0;
1283:
1284: # Construct identifiers for current contents of user's paste buffer
1285: foreach my $suffix (@currpaste) {
1286: next if ($suffix =~ /\D/);
1287: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1288: my $url = $env{'docs.markedcopy_url_'.$suffix};
1289: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1290: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1291: ($url ne '')) {
1292: $clipboardcount ++;
1293: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1294: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1295: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1296: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1297: $is_external = 1;
1298: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1299: $is_exttool = 1;
1300: }
1301: if ($folder =~ /^supplemental/) {
1302: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1303: unless ($canpaste) {
1304: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1305: }
1306: } else {
1307: $canpaste = 1;
1308: }
1309: if ($canpaste) {
1310: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1311: my $srcdom = $1;
1312: my $srcnum = $2;
1313: my $rem = $3;
1314: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1315: $othercourse = 1;
1316: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1317: $othercrs = '<br />'.&mt('(from another course)');
1318: } else {
1319: $canpaste = 0;
1320: $nopaste = &mt('Paste from another course unavailable.');
1321: }
1322: }
1323: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1324: my $prefix = $1;
1325: $parent = $2;
1326: if ($folder !~ /^\Q$prefix\E/) {
1327: $areachange = 1;
1328: }
1329: $is_uploaded_map = 1;
1330: }
1331: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1332: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1333: if ($cid ne $env{'request.course.id'}) {
1334: my ($srcdom,$srcnum) = split(/_/,$cid);
1335: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1336: $othercrs = '<br />'.&mt('(from another course)');
1337: } else {
1338: $canpaste = 0;
1339: $nopaste = &mt('Paste from another course unavailable.');
1340: }
1341: }
1342: }
1343: if ($canpaste) {
1344: push(@pasteable,$suffix);
1345: }
1346: }
1347: my $buffer;
1348: if (($is_external) || ($is_exttool)) {
1349: $buffer = &mt('External Resource').': '.
1350: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1351: &LONCAPA::map::qtescape($url).')';
1352: } else {
1353: my $icon = &Apache::loncommon::icon($extension);
1354: if ($extension eq 'sequence' &&
1355: $url =~ m{/default_\d+\.sequence$}x) {
1356: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1357: $icon .= '/navmap.folder.closed.gif';
1358: }
1359: my $title = $env{'docs.markedcopy_title_'.$suffix};
1360: if ($title eq '') {
1361: ($title) = ($url =~ m{/([^/]+)$});
1362: }
1363: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1364: ': '.
1365: &Apache::loncommon::parse_supplemental_title(
1366: &LONCAPA::map::qtescape($title));
1367: }
1368: $pasteitems .= '<div class="LC_left_float">';
1369: my ($options,$onclick);
1370: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1371: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1372: if (($is_uploaded_map) ||
1373: ($url =~ /(bulletinboard|smppg)$/) ||
1374: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1375: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1376: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1377: }
1378: }
1379: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1380: if ($nopaste) {
1381: $pasteitems .= $nopaste;
1382: } else {
1383: if ($othercrs) {
1384: $pasteitems .= $othercrs;
1385: }
1386: if ($options) {
1387: $pasteitems .= $options;
1388: }
1389: }
1390: $pasteitems .= '</div>';
1391: }
1392: }
1393: if ($pasteitems eq '') {
1394: &Apache::lonnet::delenv('docs.markedcopies');
1395: }
1396: my ($pasteform,$form_start,$buttons,$form_end);
1397: if ($pasteitems) {
1398: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1399: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1400: if (@pasteable) {
1401: my $value = &mt('Paste to current folder');
1402: if ($container eq 'page') {
1403: $value = &mt('Paste to current page');
1404: }
1405: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1406: }
1407: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1408: if ($clipboardcount > 1) {
1409: $buttons .=
1410: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1411: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1412: (' 'x2).
1413: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1414: (' 'x2);
1415: }
1416: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1417: '</form>';
1418: } else {
1419: $pasteitems = &mt('Clipboard is empty');
1420: }
1421: $r->print($form_start
1422: .'<fieldset>'
1423: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1424: .$pasteitems
1425: .'</fieldset>'
1426: .$form_end);
1427: }
1428:
1429: sub paste_options {
1430: my ($suffix,$is_uploaded_map,$parent) = @_;
1431: my ($copytext,$movetext);
1432: if ($is_uploaded_map) {
1433: $copytext = &mt('Copy to new folder');
1434: $movetext = &mt('Move old');
1435: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1436: $copytext = &mt('Copy to new board');
1437: $movetext = &mt('Move (not posts)');
1438: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1439: $copytext = &mt('Copy to new page');
1440: $movetext = &mt('Move');
1441: } else {
1442: $copytext = &mt('Copy to new file');
1443: $movetext = &mt('Move');
1444: }
1445: my $output = '<br />'.
1446: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1447: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1448: '<label>'.
1449: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1450: $copytext.'</label></span>'.(' 'x2).' '.
1451: '<span class="LC_nobreak"><label>'.
1452: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1453: $movetext.'</label></span>';
1454: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1455: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1456: '</legend><table border="0">';
1457: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1458: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1459: my $lastdir = $parent;
1460: my %depths = (
1461: $lastdir => 0,
1462: );
1463: my (%display,%deps);
1464: for (my $i=0; $i<@pastemaps; $i++) {
1465: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1466: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1467: my @subfolders = split(/,/,$subfolderstr);
1468: $deps{$lastdir} = \@subfolders;
1469: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1470: my $depth = $depths{$lastdir} + 1;
1471: my $offset = int($depth * 4);
1472: my $indent = (' ' x $offset);
1473: for (my $j=0; $j<@subfolders; $j++) {
1474: $depths{$subfolders[$j]} = $depth;
1475: $display{$subfolders[$j]} =
1476: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1477: '<td><label>'.
1478: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1479: '<label>'.
1480: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1481: &mt('Move old').'</label>'.
1482: '</td></tr>';
1483: }
1484: }
1485: &recurse_print(\$output,$parent,\%deps,\%display);
1486: $output .= '</table></fieldset>';
1487: }
1488: $output .= '</div>';
1489: return $output;
1490: }
1491:
1492: sub recurse_print {
1493: my ($outputref,$dir,$deps,$display) = @_;
1494: $$outputref .= $display->{$dir}."\n";
1495: if (ref($deps->{$dir}) eq 'ARRAY') {
1496: foreach my $subdir (@{$deps->{$dir}}) {
1497: &recurse_print($outputref,$subdir,$deps,$display);
1498: }
1499: }
1500: }
1501:
1502: sub supp_pasteable {
1503: my ($url) = @_;
1504: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1505: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1506: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1507: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1508: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1509: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1510: return 1;
1511: }
1512: return;
1513: }
1514:
1515: sub paste_popup_js {
1516: my %html_js_lt = &Apache::lonlocal::texthash(
1517: show => 'Show Options',
1518: hide => 'Hide Options',
1519: );
1520: my %js_lt = &Apache::lonlocal::texthash(
1521: none => 'No items selected from clipboard.',
1522: );
1523: &html_escape(\%html_js_lt);
1524: &js_escape(\%html_js_lt);
1525: &js_escape(\%js_lt);
1526: return <<"END";
1527:
1528: function showPasteOptions(suffix) {
1529: document.getElementById('pasteoptions_'+suffix).style.display='block';
1530: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1531: return;
1532: }
1533:
1534: function hidePasteOptions(suffix) {
1535: document.getElementById('pasteoptions_'+suffix).style.display='none';
1536: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1537: return;
1538: }
1539:
1540: function showOptions(caller,suffix) {
1541: if (document.getElementById('pasteoptionstext_'+suffix)) {
1542: if (caller.checked) {
1543: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1544: } else {
1545: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1546: }
1547: if (document.getElementById('pasteoptions_'+suffix)) {
1548: document.getElementById('pasteoptions_'+suffix).style.display='none';
1549: }
1550: }
1551: return;
1552: }
1553:
1554: function validateClipboard() {
1555: var numchk = 0;
1556: if (document.pasteform.pasting.length > 1) {
1557: for (var i=0; i<document.pasteform.pasting.length; i++) {
1558: if (document.pasteform.pasting[i].checked) {
1559: numchk ++;
1560: }
1561: }
1562: } else {
1563: if (document.pasteform.pasting.type == 'checkbox') {
1564: if (document.pasteform.pasting.checked) {
1565: numchk ++;
1566: }
1567: }
1568: }
1569: if (numchk > 0) {
1570: return true;
1571: } else {
1572: alert("$js_lt{'none'}");
1573: return false;
1574: }
1575: }
1576:
1577: function checkClipboard() {
1578: if (document.pasteform.pasting.length > 1) {
1579: for (var i=0; i<document.pasteform.pasting.length; i++) {
1580: document.pasteform.pasting[i].checked = true;
1581: }
1582: }
1583: return;
1584: }
1585:
1586: function uncheckClipboard() {
1587: if (document.pasteform.pasting.length >1) {
1588: for (var i=0; i<document.pasteform.pasting.length; i++) {
1589: document.pasteform.pasting[i].checked = false;
1590: }
1591: }
1592: return;
1593: }
1594:
1595: END
1596:
1597: }
1598:
1599: sub do_paste_from_buffer {
1600: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1601:
1602: # Array of items in paste buffer
1603: my (@currpaste,%pastebuffer,%allerrors);
1604: @currpaste = split(/,/,$env{'docs.markedcopies'});
1605:
1606: # Early out if paste buffer is empty
1607: if (@currpaste == 0) {
1608: return ();
1609: }
1610: map { $pastebuffer{$_} = 1; } @currpaste;
1611:
1612: # Array of items selected items to paste
1613: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1614:
1615: # Early out if nothing selected to paste
1616: if (@reqpaste == 0) {
1617: return();
1618: }
1619: my @topaste;
1620: foreach my $suffix (@reqpaste) {
1621: next if ($suffix =~ /\D/);
1622: next unless (exists($pastebuffer{$suffix}));
1623: push(@topaste,$suffix);
1624: }
1625:
1626: # Early out if nothing available to paste
1627: if (@topaste == 0) {
1628: return();
1629: }
1630:
1631: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1632: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1633:
1634: foreach my $suffix (@topaste) {
1635: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1636: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1637: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1638: # Supplemental content may only include certain types of content
1639: # Early out if pasted content is not supported in Supplemental area
1640: if ($folder =~ /^supplemental/) {
1641: unless (&supp_pasteable($url)) {
1642: $notinsupp{$suffix} = 1;
1643: next;
1644: }
1645: }
1646: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1647: my $srcd = $1;
1648: my $srcn = $2;
1649: # When paste buffer was populated using an active role in a different course
1650: # check for mdc privilege in the course from which the resource was pasted
1651: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1652: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1653: $notincrs{$suffix} = 1;
1654: next;
1655: }
1656: }
1657: $srcdom{$suffix} = $srcd;
1658: $srcnum{$suffix} = $srcn;
1659: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1660: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1661: my ($srcd,$srcn) = split(/_/,$cid);
1662: # When paste buffer was populated using an active role in a different course
1663: # check for mdc privilege in the course from which the resource was pasted
1664: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1665: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1666: $notincrs{$suffix} = 1;
1667: next;
1668: }
1669: }
1670: $srcdom{$suffix} = $srcd;
1671: $srcnum{$suffix} = $srcn;
1672: }
1673: $srcmapidx{$suffix} = $mapidx;
1674: push(@dopaste,$suffix);
1675: if ($url=~/\.(page|sequence)$/) {
1676: $is_map{$suffix} = 1;
1677: }
1678:
1679: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1680: my $oldprefix = $1;
1681: # When pasting content from Main Content to Supplemental Content and vice versa
1682: # URLs will contain different paths (which depend on whether pasted item is
1683: # a folder/page or a document).
1684: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1685: $prefixchg{$suffix} = 'docstosupp';
1686: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1687: $prefixchg{$suffix} = 'supptodocs';
1688: }
1689:
1690: # If pasting an uploaded map, get list of contained uploaded maps.
1691: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1692: my @nested;
1693: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1694: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1695: my @deps = map { /\d+:([\d,]+$)/ } @items;
1696: foreach my $dep (@deps) {
1697: if ($dep =~ /,/) {
1698: push(@nested,split(/,/,$dep));
1699: } else {
1700: push(@nested,$dep);
1701: }
1702: }
1703: foreach my $item (@nested) {
1704: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1705: push(@{$marktomove{$suffix}},$type.'_'.$item);
1706: }
1707: }
1708: }
1709: }
1710: }
1711:
1712: # Early out if nothing available to paste
1713: if (@dopaste == 0) {
1714: return ();
1715: }
1716:
1717: # Populate message hash and hashes used for main content <=> supplemental content
1718: # changes
1719:
1720: %msgs = &Apache::lonlocal::texthash (
1721: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1722: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1723: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1724: );
1725:
1726: %before = (
1727: docstosupp => {
1728: map => 'default',
1729: doc => 'docs',
1730: },
1731: supptodocs => {
1732: map => 'supplemental',
1733: doc => 'supplemental',
1734: },
1735: );
1736:
1737: %after = (
1738: docstosupp => {
1739: map => 'supplemental',
1740: doc => 'supplemental'
1741: },
1742: supptodocs => {
1743: map => 'default',
1744: doc => 'docs',
1745: },
1746: );
1747:
1748: # Retrieve information about all course maps in main content area
1749:
1750: my $allmaps = {};
1751: if ($folder =~ /^default/) {
1752: $allmaps =
1753: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1754: $env{"course.$env{'request.course.id'}.home"},
1755: $env{'request.course.id'});
1756: }
1757:
1758: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1759:
1760: # Loop over the items to paste
1761: foreach my $suffix (@dopaste) {
1762: # Maps need to be copied first
1763: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1764: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1765: %newurls,%tomove,%resdatacopy);
1766: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1767: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1768: }
1769: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1770: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1771: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1772: my $oldurl = $url;
1773: if ($is_map{$suffix}) {
1774: # If pasting a map, check if map contains other maps
1775: my (%hierarchy,%titles);
1776: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1777: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1778: if ($url=~ m{^/uploaded/}) {
1779: my $newurl;
1780: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1781: ($newurl,my $error) =
1782: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1783: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1784: \$title,$allmaps,\%newurls);
1785: if ($error) {
1786: $allerrors{$suffix} = $error;
1787: next;
1788: }
1789: if ($newurl ne '') {
1790: if ($newurl ne $url) {
1791: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1792: $newsubdir{$url} = $1;
1793: }
1794: $mapchanges{$url} = 1;
1795: }
1796: }
1797: }
1798: if (($srcdom{$suffix} ne $coursedom) ||
1799: ($srcnum{$suffix} ne $coursenum) ||
1800: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1801: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1802: $coursedom,$coursenum,$srcdom{$suffix},
1803: $srcnum{$suffix},$allmaps,\%rewrites,
1804: \%retitles,\%copies,\%dbcopies,
1805: \%zombies,\%params,\%mapmoves,
1806: \%mapchanges,\%tomove,\%newsubdir,
1807: \%newurls,\%resdatacopy)) {
1808: $mapmoves{$url} = 1;
1809: }
1810: $url = $newurl;
1811: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1812: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1813: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1814: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1815: \%zombies,\%params,\%mapmoves,\%mapchanges,
1816: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1817: }
1818: } elsif ($url=~m {^/res/}) {
1819: # published map can only exist once, so remove from paste buffer when done
1820: push(@toclear,$suffix);
1821: # if pasting published map (main content area only) check map not already in course
1822: if ($folder =~ /^default/) {
1823: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1824: $duplicate{$suffix} = 1;
1825: next;
1826: }
1827: }
1828: }
1829: }
1830: if ($url=~ m{/(bulletinboard|smppg)$}) {
1831: my $prefix = $1;
1832: my $fromothercrs;
1833: #need to copy the db contents to a new one, unless this is a move.
1834: my %info = (
1835: src => $url,
1836: cdom => $coursedom,
1837: cnum => $coursenum,
1838: );
1839: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1840: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1841: $fromothercrs = 1;
1842: $info{'cdom'} = $srcdom{$suffix};
1843: $info{'cnum'} = $srcnum{$suffix};
1844: }
1845: }
1846: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1847: my (%lockerr,$msg);
1848: my ($newurl,$result,$errtext) =
1849: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1850: if ($result eq 'ok') {
1851: $url = $newurl;
1852: $title=&mt('Copy of').' '.$title;
1853: } else {
1854: if ($prefix eq 'smppg') {
1855: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1856: } elsif ($prefix eq 'bulletinboard') {
1857: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1858: }
1859: $results{$suffix} = $result;
1860: $msgerrs{$suffix} = $msg;
1861: $lockerrs{$suffix} = $lockerr{$prefix};
1862: next;
1863: }
1864: if ($lockerr{$prefix}) {
1865: $lockerrs{$suffix} = $lockerr{$prefix};
1866: }
1867: }
1868: }
1869: $title = &LONCAPA::map::qtunescape($title);
1870: my $ext='false';
1871: if ($url=~m{^http(|s)://}) { $ext='true'; }
1872: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1873: if ($folder !~ /^supplemental/) {
1874: (undef,undef,$title) =
1875: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1876: }
1877: } else {
1878: if ($folder=~/^supplemental/) {
1879: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1880: $env{'user.domain'}.'___&&&___'.$title;
1881: }
1882: }
1883:
1884: # For uploaded files (excluding pages/sequences) path in copied file is changed
1885: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1886: # courses.
1887:
1888: unless ($is_map{$suffix}) {
1889: my $newidx;
1890: # Now insert the URL at the bottom
1891: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1892: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1893: my $relpath = $1;
1894: if ($relpath ne '') {
1895: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1896: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1897: my $newprefix = $newloc;
1898: if ($newloc eq 'default') {
1899: $newprefix = 'docs';
1900: }
1901: if ($newdocsdir eq '') {
1902: $newdocsdir = 'default';
1903: }
1904: if (($prefixchg{$suffix}) ||
1905: ($srcdom{$suffix} ne $coursedom) ||
1906: ($srcnum{$suffix} ne $coursenum) ||
1907: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1908: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1909: $url =
1910: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1911: &Apache::lonnet::getfile($oldurl));
1912: if ($url eq '/adm/notfound.html') {
1913: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1914: next;
1915: } else {
1916: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1917: $newsubpath =~ s{/+$}{/};
1918: $docmoves{$oldurl} = $newsubpath;
1919: }
1920: }
1921: }
1922: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1923: my $template = $1;
1924: if ($newidx) {
1925: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1926: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1927: }
1928: }
1929: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1930: ':'.$ext.':normal:res';
1931: push(@LONCAPA::map::order,$newidx);
1932: # Store the result
1933: my ($errtext,$fatal) =
1934: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1935: if ($fatal) {
1936: $save_err .= $errtext;
1937: $allresult = 'fail';
1938: }
1939: }
1940:
1941: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1942: # resourcedata for simpleproblems copied from another course
1943: unless ($allresult eq 'fail') {
1944: my %updated = (
1945: rewrites => \%rewrites,
1946: zombies => \%zombies,
1947: removefrommap => \%removefrommap,
1948: removeparam => \%removeparam,
1949: dbcopies => \%dbcopies,
1950: resdatacopy => \%resdatacopy,
1951: retitles => \%retitles,
1952: );
1953: my %info = (
1954: newsubdir => \%newsubdir,
1955: params => \%params,
1956: );
1957: if ($prefixchg{$suffix}) {
1958: $info{'before'} = $before{$prefixchg{$suffix}};
1959: $info{'after'} = $after{$prefixchg{$suffix}};
1960: }
1961: my %moves = (
1962: copies => \%copies,
1963: docmoves => \%docmoves,
1964: mapmoves => \%mapmoves,
1965: );
1966: (my $result,$msgs{$suffix},my $lockerror) =
1967: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1968: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1969: $url,'paste');
1970: $lockerrors .= $lockerror;
1971: if ($result eq 'ok') {
1972: if ($is_map{$suffix}) {
1973: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1974: $folder.'.'.$container);
1975: if ($fatal) {
1976: $allresult = 'failread';
1977: } else {
1978: if ($#LONCAPA::map::order<1) {
1979: my $idx=&LONCAPA::map::getresidx();
1980: if ($idx<=0) { $idx=1; }
1981: $LONCAPA::map::order[0]=$idx;
1982: $LONCAPA::map::resources[$idx]='';
1983: }
1984: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1985: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1986: ':'.$ext.':normal:res';
1987: push(@LONCAPA::map::order,$newidx);
1988:
1989: # Store the result
1990: my ($errtext,$fatal) =
1991: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1992: if ($fatal) {
1993: $save_err .= $errtext;
1994: $allresult = 'failstore';
1995: }
1996: }
1997: }
1998: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1999: push(@toclear,$suffix);
2000: }
2001: }
2002: }
2003: }
2004: &clear_from_buffer(\@toclear,\@currpaste);
2005: my $msgsarray;
2006: foreach my $suffix (keys(%msgs)) {
2007: if (ref($msgs{$suffix}) eq 'ARRAY') {
2008: $msgsarray .= join(',',@{$msgs{$suffix}});
2009: }
2010: }
2011: return ($allresult,$save_err,$msgsarray,$lockerrors);
2012: }
2013:
2014: sub do_buffer_empty {
2015: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2016: if (@currpaste == 0) {
2017: return &mt('Clipboard is already empty');
2018: }
2019: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2020: if (@toclear == 0) {
2021: return &mt('Nothing selected to clear from clipboard');
2022: }
2023: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2024: if ($numdel) {
2025: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2026: } else {
2027: return &mt('Clipboard unchanged');
2028: }
2029: return;
2030: }
2031:
2032: sub clear_from_buffer {
2033: my ($toclear,$currpaste) = @_;
2034: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2035: my %pastebuffer;
2036: map { $pastebuffer{$_} = 1; } @{$currpaste};
2037: my $numdel = 0;
2038: foreach my $suffix (@{$toclear}) {
2039: next if ($suffix =~ /\D/);
2040: next unless (exists($pastebuffer{$suffix}));
2041: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2042: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2043: delete($pastebuffer{$suffix});
2044: $numdel ++;
2045: }
2046: }
2047: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2048: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2049: return $numdel;
2050: }
2051:
2052: sub get_newmap_url {
2053: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2054: $titleref,$allmaps,$newurls) = @_;
2055: my $newurl;
2056: if ($url=~ m{^/uploaded/}) {
2057: $$titleref=&mt('Copy of').' '.$$titleref;
2058: }
2059: my $now = time;
2060: my $suffix=$$.int(rand(100)).$now;
2061: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2062: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2063: my $path = $1;
2064: my $prefix = $2;
2065: my $ancestor = $3;
2066: if (length($ancestor) > 10) {
2067: $ancestor = substr($ancestor,-10,10);
2068: }
2069: my $newid;
2070: if ($prefixchg) {
2071: if ($folder =~ /^supplemental/) {
2072: $prefix =~ s/^default/supplemental/;
2073: } else {
2074: $prefix =~ s/^supplemental/default/;
2075: }
2076: }
2077: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2078: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2079: } else {
2080: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2081: }
2082: my $counter = 0;
2083: my $is_unique = &uniqueness_check($newurl);
2084: if ($folder =~ /^default/) {
2085: if ($allmaps->{$newurl}) {
2086: $is_unique = 0;
2087: }
2088: }
2089: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2090: $counter ++;
2091: $suffix ++;
2092: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2093: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2094: } else {
2095: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2096: }
2097: $is_unique = &uniqueness_check($newurl);
2098: }
2099: if ($is_unique) {
2100: $newurls->{$newurl} = 1;
2101: } else {
2102: if ($url=~/\.page$/) {
2103: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2104: } else {
2105: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2106: }
2107: }
2108: }
2109: return ($newurl);
2110: }
2111:
2112: sub dbcopy {
2113: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2114: my ($url,$result,$errtext);
2115: if (ref($dbref) eq 'HASH') {
2116: $url = $dbref->{'src'};
2117: if ($url =~ m{/(smppg|bulletinboard)$}) {
2118: my $prefix = $1;
2119: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2120: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2121: my $db_name;
2122: my $marker = (split(m{/},$url))[4];
2123: $marker=~s/\D//g;
2124: if ($dbref->{'src'} =~ m{/smppg$}) {
2125: $db_name =
2126: &Apache::lonsimplepage::get_db_name($url,$marker,
2127: $dbref->{'cdom'},
2128: $dbref->{'cnum'});
2129: } else {
2130: $db_name = 'bulletinpage_'.$marker;
2131: }
2132: my ($suffix,$freedlock,$error) =
2133: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2134: $coursedom,$coursenum,
2135: 'concat');
2136: if (!$suffix) {
2137: if ($prefix eq 'smppg') {
2138: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2139: } else {
2140: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2141: }
2142: if ($error) {
2143: $errtext .= '<br />'.$error;
2144: }
2145: } else {
2146: #need to copy the db contents to a new one.
2147: my %contents=&Apache::lonnet::dump($db_name,
2148: $dbref->{'cdom'},
2149: $dbref->{'cnum'});
2150: if (exists($contents{'uploaded.photourl'})) {
2151: my $photo = $contents{'uploaded.photourl'};
2152: my ($subdir,$fname) =
2153: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2154: my $newphoto;
2155: if ($fname ne '') {
2156: my $content = &Apache::lonnet::getfile($photo);
2157: unless ($content eq '-1') {
2158: $env{'form.'.$suffix.'.photourl'} = $content;
2159: $newphoto =
2160: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2161: delete($env{'form.'.$suffix.'.photourl'});
2162: }
2163: }
2164: if ($newphoto =~ m{^/uploaded/}) {
2165: $contents{'uploaded.photourl'} = $newphoto;
2166: }
2167: }
2168: $db_name =~ s{_\d*$ }{_$suffix}x;
2169: $result=&Apache::lonnet::put($db_name,\%contents,
2170: $coursedom,$coursenum);
2171: if ($result eq 'ok') {
2172: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2173: }
2174: }
2175: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2176: $lockerrorsref->{$prefix} =
2177: '<div class="LC_error">'.
2178: &mt('There was a problem removing a lockfile.');
2179: if ($prefix eq 'smppg') {
2180: $lockerrorsref->{$prefix} .=
2181: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2182: } else {
2183: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2184: }
2185: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2186: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2187: '</div>';
2188: }
2189: }
2190: } elsif ($url =~ m{/syllabus$}) {
2191: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2192: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2193: if (($dbref->{'cdom'} ne $coursedom) ||
2194: ($dbref->{'cnum'} ne $coursenum)) {
2195: my %contents=&Apache::lonnet::dump('syllabus',
2196: $dbref->{'cdom'},
2197: $dbref->{'cnum'});
2198: $result=&Apache::lonnet::put('syllabus',\%contents,
2199: $coursedom,$coursenum);
2200: }
2201: }
2202: }
2203: }
2204: return ($url,$result,$errtext);
2205: }
2206:
2207: sub copy_templated_files {
2208: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2209: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2210: my $srccontainer = 'sequence';
2211: if ($srcwaspage) {
2212: $srccontainer = 'page';
2213: }
2214: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2215: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2216: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2217: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2218: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2219: $template.'.problem';
2220: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2221: if ($template eq 'simpleproblem') {
2222: $srcprefix .= '.0.';
2223: my $weightprefix = $newprefix;
2224: $newprefix .= '.0.';
2225: my @simpleprobqtypes = qw(radio option string essay numerical);
2226: my $qtype=$srcparms{$srcprefix.'questiontype'};
2227: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2228: my %newdata;
2229: foreach my $type (@simpleprobqtypes) {
2230: if ($type eq $qtype) {
2231: $newdata{"$weightprefix.$type.weight"}=1;
2232: } else {
2233: $newdata{"$weightprefix.$type.weight"}=0;
2234: }
2235: }
2236: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2237: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2238: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2239: if ($qtype eq 'numerical') {
2240: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2241: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2242: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2243: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2244: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2245: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2246: unless (defined($maxfoils)) { $maxfoils=10; }
2247: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2248: if ($maxfoils<=0) { $maxfoils=10; }
2249: my $randomize=$srcparms{$srcprefix.'randomize'};
2250: unless (defined($randomize)) { $randomize='yes'; }
2251: unless ($randomize eq 'no') { $randomize='yes'; }
2252: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2253: $newdata{$newprefix.'randomize'} = $randomize;
2254: if ($qtype eq 'option') {
2255: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2256: }
2257: for (my $i=1; $i<=10; $i++) {
2258: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2259: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2260: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2261: }
2262:
2263: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2264: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2265: unless (defined($maxfoils)) { $maxfoils=10; }
2266: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2267: if ($maxfoils<=0) { $maxfoils=10; }
2268: my $randomize=$srcparms{$srcprefix.'randomize'};
2269: unless (defined($randomize)) { $randomize='yes'; }
2270: unless ($randomize eq 'no') { $randomize='yes'; }
2271: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2272: $newdata{$newprefix.'randomize'} = $randomize;
2273: if ($qtype eq 'option') {
2274: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2275: }
2276: for (my $i=1; $i<=10; $i++) {
2277: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2278: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2279: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2280: }
2281: } elsif ($qtype eq 'string') {
2282: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2283: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2284: }
2285: if (keys(%newdata)) {
2286: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2287: $coursenum);
2288: if ($putres eq 'ok') {
2289: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2290: }
2291: }
2292: }
2293: }
2294: }
2295:
2296: sub uniqueness_check {
2297: my ($newurl) = @_;
2298: my $unique = 1;
2299: foreach my $res (@LONCAPA::map::order) {
2300: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2301: $url=&LONCAPA::map::qtescape($url);
2302: if ($newurl eq $url) {
2303: $unique = 0;
2304: last;
2305: }
2306: }
2307: return $unique;
2308: }
2309:
2310: sub contained_map_check {
2311: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2312: $allmaps) = @_;
2313: my $content = &Apache::lonnet::getfile($url);
2314: unless ($content eq '-1') {
2315: my $parser = HTML::TokeParser->new(\$content);
2316: $parser->attr_encoded(1);
2317: while (my $token = $parser->get_token) {
2318: next if ($token->[0] ne 'S');
2319: if ($token->[1] eq 'resource') {
2320: next if ($token->[2]->{'type'} eq 'zombie');
2321: my $ressrc = $token->[2]->{'src'};
2322: if ($folder =~ /^supplemental/) {
2323: unless (&supp_pasteable($ressrc)) {
2324: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2325: next;
2326: }
2327: }
2328: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2329: if ($1 eq 'uploaded') {
2330: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2331: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2332: } else {
2333: if ($allmaps->{$ressrc}) {
2334: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2335: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2336: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2337: } else {
2338: $addedmaps->{$ressrc} = [$url];
2339: }
2340: }
2341: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2342: $addedmaps,$hierarchy,$titles,$allmaps);
2343: }
2344: } elsif ($token->[1] eq 'param') {
2345: if ($folder =~ /^supplemental/) {
2346: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2347: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2348: } else {
2349: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2350: }
2351: }
2352: }
2353: }
2354: }
2355: return;
2356: }
2357:
2358: sub url_paste_fixups {
2359: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2360: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2361: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2362: my $checktitle;
2363: if (($prefixchg) &&
2364: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2365: $checktitle = 1;
2366: }
2367: my $skip;
2368: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2369: my $mapid = $1.$2;
2370: if ($tomove->{$mapid}) {
2371: $skip = 1;
2372: }
2373: }
2374: my $file = &Apache::lonnet::getfile($oldurl);
2375: return if ($file eq '-1');
2376: my $parser = HTML::TokeParser->new(\$file);
2377: $parser->attr_encoded(1);
2378: my $changed = 0;
2379: while (my $token = $parser->get_token) {
2380: next if ($token->[0] ne 'S');
2381: if ($token->[1] eq 'resource') {
2382: my $ressrc = $token->[2]->{'src'};
2383: next if ($ressrc eq '');
2384: my $id = $token->[2]->{'id'};
2385: my $title = $token->[2]->{'title'};
2386: if ($checktitle) {
2387: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2388: $retitles->{$oldurl}{$id} = $ressrc;
2389: }
2390: }
2391: next if ($token->[2]->{'type'} eq 'external');
2392: if ($token->[2]->{'type'} eq 'zombie') {
2393: next if ($skip);
2394: $zombies->{$oldurl}{$id} = $ressrc;
2395: $changed = 1;
2396: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2397: my $srcdom = $1;
2398: my $srcnum = $2;
2399: my $rem = $3;
2400: my $newurl;
2401: my $mapname;
2402: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2403: my $prefix = $1;
2404: $mapname = $prefix.$2;
2405: if ($tomove->{$mapname}) {
2406: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2407: $srcdom,$srcnum,$allmaps,$rewrites,
2408: $retitles,$copies,$dbcopies,$zombies,
2409: $params,$mapmoves,$mapchanges,$tomove,
2410: $newsubdir,$newurls,$resdatacopy);
2411: next;
2412: } else {
2413: ($newurl,my $error) =
2414: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2415: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2416: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2417: $newsubdir->{$ressrc} = $1;
2418: }
2419: if ($error) {
2420: next;
2421: }
2422: }
2423: }
2424: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2425: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2426:
2427: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2428: $rewrites->{$oldurl}{$id} = $ressrc;
2429: $mapchanges->{$ressrc} = 1;
2430: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2431: $cnum,$srcdom,$srcnum,$allmaps,
2432: $rewrites,$retitles,$copies,$dbcopies,
2433: $zombies,$params,$mapmoves,$mapchanges,
2434: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2435: $mapmoves->{$ressrc} = 1;
2436: }
2437: $changed = 1;
2438: } else {
2439: $rewrites->{$oldurl}{$id} = $ressrc;
2440: $copies->{$oldurl}{$ressrc} = $id;
2441: $changed = 1;
2442: }
2443: }
2444: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2445: next if ($skip);
2446: my $srcdom = $1;
2447: my $srcnum = $2;
2448: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2449: $rewrites->{$oldurl}{$id} = $ressrc;
2450: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2451: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2452: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2453: $changed = 1;
2454: }
2455: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2456: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2457: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2458: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2459: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2460: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2461: $changed = 1;
2462: }
2463: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2464: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2465: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2466: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2467: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2468: }
2469: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2470: next if ($skip);
2471: my $srcdom = $1;
2472: my $srcnum = $2;
2473: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2474: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2475: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2476: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2477: $changed = 1;
2478: }
2479: }
2480: } elsif ($token->[1] eq 'param') {
2481: next if ($skip);
2482: my $to = $token->[2]->{'to'};
2483: if ($to ne '') {
2484: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2485: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2486: } else {
2487: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2488: }
2489: }
2490: }
2491: }
2492: return $changed;
2493: }
2494:
2495: sub apply_fixups {
2496: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2497: $oldurl,$url,$caller) = @_;
2498: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2499: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2500: %resdatacopy,%lockerrors,$lockmsg);
2501: if (ref($updated) eq 'HASH') {
2502: if (ref($updated->{'rewrites'}) eq 'HASH') {
2503: %rewrites = %{$updated->{'rewrites'}};
2504: }
2505: if (ref($updated->{'zombies'}) eq 'HASH') {
2506: %zombies = %{$updated->{'zombies'}};
2507: }
2508: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2509: %removefrommap = %{$updated->{'removefrommap'}};
2510: }
2511: if (ref($updated->{'removeparam'}) eq 'HASH') {
2512: %removeparam = %{$updated->{'removeparam'}};
2513: }
2514: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2515: %dbcopies = %{$updated->{'dbcopies'}};
2516: }
2517: if (ref($updated->{'retitles'}) eq 'HASH') {
2518: %retitles = %{$updated->{'retitles'}};
2519: }
2520: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2521: %resdatacopy = %{$updated->{'resdatacopy'}};
2522: }
2523: }
2524: if (ref($info) eq 'HASH') {
2525: if (ref($info->{'newsubdir'}) eq 'HASH') {
2526: %newsubdir = %{$info->{'newsubdir'}};
2527: }
2528: if (ref($info->{'params'}) eq 'HASH') {
2529: %params = %{$info->{'params'}};
2530: }
2531: if (ref($info->{'before'}) eq 'HASH') {
2532: %before = %{$info->{'before'}};
2533: }
2534: if (ref($info->{'after'}) eq 'HASH') {
2535: %after = %{$info->{'after'}};
2536: }
2537: }
2538: if (ref($moves) eq 'HASH') {
2539: if (ref($moves->{'copies'}) eq 'HASH') {
2540: %copies = %{$moves->{'copies'}};
2541: }
2542: if (ref($moves->{'docmoves'}) eq 'HASH') {
2543: %docmoves = %{$moves->{'docmoves'}};
2544: }
2545: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2546: %mapmoves = %{$moves->{'mapmoves'}};
2547: }
2548: }
2549: foreach my $key (keys(%copies),keys(%docmoves)) {
2550: my @allcopies;
2551: if (exists($copies{$key})) {
2552: if (ref($copies{$key}) eq 'HASH') {
2553: my %added;
2554: foreach my $innerkey (keys(%{$copies{$key}})) {
2555: if (($innerkey ne '') && (!$added{$innerkey})) {
2556: push(@allcopies,$innerkey);
2557: $added{$innerkey} = 1;
2558: }
2559: }
2560: undef(%added);
2561: }
2562: }
2563: if ($key eq $oldurl) {
2564: if ((exists($docmoves{$key}))) {
2565: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2566: push(@allcopies,$oldurl);
2567: }
2568: }
2569: }
2570: if (@allcopies > 0) {
2571: foreach my $item (@allcopies) {
2572: my ($relpath,$oldsubdir,$fname) =
2573: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2574: if ($fname ne '') {
2575: my $content = &Apache::lonnet::getfile($item);
2576: unless ($content eq '-1') {
2577: my $storefn;
2578: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2579: $storefn = $docmoves{$key};
2580: } else {
2581: $storefn = $relpath;
2582: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2583: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2584: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2585: }
2586: if ($newsubdir{$key}) {
2587: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2588: }
2589: }
2590: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2591: my $copyurl =
2592: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2593: $storefn.$fname,$content);
2594: if ($copyurl eq '/adm/notfound.html') {
2595: if (exists($docmoves{$oldurl})) {
2596: return &mt('Paste failed: an error occurred copying the file.');
2597: } elsif (ref($errors) eq 'HASH') {
2598: $errors->{$item} = 1;
2599: }
2600: }
2601: }
2602: }
2603: }
2604: }
2605: }
2606: foreach my $key (keys(%mapmoves)) {
2607: my $storefn=$key;
2608: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2609: if ($prefixchg && $before{'map'} && $after{'map'}) {
2610: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2611: }
2612: if ($newsubdir{$key}) {
2613: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2614: }
2615: my $mapcontent = &Apache::lonnet::getfile($key);
2616: if ($mapcontent eq '-1') {
2617: if (ref($errors) eq 'HASH') {
2618: $errors->{$key} = 1;
2619: }
2620: } else {
2621: my $newmap =
2622: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2623: $mapcontent);
2624: if ($newmap eq '/adm/notfound.html') {
2625: if (ref($errors) eq 'HASH') {
2626: $errors->{$key} = 1;
2627: }
2628: }
2629: }
2630: }
2631: my %updates;
2632: if ($is_map) {
2633: if (ref($updated) eq 'HASH') {
2634: foreach my $type (keys(%{$updated})) {
2635: if (ref($updated->{$type}) eq 'HASH') {
2636: foreach my $key (keys(%{$updated->{$type}})) {
2637: $updates{$key} = 1;
2638: }
2639: }
2640: }
2641: }
2642: foreach my $key (keys(%updates)) {
2643: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2644: if (ref($rewrites{$key}) eq 'HASH') {
2645: %torewrite = %{$rewrites{$key}};
2646: }
2647: if (ref($retitles{$key}) eq 'HASH') {
2648: %toretitle = %{$retitles{$key}};
2649: }
2650: if (ref($removefrommap{$key}) eq 'HASH') {
2651: %toremove = %{$removefrommap{$key}};
2652: }
2653: if (ref($removeparam{$key}) eq 'HASH') {
2654: %remparam = %{$removeparam{$key}};
2655: }
2656: if (ref($zombies{$key}) eq 'HASH') {
2657: %zombie = %{$zombies{$key}};
2658: }
2659: if (ref($dbcopies{$key}) eq 'HASH') {
2660: foreach my $idx (keys(%{$dbcopies{$key}})) {
2661: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2662: my ($newurl,$result,$errtext) =
2663: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2664: if ($result eq 'ok') {
2665: $newdb{$idx} = $newurl;
2666: } elsif (ref($errors) eq 'HASH') {
2667: $errors->{$key} = 1;
2668: }
2669: push(@msgs,$errtext);
2670: }
2671: }
2672: }
2673: if (ref($resdatacopy{$key}) eq 'HASH') {
2674: if ($newsubdir{$key}) {
2675:
2676: }
2677: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2678: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2679: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2680: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2681: my $template = $1;
2682: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2683: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2684: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2685: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2686: my ($newmapname) = ($key =~ m{/([^/]+)$});
2687: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2688: my $srcmapinfo = $srcfolder.':'.$idx;
2689: if ($srccontainer eq 'page') {
2690: $srcmapinfo .= ':1';
2691: }
2692: if ($newsubdir{$key}) {
2693: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2694: }
2695: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2696: $cnum,$template,$idx,$newmapname);
2697: }
2698: }
2699: }
2700: }
2701: }
2702: if (ref($params{$key}) eq 'HASH') {
2703: %currparam = %{$params{$key}};
2704: }
2705: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2706: if ($fatal) {
2707: return ($errtext);
2708: }
2709: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2710: if (defined($LONCAPA::map::zombies[$i])) {
2711: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2712: if ($zombie{$i} eq $src) {
2713: undef($LONCAPA::map::zombies[$i]);
2714: }
2715: }
2716: }
2717: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2718: my $idx = $LONCAPA::map::order[$i];
2719: if (defined($LONCAPA::map::resources[$idx])) {
2720: my $changed;
2721: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2722: if ((exists($toremove{$idx})) &&
2723: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2724: splice(@LONCAPA::map::order,$i,1);
2725: if (ref($currparam{$idx}) eq 'ARRAY') {
2726: foreach my $name (@{$currparam{$idx}}) {
2727: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2728: }
2729: }
2730: next;
2731: }
2732: my $origsrc = $src;
2733: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2734: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2735: $changed = 1;
2736: }
2737: }
2738: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2739: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2740: if ($origsrc =~ m{^/uploaded/}) {
2741: if ($prefixchg && $before{'map'} && $after{'map'}) {
2742: if ($src =~ /\.(page|sequence)$/) {
2743: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2744: } else {
2745: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2746: }
2747: }
2748: if ($origsrc =~ /\.(page|sequence)$/) {
2749: if ($newsubdir{$origsrc}) {
2750: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2751: }
2752: } elsif ($newsubdir{$key}) {
2753: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2754: }
2755: }
2756: $changed = 1;
2757: } elsif ($newdb{$idx} ne '') {
2758: $src = $newdb{$idx};
2759: $changed = 1;
2760: }
2761: if ($changed) {
2762: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2763: }
2764: }
2765: }
2766: foreach my $idx (keys(%remparam)) {
2767: if (ref($remparam{$idx}) eq 'ARRAY') {
2768: foreach my $name (@{$remparam{$idx}}) {
2769: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2770: }
2771: }
2772: }
2773: if (values(%lockerrors) > 0) {
2774: $lockmsg = join('<br />',values(%lockerrors));
2775: }
2776: my $storefn;
2777: if ($key eq $oldurl) {
2778: $storefn = $url;
2779: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2780: } else {
2781: $storefn = $key;
2782: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2783: if ($prefixchg && $before{'map'} && $after{'map'}) {
2784: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2785: }
2786: if ($newsubdir{$key}) {
2787: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2788: }
2789: }
2790: my $report;
2791: if ($folder !~ /^supplemental/) {
2792: $report = 1;
2793: }
2794: (my $outtext,$errtext) =
2795: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2796: if ($errtext) {
2797: if ($caller eq 'paste') {
2798: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2799: }
2800: }
2801: }
2802: }
2803: return ('ok',\@msgs,$lockmsg);
2804: }
2805:
2806: sub copy_dependencies {
2807: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2808: my $content;
2809: if (ref($contentref)) {
2810: $content = $$contentref;
2811: } else {
2812: $content = &Apache::lonnet::getfile($item);
2813: }
2814: unless ($content eq '-1') {
2815: my $mm = new File::MMagic;
2816: my $mimetype = $mm->checktype_contents($content);
2817: if ($mimetype eq 'text/html') {
2818: my (%allfiles,%codebase,$state);
2819: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2820: if ($res eq 'ok') {
2821: my ($numexisting,$numpathchanges,$existing);
2822: (undef,$numexisting,$numpathchanges,$existing) =
2823: &Apache::loncommon::ask_for_embedded_content(
2824: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2825: {'error_on_invalid_names' => 1,
2826: 'ignore_remote_references' => 1,
2827: 'docs_url' => $item,
2828: 'context' => 'paste'});
2829: if ($numexisting > 0) {
2830: if (ref($existing) eq 'HASH') {
2831: foreach my $dep (keys(%{$existing})) {
2832: my $depfile = $dep;
2833: unless ($depfile =~ m{^\Q$relpath\E}) {
2834: $depfile = $relpath.$dep;
2835: }
2836: my $depcontent = &Apache::lonnet::getfile($depfile);
2837: unless ($depcontent eq '-1') {
2838: my $storedep = $dep;
2839: $storedep =~ s{^\Q$relpath\E}{};
2840: my $dep_url =
2841: &Apache::lonclonecourse::writefile(
2842: $env{'request.course.id'},
2843: $storefn.$storedep,$depcontent);
2844: if ($dep_url eq '/adm/notfound.html') {
2845: if (ref($errors) eq 'HASH') {
2846: $errors->{$depfile} = 1;
2847: }
2848: } else {
2849: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2850: }
2851: }
2852: }
2853: }
2854: }
2855: }
2856: }
2857: }
2858: return;
2859: }
2860:
2861: my %parameter_type = ( 'randompick' => 'int_pos',
2862: 'hiddenresource' => 'string_yesno',
2863: 'encrypturl' => 'string_yesno',
2864: 'randomorder' => 'string_yesno',);
2865: my $valid_parameters_re = join('|',keys(%parameter_type));
2866: # set parameters
2867: sub update_parameter {
2868: if ($env{'form.changeparms'} eq 'all') {
2869: my (@allidx,@allmapidx,%allchecked,%currchecked);
2870: %allchecked = (
2871: 'hiddenresource' => {},
2872: 'encrypturl' => {},
2873: 'randompick' => {},
2874: 'randomorder' => {},
2875: );
2876: foreach my $which (keys(%allchecked)) {
2877: $env{'form.all'.$which} =~ s/,$//;
2878: if ($which eq 'randompick') {
2879: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2880: my ($res,$value) = split(/:/,$item);
2881: if ($value =~ /^\d+$/) {
2882: $allchecked{$which}{$res} = $value;
2883: }
2884: }
2885: } else {
2886: if ($env{'form.all'.$which}) {
2887: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2888: }
2889: }
2890: }
2891: my $haschanges = 0;
2892: foreach my $res (@LONCAPA::map::order) {
2893: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2894: $name=&LONCAPA::map::qtescape($name);
2895: $url=&LONCAPA::map::qtescape($url);
2896: next unless ($name && $url);
2897: my $is_map;
2898: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2899: $is_map = 1;
2900: }
2901: foreach my $which (keys(%allchecked)) {
2902: if (($which eq 'randompick' || $which eq 'randomorder')) {
2903: next if (!$is_map);
2904: }
2905: my $oldvalue = 0;
2906: my $newvalue = 0;
2907: if ($allchecked{$which}{$res}) {
2908: $newvalue = $allchecked{$which}{$res};
2909: }
2910: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2911: if ($which eq 'randompick') {
2912: if ($current =~ /^(\d+)$/) {
2913: $oldvalue = $1;
2914: }
2915: } else {
2916: if ($current =~ /^yes$/i) {
2917: $oldvalue = 1;
2918: }
2919: }
2920: if ($oldvalue ne $newvalue) {
2921: $haschanges = 1;
2922: if ($newvalue) {
2923: my $storeval = 'yes';
2924: if ($which eq 'randompick') {
2925: $storeval = $newvalue;
2926: }
2927: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2928: $storeval,
2929: $parameter_type{$which});
2930: &remember_parms($res,$which,'set',$storeval);
2931: } elsif ($oldvalue) {
2932: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2933: &remember_parms($res,$which,'del');
2934: }
2935: }
2936: }
2937: }
2938: return $haschanges;
2939: } else {
2940: my $haschanges = 0;
2941: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
2942:
2943: my $which = $env{'form.changeparms'};
2944: my $idx = $env{'form.setparms'};
2945: my $oldvalue = 0;
2946: my $newvalue = 0;
2947: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2948: if ($which eq 'randompick') {
2949: if ($current =~ /^(\d+)$/) {
2950: $oldvalue = $1;
2951: }
2952: } elsif ($current =~ /^yes$/i) {
2953: $oldvalue = 1;
2954: }
2955: if ($env{'form.'.$which.'_'.$idx}) {
2956: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2957: : 1;
2958: }
2959: if ($oldvalue ne $newvalue) {
2960: $haschanges = 1;
2961: if ($newvalue) {
2962: my $storeval = 'yes';
2963: if ($which eq 'randompick') {
2964: $storeval = $newvalue;
2965: }
2966: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2967: $parameter_type{$which});
2968: &remember_parms($idx,$which,'set',$storeval);
2969: } else {
2970: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2971: &remember_parms($idx,$which,'del');
2972: }
2973: }
2974: return $haschanges;
2975: }
2976: }
2977:
2978: sub handle_edit_cmd {
2979: my ($coursenum,$coursedom) =@_;
2980: if ($env{'form.cmd'} eq '') {
2981: return 0;
2982: }
2983: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2984:
2985: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2986: my ($title, $url, @rrest) = split(':', $ratstr);
2987:
2988: if ($cmd eq 'remove') {
2989: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2990: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2991: &Apache::lonnet::removeuploadedurl($url);
2992: } else {
2993: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2994: }
2995: splice(@LONCAPA::map::order, $idx, 1);
2996:
2997: } elsif ($cmd eq 'cut') {
2998: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2999: splice(@LONCAPA::map::order, $idx, 1);
3000:
3001: } elsif ($cmd eq 'up'
3002: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3003: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3004:
3005: } elsif ($cmd eq 'down'
3006: && defined($LONCAPA::map::order[$idx+1])) {
3007: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3008:
3009: } elsif ($cmd eq 'rename') {
3010: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3011: if ($comment=~/\S/) {
3012: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3013: $comment.':'.join(':', $url, @rrest);
3014: }
3015: # Devalidate title cache
3016: my $renamed_url=&LONCAPA::map::qtescape($url);
3017: &Apache::lonnet::devalidate_title_cache($renamed_url);
3018:
3019: } else {
3020: return 0;
3021: }
3022: return 1;
3023: }
3024:
3025: sub editor {
3026: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3027: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3028: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3029: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3030: if ($allowed) {
3031: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3032: $is_random_order,$container) =
3033: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3034: $r->print($breadcrumbtrail);
3035: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3036: $container = 'page';
3037: } else {
3038: $container = 'sequence';
3039: }
3040:
3041: my $jumpto;
3042:
3043: unless ($supplementalflag) {
3044: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3045: }
3046:
3047: unless ($allowed) {
3048: $randompick = -1;
3049: }
3050:
3051: my ($errtext,$fatal);
3052: if (($folder eq '') && (!$supplementalflag)) {
3053: if (@LONCAPA::map::order) {
3054: undef(@LONCAPA::map::order);
3055: undef(@LONCAPA::map::resources);
3056: undef(@LONCAPA::map::resparms);
3057: undef(@LONCAPA::map::zombies);
3058: }
3059: $folder = 'default';
3060: $container = 'sequence';
3061: } else {
3062: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3063: $folder.'.'.$container);
3064: return $errtext if ($fatal);
3065: }
3066:
3067: if ($#LONCAPA::map::order<1) {
3068: my $idx=&LONCAPA::map::getresidx();
3069: if ($idx<=0) { $idx=1; }
3070: $LONCAPA::map::order[0]=$idx;
3071: $LONCAPA::map::resources[$idx]='';
3072: }
3073:
3074: # ------------------------------------------------------------ Process commands
3075:
3076: # ---------------- if they are for this folder and user allowed to make changes
3077: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3078: # set parameters and change order
3079: &snapshotbefore();
3080:
3081: if (&update_parameter()) {
3082: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3083: return $errtext if ($fatal);
3084: }
3085:
3086: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3087: # change order
3088: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3089: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3090:
3091: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3092: return $errtext if ($fatal);
3093: }
3094:
3095: if ($env{'form.pastemarked'}) {
3096: my %paste_errors;
3097: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3098: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3099: \%paste_errors);
3100: if (ref($pastemsgarray) eq 'ARRAY') {
3101: if (@{$pastemsgarray} > 0) {
3102: $r->print('<p class="LC_info">'.
3103: join('<br />',@{$pastemsgarray}).
3104: '</p>');
3105: }
3106: }
3107: if ($lockerror) {
3108: $r->print('<p class="LC_error">'.
3109: $lockerror.
3110: '</p>');
3111: }
3112: if ($save_error ne '') {
3113: return $save_error;
3114: }
3115: if ($paste_res) {
3116: my %errortext = &Apache::lonlocal::texthash (
3117: fail => 'Storage of folder contents failed',
3118: failread => 'Reading folder contents failed',
3119: failstore => 'Storage of folder contents failed',
3120: );
3121: if ($errortext{$paste_res}) {
3122: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3123: }
3124: }
3125: if (keys(%paste_errors) > 0) {
3126: $r->print('<p class="LC_warning">'."\n".
3127: &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".
3128: '<ul>'."\n");
3129: foreach my $key (sort(keys(%paste_errors))) {
3130: $r->print('<li>'.$key.'</li>'."\n");
3131: }
3132: $r->print('</ul></p>'."\n");
3133: }
3134: } elsif ($env{'form.clearmarked'}) {
3135: my $output = &do_buffer_empty();
3136: if ($output) {
3137: $r->print('<p class="LC_info">'.$output.'</p>');
3138: }
3139: }
3140:
3141: $r->print($upload_output);
3142:
3143: # Rename, cut, copy or remove a single resource
3144: if (&handle_edit_cmd($coursenum,$coursedom)) {
3145: my $contentchg;
3146: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
3147: $contentchg = 1;
3148: }
3149: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3150: return $errtext if ($fatal);
3151: }
3152:
3153: # Cut, copy and/or remove multiple resources
3154: if ($env{'form.multichange'}) {
3155: my %allchecked = (
3156: cut => {},
3157: remove => {},
3158: );
3159: my $needsupdate;
3160: foreach my $which (keys(%allchecked)) {
3161: $env{'form.multi'.$which} =~ s/,$//;
3162: if ($env{'form.multi'.$which}) {
3163: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3164: if (ref($allchecked{$which}) eq 'HASH') {
3165: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3166: }
3167: }
3168: }
3169: if ($needsupdate) {
3170: my $haschanges = 0;
3171: my %curr_groups = &Apache::longroup::coursegroups();
3172: my $total = scalar(@LONCAPA::map::order) - 1;
3173: for (my $i=$total; $i>=0; $i--) {
3174: my $res = $LONCAPA::map::order[$i];
3175: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3176: $name=&LONCAPA::map::qtescape($name);
3177: $url=&LONCAPA::map::qtescape($url);
3178: next unless $url;
3179: my %denied =
3180: &action_restrictions($coursenum,$coursedom,$url,
3181: $env{'form.folderpath'},\%curr_groups);
3182: foreach my $which (keys(%allchecked)) {
3183: next if ($denied{$which});
3184: next unless ($allchecked{$which}{$res});
3185: if ($which eq 'remove') {
3186: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3187: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3188: &Apache::lonnet::removeuploadedurl($url);
3189: } else {
3190: &LONCAPA::map::makezombie($res);
3191: }
3192: splice(@LONCAPA::map::order,$i,1);
3193: $haschanges ++;
3194: } elsif ($which eq 'cut') {
3195: &LONCAPA::map::makezombie($res);
3196: splice(@LONCAPA::map::order,$i,1);
3197: $haschanges ++;
3198: }
3199: }
3200: }
3201: if ($haschanges) {
3202: ($errtext,$fatal) =
3203: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3204: return $errtext if ($fatal);
3205: }
3206: }
3207: }
3208:
3209: # Group import/search
3210: if ($env{'form.importdetail'}) {
3211: my @imports;
3212: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3213: if (defined($item)) {
3214: my ($name,$url,$residx)=
3215: map { &unescape($_); } split(/\=/,$item);
3216: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3217: my ($suffix,$errortxt,$locknotfreed) =
3218: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3219: if ($locknotfreed) {
3220: $r->print($locknotfreed);
3221: }
3222: if ($suffix) {
3223: $url =~ s/_new\./_$suffix./;
3224: } else {
3225: return $errortxt;
3226: }
3227: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3228: my $type = $1;
3229: my ($suffix,$errortxt,$locknotfreed) =
3230: &new_timebased_suffix($coursedom,$coursenum,$type);
3231: if ($locknotfreed) {
3232: $r->print($locknotfreed);
3233: }
3234: if ($suffix) {
3235: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3236: } else {
3237: return $errortxt;
3238: }
3239: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3240: my ($suffix,$errortxt,$locknotfreed) =
3241: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3242: if ($locknotfreed) {
3243: $r->print($locknotfreed);
3244: }
3245: if ($suffix) {
3246: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3247: } else {
3248: return $errortxt;
3249: }
3250: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3251: if ($supplementalflag) {
3252: next unless ($1 eq 'supplemental');
3253: if ($folder eq 'supplemental') {
3254: next unless ($2 eq 'default');
3255: } else {
3256: next unless ($folder eq 'supplemental_'.$2);
3257: }
3258: } else {
3259: next unless ($1 eq 'docs');
3260: if ($folder eq 'default') {
3261: next unless ($2 eq 'default');
3262: } else {
3263: next unless ($folder eq 'default_'.$2);
3264: }
3265: }
3266: }
3267: push(@imports, [$name, $url, $residx]);
3268: }
3269: }
3270: ($errtext,$fatal,my $fixuperrors) =
3271: &group_import($coursenum, $coursedom, $folder,$container,
3272: 'londocs',$ltitoolsref,@imports);
3273: return $errtext if ($fatal);
3274: if ($fixuperrors) {
3275: $r->print($fixuperrors);
3276: }
3277: }
3278: # Loading a complete map
3279: if ($env{'form.loadmap'}) {
3280: if ($env{'form.importmap'}=~/\w/) {
3281: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3282: my ($title,$url,$ext,$type)=split(/\:/,$res);
3283: my $idx=&LONCAPA::map::getresidx($url);
3284: $LONCAPA::map::resources[$idx]=$res;
3285: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3286: }
3287: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3288: $folder.'.'.$container,1);
3289: return $errtext if ($fatal);
3290: } else {
3291: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3292:
3293: }
3294: }
3295: &log_differences($plain);
3296: }
3297: # ---------------------------------------------------------------- End commands
3298: # ---------------------------------------------------------------- Print screen
3299: my $idx=0;
3300: my $shown=0;
3301: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3302: $r->print('<div class="LC_Box">'.
3303: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3304: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3305: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3306: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3307: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3308: '</ol>');
3309: if ($randompick>=0) {
3310: $r->print('<p class="LC_warning">'
3311: .&mt('Caution: this folder is set to randomly pick a subset'
3312: .' of resources. Adding or removing resources from this'
3313: .' folder will change the set of resources that the'
3314: .' students see, resulting in spurious or missing credit'
3315: .' for completed problems, not limited to ones you'
3316: .' modify. Do not modify the contents of this folder if'
3317: .' it is in active student use.')
3318: .'</p>'
3319: );
3320: }
3321: if ($is_random_order) {
3322: $r->print('<p class="LC_warning">'
3323: .&mt('Caution: this folder is set to randomly order its'
3324: .' contents. Adding or removing resources from this folder'
3325: .' will change the order of resources shown.')
3326: .'</p>'
3327: );
3328: }
3329: $r->print('</div>');
3330: }
3331:
3332: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3333: %filters = (
3334: canremove => [],
3335: cancut => [],
3336: cancopy => [],
3337: hiddenresource => [],
3338: encrypturl => [],
3339: randomorder => [],
3340: randompick => [],
3341: );
3342: %curr_groups = &Apache::longroup::coursegroups();
3343: &Apache::loncommon::start_data_table_count(); #setup a row counter
3344: foreach my $res (@LONCAPA::map::order) {
3345: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3346: $name=&LONCAPA::map::qtescape($name);
3347: $url=&LONCAPA::map::qtescape($url);
3348: unless ($name) { $name=(split(/\//,$url))[-1]; }
3349: unless ($name) { $idx++; next; }
3350: push(@allidx,$res);
3351: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3352: push(@allmapidx,$res);
3353: }
3354:
3355: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3356: $coursenum,$coursedom,$crstype,
3357: $pathitem,$supplementalflag,$container,
3358: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3359: $isencrypted,$navmapref,$hostname);
3360: $idx++;
3361: $shown++;
3362: }
3363: &Apache::loncommon::end_data_table_count();
3364:
3365: my $need_save;
3366: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3367: my $toolslink;
3368: if ($allowed) {
3369: $toolslink = '<table><tr><td>'
3370: .&Apache::loncommon::help_open_menu('Navigation Screen',
3371: 'Navigation_Screen',undef,'RAT')
3372: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3373: .'<td align="left"><ul id="LC_toolbar">'
3374: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3375: .'id="LC_content_toolbar_edittoplevel" '
3376: .'class="LC_toolbarItem" '
3377: .'title="'.&mt('Supplemental Content Editor').'">'
3378: .'</a></li></ul></td></tr></table><br />';
3379: }
3380: if ($shown) {
3381: if ($allowed) {
3382: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3383: .&Apache::loncommon::start_data_table(undef,'contentlist')
3384: .&Apache::loncommon::start_data_table_header_row()
3385: .'<th colspan="2">'.&mt('Move').'</th>'
3386: .'<th colspan="2">'.&mt('Actions').'</th>'
3387: .'<th>'.&mt('Document').'</th>';
3388: if ($folder !~ /^supplemental/) {
3389: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3390: }
3391: $to_show .= &Apache::loncommon::end_data_table_header_row();
3392: if ($folder !~ /^supplemental/) {
3393: $lists{'canhide'} = join(',',@allidx);
3394: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3395: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3396: 'randomorder','randompick');
3397: foreach my $item (@possfilters) {
3398: if (ref($filters{$item}) eq 'ARRAY') {
3399: if (@{$filters{$item}} > 0) {
3400: $lists{$item} = join(',',@{$filters{$item}});
3401: }
3402: }
3403: }
3404: if (@allidx > 0) {
3405: my $path;
3406: if ($env{'form.folderpath'}) {
3407: $path =
3408: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3409: }
3410: if (@allidx > 1) {
3411: $to_show .=
3412: &Apache::loncommon::continue_data_table_row().
3413: '<td colspan="2"> </td>'.
3414: '<td>'.
3415: &multiple_check_form('actions',\%lists,$canedit).
3416: '</td>'.
3417: '<td> </td>'.
3418: '<td> </td>'.
3419: '<td colspan="4">'.
3420: &multiple_check_form('settings',\%lists,$canedit).
3421: '</td>'.
3422: &Apache::loncommon::end_data_table_row();
3423: $need_save = 1;
3424: }
3425: }
3426: }
3427: $to_show .= $output.' '
3428: .&Apache::loncommon::end_data_table()
3429: .'<br style="line-height:2px;" />'
3430: .&Apache::loncommon::end_scrollbox();
3431: } else {
3432: $to_show .= $toolslink
3433: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3434: .$output.' '
3435: .&Apache::loncommon::end_data_table();
3436: }
3437: } else {
3438: if (!$allowed) {
3439: $to_show .= $toolslink;
3440: }
3441: my $noresmsg;
3442: if ($allowed && $hiddentop && !$supplementalflag) {
3443: $noresmsg = &mt('Main Content Hidden');
3444: } else {
3445: $noresmsg = &mt('Currently empty');
3446: }
3447: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3448: .'<div class="LC_info" id="contentlist">'
3449: .$noresmsg
3450: .'</div>'
3451: .&Apache::loncommon::end_scrollbox();
3452: }
3453: } else {
3454: if ($shown) {
3455: $to_show = '<div>'
3456: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3457: .$output
3458: .&Apache::loncommon::end_data_table()
3459: .'</div>';
3460: } else {
3461: $to_show = '<div class="LC_info" id="contentlist">'
3462: .&mt('Currently empty')
3463: .'</div>'
3464: }
3465: }
3466: my $tid = 1;
3467: if ($supplementalflag) {
3468: $tid = 2;
3469: }
3470: if ($allowed) {
3471: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3472: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3473: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3474: if ($canedit) {
3475: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3476: }
3477: } else {
3478: $r->print($to_show);
3479: }
3480: return;
3481: }
3482:
3483: sub multiple_check_form {
3484: my ($caller,$listsref,$canedit) = @_;
3485: return unless (ref($listsref) eq 'HASH');
3486: my $disabled;
3487: unless ($canedit) {
3488: $disabled = 'disabled="disabled"';
3489: }
3490: my $output =
3491: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3492: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3493: '<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>'.
3494: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3495: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3496: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3497: if ($caller eq 'settings') {
3498: $output .=
3499: '<table><tr>'.
3500: '<td class="LC_docs_entry_parameter">'.
3501: '<span class="LC_nobreak"><label>'.
3502: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3503: '</label></span></td>'.
3504: '<td class="LC_docs_entry_parameter">'.
3505: '<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="" />'.
3506: '</span></td>'.
3507: '</tr>'."\n".
3508: '<tr>'.
3509: '<td class="LC_docs_entry_parameter">'.
3510: '<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').
3511: '</label></span>'.
3512: '</td></tr></table>'."\n";
3513: } else {
3514: $output .=
3515: '<table><tr>'.
3516: '<td class="LC_docs_entry_parameter">'.
3517: '<span class="LC_nobreak LC_docs_remove">'.
3518: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3519: '</label></span></td>'.
3520: '<td class="LC_docs_entry_parameter">'.
3521: '<span class="LC_nobreak LC_docs_cut">'.
3522: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3523: '</label></span></td>'."\n".
3524: '<td class="LC_docs_entry_parameter">'.
3525: '<span class="LC_nobreak LC_docs_copy">'.
3526: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3527: '</label></span></td>'.
3528: '</tr></table>'."\n";
3529: }
3530: $output .=
3531: '</fieldset>'.
3532: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3533: if ($caller eq 'settings') {
3534: $output .=
3535: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3536: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3537: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3538: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3539: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3540: } elsif ($caller eq 'actions') {
3541: $output .=
3542: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3543: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3544: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3545: }
3546: $output .=
3547: '</form>'.
3548: '</div>';
3549: return $output;
3550: }
3551:
3552: sub process_file_upload {
3553: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3554: # upload a file, if present
3555: my $filesize = length($env{'form.uploaddoc'});
3556: if (!$filesize) {
3557: $$upload_output = '<div class="LC_error">'.
3558: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3559: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3560: $filesize).'<br />'.
3561: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3562: '</div>';
3563: return;
3564: }
3565: my $quotatype = 'unofficial';
3566: if ($crstype eq 'Community') {
3567: $quotatype = 'community';
3568: } elsif ($crstype eq 'Placement') {
3569: $quotatype = 'placement';
3570: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3571: $quotatype = 'official';
3572: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3573: $quotatype = 'textbook';
3574: }
3575: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3576: $filesize = int($filesize/1000); #expressed in kb
3577: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3578: $env{'form.uploaddoc.filename'},$filesize,
3579: 'upload',$quotatype);
3580: return if ($$upload_output);
3581: }
3582: my ($parseaction,$showupload,$nextphase,$mimetype);
3583: if ($env{'form.parserflag'}) {
3584: $parseaction = 'parse';
3585: }
3586: my $folder=$env{'form.folder'};
3587: if ($folder eq '') {
3588: $folder='default';
3589: }
3590: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3591: my $errtext='';
3592: my $fatal=0;
3593: my $container='sequence';
3594: if ($env{'form.folderpath'} =~ /:1$/) {
3595: $container='page';
3596: }
3597: ($errtext,$fatal)=
3598: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3599: if ($#LONCAPA::map::order<1) {
3600: $LONCAPA::map::order[0]=1;
3601: $LONCAPA::map::resources[1]='';
3602: }
3603: my $destination = 'docs/';
3604: if ($folder =~ /^supplemental/) {
3605: $destination = 'supplemental/';
3606: }
3607: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3608: $destination .= 'default/';
3609: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3610: $destination .= $2.'/';
3611: }
3612: if ($fatal) {
3613: $$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>';
3614: return;
3615: }
3616: # this is for a course, not a user, so set context to coursedoc.
3617: my $newidx=&LONCAPA::map::getresidx();
3618: $destination .= $newidx;
3619: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3620: $parseaction,$allfiles,
3621: $codebase,undef,undef,undef,undef,
3622: undef,undef,\$mimetype);
3623: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3624: my $stored = $1;
3625: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3626: $stored.'</span>').'</p>';
3627: } else {
3628: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3629:
3630: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3631: return;
3632: }
3633: my $ext='false';
3634: if ($url=~m{^http://}) { $ext='true'; }
3635: $url = &LONCAPA::map::qtunescape($url);
3636: my $comment=$env{'form.comment'};
3637: $comment = &LONCAPA::map::qtunescape($comment);
3638: if ($folder=~/^supplemental/) {
3639: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3640: $env{'user.domain'}.'___&&&___'.$comment;
3641: }
3642:
3643: $LONCAPA::map::resources[$newidx]=
3644: $comment.':'.$url.':'.$ext.':normal:res';
3645: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3646: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3647: $folder.'.'.$container,1);
3648: if ($fatal) {
3649: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3650: return;
3651: } else {
3652: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3653: $$upload_output = $showupload;
3654: my $total_embedded = scalar(keys(%{$allfiles}));
3655: if ($total_embedded > 0) {
3656: my $uploadphase = 'upload_embedded';
3657: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3658: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3659: my ($embedded,$num) =
3660: &Apache::loncommon::ask_for_embedded_content(
3661: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3662: if ($embedded) {
3663: if ($num) {
3664: $$upload_output .=
3665: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3666: $nextphase = $uploadphase;
3667: } else {
3668: $$upload_output .= $embedded;
3669: }
3670: } else {
3671: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3672: }
3673: } else {
3674: $$upload_output .= &mt('No embedded items identified').'<br />';
3675: }
3676: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3677: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3678: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3679: $nextphase = 'decompress_uploaded';
3680: my $position = scalar(@LONCAPA::map::order)-1;
3681: my $noextract = &return_to_editor();
3682: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3683: my %archiveitems = (
3684: folderpath => $env{'form.folderpath'},
3685: cmd => $nextphase,
3686: newidx => $newidx,
3687: position => $position,
3688: phase => $nextphase,
3689: comment => $comment,
3690: );
3691: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3692: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3693: $$upload_output = $showupload.
3694: &Apache::loncommon::decompress_form($mimetype,
3695: $archiveurl,'/adm/coursedocs',$noextract,
3696: \%archiveitems,\@current);
3697: }
3698: }
3699: }
3700: return $nextphase;
3701: }
3702:
3703: sub get_dir_list {
3704: my ($url,$coursenum,$coursedom,$newidx) = @_;
3705: my ($destination,$dir_root) = &embedded_destination();
3706: my ($dirlistref,$listerror) =
3707: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3708: my @dir_lines;
3709: my $dirptr=16384;
3710: if (ref($dirlistref) eq 'ARRAY') {
3711: foreach my $dir_line (sort
3712: {
3713: my ($afile)=split('&',$a,2);
3714: my ($bfile)=split('&',$b,2);
3715: return (lc($afile) cmp lc($bfile));
3716: } (@{$dirlistref})) {
3717: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3718: $filename =~ s/\s+$//;
3719: next if ($filename =~ /^\.\.?$/);
3720: my $isdir = 0;
3721: if ($dirptr&$testdir) {
3722: $isdir = 1;
3723: }
3724: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3725: }
3726: }
3727: return @dir_lines;
3728: }
3729:
3730: sub is_supplemental_title {
3731: my ($title) = @_;
3732: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3733: }
3734:
3735: # --------------------------------------------------------------- An entry line
3736:
3737: sub entryline {
3738: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3739: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3740: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
3741: my ($foldertitle,$renametitle,$oldtitle);
3742: if (&is_supplemental_title($title)) {
3743: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3744: } else {
3745: $title=&HTML::Entities::encode($title,'"<>&\'');
3746: $renametitle=$title;
3747: $foldertitle=$title;
3748: }
3749:
3750: my ($disabled,$readonly,$js_lt);
3751: unless ($canedit) {
3752: $disabled = 'disabled="disabled"';
3753: $readonly = 1;
3754: }
3755:
3756: my $orderidx=$LONCAPA::map::order[$index];
3757:
3758: $renametitle=~s/\\/\\\\/g;
3759: $renametitle=~s/\"\;/\\\"/g;
3760: $renametitle=~s/"/%22/g;
3761: $renametitle=~s/ /%20/g;
3762: $oldtitle = $renametitle;
3763: $renametitle=~s/\'/\\\'/g;
3764: my $line=&Apache::loncommon::start_data_table_row();
3765: my ($form_start,$form_end,$form_common,$form_param);
3766: # Edit commands
3767: my ($esc_path, $path, $symb);
3768: if ($env{'form.folderpath'}) {
3769: $esc_path=&escape($env{'form.folderpath'});
3770: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3771: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3772: }
3773: my $isexternal;
3774: if ($residx) {
3775: my $currurl = $url;
3776: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3777: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3778: $isexternal = 1;
3779: }
3780: if (!$supplementalflag) {
3781: my $path = 'uploaded/'.
3782: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3783: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3784: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3785: $residx,
3786: &Apache::lonnet::declutter($currurl));
3787: }
3788: }
3789: my ($renamelink,%lt,$ishash);
3790: if (ref($filtersref) eq 'HASH') {
3791: $ishash = 1;
3792: }
3793:
3794: if ($allowed) {
3795: $form_start = '
3796: <form action="/adm/coursedocs" method="post">
3797: ';
3798: $form_common=(<<END);
3799: <input type="hidden" name="folderpath" value="$path" />
3800: <input type="hidden" name="symb" value="$symb" />
3801: END
3802: $form_param=(<<END);
3803: <input type="hidden" name="setparms" value="$orderidx" />
3804: <input type="hidden" name="changeparms" value="0" />
3805: END
3806: $form_end = '</form>';
3807:
3808: my $incindex=$index+1;
3809: my $selectbox='';
3810: if (($#LONCAPA::map::order>0) &&
3811: ((split(/\:/,
3812: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3813: ne '') &&
3814: ((split(/\:/,
3815: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
3816: ne '')) {
3817: $selectbox=
3818: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
3819: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
3820: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3821: if ($i==$incindex) {
3822: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
3823: } else {
3824: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3825: }
3826: }
3827: $selectbox.='</select>';
3828: }
3829: %lt=&Apache::lonlocal::texthash(
3830: 'up' => 'Move Up',
3831: 'dw' => 'Move Down',
3832: 'rm' => 'Remove',
3833: 'ct' => 'Cut',
3834: 'rn' => 'Rename',
3835: 'cp' => 'Copy',
3836: 'ex' => 'External Resource',
3837: 'et' => 'External Tool',
3838: 'ed' => 'Edit',
3839: 'pr' => 'Preview',
3840: 'sv' => 'Save',
3841: 'ul' => 'URL',
3842: 'ti' => 'Title',
3843: 'er' => 'Editing rights unavailable for your current role.',
3844: );
3845: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3846: $env{'form.folderpath'},
3847: $currgroups);
3848: my ($copylink,$cutlink,$removelink);
3849: my $skip_confirm = 0;
3850: my $confirm_removal = 0;
3851: if ( $folder =~ /^supplemental/
3852: || ($url =~ m{( /smppg$
3853: |/syllabus$
3854: |/aboutme$
3855: |/navmaps$
3856: |/bulletinboard$
3857: |/exttools?$
3858: |\.html$)}x)
3859: || $isexternal) {
3860: $skip_confirm = 1;
3861: }
3862: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3863: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3864: $confirm_removal = 1;
3865: }
3866:
3867: if ($denied{'copy'}) {
3868: $copylink=(<<ENDCOPY)
3869: <span style="visibility: hidden;">$lt{'cp'}</span>
3870: ENDCOPY
3871: } else {
3872: my $formname = 'edit_copy_'.$orderidx;
3873: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3874: $copylink=(<<ENDCOPY);
3875: <form name="$formname" method="post" action="/adm/coursedocs">
3876: $form_common
3877: <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>
3878: $form_end
3879: ENDCOPY
3880: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3881: push(@{$filtersref->{'cancopy'}},$orderidx);
3882: }
3883: }
3884: if ($denied{'cut'}) {
3885: $cutlink=(<<ENDCUT);
3886: <span style="visibility: hidden;">$lt{'ct'}</span>
3887: ENDCUT
3888: } else {
3889: my $formname = 'edit_cut_'.$orderidx;
3890: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3891: $cutlink=(<<ENDCUT);
3892: <form name="$formname" method="post" action="/adm/coursedocs">
3893: $form_common
3894: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
3895: <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>
3896: $form_end
3897: ENDCUT
3898: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3899: push(@{$filtersref->{'cancut'}},$orderidx);
3900: }
3901: }
3902: if ($denied{'remove'}) {
3903: $removelink=(<<ENDREM);
3904: <span style="visibility: hidden;">$lt{'rm'}</a>
3905: ENDREM
3906: } else {
3907: my $formname = 'edit_remove_'.$orderidx;
3908: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
3909: $removelink=(<<ENDREM);
3910: <form name="$formname" method="post" action="/adm/coursedocs">
3911: $form_common
3912: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
3913: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
3914: <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>
3915: $form_end
3916: ENDREM
3917: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3918: push(@{$filtersref->{'canremove'}},$orderidx);
3919: }
3920: }
3921: $renamelink=(<<ENDREN);
3922: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
3923: ENDREN
3924: my ($uplink,$downlink);
3925: if ($canedit) {
3926: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3927: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3928: } else {
3929: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3930: $downlink = $uplink;
3931: }
3932: $line.=(<<END);
3933: <td>
3934: <div class="LC_docs_entry_move">
3935: <a href="$uplink">
3936: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
3937: </a>
3938: </div>
3939: <div class="LC_docs_entry_move">
3940: <a href="$downlink">
3941: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
3942: </a>
3943: </div>
3944: </td>
3945: <td>
3946: $form_start
3947: $form_param
3948: $form_common
3949: $selectbox
3950: $form_end
3951: </td>
3952: <td class="LC_docs_entry_commands LC_nobreak">
3953: $removelink
3954: $cutlink
3955: $copylink
3956: </td>
3957: END
3958: }
3959: # Figure out what kind of a resource this is
3960: my ($extension)=($url=~/\.(\w+)$/);
3961: my $uploaded=($url=~/^\/*uploaded\//);
3962: my $icon=&Apache::loncommon::icon($url);
3963: my $isfolder;
3964: my $ispage;
3965: my $containerarg;
3966: my $folderurl;
3967: if ($uploaded) {
3968: if (($extension eq 'sequence') || ($extension eq 'page')) {
3969: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
3970: $containerarg = $1;
3971: if ($extension eq 'sequence') {
3972: $icon=$iconpath.'navmap.folder.closed.gif';
3973: $isfolder=1;
3974: } else {
3975: $icon=$iconpath.'page.gif';
3976: $ispage=1;
3977: }
3978: $folderurl = &Apache::lonnet::declutter($url);
3979: if ($allowed) {
3980: $url='/adm/coursedocs?';
3981: } else {
3982: $url='/adm/supplemental?';
3983: }
3984: } else {
3985: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3986: }
3987: }
3988:
3989: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
3990: my $orig_url = $url;
3991: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
3992: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3993: if (!$supplementalflag && $residx && $symb) {
3994: if ((!$isfolder) && (!$ispage)) {
3995: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3996: $url=&Apache::lonnet::clutter($url);
3997: if ($url=~/^\/*uploaded\//) {
3998: $url=~/\.(\w+)$/;
3999: my $embstyle=&Apache::loncommon::fileembstyle($1);
4000: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4001: $url='/adm/wrapper'.$url;
4002: } elsif ($embstyle eq 'ssi') {
4003: #do nothing with these
4004: } elsif ($url!~/\.(sequence|page)$/) {
4005: $url='/adm/coursedocs/showdoc'.$url;
4006: }
4007: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4008: my $wrapped = $1;
4009: my $exturl = $2;
4010: if ($wrapped eq '') {
4011: $url='/adm/wrapper'.$url;
4012: }
4013: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4014: $nomodal = 1;
4015: }
4016: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4017: $url='/adm/wrapper'.$url;
4018: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4019: if (($ENV{'SERVER_PORT'} == 443) &&
4020: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4021: $url .= '?usehttp=1';
4022: $nomodal = 1;
4023: }
4024: }
4025: if (&Apache::lonnet::symbverify($symb,$url)) {
4026: my $shownsymb = $symb;
4027: if ($isexternal) {
4028: if ($url =~ /^([^#]+)#([^#]+)$/) {
4029: $url = $1;
4030: $anchor = $2;
4031: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4032: $shownsymb = $1.&escape('#').$anchor;
4033: }
4034: }
4035: }
4036: unless ($env{'request.role.adv'}) {
4037: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4038: $url = '';
4039: }
4040: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4041: $url = '';
4042: $hiddenres = 1;
4043: }
4044: }
4045: if ($url ne '') {
4046: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4047: }
4048: } elsif (!$env{'request.role.adv'}) {
4049: my $checkencrypt;
4050: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4051: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4052: $checkencrypt = 1;
4053: } elsif (ref($navmapref)) {
4054: unless (ref($$navmapref)) {
4055: $$navmapref = Apache::lonnavmaps::navmap->new();
4056: }
4057: if (ref($$navmapref)) {
4058: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4059: $checkencrypt = 1;
4060: }
4061: }
4062: }
4063: if ($checkencrypt) {
4064: my $shownsymb = &Apache::lonenc::encrypted($symb);
4065: my $shownurl = &Apache::lonenc::encrypted($url);
4066: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4067: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4068: if ($env{'request.enc'} ne '') {
4069: delete($env{'request.enc'});
4070: }
4071: } else {
4072: $url='';
4073: }
4074: } else {
4075: $url='';
4076: }
4077: } else {
4078: $url='';
4079: }
4080: }
4081: } elsif ($supplementalflag) {
4082: if ($isexternal) {
4083: if ($url =~ /^([^#]+)#([^#]+)$/) {
4084: $url = $1;
4085: $anchor = $2;
4086: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4087: if ($hostname ne '') {
4088: $url = 'http://'.$hostname.$url;
4089: }
4090: $nomodal = 1;
4091: }
4092: }
4093: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4094: if (($ENV{'SERVER_PORT'} == 443) &&
4095: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4096: if ($hostname ne '') {
4097: $url = 'http://'.$hostname.$url;
4098: }
4099: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4100: $nomodal = 1;
4101: }
4102: }
4103: }
4104: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4105: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4106: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4107: my $foldername=&escape($foldertitle);
4108: my $folderpath=$env{'form.folderpath'};
4109: if ($folderpath) { $folderpath.='&' };
4110: if (!$allowed && $supplementalflag) {
4111: $folderpath.=$containerarg.'&'.$foldername;
4112: $url.='folderpath='.&escape($folderpath);
4113: } else {
4114: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4115: 'parameter_randompick'))[0];
4116: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4117: 'parameter_randomorder'))[0]=~/^yes$/i);
4118: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4119: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4120: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4121: 'parameter_encrypturl'))[0]=~/^yes$/i);
4122: unless ($hiddenmap) {
4123: if (ref($navmapref)) {
4124: unless (ref($$navmapref)) {
4125: $$navmapref = Apache::lonnavmaps::navmap->new();
4126: }
4127: if (ref($$navmapref)) {
4128: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4129: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4130: unless (@resources) {
4131: $hiddenmap = 1;
4132: unless ($env{'request.role.adv'}) {
4133: $url = '';
4134: $hiddenfolder = 1;
4135: }
4136: }
4137: }
4138: }
4139: }
4140: }
4141: unless ($encryptmap) {
4142: if ((ref($navmapref)) && (ref($$navmapref))) {
4143: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4144: $encryptmap = 1;
4145: }
4146: }
4147: }
4148:
4149: # Append randompick number, hidden, and encrypted with ":" to foldername,
4150: # so it gets transferred between levels
4151: $folderpath.=$containerarg.'&'.$foldername.
4152: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4153: unless ($url eq '') {
4154: $url.='folderpath='.&escape($folderpath);
4155: }
4156: my $rpckchk;
4157: if ($rpicknum) {
4158: $rpckchk = ' checked="checked"';
4159: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4160: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4161: }
4162: }
4163: my $formname = 'edit_randompick_'.$orderidx;
4164: $rand_pick_text =
4165: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4166: $form_param."\n".
4167: $form_common."\n".
4168: '<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.'">';
4169: if ($rpicknum ne '') {
4170: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4171: }
4172: $rand_pick_text .= '</span></span>'.
4173: $form_end;
4174: my $ro_set;
4175: if ($randorder) {
4176: $ro_set = 'checked="checked"';
4177: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4178: push(@{$filtersref->{'randomorder'}},$orderidx);
4179: }
4180: }
4181: $formname = 'edit_rorder_'.$orderidx;
4182: $rand_order_text =
4183: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4184: $form_param."\n".
4185: $form_common."\n".
4186: '<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>'.
4187: $form_end;
4188: }
4189: } elsif ($supplementalflag && !$allowed) {
4190: my $isexttool;
4191: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4192: $url='/adm/wrapper'.$url;
4193: $isexttool = 1;
4194: }
4195: $url .= ($url =~ /\?/) ? '&':'?';
4196: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4197: if ($title) {
4198: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4199: }
4200: if ((($isexternal) || ($isexttool)) && $orderidx) {
4201: $url .= '&idx='.$orderidx;
4202: }
4203: if ($anchor ne '') {
4204: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4205: }
4206: }
4207: my ($tdalign,$tdwidth);
4208: if ($allowed) {
4209: my $fileloc =
4210: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4211: if ($isexternal) {
4212: ($editlink,$extresform) =
4213: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4214: undef,undef,undef,undef,undef,undef,
4215: undef,$disabled);
4216: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4217: ($editlink,$extresform) =
4218: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4219: undef,undef,undef,'tool',$coursedom,
4220: $coursenum,$ltitoolsref,$disabled);
4221: } elsif (!$isfolder && !$ispage) {
4222: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4223: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4224: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4225: my $suppanchor;
4226: if ($supplementalflag) {
4227: $suppanchor = $anchor;
4228: }
4229: my $jscall =
4230: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4231: $switchserver,
4232: $forceedit,
4233: undef,$symb,
4234: &escape($env{'form.folderpath'}),
4235: $renametitle,$hostname,
4236: '','',1,$suppanchor);
4237: if ($jscall) {
4238: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4239: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4240: }
4241: }
4242: }
4243: $tdalign = ' align="right" valign="top"';
4244: $tdwidth = ' width="80%"';
4245: }
4246: my $reinit;
4247: if ($crstype eq 'Community') {
4248: $reinit = &mt('(re-initialize community to access)');
4249: } else {
4250: $reinit = &mt('(re-initialize course to access)');
4251: }
4252: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4253: my $link;
4254: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4255: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4256: } elsif ($url) {
4257: if ($anchor ne '') {
4258: if ($supplementalflag) {
4259: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4260: } else {
4261: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4262: }
4263: }
4264: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4265: $link = 'http://'.$hostname.$url;
4266: } else {
4267: $link = $url;
4268: }
4269: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4270: (($anchor ne '')?$anchor:''));
4271: if ($nomodal) {
4272: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4273: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4274: } else {
4275: $line.=&Apache::loncommon::modal_link($link,
4276: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4277: }
4278: } else {
4279: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4280: }
4281: $line.='</span></td><td'.$tdwidth.'>';
4282: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4283: $line.='<a href="'.$url.'">'.$title.'</a>';
4284: } elsif ($url) {
4285: if ($nomodal) {
4286: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4287: $title.'</a>';
4288: } else {
4289: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4290: }
4291: } elsif (($hiddenfolder) || ($hiddenres)) {
4292: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
4293: } else {
4294: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4295: }
4296: $line.="$extresform</td>";
4297: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4298: $rand_order_text = ' ' if ($rand_order_text eq '');
4299: if (($allowed) && ($folder!~/^supplemental/)) {
4300: my %lt=&Apache::lonlocal::texthash(
4301: 'hd' => 'Hidden',
4302: 'ec' => 'URL hidden');
4303: my ($enctext,$hidtext);
4304: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4305: $enctext = ' checked="checked"';
4306: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4307: push(@{$filtersref->{'encrypturl'}},$orderidx);
4308: }
4309: }
4310: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4311: $hidtext = ' checked="checked"';
4312: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4313: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4314: }
4315: }
4316: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4317: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
4318: $line.=(<<ENDPARMS);
4319: <td class="LC_docs_entry_parameter">
4320: <form action="/adm/coursedocs" method="post" name="$formhidden">
4321: $form_param
4322: $form_common
4323: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4324: $form_end
4325: <br />
4326: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4327: $form_param
4328: $form_common
4329: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4330: $form_end
4331: </td>
4332: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4333: $rand_order_text</td>
4334: ENDPARMS
4335: }
4336: $line.=&Apache::loncommon::end_data_table_row();
4337: return $line;
4338: }
4339:
4340: sub action_restrictions {
4341: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4342: my %denied = (
4343: cut => 0,
4344: copy => 0,
4345: remove => 0,
4346: );
4347: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4348: # no copy for published maps
4349: $denied{'copy'} = 1;
4350: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4351: unless ($1 eq 'simpleproblem') {
4352: $denied{'copy'} = 1;
4353: }
4354: $denied{'cut'} = 1;
4355: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4356: if ($folderpath =~ /^default&[^\&]+$/) {
4357: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4358: $denied{'remove'} = 1;
4359: }
4360: $denied{'cut'} = 1;
4361: $denied{'copy'} = 1;
4362: }
4363: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4364: my $group = $1;
4365: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4366: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4367: $denied{'remove'} = 1;
4368: }
4369: }
4370: $denied{'cut'} = 1;
4371: $denied{'copy'} = 1;
4372: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4373: my $group = $1;
4374: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4375: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4376: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4377: if (keys(%groupsettings) > 0) {
4378: $denied{'remove'} = 1;
4379: }
4380: $denied{'cut'} = 1;
4381: $denied{'copy'} = 1;
4382: }
4383: }
4384: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4385: my $group = $1;
4386: if ($url =~ /group_boards_\Q$group\E/) {
4387: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4388: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4389: if (keys(%groupsettings) > 0) {
4390: if (ref($groupsettings{'functions'}) eq 'HASH') {
4391: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4392: $denied{'remove'} = 1;
4393: }
4394: }
4395: }
4396: $denied{'cut'} = 1;
4397: $denied{'copy'} = 1;
4398: }
4399: }
4400: }
4401: return %denied;
4402: }
4403:
4404: sub new_timebased_suffix {
4405: my ($dom,$num,$type,$area,$container) = @_;
4406: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4407: if ($type eq 'paste') {
4408: $prefix = $type;
4409: $namespace = 'courseeditor';
4410: $idtype = 'addcode';
4411: } elsif ($type eq 'map') {
4412: $prefix = 'docs';
4413: if ($area eq 'supplemental') {
4414: $prefix = 'supp';
4415: }
4416: $prefix .= $container;
4417: $namespace = 'uploadedmaps';
4418: } else {
4419: $prefix = $type;
4420: $namespace = 'templated';
4421: }
4422: my ($suffix,$freedlock,$error) =
4423: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4424: if (!$suffix) {
4425: if ($type eq 'paste') {
4426: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4427: } elsif ($type eq 'map') {
4428: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4429: } elsif ($type eq 'smppg') {
4430: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4431: } else {
4432: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4433: }
4434: if ($error) {
4435: $errtext .= '<br />'.$error;
4436: }
4437: }
4438: if ($freedlock ne 'ok') {
4439: $locknotfreed =
4440: '<div class="LC_error">'.
4441: &mt('There was a problem removing a lockfile.').' ';
4442: if ($type eq 'paste') {
4443: if ($freedlock eq 'nolock') {
4444: $locknotfreed =
4445: '<div class="LC_error">'.
4446: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4447:
4448: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4449: } else {
4450: $locknotfreed .=
4451: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4452: }
4453: } elsif ($type eq 'map') {
4454: $locknotfreed .=
4455: &mt('This will prevent creation of additional folders or composite pages in this course.');
4456: } elsif ($type eq 'smppg') {
4457: $locknotfreed .=
4458: &mt('This will prevent creation of additional simple pages in this course.');
4459: } else {
4460: $locknotfreed .=
4461: &mt('This will prevent creation of additional discussion boards in this course.');
4462: }
4463: unless ($type eq 'paste') {
4464: $locknotfreed .=
4465: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4466: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4467: }
4468: $locknotfreed .= '</div>';
4469: }
4470: return ($suffix,$errtext,$locknotfreed);
4471: }
4472:
4473: =pod
4474:
4475: =item tiehash()
4476:
4477: tie the hash
4478:
4479: =cut
4480:
4481: sub tiehash {
4482: my ($mode)=@_;
4483: $hashtied=0;
4484: if ($env{'request.course.fn'}) {
4485: if ($mode eq 'write') {
4486: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4487: &GDBM_WRCREAT(),0640)) {
4488: $hashtied=2;
4489: }
4490: } else {
4491: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4492: &GDBM_READER(),0640)) {
4493: $hashtied=1;
4494: }
4495: }
4496: }
4497: }
4498:
4499: sub untiehash {
4500: if ($hashtied) { untie %hash; }
4501: $hashtied=0;
4502: return OK;
4503: }
4504:
4505:
4506:
4507:
4508: sub checkonthis {
4509: my ($r,$url,$level,$title)=@_;
4510: $url=&unescape($url);
4511: $alreadyseen{$url}=1;
4512: $r->rflush();
4513: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4514: $r->print("\n<br />");
4515: if ($level==0) {
4516: $r->print("<br />");
4517: }
4518: for (my $i=0;$i<=$level*5;$i++) {
4519: $r->print(' ');
4520: }
4521: $r->print('<a href="'.$url.'" target="cat">'.
4522: ($title?$title:$url).'</a> ');
4523: if ($url=~/^\/res\//) {
4524: my $result=&Apache::lonnet::repcopy(
4525: &Apache::lonnet::filelocation('',$url));
4526: if ($result eq 'ok') {
4527: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4528: $r->rflush();
4529: &Apache::lonnet::countacc($url);
4530: $url=~/\.(\w+)$/;
4531: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4532: $r->print('<br />');
4533: $r->rflush();
4534: for (my $i=0;$i<=$level*5;$i++) {
4535: $r->print(' ');
4536: }
4537: $r->print('- '.&mt('Rendering:').' ');
4538: my ($errorcount,$warningcount)=split(/:/,
4539: &Apache::lonnet::ssi_body($url,
4540: ('grade_target'=>'web',
4541: 'return_only_error_and_warning_counts' => 1)));
4542: if (($errorcount) ||
4543: ($warningcount)) {
4544: if ($errorcount) {
4545: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4546: &mt('[quant,_1,error]',$errorcount).'</span>');
4547: }
4548: if ($warningcount) {
4549: $r->print('<span class="LC_warning">'.
4550: &mt('[quant,_1,warning]',$warningcount).'</span>');
4551: }
4552: } else {
4553: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4554: }
4555: $r->rflush();
4556: }
4557: my $dependencies=
4558: &Apache::lonnet::metadata($url,'dependencies');
4559: foreach my $dep (split(/\,/,$dependencies)) {
4560: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4561: &checkonthis($r,$dep,$level+1);
4562: }
4563: }
4564: } elsif ($result eq 'unavailable') {
4565: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4566: } elsif ($result eq 'not_found') {
4567: unless ($url=~/\$/) {
4568: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4569: } else {
4570: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4571: }
4572: } else {
4573: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4574: }
4575: }
4576: }
4577: }
4578:
4579:
4580:
4581: =pod
4582:
4583: =item list_symbs()
4584:
4585: List Content Identifiers
4586:
4587: =cut
4588:
4589: sub list_symbs {
4590: my ($r) = @_;
4591:
4592: my $crstype = &Apache::loncommon::course_type();
4593: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4594: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4595: $r->print(&startContentScreen('tools'));
4596: my $navmap = Apache::lonnavmaps::navmap->new();
4597: if (!defined($navmap)) {
4598: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4599: '<div class="LC_error">'.
4600: &mt('Unable to retrieve information about course contents').
4601: '</div>');
4602: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4603: } else {
4604: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4605: &Apache::loncommon::start_data_table().
4606: &Apache::loncommon::start_data_table_header_row().
4607: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4608: &Apache::loncommon::end_data_table_header_row()."\n");
4609: my $count;
4610: foreach my $res ($navmap->retrieveResources()) {
4611: $r->print(&Apache::loncommon::start_data_table_row().
4612: '<td>'.$res->compTitle().'</td>'.
4613: '<td>'.$res->symb().'</td>'.
4614: &Apache::loncommon::end_data_table_row());
4615: $count ++;
4616: }
4617: if (!$count) {
4618: $r->print(&Apache::loncommon::start_data_table_row().
4619: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4620: &Apache::loncommon::end_data_table_row());
4621: }
4622: $r->print(&Apache::loncommon::end_data_table());
4623: }
4624: $r->print(&endContentScreen());
4625: }
4626:
4627:
4628: sub verifycontent {
4629: my ($r) = @_;
4630: my $crstype = &Apache::loncommon::course_type();
4631: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4632: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4633: $r->print(&startContentScreen('tools'));
4634: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4635: $hashtied=0;
4636: undef %alreadyseen;
4637: %alreadyseen=();
4638: &tiehash();
4639:
4640: foreach my $key (keys(%hash)) {
4641: if ($hash{$key}=~/\.(page|sequence)$/) {
4642: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4643: $r->print('<hr /><span class="LC_error">'.
4644: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
4645: &unescape($hash{$key}).'</span><br />'.
4646: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
4647: }
4648: }
4649: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4650: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4651: }
4652: }
4653: &untiehash();
4654: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
4655: $r->print(&endContentScreen());
4656: }
4657:
4658:
4659: sub devalidateversioncache {
4660: my $src=shift;
4661: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4662: &Apache::lonnet::clutter($src));
4663: }
4664:
4665: sub checkversions {
4666: my ($r,$canedit) = @_;
4667: my $crstype = &Apache::loncommon::course_type();
4668: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4669: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
4670: $r->print(&startContentScreen('tools'));
4671:
4672: my $header='';
4673: my $startsel='';
4674: my $monthsel='';
4675: my $weeksel='';
4676: my $daysel='';
4677: my $allsel='';
4678: my %changes=();
4679: my $starttime=0;
4680: my $haschanged=0;
4681: my %setversions=&Apache::lonnet::dump('resourceversions',
4682: $env{'course.'.$env{'request.course.id'}.'.domain'},
4683: $env{'course.'.$env{'request.course.id'}.'.num'});
4684:
4685: $hashtied=0;
4686: &tiehash();
4687: if ($canedit) {
4688: my %newsetversions=();
4689: if ($env{'form.setmostrecent'}) {
4690: $haschanged=1;
4691: foreach my $key (keys(%hash)) {
4692: if ($key=~/^ids\_(\/res\/.+)$/) {
4693: $newsetversions{$1}='mostrecent';
4694: &devalidateversioncache($1);
4695: }
4696: }
4697: } elsif ($env{'form.setcurrent'}) {
4698: $haschanged=1;
4699: foreach my $key (keys(%hash)) {
4700: if ($key=~/^ids\_(\/res\/.+)$/) {
4701: my $getvers=&Apache::lonnet::getversion($1);
4702: if ($getvers>0) {
4703: $newsetversions{$1}=$getvers;
4704: &devalidateversioncache($1);
4705: }
4706: }
4707: }
4708: } elsif ($env{'form.setversions'}) {
4709: $haschanged=1;
4710: foreach my $key (keys(%env)) {
4711: if ($key=~/^form\.set_version_(.+)$/) {
4712: my $src=$1;
4713: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4714: $newsetversions{$src}=$env{$key};
4715: &devalidateversioncache($src);
4716: }
4717: }
4718: }
4719: }
4720: if ($haschanged) {
4721: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4722: $env{'course.'.$env{'request.course.id'}.'.domain'},
4723: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4724: $r->print(&Apache::loncommon::confirmwrapper(
4725: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4726: } else {
4727: $r->print(&Apache::loncommon::confirmwrapper(
4728: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4729: }
4730: &mark_hash_old();
4731: }
4732: &changewarning($r,'');
4733: }
4734: if ($env{'form.timerange'} eq 'all') {
4735: # show all documents
4736: $header=&mt('All content in '.$crstype);
4737: $allsel=' selected="selected"';
4738: foreach my $key (keys(%hash)) {
4739: if ($key=~/^ids\_(\/res\/.+)$/) {
4740: my $src=$1;
4741: $changes{$src}=1;
4742: }
4743: }
4744: } else {
4745: # show documents which changed
4746: %changes=&Apache::lonnet::dump
4747: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4748: $env{'course.'.$env{'request.course.id'}.'.num'});
4749: my $firstkey=(keys(%changes))[0];
4750: unless ($firstkey=~/^error\:/) {
4751: unless ($env{'form.timerange'}) {
4752: $env{'form.timerange'}=604800;
4753: }
4754: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4755: .&mt('seconds');
4756: if ($env{'form.timerange'}==-1) {
4757: $seltext='since start of course';
4758: $startsel=' selected="selected"';
4759: $env{'form.timerange'}=time;
4760: }
4761: $starttime=time-$env{'form.timerange'};
4762: if ($env{'form.timerange'}==2592000) {
4763: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4764: $monthsel=' selected="selected"';
4765: } elsif ($env{'form.timerange'}==604800) {
4766: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4767: $weeksel=' selected="selected"';
4768: } elsif ($env{'form.timerange'}==86400) {
4769: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4770: $daysel=' selected="selected"';
4771: }
4772: $header=&mt('Content changed').' '.$seltext;
4773: } else {
4774: $header=&mt('No content modifications yet.');
4775: }
4776: }
4777: %setversions=&Apache::lonnet::dump('resourceversions',
4778: $env{'course.'.$env{'request.course.id'}.'.domain'},
4779: $env{'course.'.$env{'request.course.id'}.'.num'});
4780: my %lt=&Apache::lonlocal::texthash
4781: ('st' => 'Version changes since start of '.$crstype,
4782: 'lm' => 'Version changes since last Month',
4783: 'lw' => 'Version changes since last Week',
4784: 'sy' => 'Version changes since Yesterday',
4785: 'al' => 'All Resources (possibly large output)',
4786: 'cd' => 'Change display',
4787: 'sd' => 'Display',
4788: 'fi' => 'File',
4789: 'md' => 'Modification Date',
4790: 'mr' => 'Most recently published Version',
4791: 've' => 'Version used in '.$crstype,
4792: 'vu' => 'Set Version to be used in '.$crstype,
4793: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
4794: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4795: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
4796: 'di' => 'Differences',
4797: 'save' => 'Save changes',
4798: 'vers' => 'Version choice(s) for specific resources',
4799: 'act' => 'Actions');
4800: my ($disabled,$readonly);
4801: unless ($canedit) {
4802: $disabled = 'disabled="disabled"';
4803: $readonly = 1;
4804: }
4805: $r->print(<<ENDHEADERS);
4806: <h4 class="LC_info">$header</h4>
4807: <form action="/adm/coursedocs" method="post">
4808: <input type="hidden" name="versions" value="1" />
4809: <div class="LC_left_float">
4810: <fieldset>
4811: <legend>$lt{'cd'}</legend>
4812: <select name="timerange">
4813: <option value='all'$allsel>$lt{'al'}</option>
4814: <option value="-1"$startsel>$lt{'st'}</option>
4815: <option value="2592000"$monthsel>$lt{'lm'}</option>
4816: <option value="604800"$weeksel>$lt{'lw'}</option>
4817: <option value="86400"$daysel>$lt{'sy'}</option>
4818: </select>
4819: <input type="submit" name="display" value="$lt{'sd'}" />
4820: </fieldset>
4821: </div>
4822: <div class="LC_left_float">
4823: <fieldset>
4824: <legend>$lt{'act'}</legend>
4825: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4826: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
4827: </fieldset>
4828: </div>
4829: <br clear="all" />
4830: <hr />
4831: <h4>$lt{'vers'}</h4>
4832: ENDHEADERS
4833: #number of columns for version history
4834: my %changedbytime;
4835: foreach my $key (keys(%changes)) {
4836: #excludes not versionable problems from resource version history:
4837: next if ($key =~ /^\/res\/lib\/templates/);
4838: my $chg;
4839: if ($env{'form.timerange'} eq 'all') {
4840: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4841: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4842: } else {
4843: $chg = $changes{$key};
4844: next if ($chg < $starttime);
4845: }
4846: push(@{$changedbytime{$chg}},$key);
4847: }
4848: if (keys(%changedbytime) == 0) {
4849: &untiehash();
4850: $r->print(&mt('No content changes in imported content in specified time frame').
4851: &endContentScreen());
4852: return;
4853: }
4854: $r->print(
4855: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
4856: &Apache::loncommon::start_data_table().
4857: &Apache::loncommon::start_data_table_header_row().
4858: '<th>'.&mt('Resources').'</th>'.
4859: "<th>$lt{'mr'}</th>".
4860: "<th>$lt{'ve'}</th>".
4861: "<th>$lt{'vu'}</th>".
4862: '<th>'.&mt('History').'</th>'.
4863: &Apache::loncommon::end_data_table_header_row()
4864: );
4865: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4866: foreach my $key (sort(@{$changedbytime{$chg}})) {
4867: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4868: my $currentversion=&Apache::lonnet::getversion($key);
4869: if ($currentversion<0) {
4870: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4871: }
4872: my $linkurl=&Apache::lonnet::clutter($key);
4873: $r->print(
4874: &Apache::loncommon::start_data_table_row().
4875: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4876: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4877: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4878: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4879: '<td align="right">'
4880: );
4881: # Used in course
4882: my $usedversion=$hash{'version_'.$linkurl};
4883: if (($usedversion) && ($usedversion ne 'mostrecent')) {
4884: if ($usedversion != $currentversion) {
4885: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
4886: } else {
4887: $r->print($usedversion);
4888: }
4889: } else {
4890: $r->print($currentversion);
4891: }
4892: $r->print('</td><td title="'.$lt{'vu'}.'">');
4893: # Set version
4894: $r->print(&Apache::loncommon::select_form(
4895: $setversions{$linkurl},
4896: 'set_version_'.$linkurl,
4897: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4898: '' => '',
4899: 'mostrecent' => &mt('most recent'),
4900: map {$_,$_} (1..$currentversion)},'',$readonly));
4901: my $lastold=1;
4902: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4903: my $url=$root.'.'.$prevvers.'.'.$extension;
4904: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4905: $lastold=$prevvers;
4906: }
4907: }
4908: $r->print('</td>');
4909: # List all available versions
4910: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4911: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4912: my $url=$root.'.'.$prevvers.'.'.$extension;
4913: $r->print(
4914: '<span class="LC_nobreak">'
4915: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4916: .&mt('Version [_1]',$prevvers).'</a>'
4917: .' ('.&Apache::lonlocal::locallocaltime(
4918: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4919: .')');
4920: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4921: $r->print(
4922: ' <a href="/adm/diff?filename='.
4923: &Apache::lonnet::clutter($root.'.'.$extension).
4924: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4925: '" target="diffs">'.&mt('Diffs').'</a>');
4926: }
4927: $r->print('</span><br />');
4928: }
4929: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
4930: }
4931: }
4932: $r->print(
4933: &Apache::loncommon::end_data_table().
4934: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
4935: '</form>'
4936: );
4937:
4938: &untiehash();
4939: $r->print(&endContentScreen());
4940: return;
4941: }
4942:
4943: sub mark_hash_old {
4944: my $retie_hash=0;
4945: if ($hashtied) {
4946: $retie_hash=1;
4947: &untiehash();
4948: }
4949: &tiehash('write');
4950: $hash{'old'}=1;
4951: &untiehash();
4952: if ($retie_hash) { &tiehash(); }
4953: }
4954:
4955: sub is_hash_old {
4956: my $untie_hash=0;
4957: if (!$hashtied) {
4958: $untie_hash=1;
4959: &tiehash();
4960: }
4961: my $return=$hash{'old'};
4962: if ($untie_hash) { &untiehash(); }
4963: return $return;
4964: }
4965:
4966: sub changewarning {
4967: my ($r,$postexec,$message,$url)=@_;
4968: if (!&is_hash_old()) { return; }
4969: my $pathvar='folderpath';
4970: my $path=&escape($env{'form.folderpath'});
4971: if (!defined($url)) {
4972: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4973: }
4974: my $course_type = &Apache::loncommon::course_type();
4975: if (!defined($message)) {
4976: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4977: }
4978: $r->print("\n\n".
4979: '<script type="text/javascript">'."\n".
4980: '// <![CDATA['."\n".
4981: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4982: '// ]]>'."\n".
4983: '</script>'."\n".
4984: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
4985: '<input type="hidden" name="orgurl" value="'.$url.
4986: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
4987: &mt($message,' <input type="hidden" name="'.
4988: $env{'request.role'}.'" value="1" /><input type="button" value="'.
4989: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
4990: $help{'Caching'}.'</p></form>'."\n\n");
4991: }
4992:
4993:
4994: sub init_breadcrumbs {
4995: my ($form,$text,$help)=@_;
4996: &Apache::lonhtmlcommon::clear_breadcrumbs();
4997: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
4998: text=>&Apache::loncommon::course_type().' Editor',
4999: faq=>273,
5000: bug=>'Instructor Interface',
5001: help => $help});
5002: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5003: text=>$text,
5004: faq=>273,
5005: bug=>'Instructor Interface'});
5006: }
5007:
5008: # subroutine to list form elements
5009: sub create_list_elements {
5010: my @formarr = @_;
5011: my $list = '';
5012: foreach my $button (@formarr){
5013: foreach my $picture (keys(%{$button})) {
5014: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5015: }
5016: }
5017: return $list;
5018: }
5019:
5020: # subroutine to create ul from list elements
5021: sub create_form_ul {
5022: my $list = shift;
5023: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5024: return $ul;
5025: }
5026:
5027: #
5028: # Start tabs
5029: #
5030:
5031: sub startContentScreen {
5032: my ($mode) = @_;
5033: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5034: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5035: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5036: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5037: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5038: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5039: } else {
5040: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5041: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5042: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5043: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5044: }
5045: $output .= "\n".'</ul>'."\n";
5046: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5047: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5048: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5049: return $output;
5050: }
5051:
5052: #
5053: # End tabs
5054: #
5055:
5056: sub endContentScreen {
5057: return '</div></div></div>';
5058: }
5059:
5060: sub supplemental_base {
5061: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5062: }
5063:
5064: sub handler {
5065: my $r = shift;
5066: &Apache::loncommon::content_type($r,'text/html');
5067: $r->send_http_header;
5068: return OK if $r->header_only;
5069:
5070: # get course data
5071: my $crstype = &Apache::loncommon::course_type();
5072: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5073: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5074:
5075: # get docroot
5076: my $londocroot = $r->dir_config('lonDocRoot');
5077:
5078: # graphics settings
5079: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5080:
5081: #
5082: # --------------------------------------------- Initialize help topics for this
5083: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5084: 'Adding_External_Resource','Navigate_Content',
5085: 'Adding_Folders','Docs_Overview', 'Load_Map',
5086: 'Supplemental','Score_Upload_Form','Adding_Pages',
5087: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
5088: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5089: 'Dropbox','Simple_Problem') {
5090: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5091: }
5092: # Composite help files
5093: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5094: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5095: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5096: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5097: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5098: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5099: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5100: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5101: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5102: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5103:
5104: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5105: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5106: unless ($r->uri eq '/adm/supplemental') {
5107: # does this user have privileges to modify content.
5108: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5109: $allowed = 1;
5110: $canedit = 1;
5111: $canview = 1;
5112: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5113: $allowed = 1;
5114: $canview = 1;
5115: }
5116: }
5117: unless ($canedit) {
5118: $disabled = ' disabled="disabled"';
5119: }
5120: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5121: if ($allowed && $env{'form.verify'}) {
5122: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5123: &verifycontent($r);
5124: } elsif ($allowed && $env{'form.listsymbs'}) {
5125: &init_breadcrumbs('listsymbs','List Content IDs');
5126: &list_symbs($r);
5127: } elsif ($allowed && $env{'form.docslog'}) {
5128: &init_breadcrumbs('docslog','Show Log');
5129: my $folder = $env{'form.folder'};
5130: if ($folder eq '') {
5131: $folder='default';
5132: }
5133: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5134: } elsif ($allowed && $env{'form.versions'}) {
5135: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5136: &checkversions($r,$canedit);
5137: } elsif ($canedit && $env{'form.dumpcourse'}) {
5138: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5139: &dumpcourse($r);
5140: } elsif ($canedit && $env{'form.exportcourse'}) {
5141: &init_breadcrumbs('exportcourse','IMS Export');
5142: &Apache::imsexport::exportcourse($r);
5143: } else {
5144: if ($canedit && $env{'form.authorrole'}) {
5145: $noendpage = 1;
5146: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5147: if ($redirect) {
5148: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5149: my $container = 'sequence';
5150: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5151: $is_random_order,$container) =
5152: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5153: my (@folders)=split('&',$env{'form.folderpath'});
5154: $env{'form.foldername'}=&unescape(pop(@folders));
5155: my $folder=pop(@folders);
5156: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5157: $folder.'.'.$container);
5158: my $warning;
5159: if ($fatal) {
5160: if ($container eq 'page') {
5161: $warning = &mt('An error occurred retrieving the contents of the current page.');
5162: } else {
5163: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5164: }
5165: } else {
5166: my $url = $redirect;
5167: my $srcfile = $londocroot.$url;
5168: $url =~ s{^/priv/}{/res/};
5169: my $targetfile = $londocroot.$url;
5170: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5171: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5172: $env{'form.folder'} = $folder;
5173: &snapshotbefore();
5174: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5175: my $ext = 'false';
5176: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5177: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5178: ':'.$ext.':normal:res';
5179: push(@LONCAPA::map::order,$newidx);
5180: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5181: 'string_yesno');
5182: &remember_parms($newidx,'hiddenresource','set','yes');
5183: ($errtext,$fatal) =
5184: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5185: &log_differences($plain);
5186: &mark_hash_old();
5187: $r->internal_redirect($redirect);
5188: return OK;
5189: }
5190: }
5191: }
5192: }
5193: #
5194: # Done catching special calls
5195: # The whole rest is for course and supplemental documents and utilities menu
5196: # Get the parameters that may be needed
5197: #
5198: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5199: ['folderpath',
5200: 'forcesupplement','forcestandard',
5201: 'tools','symb','command','supppath']);
5202:
5203: # standard=1: this is a "new-style" course with an uploaded map as top level
5204: # standard=2: this is a "old-style" course, and there is nothing we can do
5205:
5206: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5207:
5208: # Decide whether this should display supplemental or main content or utilities
5209: # supplementalflag=1: show supplemental documents
5210: # supplementalflag=0: show standard documents
5211: # toolsflag=1: show utilities
5212:
5213: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5214: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5215: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5216: $supplementalflag=0;
5217: }
5218: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5219: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5220: unless ($allowed) { $supplementalflag=1; }
5221: unless ($standard) { $supplementalflag=1; }
5222: my $toolsflag=0;
5223: if ($env{'form.tools'}) { $toolsflag=1; }
5224:
5225: my $script='';
5226: my $showdoc=0;
5227: my $addentries = {};
5228: my $container;
5229: my $containertag;
5230: my $pathitem;
5231: my %ltitools;
5232: my $hiddentop;
5233: my $navmap;
5234: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5235:
5236: # Do we directly jump somewhere?
5237: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5238: if ($env{'form.symb'} ne '') {
5239: $env{'form.folderpath'}=
5240: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5241: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5242: $env{'form.command'}.'_'.$env{'form.symb'}});
5243: } elsif ($env{'form.supppath'} ne '') {
5244: $env{'form.folderpath'}=$env{'form.supppath'};
5245: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5246: $env{'form.command'}.'_'.$env{'form.supppath'}});
5247: }
5248: } elsif ($env{'form.command'} eq 'editdocs') {
5249: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5250: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5251: } elsif ($env{'form.command'} eq 'editsupp') {
5252: $env{'form.folderpath'} = &supplemental_base();
5253: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5254: } elsif ($env{'form.command'} eq 'contents') {
5255: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5256: } elsif ($env{'form.command'} eq 'home') {
5257: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5258: }
5259:
5260:
5261: # Where do we store these for when we come back?
5262: my $stored_folderpath='docs_folderpath';
5263: if ($supplementalflag) {
5264: $stored_folderpath='docs_sup_folderpath';
5265: }
5266:
5267: # No folderpath, and in edit mode, see if we have something stored
5268: if ((!$env{'form.folderpath'}) && $allowed) {
5269: &Apache::loncommon::restore_course_settings($stored_folderpath,
5270: {'folderpath' => 'scalar'});
5271:
5272: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5273: if ($supplementalflag) {
5274: undef($env{'form.folderpath'}) if ($1 eq 'default');
5275: } else {
5276: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5277: }
5278: } else {
5279: undef($env{'form.folderpath'});
5280: }
5281: }
5282:
5283: # If we are not allowed to make changes, all we can see are supplemental docs
5284: if (!$allowed) {
5285: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5286: $env{'form.folderpath'} = &supplemental_base();
5287: }
5288: }
5289: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5290: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5291: $env{'form.folderpath'} = &supplemental_base()
5292: .'&'.
5293: $env{'form.folderpath'};
5294: }
5295: # If allowed and user's role is not advanced check folderpath is not hidden
5296: if (($allowed) && (!$env{'request.role.adv'}) &&
5297: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5298: my $folderurl;
5299: my @pathitems = split(/\&/,$env{'form.folderpath'});
5300: my $folder = $pathitems[-2];
5301: if ($folder eq '') {
5302: undef($env{'form.folderpath'});
5303: } else {
5304: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5305: if ((split(/\:/,$pathitems[-1]))[4]) {
5306: $folderurl .= '.page';
5307: } else {
5308: $folderurl .= '.sequence';
5309: }
5310: unless (ref($navmap)) {
5311: $navmap = Apache::lonnavmaps::navmap->new();
5312: }
5313: if (ref($navmap)) {
5314: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5315: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5316: unless (@resources) {
5317: undef($env{'form.folderpath'});
5318: }
5319: }
5320: }
5321: }
5322: }
5323:
5324:
5325: # If after all of this, we still don't have any paths, make them
5326: unless ($env{'form.folderpath'}) {
5327: if ($supplementalflag) {
5328: $env{'form.folderpath'}=&supplemental_base();
5329: } elsif ($allowed) {
5330: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5331: }
5332: }
5333:
5334: # Store this
5335: unless ($toolsflag) {
5336: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5337: &Apache::loncommon::store_course_settings($stored_folderpath,
5338: {'folderpath' => 'scalar'});
5339: }
5340: my $folderpath;
5341: if ($env{'form.folderpath'}) {
5342: $folderpath = $env{'form.folderpath'};
5343: my (@folders)=split('&',$env{'form.folderpath'});
5344: $env{'form.foldername'}=&unescape(pop(@folders));
5345: if ($env{'form.foldername'} =~ /\:1$/) {
5346: $container = 'page';
5347: } else {
5348: $container = 'sequence';
5349: }
5350: $env{'form.folder'}=pop(@folders);
5351: } else {
5352: if ($env{'form.folder'} eq '' ||
5353: $env{'form.folder'} eq 'supplemental') {
5354: if ($env{'form.folder'} eq 'supplemental') {
5355: $folderpath=&supplemental_base();
5356: } elsif (!$hiddentop) {
5357: $folderpath='default&'.
5358: &escape(&mt('Main Content').':::::');
5359: }
5360: }
5361: }
5362: $containertag = '<input type="hidden" name="folderpath" value="" />';
5363: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5364: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5365: $showdoc='/'.$1;
5366: }
5367: if ($showdoc) { # got called in sequence from course
5368: $allowed=0;
5369: } else {
5370: if ($canedit) {
5371: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5372: $script=&Apache::lonratedt::editscript('simple');
5373: }
5374: }
5375: }
5376:
5377: # get personal data
5378: my $uname=$env{'user.name'};
5379: my $udom=$env{'user.domain'};
5380: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5381:
5382: if ($allowed) {
5383: if ($toolsflag) {
5384: $script .= &inject_data_js();
5385: my ($home,$other,%outhash)=&authorhosts();
5386: if (!$home && $other) {
5387: my @hosts;
5388: foreach my $aurole (keys(%outhash)) {
5389: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5390: push(@hosts,$outhash{$aurole});
5391: }
5392: }
5393: $script .= &dump_switchserver_js(@hosts);
5394: }
5395: } else {
5396: my $tid = 1;
5397: my @tabids;
5398: if ($supplementalflag) {
5399: @tabids = ('002','ee2','ff2');
5400: $tid = 2;
5401: } else {
5402: @tabids = ('aa1','bb1','cc1','ff1');
5403: unless ($env{'form.folderpath'} =~ /\:1$/) {
5404: unshift(@tabids,'001');
5405: push(@tabids,('dd1','ee1'));
5406: }
5407: }
5408: my $tabidstr = join("','",@tabids);
5409: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
5410: my $posslti = keys(%ltitools);
5411: my $hostname = $r->hostname();
5412: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5413: $londocroot,$canedit,$hostname,\$navmap).
5414: &history_tab_js().
5415: &inject_data_js().
5416: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5417: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5418: $addentries = {
5419: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5420: };
5421: }
5422: $script .= &paste_popup_js();
5423: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5424: &mt('Switch server?');
5425:
5426:
5427: }
5428: # -------------------------------------------------------------------- Body tag
5429: $script = '<script type="text/javascript">'."\n"
5430: .'// <![CDATA['."\n"
5431: .$script."\n"
5432: .'// ]]>'."\n"
5433: .'</script>'."\n"
5434: .'<script type="text/javascript"
5435: src="/res/adm/includes/file_upload.js"></script>'."\n";
5436:
5437: # Breadcrumbs
5438: &Apache::lonhtmlcommon::clear_breadcrumbs();
5439:
5440: if ($showdoc) {
5441: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5442: {'force_register' => $showdoc,}));
5443: } elsif ($toolsflag) {
5444: my ($breadtext,$breadtitle);
5445: $breadtext = "$crstype Editor";
5446: if ($canedit) {
5447: $breadtitle = 'Editing '.$crstype.' Contents';
5448: } else {
5449: $breadtext .= ' (View-only mode)';
5450: $breadtitle = 'Viewing '.$crstype.' Contents';
5451: }
5452: &Apache::lonhtmlcommon::add_breadcrumb({
5453: href=>"/adm/coursedocs",text=>$breadtext});
5454: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5455: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5456: .&Apache::lonhtmlcommon::breadcrumbs(
5457: $breadtitle)
5458: );
5459: } elsif ($r->uri eq '/adm/supplemental') {
5460: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5461: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5462: {'bread_crumbs' => $brcrum,}));
5463: } else {
5464: my ($breadtext,$breadtitle,$helpitem);
5465: $breadtext = "$crstype Editor";
5466: if ($canedit) {
5467: $breadtitle = 'Editing '.$crstype.' Contents';
5468: $helpitem = 'Docs_Adding_Course_Doc';
5469: } else {
5470: $breadtext .= ' (View-only mode)';
5471: $breadtitle = 'Viewing '.$crstype.' Contents';
5472: $helpitem = 'Docs_Viewing_Course_Doc';
5473: }
5474: &Apache::lonhtmlcommon::add_breadcrumb({
5475: href=>"/adm/coursedocs",text=>$breadtext});
5476: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5477: {'add_entries' => $addentries}
5478: )
5479: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5480: .&Apache::lonhtmlcommon::breadcrumbs(
5481: $breadtitle,
5482: $helpitem)
5483: );
5484: }
5485:
5486: my %allfiles = ();
5487: my %codebase = ();
5488: my ($upload_result,$upload_output,$uploadphase);
5489: if ($canedit) {
5490: if (($env{'form.uploaddoc.filename'}) &&
5491: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5492: my $context = $1;
5493: # Process file upload - phase one - upload and parse primary file.
5494: undef($hadchanges);
5495: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5496: \%allfiles,\%codebase,$context,$crstype);
5497: if ($hadchanges) {
5498: &mark_hash_old();
5499: }
5500: $r->print($upload_output);
5501: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5502: # Process file upload - phase two - upload embedded objects
5503: $uploadphase = 'check_embedded';
5504: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5505: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5506: $env{'form.newidx'});
5507: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5508: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5509: my ($destination,$dir_root) = &embedded_destination();
5510: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5511: my $actionurl = '/adm/coursedocs';
5512: my ($result,$flag) =
5513: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5514: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5515: $actionurl);
5516: $r->print($result.&return_to_editor());
5517: } elsif ($env{'form.phase'} eq 'check_embedded') {
5518: # Process file upload - phase three - modify references in HTML file
5519: $uploadphase = 'modified_orightml';
5520: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5521: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5522: my ($destination,$dir_root) = &embedded_destination();
5523: my $result =
5524: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5525: $docuname,$docudom,undef,
5526: $dir_root);
5527: $r->print($result.&return_to_editor());
5528: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5529: $uploadphase = 'decompress_phase_one';
5530: $r->print(&decompression_phase_one().
5531: &return_to_editor());
5532: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5533: $uploadphase = 'decompress_phase_two';
5534: $r->print(&decompression_phase_two().
5535: &return_to_editor());
5536: }
5537: }
5538:
5539: if ($allowed && $toolsflag) {
5540: $r->print(&startContentScreen('tools'));
5541: $r->print(&generate_admin_menu($crstype,$canedit));
5542: $r->print(&endContentScreen());
5543: } elsif ((!$showdoc) && (!$uploadphase)) {
5544: # -----------------------------------------------------------------------------
5545: my %lt=&Apache::lonlocal::texthash(
5546: 'copm' => 'All documents out of a published map into this folder',
5547: 'upfi' => 'Upload File',
5548: 'upld' => 'Upload Content',
5549: 'srch' => 'Search',
5550: 'impo' => 'Import',
5551: 'lnks' => 'Import from Stored Links',
5552: 'impm' => 'Import from Assembled Map',
5553: 'imcr' => 'Import from Course Resources',
5554: 'extr' => 'External Resource',
5555: 'extt' => 'External Tool',
5556: 'selm' => 'Select Map',
5557: 'load' => 'Load Map',
5558: 'newf' => 'New Folder',
5559: 'newp' => 'New Composite Page',
5560: 'syll' => 'Syllabus',
5561: 'navc' => 'Table of Contents',
5562: 'sipa' => 'Simple Course Page',
5563: 'sipr' => 'Simple Problem',
5564: 'webp' => 'Blank Web Page (editable)',
5565: 'stpr' => 'Standard Problem',
5566: 'news' => 'New sub-directory',
5567: 'crpr' => 'Create Problem',
5568: 'drbx' => 'Drop Box',
5569: 'scuf' => 'External Scores (handgrade, upload, clicker)',
5570: 'bull' => 'Discussion Board',
5571: 'mypi' => 'My Personal Information Page',
5572: 'grpo' => 'Group Portfolio',
5573: 'rost' => 'Course Roster',
5574: 'abou' => 'Personal Information Page for a User',
5575: 'imsf' => 'IMS Upload',
5576: 'imsl' => 'Upload IMS package',
5577: 'cms' => 'Origin of IMS package',
5578: 'se' => 'Select',
5579: 'file' => 'File',
5580: 'title' => 'Title',
5581: 'addp' => 'Add Placeholder to course?',
5582: 'uste' => 'Use Template?',
5583: 'fnam' => 'File Name:',
5584: 'loca' => 'Location:',
5585: 'dire' => 'Directory:',
5586: 'cate' => 'Category:',
5587: 'tmpl' => 'Template:',
5588: 'comment' => 'Comment',
5589: 'parse' => 'Upload embedded images/multimedia files if HTML file',
5590: 'bb5' => 'Blackboard 5',
5591: 'bb6' => 'Blackboard 6',
5592: 'angel5' => 'ANGEL 5.5',
5593: 'webctce4' => 'WebCT 4 Campus Edition',
5594: 'yes' => 'Yes',
5595: 'no' => 'No',
5596: 'er' => 'Editing rights unavailable for your current role.',
5597: );
5598: # -----------------------------------------------------------------------------
5599:
5600: # Calculate free quota space for a user or course. A javascript function checks
5601: # file size to determine if upload should be allowed.
5602: my $quotatype = 'unofficial';
5603: if ($crstype eq 'Community') {
5604: $quotatype = 'community';
5605: } elsif ($crstype eq 'Placement') {
5606: $quotatype = 'placement';
5607: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5608: $quotatype = 'official';
5609: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5610: $quotatype = 'textbook';
5611: }
5612: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5613: 'course',$quotatype); # expressed in MB
5614: my $current_disk_usage = 0;
5615: foreach my $subdir ('docs','supplemental') {
5616: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5617: "userfiles/$subdir",1); # expressed in kB
5618: }
5619: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5620: my $usage = $current_disk_usage/1024; # in MB
5621: my $quota = $disk_quota;
5622: my $percent;
5623: if ($disk_quota == 0) {
5624: $percent = 100.0;
5625: } else {
5626: $percent = 100*($usage/$disk_quota);
5627: }
5628: $usage = sprintf("%.2f",$usage);
5629: $quota = sprintf("%.2f",$quota);
5630: $percent = sprintf("%.0f",$percent);
5631: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5632: $percent.'%',$quota.' MB').'</p>';
5633:
5634: my $fileupload=(<<FIUP);
5635: $quotainfo
5636: $lt{'file'}:<br />
5637: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
5638: <input type="hidden" id="free_space" value="$free_space" />
5639: FIUP
5640:
5641: my $checkbox=(<<CHBO);
5642: <!-- <label>$lt{'parse'}?
5643: <input type="checkbox" name="parserflag" />
5644: </label> -->
5645: <label>
5646: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
5647: </label>
5648: CHBO
5649: my $imsfolder = $env{'form.folder'};
5650: if ($imsfolder eq '') {
5651: $imsfolder = 'default';
5652: }
5653: my $imspform=(<<IMSFORM);
5654: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5655: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5656: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
5657: <fieldset id="uploadimsform" style="display: none;">
5658: <legend>$lt{'imsf'}</legend>
5659: $fileupload
5660: <br />
5661: <p>
5662: $lt{'cms'}:
5663: <select name="source" $disabled>
5664: <option value="-1" selected="selected">$lt{'se'}</option>
5665: <option value="bb5">$lt{'bb5'}</option>
5666: <option value="bb6">$lt{'bb6'}</option>
5667: <option value="angel5">$lt{'angel5'}</option>
5668: <option value="webctce4">$lt{'webctce4'}</option>
5669: </select>
5670: <input type="hidden" name="folder" value="$imsfolder" />
5671: </p>
5672: <input type="hidden" name="phase" value="one" />
5673: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
5674: </fieldset>
5675: </form>
5676: IMSFORM
5677:
5678: my $fileuploadform=(<<FUFORM);
5679: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5680: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5681: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
5682: <fieldset id="uploaddocform" style="display: none;">
5683: <legend>$lt{'upfi'}</legend>
5684: <input type="hidden" name="active" value="aa" />
5685: $fileupload
5686: <br />
5687: $lt{'title'}:<br />
5688: <input type="text" size="60" name="comment" $disabled />
5689: $pathitem
5690: <input type="hidden" name="cmd" value="upload_default" />
5691: <br />
5692: <span class="LC_nobreak" style="float:left">
5693: $checkbox
5694: </span>
5695: <br clear="all" />
5696: <input type="submit" value="$lt{'upld'}" $disabled />
5697: </fieldset>
5698: </form>
5699: FUFORM
5700:
5701: my $mapimportjs;
5702: if ($canedit) {
5703: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5704: } else {
5705: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5706: }
5707: my $importpubform=(<<SEDFFORM);
5708: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
5709: $lt{'impm'}</a>$help{'Load_Map'}
5710: <form action="/adm/coursedocs" method="post" name="mapimportform">
5711: <fieldset id="importmapform" style="display: none;">
5712: <legend>$lt{'impm'}</legend>
5713: <input type="hidden" name="active" value="bb" />
5714: $lt{'copm'}<br />
5715: <span class="LC_nobreak">
5716: <input type="text" name="importmap" size="40" value=""
5717: onfocus="this.blur();$mapimportjs" $disabled />
5718: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5719: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
5720: </fieldset>
5721: </form>
5722:
5723: SEDFFORM
5724: my $importcrsresform;
5725: my ($numdirs,$pickfile) =
5726: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5727: "resize_scrollbox('contentscroll','1','0');",
5728: undef,'res');
5729: if ($pickfile) {
5730: $importcrsresform=(<<CRSFORM);
5731: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5732: $lt{'imcr'}</a>$help{'Course_Resources'}
5733: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5734: <fieldset id="importcrsresform" style="display: none;">
5735: <legend>$lt{'imcr'}</legend>
5736: <input type="hidden" name="active" value="bb" />
5737: $pickfile
5738: <p>
5739: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
5740: </p>
5741: <input type="hidden" name="importdetail" value="" />
5742: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
5743: </fieldset>
5744: </form>
5745: CRSFORM
5746: }
5747:
5748: my $fromstoredjs;
5749: if ($canedit) {
5750: $fromstoredjs = 'open_StoredLinks_Import()';
5751: } else {
5752: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5753: }
5754:
5755: my @importpubforma = (
5756: { '<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>" },
5757: { '<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'}" },
5758: { '<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>' },
5759: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5760: );
5761: if ($pickfile) {
5762: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5763: }
5764: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5765: my $extresourcesform =
5766: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5767: $help{'Adding_External_Resource'},
5768: undef,undef,undef,undef,undef,undef,$disabled);
5769: my $exttoolform =
5770: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5771: $help{'Adding_External_Tool'},undef,
5772: undef,'tool',$coursedom,$coursenum,
5773: \%ltitools,$disabled);
5774: if ($allowed) {
5775: my $folder = $env{'form.folder'};
5776: if ($folder eq '') {
5777: $folder='default';
5778: }
5779: if ($canedit) {
5780: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5781: if ($output) {
5782: $r->print($output);
5783: }
5784: }
5785: $r->print(<<HIDDENFORM);
5786: <form name="renameform" method="post" action="/adm/coursedocs">
5787: <input type="hidden" name="title" />
5788: <input type="hidden" name="cmd" />
5789: <input type="hidden" name="markcopy" />
5790: <input type="hidden" name="copyfolder" />
5791: $containertag
5792: </form>
5793:
5794: HIDDENFORM
5795: $r->print(&makesimpleeditform($pathitem)."\n".
5796: &makedocslogform($pathitem."\n".
5797: '<input type="hidden" name="folder" value="'.
5798: $env{'form.folder'}.'" />'."\n"));
5799: }
5800:
5801: # Generate the tabs
5802: my ($mode,$needs_end);
5803: if (($supplementalflag) && (!$allowed)) {
5804: my @folders = split('&',$env{'form.folderpath'});
5805: unless (@folders > 2) {
5806: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5807: $needs_end = 1;
5808: }
5809: } else {
5810: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
5811: $needs_end = 1;
5812: }
5813:
5814: #
5815: my $hostname = $r->hostname();
5816: my $savefolderpath;
5817:
5818: if ($allowed) {
5819: my $folder=$env{'form.folder'};
5820: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
5821: $folder='default';
5822: $savefolderpath = $env{'form.folderpath'};
5823: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
5824: $pathitem = '<input type="hidden" name="folderpath" value="'.
5825: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5826: }
5827: my $postexec='';
5828: if ($folder eq 'default') {
5829: $r->print('<script type="text/javascript">'."\n"
5830: .'// <![CDATA['."\n"
5831: .'this.window.name="loncapaclient";'."\n"
5832: .'// ]]>'."\n"
5833: .'</script>'."\n"
5834: );
5835: } else {
5836: #$postexec='self.close();';
5837: }
5838: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5839: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
5840: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5841:
5842: my $newnavform=(<<NNFORM);
5843: <form action="/adm/coursedocs" method="post" name="newnav">
5844: <input type="hidden" name="active" value="ee" />
5845: $pathitem
5846: <input type="hidden" name="importdetail"
5847: value="$lt{'navc'}=/adm/navmaps" />
5848: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
5849: $help{'Navigate_Content'}
5850: </form>
5851: NNFORM
5852: my $newsmppageform=(<<NSPFORM);
5853: <form action="/adm/coursedocs" method="post" name="newsmppg">
5854: <input type="hidden" name="active" value="ee" />
5855: $pathitem
5856: <input type="hidden" name="importdetail" value="" />
5857: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
5858: $help{'Simple Page'}
5859: </form>
5860: NSPFORM
5861:
5862: my $newsmpproblemform=(<<NSPROBFORM);
5863: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
5864: <input type="hidden" name="active" value="cc" />
5865: $pathitem
5866: <input type="hidden" name="importdetail" value="" />
5867: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
5868: $help{'Simple_Problem'}
5869: </form>
5870:
5871: NSPROBFORM
5872:
5873: my $newdropboxform=(<<NDBFORM);
5874: <form action="/adm/coursedocs" method="post" name="newdropbox">
5875: <input type="hidden" name="active" value="cc" />
5876: $pathitem
5877: <input type="hidden" name="importdetail" value="" />
5878: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
5879: $help{'Dropbox'}
5880: </form>
5881: NDBFORM
5882:
5883: my $newexuploadform=(<<NEXUFORM);
5884: <form action="/adm/coursedocs" method="post" name="newexamupload">
5885: <input type="hidden" name="active" value="cc" />
5886: $pathitem
5887: <input type="hidden" name="importdetail" value="" />
5888: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
5889: $help{'Score_Upload_Form'}
5890: </form>
5891: NEXUFORM
5892:
5893: my $newbulform=(<<NBFORM);
5894: <form action="/adm/coursedocs" method="post" name="newbul">
5895: <input type="hidden" name="active" value="dd" />
5896: $pathitem
5897: <input type="hidden" name="importdetail" value="" />
5898: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
5899: $help{'Bulletin Board'}
5900: </form>
5901: NBFORM
5902:
5903: my $newaboutmeform=(<<NAMFORM);
5904: <form action="/adm/coursedocs" method="post" name="newaboutme">
5905: <input type="hidden" name="active" value="dd" />
5906: $pathitem
5907: <input type="hidden" name="importdetail"
5908: value="$plainname=/adm/$udom/$uname/aboutme" />
5909: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
5910: $help{'My Personal Information Page'}
5911: </form>
5912: NAMFORM
5913:
5914: my $newaboutsomeoneform=(<<NASOFORM);
5915: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
5916: <input type="hidden" name="active" value="dd" />
5917: $pathitem
5918: <input type="hidden" name="importdetail" value="" />
5919: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
5920: </form>
5921: NASOFORM
5922:
5923: my $newrosterform=(<<NROSTFORM);
5924: <form action="/adm/coursedocs" method="post" name="newroster">
5925: <input type="hidden" name="active" value="dd" />
5926: $pathitem
5927: <input type="hidden" name="importdetail"
5928: value="$lt{'rost'}=/adm/viewclasslist" />
5929: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
5930: $help{'Course_Roster'}
5931: </form>
5932: NROSTFORM
5933:
5934: my $newwebpage;
5935: if ($folder =~ /^default_?(\d*)$/) {
5936: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5937: if ($1) {
5938: $newwebpage .= $1;
5939: } else {
5940: $newwebpage .= 'default';
5941: }
5942: $newwebpage .= '/new.html';
5943: }
5944: my $newwebpageform =(<<NWEBFORM);
5945: <form action="/adm/coursedocs" method="post" name="newwebpage">
5946: <input type="hidden" name="active" value="ee" />
5947: $pathitem
5948: <input type="hidden" name="importdetail" value="$newwebpage" />
5949: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
5950: $help{'Web_Page'}
5951: </form>
5952: NWEBFORM
5953:
5954: my @ids=&Apache::lonnet::current_machine_ids();
5955: my %select_menus;
5956: my $numauthor = 0;
5957: my $numcrsdirs = 0;
5958: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5959: if ($env{'user.author'}) {
5960: $numauthor ++;
5961: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5962: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5963: my $is_home = 1;
5964: my %subdirs;
5965: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5966: $select_menus{'author'}->{'default'} = '/';
5967: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5968: my @ordered = ('/');
5969: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5970: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5971: push(@ordered,$relpath);
5972: }
5973: $select_menus{'author'}->{'order'} = \@ordered;
5974: } else {
5975: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5976: $select_menus{'author'}->{'default'} = 'switch';
5977: $select_menus{'author'}->{'order'} = ['switch'];
5978: }
5979: }
5980: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5981: ['active'],['ca','aa']);
5982: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5983: my %by_roletype;
5984: if (keys(%roleshash)) {
5985: foreach my $entry (keys(%roleshash)) {
5986: my ($auname,$audom,$roletype) = split(/:/,$entry);
5987: my $key = $entry;
5988: $key =~ s/:/___/g;
5989: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5990: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5991: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5992: if (grep(/^\Q$rolehome\E$/,@ids)) {
5993: my $is_home = 1;
5994: my (%subdirs,@ordered);
5995: my $toppath="/priv/$audom/$auname";
5996: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5997: $select_menus{$key}->{'default'} = '/';
5998: $select_menus{$key}->{'select2'}->{'/'} = '/';
5999: my @ordered = ('/');
6000: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6001: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6002: push(@ordered,$relpath);
6003: }
6004: $select_menus{$key}->{'order'} = \@ordered;
6005: } else {
6006: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6007: $select_menus{$key}->{'default'} = 'switch';
6008: $select_menus{$key}->{'order'} = ['switch'];
6009: }
6010: $numauthor ++;
6011: }
6012: }
6013: my ($pickdir,$showtitle);;
6014: if ($numauthor) {
6015: my @order;
6016: my $defrole;
6017: if ($env{'user.author'}) {
6018: push(@order,'author');
6019: $defrole = 'author';
6020: }
6021: if (keys(%by_roletype)) {
6022: foreach my $possrole ('ca','aa') {
6023: if (ref($by_roletype{$possrole}) eq 'HASH') {
6024: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6025: unless ($defrole) {
6026: $defrole = $author;
6027: }
6028: push(@order,$author.'___'.$possrole);
6029: }
6030: }
6031: }
6032: }
6033: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6034: if (grep(/^\Q$crshome\E$/,@ids)) {
6035: my $is_home = 1;
6036: my %subdirs;
6037: my $toppath="/priv/$coursedom/$coursenum";
6038: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6039: $numcrsdirs = keys(%subdirs);
6040: $select_menus{'course'}->{'default'} = '/';
6041: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6042: my @ordered = ('/');
6043: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6044: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6045: push(@ordered,$relpath);
6046: }
6047: $select_menus{'course'}->{'order'} = \@ordered;
6048: } else {
6049: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6050: $select_menus{'course'}->{'default'} = 'switch';
6051: $select_menus{'course'}->{'order'} = ['switch'];
6052: }
6053: push(@order,'course');
6054: $pickdir = $lt{'loca'}.
6055: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6056: $defrole,'authorrole','authorpath',
6057: \%select_menus,\@order,'toggleCrsResTitle();',
6058: '','priv').'<br />';
6059: $showtitle = 'none';
6060: } else {
6061: my $is_home;
6062: $showtitle = 'inline';
6063: if (grep(/^\Q$crshome\E$/,@ids)) {
6064: $is_home = 1;
6065: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6066: my $toppath="/priv/$coursedom/$coursenum'}";
6067: my %subdirs;
6068: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6069: $numcrsdirs = keys(%subdirs);
6070: if ($numcrsdirs) {
6071: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6072: '<option value="/">/</option>'."\n";
6073: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6074: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
6075: }
6076: $pickdir .= '</select>';
6077: } else {
6078: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6079: }
6080: }
6081: }
6082:
6083: my %seltemplate_menus;
6084: my @files = &Apache::lonhomework::get_template_list('problem');
6085: my @noexamplelink = ('blank.problem','blank.library','script.library');
6086: my $currentcategory = '';
6087: my @ordered = ('');
6088: my %templatehelp;
6089: my $defcategory = '';
6090: my @catorder = ($defcategory);
6091: $seltemplate_menus{$defcategory}->{'order'} = [''];
6092: $seltemplate_menus{$defcategory}->{'text'} = '';
6093: foreach my $file (@files) {
6094: if (ref($file) eq 'ARRAY') {
6095: my ($path,$title,$category,$help) = @{$file};
6096: next if ($title !~ /\S/);
6097: if (&js_escape($category) ne $currentcategory) {
6098: $currentcategory = &js_escape($category);
6099: push(@catorder,&js_escape($currentcategory));
6100: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6101: $seltemplate_menus{$currentcategory}->{'default'} = '';
6102: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6103: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6104: }
6105: if ($path) {
6106: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6107: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6108: if ($help) {
6109: $templatehelp{$path} = $help;
6110: }
6111: }
6112: }
6113: }
6114:
6115: my $templates = $lt{'cate'}.' '.
6116: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6117: $defcategory,'tempcategory','template',
6118: \%seltemplate_menus,\@catorder,
6119: "resize_scrollbox('contentscroll','1','0');",
6120: "toggleExampleText();",'template').'<br />';
6121: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6122: '<span id="newresexample">'.&mt('Example').'<span></a>';
6123: my $crsresform=(<<RESFORM);
6124: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6125: $lt{'stpr'}</a>$help{'Course_Resource'}
6126: <form action="/adm/coursedocs" method="post" name="courseresform">
6127: <fieldset id="crsresform" style="display:none;">
6128: <legend>$lt{'stpr'}</legend>
6129: <input type="hidden" name="active" value="ee" />
6130: <p>
6131: $pickdir
6132: <span class="LC_nobreak">$lt{'news'}?
6133: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6134:
6135: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6136: </span><span id="newsubdir"></span>
6137: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6138: </p>
6139: $lt{'fnam'}
6140: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6141: <p>
6142: <div id="newresource" style="display:$showtitle">
6143: $lt{'addp'}
6144: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6145: $lt{'no'}</label>
6146: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6147: $lt{'yes'}</label>
6148: <span id="newrestitle"></span>
6149: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6150: </div>
6151: </p>
6152: <p>
6153: $lt{'uste'}
6154: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6155: $lt{'no'}</label>
6156: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6157: $lt{'yes'}</label>
6158: <div id="newrestemplate" style="display:none">
6159: $templates
6160: $templatepreview
6161: </div>
6162: </p>
6163: <span class="LC_nobreak">
6164: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6165: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6166: </span>
6167: </fieldset>
6168: </form>
6169:
6170: RESFORM
6171:
6172: my $specialdocumentsform;
6173: my @specialdocumentsforma;
6174: my $gradingform;
6175: my @gradingforma;
6176: my $communityform;
6177: my @communityforma;
6178: my $newfolderform;
6179: my $newfolderb;
6180:
6181: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6182:
6183: my $newpageform=(<<NPFORM);
6184: <form action="/adm/coursedocs" method="post" name="newpage">
6185: <input type="hidden" name="folderpath" value="$path" />
6186: <input type="hidden" name="importdetail" value="" />
6187: <input type="hidden" name="active" value="ee" />
6188: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6189: $help{'Adding_Pages'}
6190: </form>
6191: NPFORM
6192:
6193:
6194: $newfolderform=(<<NFFORM);
6195: <form action="/adm/coursedocs" method="post" name="newfolder">
6196: $pathitem
6197: <input type="hidden" name="importdetail" value="" />
6198: <input type="hidden" name="active" value="" />
6199: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6200: </form>
6201: NFFORM
6202:
6203: my $newsylform=(<<NSYLFORM);
6204: <form action="/adm/coursedocs" method="post" name="newsyl">
6205: <input type="hidden" name="active" value="ee" />
6206: $pathitem
6207: <input type="hidden" name="importdetail"
6208: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6209: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6210: $help{'Syllabus'}
6211:
6212: </form>
6213: NSYLFORM
6214:
6215: my $newgroupfileform=(<<NGFFORM);
6216: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6217: <input type="hidden" name="active" value="dd" />
6218: $pathitem
6219: <input type="hidden" name="importdetail"
6220: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6221: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6222: $help{'Group Portfolio'}
6223: </form>
6224: NGFFORM
6225: @specialdocumentsforma=(
6226: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6227: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6228: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6229: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6230: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6231: );
6232: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6233:
6234:
6235: my @importdoc = (
6236: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6237: );
6238: if (keys(%ltitools)) {
6239: push(@importdoc,
6240: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6241: );
6242: }
6243: unless ($container eq 'page') {
6244: push(@importdoc,
6245: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6246: );
6247: }
6248: push(@importdoc,
6249: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6250: );
6251: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6252:
6253: @gradingforma=(
6254: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6255: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6256: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6257: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6258: );
6259: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6260:
6261: @communityforma=(
6262: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6263: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6264: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6265: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6266: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6267: );
6268: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6269:
6270: my %orderhash = (
6271: 'aa' => ['Upload',$fileuploadform],
6272: 'bb' => ['Import',$importpubform],
6273: 'cc' => ['Grading',$gradingform],
6274: );
6275: unless ($container eq 'page') {
6276: $orderhash{'00'} = ['Newfolder',$newfolderform];
6277: $orderhash{'dd'} = ['Collaboration',$communityform];
6278: $orderhash{'ee'} = ['Other',$specialdocumentsform];
6279: }
6280:
6281: $hadchanges=0;
6282: unless (($supplementalflag || $toolsflag)) {
6283: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6284: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6285: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
6286: undef($navmap);
6287: if ($error) {
6288: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6289: }
6290: if ($hadchanges) {
6291: &mark_hash_old();
6292: }
6293:
6294: &changewarning($r,'');
6295: }
6296: }
6297:
6298: # Supplemental documents start here
6299:
6300: my $folder=$env{'form.folder'};
6301: unless ($supplementalflag) {
6302: $folder='supplemental';
6303: }
6304: if ($folder =~ /^supplemental$/ &&
6305: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6306: $env{'form.folderpath'} = &supplemental_base();
6307: } elsif ($allowed) {
6308: $env{'form.folderpath'} = $savefolderpath;
6309: }
6310: $pathitem = '<input type="hidden" name="folderpath" value="'.
6311: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6312: if ($allowed) {
6313: my $folderseq=
6314: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6315:
6316: my $supupdocform=(<<SUPDOCFORM);
6317: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6318: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6319: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6320: <fieldset id="uploadsuppdocform" style="display: none;">
6321: <legend>$lt{'upfi'}</legend>
6322: <input type="hidden" name="active" value="ee" />
6323: $fileupload
6324: <br />
6325: <br />
6326: <span class="LC_nobreak">
6327: $checkbox
6328: </span>
6329: <br /><br />
6330: $lt{'comment'}:<br />
6331: <textarea cols="50" rows="4" name="comment"></textarea>
6332: <br />
6333: $pathitem
6334: <input type="hidden" name="cmd" value="upload_supplemental" />
6335: <input type='submit' value="$lt{'upld'}" />
6336: </form>
6337: SUPDOCFORM
6338:
6339: my $supnewfolderform=(<<SNFFORM);
6340: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6341: <input type="hidden" name="active" value="" />
6342: $pathitem
6343: <input type="hidden" name="importdetail" value="" />
6344: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6345: $help{'Adding_Folders'}
6346: </form>
6347: SNFFORM
6348:
6349: my $supextform =
6350: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6351: $help{'Adding_External_Resource'},
6352: undef,undef,undef,undef,undef,undef,
6353: $disabled);
6354:
6355: my $supexttoolform =
6356: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6357: $help{'Adding_External_Tool'},
6358: undef,undef,'tool',$coursedom,
6359: $coursenum,\%ltitools,$disabled);
6360:
6361: my $supnewsylform=(<<SNSFORM);
6362: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6363: <input type="hidden" name="active" value="ff" />
6364: $pathitem
6365: <input type="hidden" name="importdetail"
6366: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6367: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6368: $help{'Syllabus'}
6369: </form>
6370: SNSFORM
6371:
6372: my $supnewaboutmeform=(<<SNAMFORM);
6373: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6374: <input type="hidden" name="active" value="ff" />
6375: $pathitem
6376: <input type="hidden" name="importdetail"
6377: value="$plainname=/adm/$udom/$uname/aboutme" />
6378: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6379: $help{'My Personal Information Page'}
6380: </form>
6381: SNAMFORM
6382:
6383: my $supwebpage;
6384: if ($folder =~ /^supplemental_?(\d*)$/) {
6385: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6386: if ($1) {
6387: $supwebpage .= $1;
6388: } else {
6389: $supwebpage .= 'default';
6390: }
6391: $supwebpage .= '/new.html';
6392: }
6393: my $supwebpageform =(<<SWEBFORM);
6394: <form action="/adm/coursedocs" method="post" name="supwebpage">
6395: <input type="hidden" name="active" value="cc" />
6396: $pathitem
6397: <input type="hidden" name="importdetail" value="$supwebpage" />
6398: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6399: $help{'Web_Page'}
6400: </form>
6401: SWEBFORM
6402:
6403:
6404: my @specialdocs = (
6405: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
6406: =>$supnewsylform},
6407: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6408: =>$supnewaboutmeform},
6409: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6410:
6411: );
6412: my @supimportdoc = (
6413: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
6414: =>$supextform});
6415: if (keys(%ltitools)) {
6416: push(@supimportdoc,
6417: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6418: =>$supexttoolform});
6419: }
6420: push(@supimportdoc,
6421: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6422: =>$supupdocform},
6423: );
6424:
6425: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6426: my %suporderhash = (
6427: '00' => ['Supnewfolder', $supnewfolderform],
6428: 'ee' => ['Upload',$supupdocform],
6429: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6430: );
6431: if ($supplementalflag) {
6432: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6433: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6434: \%ltitools,$canedit,$hostname);
6435: if ($error) {
6436: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6437: } else {
6438: if ($suppchanges) {
6439: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6440: my @ids=&Apache::lonnet::current_machine_ids();
6441: foreach my $server (keys(%servers)) {
6442: next if (grep(/^\Q$server\E$/,@ids));
6443: my $hashid=$coursenum.':'.$coursedom;
6444: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6445: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
6446: }
6447: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6448: undef($suppchanges);
6449: }
6450: }
6451: }
6452: } elsif ($supplementalflag) {
6453: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6454: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
6455: if ($error) {
6456: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6457: }
6458: }
6459:
6460: if ($needs_end) {
6461: $r->print(&endContentScreen());
6462: }
6463:
6464: if ($allowed) {
6465: $r->print('
6466: <form method="post" name="extimport" action="/adm/coursedocs">
6467: <input type="hidden" name="title" />
6468: <input type="hidden" name="url" />
6469: <input type="hidden" name="useform" />
6470: <input type="hidden" name="residx" />
6471: </form>');
6472: }
6473: } elsif ($showdoc) {
6474: # -------------------------------------------------------- This is showdoc mode
6475: $r->print("<h1>".&mt('Uploaded Document').' - '.
6476: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6477: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6478: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6479: }
6480: }
6481: unless ($noendpage) {
6482: $r->print(&Apache::loncommon::end_page());
6483: }
6484: return OK;
6485: }
6486:
6487: sub embedded_form_elems {
6488: my ($phase,$primaryurl,$newidx) = @_;
6489: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6490: return <<STATE;
6491: <input type="hidden" name="folderpath" value="$folderpath" />
6492: <input type="hidden" name="cmd" value="upload_embedded" />
6493: <input type="hidden" name="newidx" value="$newidx" />
6494: <input type="hidden" name="phase" value="$phase" />
6495: <input type="hidden" name="primaryurl" value="$primaryurl" />
6496: STATE
6497: }
6498:
6499: sub embedded_destination {
6500: my $folder=$env{'form.folder'};
6501: my $destination = 'docs/';
6502: if ($folder =~ /^supplemental/) {
6503: $destination = 'supplemental/';
6504: }
6505: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6506: $destination .= 'default/';
6507: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6508: $destination .= $2.'/';
6509: }
6510: $destination .= $env{'form.newidx'};
6511: my $dir_root = '/userfiles';
6512: return ($destination,$dir_root);
6513: }
6514:
6515: sub return_to_editor {
6516: my $actionurl = '/adm/coursedocs';
6517: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6518: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6519: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6520: '</a></p>';
6521: }
6522:
6523: sub decompression_info {
6524: my ($destination,$dir_root) = &embedded_destination();
6525: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6526: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6527: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6528: my $container='sequence';
6529: my ($pathitem,$hiddenelem);
6530: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
6531: if ($env{'form.folderpath'} =~ /\:1$/) {
6532: $container='page';
6533: }
6534: unshift(@hiddens,$pathitem);
6535: foreach my $item (@hiddens) {
6536: if ($env{'form.'.$item}) {
6537: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
6538: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
6539: }
6540: }
6541: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6542: $hiddenelem);
6543: }
6544:
6545: sub decompression_phase_one {
6546: my ($dir,$file,$warning,$error,$output);
6547: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6548: &decompression_info();
6549: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
6550: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6551: } else {
6552: my $file = $1;
6553: $output =
6554: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6555: $destination,$dir_root,
6556: $hiddenelem);
6557: if ($env{'form.autoextract_camtasia'}) {
6558: $output .= &remove_archive($docudom,$docuname,$container);
6559: }
6560: }
6561: if ($error) {
6562: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6563: $error.'</p>'."\n";
6564: }
6565: if ($warning) {
6566: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6567: }
6568: return $output;
6569: }
6570:
6571: sub decompression_phase_two {
6572: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6573: &decompression_info();
6574: my $output;
6575: if ($env{'form.archivedelete'}) {
6576: $output = &remove_archive($docudom,$docuname,$container);
6577: }
6578: $output .=
6579: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
6580: $destination,$dir_root,$hiddenelem);
6581: return $output;
6582: }
6583:
6584: sub remove_archive {
6585: my ($docudom,$docuname,$container) = @_;
6586: my $map = $env{'form.folder'}.'.'.$container;
6587: my ($output,$delwarning,$delresult,$url);
6588: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6589: if ($fatal) {
6590: if ($container eq 'page') {
6591: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6592: } else {
6593: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6594: }
6595: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
6596: } else {
6597: my $currcmd = $env{'form.cmd'};
6598: my $position = $env{'form.position'};
6599: my $archiveidx = $position;
6600: if ($position > 0) {
6601: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6602: $archiveidx = $position-1;
6603: }
6604: $env{'form.cmd'} = 'remove_'.$archiveidx;
6605: my ($title,$url,@rrest) =
6606: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6607: if ($url eq $env{'form.archiveurl'}) {
6608: if (&handle_edit_cmd($docuname,$docudom)) {
6609: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6610: if ($fatal) {
6611: if ($container eq 'page') {
6612: $delwarning = &mt('An error occurred updating the contents of the current page.');
6613: } else {
6614: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6615: }
6616: } else {
6617: $delresult = &mt('Archive file removed.');
6618: }
6619: }
6620: } else {
6621: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6622: ' '.&mt('As a result the archive file has not been removed.');
6623: }
6624: }
6625: $env{'form.cmd'} = $currcmd;
6626: }
6627: if ($delwarning) {
6628: $output = '<p class="LC_warning">'.
6629: $delwarning.
6630: '</p>';
6631: }
6632: if ($delresult) {
6633: $output .= '<p class="LC_info">'.
6634: $delresult.
6635: '</p>';
6636: }
6637: return $output;
6638: }
6639:
6640: sub generate_admin_menu {
6641: my ($crstype,$canedit) = @_;
6642: my $lc_crstype = lc($crstype);
6643: my ($home,$other,%outhash)=&authorhosts();
6644: my %lt= ( # do not translate here
6645: 'vc' => 'Verify Content',
6646: 'cv' => 'Check/Set Resource Versions',
6647: 'ls' => 'List Resource Identifiers',
6648: 'imse' => 'Export contents to IMS Archive',
6649: 'dcd' => "Copy $crstype Content to Authoring Space",
6650: );
6651: my ($candump,$dumpurl);
6652: if ($home + $other > 0) {
6653: $candump = 'F';
6654: if ($home) {
6655: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6656: } else {
6657: my @hosts;
6658: foreach my $aurole (keys(%outhash)) {
6659: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6660: push(@hosts,$outhash{$aurole});
6661: }
6662: }
6663: if (@hosts == 1) {
6664: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6665: '&role='.
6666: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6667: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6668: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6669: } else {
6670: $dumpurl = "javascript:choose_switchserver_window()";
6671: }
6672: }
6673: }
6674: my @menu=
6675: ({ categorytitle=>'Administration',
6676: items =>[
6677: { linktext => $lt{'vc'},
6678: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6679: permission => 'F',
6680: help => 'Docs_Verify_Content',
6681: icon => 'verify.png',
6682: linktitle => 'Verify contents can be retrieved/rendered',
6683: },
6684: { linktext => $lt{'cv'},
6685: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6686: permission => 'F',
6687: help => 'Docs_Check_Resource_Versions',
6688: icon => 'resversion.png',
6689: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6690: },
6691: { linktext => $lt{'ls'},
6692: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6693: permission => 'F',
6694: #help => '',
6695: icon => 'symbs.png',
6696: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6697: },
6698: ]
6699: });
6700: if ($canedit) {
6701: push(@menu,
6702: { categorytitle=>'Export',
6703: items =>[
6704: { linktext => $lt{'imse'},
6705: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6706: permission => 'F',
6707: help => 'Docs_Export_Course_Docs',
6708: icon => 'imsexport.png',
6709: linktitle => $lt{'imse'},
6710: },
6711: { linktext => $lt{'dcd'},
6712: url => $dumpurl,
6713: permission => $candump,
6714: help => 'Docs_Dump_Course_Docs',
6715: icon => 'dump.png',
6716: linktitle => $lt{'dcd'},
6717: },
6718: ]
6719: });
6720: }
6721: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6722: '<input type="hidden" id="dummy" />'."\n".
6723: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6724: '</form>';
6725: }
6726:
6727: sub generate_edit_table {
6728: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
6729: $need_save,$copyfolder,$canedit) = @_;
6730: return unless(ref($orderhash_ref) eq 'HASH');
6731: my %orderhash = %{$orderhash_ref};
6732: my ($form, $activetab, $active, $disabled);
6733: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
6734: $activetab = $env{'form.active'};
6735: }
6736: unless ($canedit) {
6737: $disabled = ' disabled="disabled"';
6738: }
6739: my $backicon = $iconpath.'clickhere.gif';
6740: my $backtext = &mt('Exit Editor');
6741: $form = '<div class="LC_Box" style="margin:0;">'.
6742: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6743: '<li class="goback">'.
6744: '<a href="javascript:toContents('."'$jumpto'".');">'.
6745: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6746: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6747: '<li>'.
6748: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6749: &mt('Undo Delete').'</a></li>'."\n";
6750: if ($env{'form.docslog'}) {
6751: $form .= '<li class="active">';
6752: } else {
6753: $form .= '<li>';
6754: }
6755: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6756: &mt('History').'</a></li>'."\n";
6757: if ($env{'form.docslog'}) {
6758: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6759: &mt('Edit').'</a></li>'."\n";
6760: }
6761: foreach my $name (reverse(sort(keys(%orderhash)))) {
6762: if($name ne '00'){
6763: if($activetab eq '' || $activetab ne $name){
6764: $active = '';
6765: }elsif($activetab eq $name){
6766: $active = 'class="active"';
6767: }
6768: $form .= '<li style="float:right" '.$active
6769: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
6770: } else {
6771: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
6772:
6773: }
6774: }
6775: $form .= '</ul>'."\n";
6776: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
6777:
6778: if ($to_show ne '') {
6779: my $saveform;
6780: if ($need_save) {
6781: my $button = &mt('Make changes');
6782: my $path;
6783: if ($env{'form.folderpath'}) {
6784: $path =
6785: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6786: }
6787: $saveform = <<"END";
6788: <div id="multisave" style="display:none; clear:both;" >
6789: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6790: <input type="hidden" name="folderpath" value="$path" />
6791: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6792: <input type="hidden" name="allhiddenresource" value="" />
6793: <input type="hidden" name="allencrypturl" value="" />
6794: <input type="hidden" name="allrandompick" value="" />
6795: <input type="hidden" name="allrandomorder" value="" />
6796: <input type="hidden" name="changeparms" value="" />
6797: <input type="hidden" name="multiremove" value="" />
6798: <input type="hidden" name="multicut" value="" />
6799: <input type="hidden" name="multicopy" value="" />
6800: <input type="hidden" name="multichange" value="" />
6801: <input type="hidden" name="copyfolder" value="$copyfolder" />
6802: <input type="submit" name="savemultiples" value="$button" $disabled />
6803: </form>
6804: </div>
6805: END
6806: }
6807: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
6808: }
6809: foreach my $field (keys(%orderhash)){
6810: if($field ne '00'){
6811: if($activetab eq '' || $activetab ne $field){
6812: $active = 'style="display: none;float:left"';
6813: }elsif($activetab eq $field){
6814: $active = 'style="display:block;float:left"';
6815: }
6816: $form .= '<div id="'.$field.$tid.'"'
6817: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
6818: .'</div>'."\n";
6819: }
6820: }
6821: unless ($env{'form.docslog'}) {
6822: $form .= '</div></div>'."\n";
6823: }
6824: return $form;
6825: }
6826:
6827: sub editing_js {
6828: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6829: $londocroot,$canedit,$hostname,$navmapref) = @_;
6830: my %js_lt = &Apache::lonlocal::texthash(
6831: p_mnf => 'Name of New Folder',
6832: t_mnf => 'New Folder',
6833: p_mnp => 'Name of New Page',
6834: t_mnp => 'New Page',
6835: p_mxu => 'Title for the External Score',
6836: p_msp => 'Name of Simple Course Page',
6837: p_msb => 'Title for the Problem',
6838: p_mdb => 'Title for the Drop Box',
6839: p_mbb => 'Title for the Discussion Board',
6840: p_mwp => 'Title for Web Page',
6841: p_mnr => 'Title for the Resource',
6842: p_mab => "Enter user:domain for User's Personal Information Page",
6843: p_mab2 => 'Personal Information Page of ',
6844: p_mab_alrt1 => 'Not a valid user:domain',
6845: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6846: p_chn => 'New Title',
6847: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
6848: p_rmr2a => 'Remove',
6849: p_rmr2b => '?',
6850: p_rmr3a => 'Remove those',
6851: p_rmr3b => 'items?',
6852: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6853: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
6854: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6855: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
6856: p_ctr2a => 'Cut',
6857: p_ctr2b => '?',
6858: p_ctr3a => 'Cut those',
6859: p_ctr3b => 'items?',
6860: rpck => 'Enter number to pick (e.g., 3)',
6861: imsfile => 'You must choose an IMS package for import',
6862: imscms => 'You must select which Course Management System was the source of the IMS package',
6863: invurl => 'Invalid URL',
6864: titbl => 'Title is blank',
6865: more => '(More ...)',
6866: less => '(Less ...)',
6867: noor => 'No actions selected or changes to settings specified.',
6868: noch => 'No changes to settings specified.',
6869: noac => 'No actions selected.',
6870: nofi => 'No file selected',
6871: tinc => 'Title in course',
6872: sunm => 'Sub-directory name',
6873: edri => 'Editing rights unavailable for your current role.',
6874: );
6875: &js_escape(\%js_lt);
6876: my $crstype = &Apache::loncommon::course_type();
6877: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6878: my $main_container_page;
6879: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6880: $main_container_page = 1;
6881: }
6882: my $backtourl;
6883: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
6884: my $toplevelsupp = &supplemental_base();
6885:
6886: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6887: my $caller = $1;
6888: if ($caller =~ /^supplemental/) {
6889: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6890: } else {
6891: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6892: $res = &Apache::lonnet::clutter($res);
6893: if (&Apache::lonnet::is_on_map($res)) {
6894: my ($url,$anchor);
6895: if ($res =~ /^([^#]+)#([^#]+)$/) {
6896: $url = $1;
6897: $anchor = $2;
6898: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6899: $caller = $1.&escape('#').$anchor;
6900: }
6901: } else {
6902: $url = $res;
6903: }
6904: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
6905: &HTML::Entities::encode($caller,'<>&"');
6906: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6907: if (($ENV{'SERVER_PORT'} == 443) &&
6908: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6909: if ($hostname ne '') {
6910: $backtourl = 'http://'.$hostname.$backtourl;
6911: }
6912: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6913: }
6914: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6915: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6916: $backtourl = 'http://'.$hostname.$backtourl;
6917: }
6918: }
6919: if ($anchor ne '') {
6920: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6921: }
6922: $backtourl = &Apache::loncommon::escape_single($backtourl);
6923: } else {
6924: $backtourl = '/adm/navmaps';
6925: }
6926: }
6927: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6928: $backtourl = '/adm/menu';
6929: } elsif ($supplementalflag) {
6930: $backtourl = '/adm/supplemental';
6931: } else {
6932: $backtourl = '/adm/navmaps';
6933: }
6934:
6935: my $fieldsets = "'ext','doc'";
6936: if ($posslti) {
6937: $fieldsets .= ",'tool'";
6938: }
6939: unless ($main_container_page) {
6940: $fieldsets .=",'ims'";
6941: }
6942: if ($supplementalflag) {
6943: $fieldsets = "'suppext','suppdoc'";
6944: if ($posslti) {
6945: $fieldsets .= ",'supptool'";
6946: }
6947: }
6948:
6949: my $jsmakefunctions;
6950: if ($canedit) {
6951: $jsmakefunctions = <<ENDNEWSCRIPT;
6952: function makenewfolder(targetform,folderseq) {
6953: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
6954: if (foldername) {
6955: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6956: targetform.submit();
6957: }
6958: }
6959:
6960: function makenewpage(targetform,folderseq) {
6961: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
6962: if (pagename) {
6963: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6964: targetform.submit();
6965: }
6966: }
6967:
6968: function makeexamupload() {
6969: var title=prompt('$js_lt{"p_mxu"}');
6970: if (title) {
6971: this.document.forms.newexamupload.importdetail.value=
6972: escape(title)+'=/res/lib/templates/examupload.problem';
6973: this.document.forms.newexamupload.submit();
6974: }
6975: }
6976:
6977: function makesmppage() {
6978: var title=prompt('$js_lt{"p_msp"}');
6979: if (title) {
6980: this.document.forms.newsmppg.importdetail.value=
6981: escape(title)+'=/adm/$udom/$uname/new/smppg';
6982: this.document.forms.newsmppg.submit();
6983: }
6984: }
6985:
6986: function makewebpage(type) {
6987: var title=prompt('$js_lt{"p_mwp"}');
6988: var formname;
6989: if (type == 'supp') {
6990: formname = this.document.forms.supwebpage;
6991: } else {
6992: formname = this.document.forms.newwebpage;
6993: }
6994: if (title) {
6995: var webpage = formname.importdetail.value;
6996: formname.importdetail.value = escape(title)+'='+webpage;
6997: formname.submit();
6998: }
6999: }
7000:
7001: function makesmpproblem() {
7002: var title=prompt('$js_lt{"p_msb"}');
7003: if (title) {
7004: this.document.forms.newsmpproblem.importdetail.value=
7005: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7006: this.document.forms.newsmpproblem.submit();
7007: }
7008: }
7009:
7010: function makedropbox() {
7011: var title=prompt('$js_lt{"p_mdb"}');
7012: if (title) {
7013: this.document.forms.newdropbox.importdetail.value=
7014: escape(title)+'=/res/lib/templates/DropBox.problem';
7015: this.document.forms.newdropbox.submit();
7016: }
7017: }
7018:
7019: function makebulboard() {
7020: var title=prompt('$js_lt{"p_mbb"}');
7021: if (title) {
7022: this.document.forms.newbul.importdetail.value=
7023: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
7024: this.document.forms.newbul.submit();
7025: }
7026: }
7027:
7028: function makeabout() {
7029: var user=prompt("$js_lt{'p_mab'}");
7030: if (user) {
7031: var comp=new Array();
7032: comp=user.split(':');
7033: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7034: if ((comp[0]) && (comp[1])) {
7035: this.document.forms.newaboutsomeone.importdetail.value=
7036: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7037: this.document.forms.newaboutsomeone.submit();
7038: } else {
7039: alert("$js_lt{'p_mab_alrt1'}");
7040: }
7041: } else {
7042: alert("$js_lt{'p_mab_alrt2'}");
7043: }
7044: }
7045: }
7046:
7047: function makenew(targetform) {
7048: targetform.submit();
7049: }
7050:
7051: function changename(folderpath,index,oldtitle) {
7052: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7053: if (title) {
7054: this.document.forms.renameform.markcopy.value='';
7055: this.document.forms.renameform.title.value=title;
7056: this.document.forms.renameform.cmd.value='rename_'+index;
7057: this.document.forms.renameform.folderpath.value=folderpath;
7058: this.document.forms.renameform.submit();
7059: }
7060: }
7061:
7062: ENDNEWSCRIPT
7063: } else {
7064: $jsmakefunctions = <<ENDNEWSCRIPT;
7065:
7066: function makenewfolder() {
7067: alert("$js_lt{'edri'}");
7068: }
7069:
7070: function makenewpage() {
7071: alert("$js_lt{'edri'}");
7072: }
7073:
7074: function makeexamupload() {
7075: alert("$js_lt{'edri'}");
7076: }
7077:
7078: function makesmppage() {
7079: alert("$js_lt{'edri'}");
7080: }
7081:
7082: function makewebpage(type) {
7083: alert("$js_lt{'edri'}");
7084: }
7085:
7086: function makesmpproblem() {
7087: alert("$js_lt{'edri'}");
7088: }
7089:
7090: function makedropbox() {
7091: alert("$js_lt{'edri'}");
7092: }
7093:
7094: function makebulboard() {
7095: alert("$js_lt{'edri'}");
7096: }
7097:
7098: function makeabout() {
7099: alert("$js_lt{'edri'}");
7100: }
7101:
7102: function changename() {
7103: alert("$js_lt{'edri'}");
7104: }
7105:
7106: function makenew() {
7107: alert("$js_lt{'edri'}");
7108: }
7109:
7110: function groupimport() {
7111: alert("$js_lt{'edri'}");
7112: }
7113:
7114: function groupsearch() {
7115: alert("$js_lt{'edri'}");
7116: }
7117:
7118: function groupopen(url,recover) {
7119: var options="scrollbars=1,resizable=1,menubar=0";
7120: idxflag=1;
7121: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7122: idx.focus();
7123: }
7124:
7125: ENDNEWSCRIPT
7126:
7127: }
7128: return <<ENDSCRIPT;
7129:
7130: $jsmakefunctions
7131:
7132: function toggleUpload(caller) {
7133: var blocks = Array($fieldsets);
7134: for (var i=0; i<blocks.length; i++) {
7135: var disp = 'none';
7136: if (caller == blocks[i]) {
7137: var curr = document.getElementById('upload'+caller+'form').style.display;
7138: if (curr == 'none') {
7139: disp='block';
7140: }
7141: }
7142: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7143: if ((caller == 'tool') || (caller == 'supptool')) {
7144: if (disp == 'block') {
7145: if (document.getElementById('LC_exttoolid')) {
7146: var toolselector = document.getElementById('LC_exttoolid');
7147: var suppflag = 0;
7148: if (caller == 'supptool') {
7149: suppflag = 1;
7150: }
7151: currForm = document.getElementById('new'+caller);
7152: updateExttool(toolselector,currForm,suppflag);
7153: }
7154: }
7155: }
7156: }
7157: resize_scrollbox('contentscroll','1','1');
7158: return;
7159: }
7160:
7161: function toggleMap(caller) {
7162: var disp = 'none';
7163: if (document.getElementById('importmapform')) {
7164: if (caller == 'map') {
7165: var curr = document.getElementById('importmapform').style.display;
7166: if (curr == 'none') {
7167: disp='block';
7168: }
7169: }
7170: document.getElementById('importmapform').style.display=disp;
7171: resize_scrollbox('contentscroll','1','1');
7172: }
7173: return;
7174: }
7175:
7176: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7177: var disp = 'none';
7178: if (document.getElementById('crsresform')) {
7179: if (caller == 'res') {
7180: var curr = document.getElementById('crsresform').style.display;
7181: if (curr == 'none') {
7182: disp='block';
7183: numauthor = parseInt(numauthorrole);
7184: if (numauthor > 0) {
7185: document.courseresform.authorrole.selectedIndex = 0;
7186: select1priv_changed();
7187: document.courseresform.authorpath.selectedIndex = 0;
7188: document.courseresform.newresourceadd.selectedIndex = 0;
7189: toggleNewInCourse(document.courseresform);
7190: if (document.getElementById('newresource')) {
7191: document.getElementById('newresource').style.display = 'none';
7192: }
7193: } else {
7194: if (numcrsdirs) {
7195: document.courseresform.authorpath.selectedIndex = 0;
7196: }
7197: }
7198: if (document.courseresform.newresusetemp.length) {
7199: document.courseresform.newresusetemp[0].checked = true;
7200: toggleWithTemplate(document.courseresform);
7201: }
7202: document.courseresform.newresourcename.value = '';
7203: }
7204: }
7205: if (document.courseresform.newsubdir.length) {
7206: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7207: if (document.courseresform.newsubdir[j].value == 0) {
7208: document.courseresform.newsubdir[j].checked = true;
7209: }
7210: break;
7211: }
7212: if (document.getElementById('newsubdirname')) {
7213: document.getElementById('newsubdirname').type = "hidden";
7214: document.getElementById('newsubdirname').value = "";
7215: }
7216: if (document.getElementById('newsubdir')) {
7217: document.getElementById('newsubdir').innerHTML = "";
7218: }
7219: }
7220: document.getElementById('crsresform').style.display=disp;
7221: resize_scrollbox('contentscroll','1','0');
7222: }
7223: return;
7224: }
7225:
7226: function toggleNewsubdir(form) {
7227: if (form.newsubdir.length) {
7228: for (var j=0; j<form.newsubdir.length; j++) {
7229: if (form.newsubdir[j].checked) {
7230: if (document.getElementById('newsubdirname')) {
7231: if (form.newsubdir[j].value == '1') {
7232: document.getElementById('newsubdirname').type = "text";
7233: if (document.getElementById('newsubdir')) {
7234: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7235: }
7236: } else {
7237: document.getElementById('newsubdirname').type = "hidden";
7238: document.getElementById('newsubdirname').value = "";
7239: document.getElementById('newsubdir').innerHTML = "";
7240: }
7241: }
7242: break;
7243: }
7244: }
7245: }
7246: }
7247:
7248: function toggleCrsResTitle() {
7249: if (document.getElementById('newresource')) {
7250: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7251: document.getElementById('newresource').style.display = 'inline';
7252: document.courseresform.newresourceadd[0].checked = true;
7253: toggleNewInCourse(document.courseresform);
7254: } else {
7255: document.getElementById('newresource').style.display = 'none';
7256: }
7257: }
7258: }
7259:
7260: function toggleNewInCourse(form) {
7261: if (form.newresourceadd.length) {
7262: for (var i=0; i<form.newresourceadd.length; i++) {
7263: if (form.newresourceadd[i].checked) {
7264: if (document.getElementById('newresourcetitle')) {
7265: if (form.newresourceadd[i].value == '1') {
7266: document.getElementById('newresourcetitle').type = 'text';
7267: if (document.getElementById('newrestitle')) {
7268: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7269: }
7270: } else {
7271: document.getElementById('newresourcetitle').type = 'hidden';
7272: document.getElementById('newresourcetitle').value = '';
7273: if (document.getElementById('newrestitle')) {
7274: document.getElementById('newrestitle').innerHTML = '';
7275: }
7276: }
7277: }
7278: break;
7279: }
7280: }
7281: }
7282: }
7283:
7284: function toggleWithTemplate(form) {
7285: if (form.newresusetemp.length) {
7286: for (var i=0; i<form.newresusetemp.length; i++) {
7287: if (form.newresusetemp[i].checked) {
7288: if (document.getElementById('newrestemplate')) {
7289: if (form.newresusetemp[i].value == '1') {
7290: document.getElementById('newrestemplate').style.display = 'inline';
7291: toggleExampleText();
7292: } else {
7293: form.tempcategory.selectedIndex = 0;
7294: select1template_changed();
7295: document.getElementById('newrestemplate').style.display = 'none';
7296: }
7297: }
7298: }
7299: }
7300: }
7301: }
7302:
7303: function toggleExampleText() {
7304: if (document.getElementById('newresexample')) {
7305: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7306: if (url == '') {
7307: document.getElementById('newresexample').style.fontWeight = 'normal';
7308: } else {
7309: document.getElementById('newresexample').style.fontWeight = 'bold';
7310: }
7311: }
7312: }
7313:
7314: function getExample(width,height,scrolling,transparency) {
7315: var url;
7316: if (document.courseresform.newresusetemp.length) {
7317: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7318: if (document.courseresform.newresusetemp[i].checked) {
7319: if (document.courseresform.newresusetemp[i].value == '1') {
7320: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7321: if (url == '') {
7322: alert('Pick a category and template');
7323: } else {
7324: url = url.replace("$londocroot","");
7325: url += '?inhibitmenu=yes';
7326: }
7327: }
7328: break;
7329: }
7330: }
7331: }
7332: if (url != '') {
7333: openMyModal(url,width,height,scrolling,transparency,'');
7334: }
7335: }
7336:
7337: function toggleImportCrsres(caller,dircount) {
7338: var disp = 'none';
7339: if (document.getElementById('importcrsresform')) {
7340: if (caller == 'res') {
7341: var numdirs = parseInt(dircount);
7342: var curr = document.getElementById('importcrsresform').style.display;
7343: if (curr == 'none') {
7344: disp='block';
7345: if (numdirs > 1) {
7346: select1res_changed();
7347: }
7348: }
7349: }
7350: document.getElementById('importcrsresform').style.display=disp;
7351: resize_scrollbox('contentscroll','1','0');
7352: }
7353: return;
7354: }
7355:
7356: function makeims(imsform) {
7357: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7358: alert("$js_lt{'imsfile'}");
7359: return;
7360: }
7361: if (imsform.source.selectedIndex == 0) {
7362: alert("$js_lt{'imscms'}");
7363: return;
7364: }
7365: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7366: imsform.submit();
7367: }
7368:
7369: function updatePick(targetform,index,caller) {
7370: var pickitem;
7371: var picknumitem;
7372: var picknumtext;
7373: if (index == 'all') {
7374: pickitem = document.getElementById('randompickall');
7375: picknumitem = document.getElementById('rpicknumall');
7376: picknumtext = document.getElementById('rpicktextall');
7377: } else {
7378: pickitem = document.getElementById('randompick_'+index);
7379: picknumitem = document.getElementById('rpicknum_'+index);
7380: picknumtext = document.getElementById('randompicknum_'+index);
7381: }
7382: if (pickitem.checked) {
7383: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7384: if (picknum == '' || picknum == null) {
7385: if (caller == 'check') {
7386: pickitem.checked=false;
7387: if (index == 'all') {
7388: picknumtext.innerHTML = '';
7389: if (caller == 'link') {
7390: propagateState(targetform,'rpicknum');
7391: }
7392: } else {
7393: checkForSubmit(targetform,'randompick','settings');
7394: }
7395: }
7396: } else {
7397: picknum.toString();
7398: var regexdigit=/^\\d+\$/;
7399: if (regexdigit.test(picknum)) {
7400: picknumitem.value = picknum;
7401: if (index == 'all') {
7402: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7403: if (caller == 'link') {
7404: propagateState(targetform,'rpicknum');
7405: }
7406: } else {
7407: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7408: checkForSubmit(targetform,'randompick','settings');
7409: }
7410: } else {
7411: if (caller == 'check') {
7412: if (index == 'all') {
7413: picknumtext.innerHTML = '';
7414: if (caller == 'link') {
7415: propagateState(targetform,'rpicknum');
7416: }
7417: } else {
7418: pickitem.checked=false;
7419: checkForSubmit(targetform,'randompick','settings');
7420: }
7421: }
7422: return;
7423: }
7424: }
7425: } else {
7426: picknumitem.value = '';
7427: picknumtext.innerHTML = '';
7428: if (index == 'all') {
7429: if (caller == 'link') {
7430: propagateState(targetform,'rpicknum');
7431: }
7432: } else {
7433: checkForSubmit(targetform,'randompick','settings');
7434: }
7435: }
7436: }
7437:
7438: function propagateState(form,param) {
7439: if (document.getElementById(param+'all')) {
7440: var setcheck = 0;
7441: var rpick = 0;
7442: if (param == 'rpicknum') {
7443: if (document.getElementById('randompickall')) {
7444: if (document.getElementById('randompickall').checked) {
7445: if (document.getElementById('rpicknumall')) {
7446: rpick = document.getElementById('rpicknumall').value;
7447: }
7448: }
7449: }
7450: } else {
7451: if (document.getElementById(param+'all').checked) {
7452: setcheck = 1;
7453: }
7454: }
7455: var allidxlist;
7456: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7457: if (document.getElementById('all'+param+'idx')) {
7458: allidxlist = document.getElementById('all'+param+'idx').value;
7459: }
7460: var actions = new Array ('remove','cut','copy');
7461: for (var i=0; i<actions.length; i++) {
7462: if (actions[i] != param) {
7463: if (document.getElementById(actions[i]+'all')) {
7464: document.getElementById(actions[i]+'all').checked = false;
7465: }
7466: }
7467: }
7468: }
7469: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
7470: allidxlist = form.allidx.value;
7471: }
7472: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7473: allidxlist = form.allmapidx.value;
7474: }
7475: if ((allidxlist != '') && (allidxlist != null)) {
7476: var allidxs = allidxlist.split(',');
7477: if (allidxs.length > 1) {
7478: for (var i=0; i<allidxs.length; i++) {
7479: if (document.getElementById(param+'_'+allidxs[i])) {
7480: if (param == 'rpicknum') {
7481: if (document.getElementById('randompick_'+allidxs[i])) {
7482: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7483: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7484: if (rpick > 0) {
7485: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7486: } else {
7487: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7488: }
7489: }
7490: }
7491: } else {
7492: if (setcheck == 1) {
7493: document.getElementById(param+'_'+allidxs[i]).checked = true;
7494: } else {
7495: document.getElementById(param+'_'+allidxs[i]).checked = false;
7496: if (param == 'randompick') {
7497: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7498: }
7499: }
7500: }
7501: }
7502: }
7503: if (setcheck == 1) {
7504: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7505: var actions = new Array('copy','cut','remove');
7506: for (var i=0; i<actions.length; i++) {
7507: var otheractions;
7508: var otheridxs;
7509: if (actions[i] === param) {
7510: continue;
7511: } else {
7512: if (document.getElementById('all'+actions[i]+'idx')) {
7513: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7514: otheridxs = otheractions.split(',');
7515: if (otheridxs.length > 1) {
7516: for (var j=0; j<otheridxs.length; j++) {
7517: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7518: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7519: }
7520: }
7521: }
7522: }
7523: }
7524: }
7525: }
7526: }
7527: }
7528: }
7529: }
7530: return;
7531: }
7532:
7533: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
7534: var canedit = '$canedit';
7535: if (canedit == '') {
7536: alert("$js_lt{'edri'}");
7537: return;
7538: }
7539: var dosettings;
7540: var doaction;
7541: var control = document.togglemultsettings;
7542: if (context == 'actions') {
7543: control = document.togglemultactions;
7544: doaction = 1;
7545: } else {
7546: dosettings = 1;
7547: }
7548: if (control) {
7549: if (control.showmultpick.length) {
7550: for (var i=0; i<control.showmultpick.length; i++) {
7551: if (control.showmultpick[i].checked) {
7552: if (control.showmultpick[i].value == 1) {
7553: if (context == 'settings') {
7554: dosettings = 0;
7555: } else {
7556: doaction = 0;
7557: }
7558: }
7559: }
7560: }
7561: }
7562: }
7563: if (context == 'settings') {
7564: if (dosettings == 1) {
7565: targetform.changeparms.value=param;
7566: targetform.submit();
7567: }
7568: }
7569: if (context == 'actions') {
7570: if (doaction == 1) {
7571: targetform.cmd.value=param+'_'+index;
7572: targetform.folderpath.value=folderpath;
7573: targetform.markcopy.value=idx+':'+param;
7574: targetform.copyfolder.value=folder+'.'+container;
7575: if (param == 'remove') {
7576: var doremove = 0;
7577: if (skip_confirm) {
7578: if (confirm_removal) {
7579: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7580: doremove = 1;
7581: }
7582: } else {
7583: doremove = 1;
7584: }
7585: } else {
7586: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7587: doremove = 1;
7588: }
7589: }
7590: if (doremove) {
7591: targetform.markcopy.value='';
7592: targetform.copyfolder.value='';
7593: targetform.submit();
7594: }
7595: }
7596: if (param == 'cut') {
7597: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
7598: targetform.submit();
7599: return;
7600: }
7601: }
7602: if (param == 'copy') {
7603: targetform.submit();
7604: return;
7605: }
7606: targetform.markcopy.value='';
7607: targetform.copyfolder.value='';
7608: targetform.cmd.value='';
7609: targetform.folderpath.value='';
7610: return;
7611: } else {
7612: if (document.getElementById(param+'_'+idx)) {
7613: item = document.getElementById(param+'_'+idx);
7614: if (item.type == 'checkbox') {
7615: if (item.checked) {
7616: item.checked = false;
7617: } else {
7618: item.checked = true;
7619: singleCheck(item,idx,param);
7620: }
7621: }
7622: }
7623: }
7624: }
7625: return;
7626: }
7627:
7628: function singleCheck(caller,idx,action) {
7629: actions = new Array('cut','copy','remove');
7630: if (caller.checked) {
7631: for (var i=0; i<actions.length; i++) {
7632: if (actions[i] != action) {
7633: if (document.getElementById(actions[i]+'_'+idx)) {
7634: if (document.getElementById(actions[i]+'_'+idx).checked) {
7635: document.getElementById(actions[i]+'_'+idx).checked = false;
7636: }
7637: }
7638: }
7639: }
7640: }
7641: return;
7642: }
7643:
7644: function unselectInactive(nav) {
7645: currentNav = document.getElementById(nav);
7646: currentLis = currentNav.getElementsByTagName('LI');
7647: for (i = 0; i < currentLis.length; i++) {
7648: if (currentLis[i].className == 'goback') {
7649: currentLis[i].className = 'goback';
7650: } else {
7651: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
7652: currentLis[i].className = 'right';
7653: } else {
7654: currentLis[i].className = 'i';
7655: }
7656: }
7657: }
7658: }
7659:
7660: function hideAll(current, nav, data) {
7661: unselectInactive(nav);
7662: if (current) {
7663: if (current.className == 'right'){
7664: current.className = 'right active'
7665: } else {
7666: current.className = 'active';
7667: }
7668: }
7669: currentData = document.getElementById(data);
7670: currentDivs = currentData.getElementsByTagName('DIV');
7671: for (i = 0; i < currentDivs.length; i++) {
7672: if(currentDivs[i].className == 'LC_ContentBox'){
7673: currentDivs[i].style.display = 'none';
7674: }
7675: }
7676: }
7677:
7678: function openTabs(pageId) {
7679: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
7680: if(tabnav.length > 2 ){
7681: currentNav = document.getElementById(tabnav[1].id);
7682: currentLis = currentNav.getElementsByTagName('LI');
7683: for(i = 0; i< currentLis.length; i++){
7684: if(currentLis[i].className == 'active') {
7685: funcString = currentLis[i].onclick.toString();
7686: tab = funcString.split('"');
7687: if(tab.length < 2) {
7688: tab = funcString.split("'");
7689: }
7690: currentData = document.getElementById(tab[1]);
7691: currentData.style.display = 'block';
7692: }
7693: }
7694: }
7695: }
7696:
7697: function showPage(current, pageId, nav, data) {
7698: currstate = current.className;
7699: hideAll(current, nav, data);
7700: openTabs(pageId);
7701: unselectInactive(nav);
7702: if ((currstate == 'active') || (currstate == 'right active')) {
7703: if (currstate == 'active') {
7704: current.className = '';
7705: } else {
7706: current.className = 'right';
7707: }
7708: activeTab = '';
7709: toggleUpload();
7710: toggleMap();
7711: toggleCrsRes();
7712: toggleImportCrsres();
7713: resize_scrollbox('contentscroll','1','0');
7714: return;
7715: } else {
7716: current.className = 'active';
7717: }
7718: currentData = document.getElementById(pageId);
7719: currentData.style.display = 'block';
7720: activeTab = pageId;
7721: toggleUpload();
7722: toggleMap();
7723: toggleCrsRes();
7724: toggleImportCrsres();
7725: if (nav == 'mainnav') {
7726: var storedpath = "$docs_folderpath";
7727: var storedpage = "$main_container_page";
7728: var reg = new RegExp("^supplemental");
7729: if (pageId == 'mainCourseDocuments') {
7730: if (storedpage == 1) {
7731: document.simpleedit.folderpath.value = '';
7732: document.uploaddocument.folderpath.value = '';
7733: } else {
7734: if (reg.test(storedpath)) {
7735: document.simpleedit.folderpath.value = '$toplevelmain';
7736: document.uploaddocument.folderpath.value = '$toplevelmain';
7737: document.newext.folderpath.value = '$toplevelmain';
7738: } else {
7739: document.simpleedit.folderpath.value = storedpath;
7740: document.uploaddocument.folderpath.value = storedpath;
7741: document.newext.folderpath.value = storedpath;
7742: }
7743: }
7744: } else {
7745: if (reg.test(storedpath)) {
7746: document.simpleedit.folderpath.value = storedpath;
7747: document.supuploaddocument.folderpath.value = storedpath;
7748: document.supnewext.folderpath.value = storedpath;
7749: } else {
7750: document.simpleedit.folderpath.value = '$toplevelsupp';
7751: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7752: document.supnewext.folderpath.value = '$toplevelsupp';
7753: }
7754: }
7755: }
7756: resize_scrollbox('contentscroll','1','0');
7757: return false;
7758: }
7759:
7760: function toContents(jumpto) {
7761: var newurl = '$backtourl';
7762: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
7763: newurl = newurl+'?postdata='+jumpto;
7764: }
7765: location.href=newurl;
7766: }
7767:
7768: function togglePick(caller,value) {
7769: var disp = 'none';
7770: if (document.getElementById('multi'+caller)) {
7771: var curr = document.getElementById('multi'+caller).style.display;
7772: if (value == 1) {
7773: disp='block';
7774: }
7775: if (curr == disp) {
7776: return;
7777: }
7778: document.getElementById('multi'+caller).style.display=disp;
7779: if (value == 1) {
7780: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
7781: } else {
7782: document.getElementById('more'+caller).innerHTML = '';
7783: }
7784: if (caller == 'actions') {
7785: setClass(value);
7786: setBoxes(value);
7787: }
7788: }
7789: var showButton = multiSettings();
7790: if (showButton != 1) {
7791: showButton = multiActions();
7792: }
7793: if (document.getElementById('multisave')) {
7794: if (showButton == 1) {
7795: document.getElementById('multisave').style.display='block';
7796: } else {
7797: document.getElementById('multisave').style.display='none';
7798: }
7799: }
7800: resize_scrollbox('contentscroll','1','1');
7801: return;
7802: }
7803:
7804: function toggleCheckUncheck(caller,more) {
7805: if (more == 1) {
7806: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
7807: document.getElementById('allfields'+caller).style.display='block';
7808: } else {
7809: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
7810: document.getElementById('allfields'+caller).style.display='none';
7811: }
7812: resize_scrollbox('contentscroll','1','1');
7813: }
7814:
7815: function multiSettings() {
7816: var inuse = 0;
7817: var settingsform = document.togglemultsettings;
7818: if (settingsform.showmultpick.length > 1) {
7819: for (var i=0; i<settingsform.showmultpick.length; i++) {
7820: if (settingsform.showmultpick[i].checked) {
7821: if (settingsform.showmultpick[i].value == 1) {
7822: inuse = 1;
7823: }
7824: }
7825: }
7826: }
7827: return inuse;
7828: }
7829:
7830: function multiActions() {
7831: var inuse = 0;
7832: var actionsform = document.togglemultactions;
7833: if (actionsform.showmultpick.length > 1) {
7834: for (var i=0; i<actionsform.showmultpick.length; i++) {
7835: if (actionsform.showmultpick[i].checked) {
7836: if (actionsform.showmultpick[i].value == 1) {
7837: inuse = 1;
7838: }
7839: }
7840: }
7841: }
7842: return inuse;
7843: }
7844:
7845: function checkSubmits() {
7846: var numchanges = 0;
7847: var form = document.saveactions;
7848: var doactions = multiActions();
7849: var cutwarnings = 0;
7850: var remwarnings = 0;
7851: var removalinfo = 0;
7852: if (doactions == 1) {
7853: var remidxlist = document.cumulativeactions.allremoveidx.value;
7854: if ((remidxlist != '') && (remidxlist != null)) {
7855: var remidxs = remidxlist.split(',');
7856: for (var i=0; i<remidxs.length; i++) {
7857: if (document.getElementById('remove_'+remidxs[i])) {
7858: if (document.getElementById('remove_'+remidxs[i]).checked) {
7859: form.multiremove.value += remidxs[i]+',';
7860: numchanges ++;
7861: if (document.getElementById('skip_remove_'+remidxs[i])) {
7862: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7863: remwarnings ++;
7864: }
7865: }
7866: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7867: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7868: removalinfo ++;
7869: }
7870: }
7871: }
7872: }
7873: }
7874: }
7875: var cutidxlist = document.cumulativeactions.allcutidx.value;
7876: if ((cutidxlist != '') && (cutidxlist != null)) {
7877: var cutidxs = cutidxlist.split(',');
7878: for (var i=0; i<cutidxs.length; i++) {
7879: if (document.getElementById('cut_'+cutidxs[i])) {
7880: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7881: form.multicut.value += cutidxs[i]+',';
7882: numchanges ++;
7883: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7884: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7885: cutwarnings ++;
7886: }
7887: }
7888: }
7889: }
7890: }
7891: }
7892: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7893: if ((copyidxlist != '') && (copyidxlist != null)) {
7894: var copyidxs = copyidxlist.split(',');
7895: for (var i=0; i<copyidxs.length; i++) {
7896: if (document.getElementById('copy_'+copyidxs[i])) {
7897: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7898: form.multicopy.value += copyidxs[i]+',';
7899: numchanges ++;
7900: }
7901: }
7902: }
7903: }
7904: if (numchanges > 0) {
7905: form.multichange.value = numchanges;
7906: }
7907: }
7908: var dosettings = multiSettings();
7909: var haschanges = 0;
7910: if (dosettings == 1) {
7911: form.allencrypturl.value = '';
7912: form.allhiddenresource.value = '';
7913: form.changeparms.value = 'all';
7914: var patt=new RegExp(",\$");
7915: var allidxlist = document.cumulativesettings.allidx.value;
7916: if ((allidxlist != '') && (allidxlist != null)) {
7917: var allidxs = allidxlist.split(',');
7918: if (allidxs.length > 1) {
7919: for (var i=0; i<allidxs.length; i++) {
7920: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7921: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7922: form.allhiddenresource.value += allidxs[i]+',';
7923: }
7924: }
7925: if (document.getElementById('encrypturl_'+allidxs[i])) {
7926: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7927: form.allencrypturl.value += allidxs[i]+',';
7928: }
7929: }
7930: }
7931: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7932: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7933: }
7934: }
7935: form.allrandompick.value = '';
7936: form.allrandomorder.value = '';
7937: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7938: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7939: var allmapidxs = allmapidxlist.split(',');
7940: for (var i=0; i<allmapidxs.length; i++) {
7941: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7942: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7943: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7944: if ((randompick.checked) && (rpicknum.value != '')) {
7945: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7946: }
7947: if (randorder.checked) {
7948: form.allrandomorder.value += allmapidxs[i]+',';
7949: }
7950: }
7951: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7952: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7953: }
7954: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7955: haschanges = 1;
7956: }
7957: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7958: haschanges = 1;
7959: }
7960: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7961: haschanges = 1;
7962: }
7963: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7964: haschanges = 1;
7965: }
7966: }
7967: if (doactions == 1) {
7968: if (numchanges > 0) {
7969: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
7970: if (remwarnings > 0) {
7971: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
7972: return false;
7973: }
7974: }
7975: if (removalinfo > 0) {
7976: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7977: return false;
7978: }
7979: }
7980: if (cutwarnings > 0) {
7981: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
7982: return false;
7983: }
7984: }
7985: }
7986: form.submit();
7987: return true;
7988: }
7989: }
7990: if (dosettings == 1) {
7991: if (haschanges == 1) {
7992: form.submit();
7993: return true;
7994: }
7995: }
7996: if ((dosettings == 1) && (doactions == 1)) {
7997: alert("$js_lt{'noor'}");
7998: } else {
7999: if (dosettings == 1) {
8000: alert("$js_lt{'noch'}");
8001: } else {
8002: alert("$js_lt{'noac'}");
8003: }
8004: }
8005: return false;
8006: }
8007:
8008: function setClass(value) {
8009: var cutclass = 'LC_docs_cut';
8010: var copyclass = 'LC_docs_copy';
8011: var removeclass = 'LC_docs_remove';
8012: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8013: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8014: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8015: var links = document.getElementsByTagName('a');
8016: for (var i=0; i<links.length; i++) {
8017: var classes = links[i].className;
8018: if (cutreg.test(classes)) {
8019: links[i].className = cutclass;
8020: if (value == 1) {
8021: links[i].className += " LC_menubuttons_link";
8022: }
8023: } else {
8024: if (copyreg.test(classes)) {
8025: links[i].className = copyclass;
8026: if (value == 1) {
8027: links[i].className += " LC_menubuttons_link";
8028: }
8029: } else {
8030: if (removereg.test(classes)) {
8031: links[i].className = removeclass;
8032: if (value == 1) {
8033: links[i].className += " LC_menubuttons_link";
8034: }
8035: }
8036: }
8037: }
8038: }
8039: return;
8040: }
8041:
8042: function setBoxes(value) {
8043: var remidxlist = document.cumulativeactions.allremoveidx.value;
8044: if ((remidxlist != '') && (remidxlist != null)) {
8045: var remidxs = remidxlist.split(',');
8046: for (var i=0; i<remidxs.length; i++) {
8047: if (document.getElementById('remove_'+remidxs[i])) {
8048: var item = document.getElementById('remove_'+remidxs[i]);
8049: if (value == 1) {
8050: item.className = 'LC_docs_remove';
8051: } else {
8052: item.className = 'LC_hidden';
8053: }
8054: }
8055: }
8056: }
8057: var cutidxlist = document.cumulativeactions.allcutidx.value;
8058: if ((cutidxlist != '') && (cutidxlist != null)) {
8059: var cutidxs = cutidxlist.split(',');
8060: for (var i=0; i<cutidxs.length; i++) {
8061: if (document.getElementById('cut_'+cutidxs[i])) {
8062: var item = document.getElementById('cut_'+cutidxs[i]);
8063: if (value == 1) {
8064: item.className = 'LC_docs_cut';
8065: } else {
8066: item.className = 'LC_hidden';
8067: }
8068: }
8069: }
8070: }
8071: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8072: if ((copyidxlist != '') && (copyidxlist != null)) {
8073: var copyidxs = copyidxlist.split(',');
8074: for (var i=0; i<copyidxs.length; i++) {
8075: if (document.getElementById('copy_'+copyidxs[i])) {
8076: var item = document.getElementById('copy_'+copyidxs[i]);
8077: if (value == 1) {
8078: item.className = 'LC_docs_copy';
8079: } else {
8080: item.className = 'LC_hidden';
8081: }
8082: }
8083: }
8084: }
8085: return;
8086: }
8087:
8088: function validImportCrsRes() {
8089: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8090: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8091: if ((fname == '') || (fname == null)) {
8092: alert("$js_lt{'nofi'}");
8093: return false;
8094: }
8095: var url = '/res/$coursedom/$coursenum/';
8096: if (path && path != '/') {
8097: url += path+'/';
8098: }
8099: if (fname != '') {
8100: url += fname;
8101: }
8102: var title = document.crsresimportform.crsrestitle.value;
8103: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8104: return true;
8105: }
8106:
8107: function validateNewRes(caller) {
8108: if (caller == 'single') {
8109: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8110: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8111: var resname = document.courseresform.newresourcename.value;
8112: }
8113: }
8114:
8115: ENDSCRIPT
8116: }
8117:
8118: sub history_tab_js {
8119: return <<"ENDHIST";
8120: function toggleHistoryDisp(choice) {
8121: document.docslogform.docslog.value = choice;
8122: document.docslogform.submit();
8123: return;
8124: }
8125:
8126: ENDHIST
8127: }
8128:
8129: sub inject_data_js {
8130: return <<ENDINJECT;
8131:
8132: function injectData(current, hiddenField, name, value) {
8133: currentElement = document.getElementById(hiddenField);
8134: currentElement.name = name;
8135: currentElement.value = value;
8136: current.submit();
8137: }
8138:
8139: ENDINJECT
8140: }
8141:
8142: sub dump_switchserver_js {
8143: my @hosts = @_;
8144: my %js_lt = &Apache::lonlocal::texthash(
8145: dump => 'Copying content to Authoring Space requires switching server.',
8146: swit => 'Switch server?',
8147: );
8148: my %html_js_lt = &Apache::lonlocal::texthash(
8149: swit => 'Switch server?',
8150: duco => 'Copying Content to Authoring Space',
8151: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8152: chos => 'Choose server',
8153: );
8154: &js_escape(\%js_lt);
8155: &html_escape(\%html_js_lt);
8156: &js_escape(\%html_js_lt);
8157: my $role = $env{'request.role'};
8158: my $js = <<"ENDSWJS";
8159: <script type="text/javascript">
8160: function write_switchserver() {
8161: var server;
8162: if (document.setserver.posshosts.length > 0) {
8163: for (var i=0; i<document.setserver.posshosts.length; i++) {
8164: if (document.setserver.posshosts[i].checked) {
8165: server = document.setserver.posshosts[i].value;
8166: }
8167: }
8168: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8169: }
8170: window.close();
8171: }
8172: </script>
8173:
8174: ENDSWJS
8175:
8176: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8177: {'only_body' => 1,
8178: 'js_ready' => 1,});
8179: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8180:
8181: my $hostpicker;
8182: my $count = 0;
8183: foreach my $host (sort(@hosts)) {
8184: my $checked;
8185: if ($count == 0) {
8186: $checked = ' checked="checked"';
8187: }
8188: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8189: $host.'"'.$checked.' />'.$host.'</label> ';
8190: $count++;
8191: }
8192:
8193: return <<"ENDSWITCHJS";
8194:
8195: function dump_needs_switchserver(url) {
8196: if (url!='' && url!= null) {
8197: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8198: go(url);
8199: }
8200: }
8201: return;
8202: }
8203:
8204: function choose_switchserver_window() {
8205: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8206: newWindow.document.open();
8207: newWindow.document.writeln('$startpage');
8208: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8209: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8210: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8211: '<form name="setserver" method="post" action="" \\/>\\n'+
8212: '$hostpicker\\n'+
8213: '<br \\/><br \\/>\\n'+
8214: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8215: 'onclick="write_switchserver();" \\/>\\n'+
8216: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8217: newWindow.document.writeln('$endpage');
8218: newWindow.document.close();
8219: newWindow.focus();
8220: }
8221:
8222: ENDSWITCHJS
8223: }
8224:
8225: sub makedocslogform {
8226: my ($formelems,$docslog) = @_;
8227: return <<"LOGSFORM";
8228: <form action="/adm/coursedocs" method="post" name="docslogform">
8229: <input type="hidden" name="docslog" value="$docslog" />
8230: $formelems
8231: </form>
8232: LOGSFORM
8233: }
8234:
8235: sub makesimpleeditform {
8236: my ($formelems) = @_;
8237: return <<"SIMPFORM";
8238: <form name="simpleedit" method="post" action="/adm/coursedocs">
8239: <input type="hidden" name="importdetail" value="" />
8240: $formelems
8241: </form>
8242: SIMPFORM
8243: }
8244:
8245: sub makenewproblem {
8246: my ($r,$coursedom,$coursenum) = @_;
8247: # Creating a new problem
8248: my ($redirect,$error);
8249: if ($env{'form.authorrole'}) {
8250: my ($newsubdir,$filename);
8251: if ($env{'form.newsubdir'}) {
8252: if ($env{'form.newsubdirname'} ne '') {
8253: $newsubdir = $env{'form.newsubdirname'};
8254: }
8255: }
8256: if ($env{'form.newresourcename'}) {
8257: $filename = $env{'form.newresourcename'};
8258: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8259: $filename =~ s/`//g;
8260: $filename =~ s{/\.\./}{_}g;
8261: $filename =~ s/\.+/./g;
8262: $filename =~ s{/+}{_}g;
8263: if ($filename ne '') {
8264: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8265: if (($ext) && ($ext ne '.problem')) {
8266: $filename = $name.'.problem';
8267: } elsif ($ext eq '') {
8268: $filename .= '.problem';
8269: }
8270: my $docroot = $r->dir_config('lonDocRoot');
8271: my @ids=&Apache::lonnet::current_machine_ids();
8272: if ($env{'form.authorrole'} eq 'author') {
8273: if ($env{'user.author'}) {
8274: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8275: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8276: my $path = $docroot.$url;
8277: my $subdir = $env{'form.authorpath'};
8278: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8279: }
8280: }
8281: } elsif ($env{'form.authorrole'} eq 'course') {
8282: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8283: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8284: my $url = "/priv/$coursedom/$coursenum";
8285: my $path=$docroot.$url;
8286: my $subdir = $env{'form.authorpath'};
8287: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8288: if ($redirect) {
8289: my $rightsfile = 'default.rights';
8290: my $sourcerights = "$path/$rightsfile";
8291: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8292: my $now = time;
8293: if (!-e $sourcerights) {
8294: my $cid = $coursedom.'_'.$coursenum;
8295: if (open(my $fh,">$sourcerights")) {
8296: print $fh <<END;
8297: <accessrule effect="deny" realm="" type="course" role="" />
8298: <accessrule effect="allow" realm="$cid" type="course" role="" />
8299: END
8300: close($fh);
8301: }
8302: }
8303: if (!-e "$sourcerights.meta") {
8304: if (open(my $fh,">$sourcerights.meta")) {
8305: my $author=$env{'environment.firstname'}.' '.
8306: $env{'environment.middlename'}.' '.
8307: $env{'environment.lastname'}.' '.
8308: $env{'environment.generation'};
8309: $author =~ s/\s+$//;
8310: print $fh <<"END";
8311:
8312: <abstract></abstract>
8313: <author>$author</author>
8314: <authorspace>$coursenum:$coursedom</authorspace>
8315: <copyright>private</copyright>
8316: <creationdate>$now</creationdate>
8317: <customdistributionfile></customdistributionfile>
8318: <dependencies></dependencies>
8319: <domain>$coursedom</domain>
8320: <highestgradelevel>0</highestgradelevel>
8321: <keywords></keywords>
8322: <language>notset </language>
8323: <lastrevisiondate>$now</lastrevisiondate>
8324: <lowestgradelevel>0</lowestgradelevel>
8325: <mime>rights</mime>
8326: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8327: <notes></notes>
8328: <obsolete></obsolete>
8329: <obsoletereplacement></obsoletereplacement>
8330: <owner>$coursenum:$coursedom</owner>
8331: <rule>deny:::course,allow:$cid::course</rule>
8332: <sourceavail></sourceavail>
8333: <standards></standards>
8334: <subject></subject>
8335: <title></title>
8336: END
8337: close($fh);
8338: }
8339: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8340: if (!-e "$docroot/res/$coursedom") {
8341: mkdir("$docroot/res/$coursedom",0755);
8342: }
8343: if (!-e "$docroot/res/$coursedom/$coursenum") {
8344: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8345: }
8346: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8347: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8348: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8349: }
8350: }
8351: }
8352: if ($env{'form.newresourceadd'}) {
8353: my $template = $env{'form.template'};
8354: my $source = $docroot.$redirect;
8355: my $target = $redirect;
8356: $target =~ s{^/priv/}{/res/};
8357: $target = $docroot.$target;
8358: if (!-e $source) {
8359: my $copyfrom;
8360: if ($template) {
8361: my %templates;
8362: my @files = &Apache::lonhomework::get_template_list('problem');
8363: foreach my $poss (@files) {
8364: if (ref($poss) eq 'ARRAY') {
8365: if ($template eq $poss->[0]) {
8366: $templates{$template} = 1;
8367: last;
8368: }
8369: }
8370: }
8371: if ($templates{$template}) {
8372: $copyfrom = $template;
8373: }
8374: }
8375: unless ($copyfrom) {
8376: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8377: }
8378: &File::Copy::copy($copyfrom,$source);
8379: }
8380: if (!-e "$source.meta") {
8381: my $cid = $coursedom.'_'.$coursenum;
8382: my $now = time;
8383: if (open(my $fh,">$source.meta")) {
8384: my $author=$env{'environment.firstname'}.' '.
8385: $env{'environment.middlename'}.' '.
8386: $env{'environment.lastname'}.' '.
8387: $env{'environment.generation'};
8388: $author =~ s/\s+$//;
8389: my $title = $env{'form.newresourcetitle'};
8390: $title =~ s/^\s+|\s+$//g;
8391: print $fh <<END;
8392:
8393: <abstract></abstract>
8394: <author>$author</author>
8395: <authorspace>$coursenum:$coursedom</authorspace>
8396: <copyright>custom</copyright>
8397: <creationdate>$now</creationdate>
8398: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8399: <dependencies></dependencies>
8400: <domain>$coursedom</domain>
8401: <highestgradelevel>0</highestgradelevel>
8402: <keywords></keywords>
8403: <language>notset </language>
8404: <lastrevisiondate>$now</lastrevisiondate>
8405: <lowestgradelevel>0</lowestgradelevel>
8406: <mime>problem</mime>
8407: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8408: <notes></notes>
8409: <obsolete></obsolete>
8410: <obsoletereplacement></obsoletereplacement>
8411: <owner>$coursenum:$coursedom</owner>
8412: <sourceavail></sourceavail>
8413: <standards></standards>
8414: <subject></subject>
8415: <title>$title</title>
8416: END
8417: close($fh);
8418: }
8419: }
8420: }
8421: }
8422: }
8423: } else {
8424: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8425: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8426: if (grep(/^\Q$rolehome\E$/,@ids)) {
8427: my $now = time;
8428: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8429: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8430: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8431: my $url = "/priv/$audom/$auname";
8432: my $path = $r->dir_config('lonDocRoot').$url;
8433: my $subdir = $env{'form.authorpath'};
8434: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8435: }
8436: }
8437: }
8438: }
8439: }
8440: }
8441: }
8442: return ($redirect,$error);
8443: }
8444:
8445: sub finishnewprob {
8446: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
8447: unless (-d $path) {
8448: unless (mkdir($path,02770)) {
8449: return;
8450: }
8451: }
8452: my $redirect;
8453: if ($subdir ne '/') {
8454: $subdir = &cleandir($subdir);
8455: if (($subdir ne '') && (-d "$path/$subdir")) {
8456: $path .= "/$subdir";
8457: $url .= "/$subdir";
8458: }
8459: }
8460: my $dest;
8461: if ($newsubdir ne '') {
8462: $newsubdir = &cleandir($newsubdir);
8463: }
8464: if ($newsubdir ne '') {
8465: if (-d "$path/$newsubdir") {
8466: $dest = "$path/$newsubdir/$filename";
8467: } else {
8468: my $dirok;
8469: unless (-e "$path/$newsubdir") {
8470: if (mkdir("$path/$newsubdir",02770)) {
8471: if (chmod(02770,"$path/$newsubdir")) {
8472: $dirok = 1;
8473: }
8474: }
8475: }
8476: if ($dirok) {
8477: $dest = "$path/$newsubdir/$filename";
8478: }
8479: }
8480: if (($dest ne '') && (!-e $dest)) {
8481: $redirect = "$url/$newsubdir/$filename";
8482: }
8483: } else {
8484: $dest = "$path/$filename";
8485: if (($dest ne '') && (!-e $dest)) {
8486: $redirect = "$url/$filename";
8487: }
8488: }
8489: return $redirect;
8490: }
8491:
8492: sub cleandir {
8493: my ($dir) = @_;
8494: $dir =~ s/^\s+//;
8495: $dir =~ s/\s+$//;
8496: $dir =~ s/\.+//g;
8497: $dir =~ s/[\#\?&%\":]//g;
8498: return $dir;
8499: }
8500:
8501: 1;
8502: __END__
8503:
8504:
8505: =head1 NAME
8506:
8507: Apache::londocs.pm
8508:
8509: =head1 SYNOPSIS
8510:
8511: This is part of the LearningOnline Network with CAPA project
8512: described at http://www.lon-capa.org.
8513:
8514: =head1 SUBROUTINES
8515:
8516: =over
8517:
8518: =item %help=()
8519:
8520: Available help topics
8521:
8522: =item mapread()
8523:
8524: Mapread read maps into LONCAPA::map:: global arrays
8525: @order and @resources, determines status
8526: sets @order - pointer to resources in right order
8527: sets @resources - array with the resources with correct idx
8528:
8529: =item authorhosts()
8530:
8531: Return hash with valid author names
8532:
8533: =item clean()
8534:
8535: =item dumpcourse()
8536:
8537: Actually dump course
8538:
8539: =item group_import()
8540:
8541: Imports the given (name, url) resources into the course
8542: coursenum, coursedom, and folder must precede the list
8543:
8544: =item breadcrumbs()
8545:
8546: =item log_docs()
8547:
8548: =item docs_change_log()
8549:
8550: =item update_paste_buffer()
8551:
8552: =item print_paste_buffer()
8553:
8554: =item do_paste_from_buffer()
8555:
8556: =item do_buffer_empty()
8557:
8558: =item clear_from_buffer()
8559:
8560: =item get_newmap_url()
8561:
8562: =item dbcopy()
8563:
8564: =item uniqueness_check()
8565:
8566: =item contained_map_check()
8567:
8568: =item url_paste_fixups()
8569:
8570: =item apply_fixups()
8571:
8572: =item copy_dependencies()
8573:
8574: =item update_parameter()
8575:
8576: =item handle_edit_cmd()
8577:
8578: =item editor()
8579:
8580: =item process_file_upload()
8581:
8582: =item process_secondary_uploads()
8583:
8584: =item is_supplemental_title()
8585:
8586: =item entryline()
8587:
8588: =item tiehash()
8589:
8590: =item untiehash()
8591:
8592: =item checkonthis()
8593:
8594: check on this
8595:
8596: =item verifycontent()
8597:
8598: Verify Content
8599:
8600: =item devalidateversioncache() & checkversions()
8601:
8602: Check Versions
8603:
8604: =item mark_hash_old()
8605:
8606: =item is_hash_old()
8607:
8608: =item changewarning()
8609:
8610: =item init_breadcrumbs()
8611:
8612: Breadcrumbs for special functions
8613:
8614: =item create_list_elements()
8615:
8616: =item create_form_ul()
8617:
8618: =item startContentScreen()
8619:
8620: =item endContentScreen()
8621:
8622: =item supplemental_base()
8623:
8624: =item embedded_form_elems()
8625:
8626: =item embedded_destination()
8627:
8628: =item return_to_editor()
8629:
8630: =item decompression_info()
8631:
8632: =item decompression_phase_one()
8633:
8634: =item decompression_phase_two()
8635:
8636: =item remove_archive()
8637:
8638: =item generate_admin_menu()
8639:
8640: =item generate_edit_table()
8641:
8642: =item editing_js()
8643:
8644: =item history_tab_js()
8645:
8646: =item inject_data_js()
8647:
8648: =item dump_switchserver_js()
8649:
8650: =item resize_scrollbox_js()
8651:
8652: =item makedocslogform()
8653:
8654: =item makesimpleeditform()
8655:
8656: =back
8657:
8658: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>