File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.617:
download - view:
text,
annotated -
select for diffs
Tue Nov 29 03:01:04 2016 UTC (7 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Support case where custom role can access Course Editor, but adv priv
not set at system level for current role.
- Display of hidden status for folder takes into account parameters set at
Enclosing map/folder level for resource, and factors in whether resources
within sub-folders made visible by "no" for hiddenresource parameter make
higher-level folder(s) unhidden.
- Parameters: contents hidden and Parameters: URLs hidden shown between
DOCS breadcrumbs and DOCS inline menu influenced by both <param> tags in
a map, and hiddenresource or encrypturl parameter in resourcedata.db
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.617 2016/11/29 03:01:04 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 @toolinfo = split(/:/,$info);
663: if ($residx) {
664: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
665: $toolid = $toolsettings{'id'};
666: } else {
667: $toolid = shift(@toolinfo);
668: }
669: $toolid =~ s/\D//g;
670: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
671: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
672: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
673: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
674: if (ref($ltitoolsref) eq 'HASH') {
675: my @deleted;
676: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
677: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
678: $url =~ s/exttool$/exttools/;
679: }
680: $toolhash{'id'} = $toolid;
681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
686: }
687: }
688: } elsif ($residx) {
689: $toolhash{'target'} = $toolsettings{'target'};
690: if ($toolhash{'target'} eq 'window') {
691: $toolhash{'width'} = $toolsettings{'width'};
692: $toolhash{'height'} = $toolsettings{'height'};
693: }
694: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
695: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
696: if ($toolhash{'target'} eq 'window') {
697: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
698: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
699: }
700: }
701: if ($toolhash{'target'} eq 'iframe') {
702: delete($toolhash{'width'});
703: delete($toolhash{'height'});
704: if ($residx) {
705: if ($toolsettings{'width'}) {
706: push(@deleted,'width');
707: }
708: if ($toolsettings{'height'}) {
709: push(@deleted,'height');
710: }
711: }
712: }
713: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
714: foreach my $item ('label','title') {
715: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
716: $toolhash{'crs'.$item} =~ s/^\s+//;
717: $toolhash{'crs'.$item} =~ s/\s+$//;
718: if ($toolhash{'crs'.$item} eq '') {
719: delete($toolhash{'crs'.$item});
720: }
721: } else {
722: delete($toolhash{'crs'.$item});
723: }
724: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
725: unless (exists($toolhash{'crs'.$item})) {
726: push(@deleted,'crs'.$item);
727: }
728: }
729: }
730: }
731: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
732: if ($putres eq 'ok') {
733: if (@deleted) {
734: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
735: }
736: }
737: }
738: }
739: }
740: if (($caller eq 'londocs') &&
741: ($folder =~ /^default/)) {
742: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
743: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
744: my $cid = $coursedom.'_'.$coursenum;
745: $allmaps =
746: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
747: $chome,$cid);
748: $donechk = 1;
749: }
750: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
751: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
752: \%addedmaps,\%hierarchy,\%titles,$allmaps);
753: $importuploaded = 1;
754: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
755: next if ($allmaps->{$url});
756: }
757: }
758: if (!$residx
759: || defined($LONCAPA::map::zombies[$residx])) {
760: $residx = &LONCAPA::map::getresidx($url,$residx);
761: push(@LONCAPA::map::order, $residx);
762: }
763: my $ext = 'false';
764: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
765: $name = &LONCAPA::map::qtunescape($name);
766: if ($name eq '') {
767: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
768: }
769: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
770: my $filepath = $1;
771: my $fname = $name;
772: if ($fname =~ /^\W+$/) {
773: $fname = 'web';
774: } else {
775: $fname =~ s/\W/_/g;
776: }
777: if (length($fname) > 15) {
778: $fname = substr($fname,0,14);
779: }
780: my $initialtext = &mt('Replace with your own content.');
781: my $newhtml = <<END;
782: <html>
783: <head>
784: <title>$name</title>
785: </head>
786: <body bgcolor="#ffffff">
787: $initialtext
788: </body>
789: </html>
790: END
791: $env{'form.output'}=$newhtml;
792: my $result =
793: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
794: 'output',
795: "$filepath/$residx/$fname.html");
796: if ($result =~ m{^/uploaded/}) {
797: $url = $result;
798: if ($filepath =~ /^supplemental/) {
799: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
800: $env{'user.domain'}.'___&&&___'.$name;
801: }
802: } else {
803: return (&mt('Failed to save new web page.'),1);
804: }
805: }
806: $url = &LONCAPA::map::qtunescape($url);
807: $LONCAPA::map::resources[$residx] =
808: join(':', ($name, $url, $ext, 'normal', 'res'));
809: }
810: }
811: if ($importuploaded) {
812: my %import_errors;
813: my %updated = (
814: removefrommap => \%removefrommap,
815: removeparam => \%removeparam,
816: );
817: my ($result,$msgsarray,$lockerror) =
818: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
819: if (keys(%import_errors) > 0) {
820: $fixuperrors =
821: '<p span class="LC_warning">'."\n".
822: &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".
823: '<ul>'."\n";
824: foreach my $key (sort(keys(%import_errors))) {
825: $fixuperrors .= '<li>'.$key.'</li>'."\n";
826: }
827: $fixuperrors .= '</ul></p>'."\n";
828: }
829: if (ref($msgsarray) eq 'ARRAY') {
830: if (@{$msgsarray} > 0) {
831: $fixuperrors .= '<p class="LC_info">'.
832: join('<br />',@{$msgsarray}).
833: '</p>';
834: }
835: }
836: if ($lockerror) {
837: $fixuperrors .= '<p class="LC_error">'.
838: $lockerror.
839: '</p>';
840: }
841: }
842: my ($errtext,$fatal) =
843: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
844: unless ($fatal) {
845: if ($folder =~ /^supplemental/) {
846: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
847: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
848: $folder.'.'.$container);
849: }
850: }
851: return ($errtext,$fatal,$fixuperrors);
852: }
853:
854: sub log_docs {
855: return &Apache::lonnet::write_log('course','docslog',@_);
856: }
857:
858: {
859: my @oldresources=();
860: my @oldorder=();
861: my $parmidx;
862: my %parmaction=();
863: my %parmvalue=();
864: my $changedflag;
865:
866: sub snapshotbefore {
867: @oldresources=@LONCAPA::map::resources;
868: @oldorder=@LONCAPA::map::order;
869: $parmidx=undef;
870: %parmaction=();
871: %parmvalue=();
872: $changedflag=0;
873: }
874:
875: sub remember_parms {
876: my ($idx,$parameter,$action,$value)=@_;
877: $parmidx=$idx;
878: $parmaction{$parameter}=$action;
879: $parmvalue{$parameter}=$value;
880: $changedflag=1;
881: }
882:
883: sub log_differences {
884: my ($plain)=@_;
885: my %storehash=('folder' => $plain,
886: 'currentfolder' => $env{'form.folder'});
887: if ($parmidx) {
888: $storehash{'parameter_res'}=$oldresources[$parmidx];
889: foreach my $parm (keys(%parmaction)) {
890: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
891: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
892: }
893: }
894: my $maxidx=$#oldresources;
895: if ($#LONCAPA::map::resources>$#oldresources) {
896: $maxidx=$#LONCAPA::map::resources;
897: }
898: for (my $idx=0; $idx<=$maxidx; $idx++) {
899: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
900: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
901: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
902: $changedflag=1;
903: }
904: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
905: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
906: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
907: $changedflag=1;
908: }
909: }
910: $storehash{'maxidx'}=$maxidx;
911: if ($changedflag) { &log_docs(\%storehash); }
912: }
913: }
914:
915: sub docs_change_log {
916: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
917: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
918: my $navmap;
919: my $js = '<script type="text/javascript">'."\n".
920: '// <![CDATA['."\n".
921: &Apache::loncommon::display_filter_js('docslog')."\n".
922: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
923: $coursedom,$coursenum,'','',$canedit,\$navmap)."\n".
924: &history_tab_js()."\n".
925: &Apache::lonratedt::editscript('simple')."\n".
926: '// ]]>'."\n".
927: '</script>'."\n";
928: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
929: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
930: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
931: my %orderhash;
932: my $container='sequence';
933: my $pathitem;
934: if ($env{'form.folderpath'} =~ /\:1$/) {
935: $container='page';
936: }
937: my $folderpath=$env{'form.folderpath'};
938: if ($folderpath eq '') {
939: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
940: }
941: undef($navmap);
942: $pathitem = '<input type="hidden" name="folderpath" value="'.
943: &HTML::Entities::encode($folderpath,'<>&"').'" />';
944: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
945: my $jumpto = $readfile;
946: $jumpto =~ s{^/}{};
947: my $tid = 1;
948: if ($supplementalflag) {
949: $tid = 2;
950: }
951: my ($breadcrumbtrail) =
952: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
953: $r->print($breadcrumbtrail.
954: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
955: $readfile));
956: my %docslog=&Apache::lonnet::dump('nohist_docslog',
957: $env{'course.'.$env{'request.course.id'}.'.domain'},
958: $env{'course.'.$env{'request.course.id'}.'.num'});
959:
960: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
961:
962: my %saveable_parameters = ('show' => 'scalar',);
963: &Apache::loncommon::store_course_settings('docs_log',
964: \%saveable_parameters);
965: &Apache::loncommon::restore_course_settings('docs_log',
966: \%saveable_parameters);
967: if (!$env{'form.show'}) { $env{'form.show'}=10; }
968: # FIXME: internationalization seems wrong here
969: my %lt=('hiddenresource' => 'Resources hidden',
970: 'encrypturl' => 'URL hidden',
971: 'randompick' => 'Randomly pick',
972: 'randomorder' => 'Randomly ordered',
973: 'set' => 'set to',
974: 'del' => 'deleted');
975: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
976: $pathitem."\n".
977: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
978: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
979: $r->print('<div class="LC_left_float">'.
980: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
981: &makedocslogform($filter,1).
982: '</fieldset></div><br clear="all" />');
983: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
984: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
985: &mt('After').'</th>'.
986: &Apache::loncommon::end_data_table_header_row());
987: my $shown=0;
988: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
989: if ($env{'form.displayfilter'} eq 'currentfolder') {
990: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
991: }
992: my @changes=keys(%{$docslog{$id}{'logentry'}});
993: if ($env{'form.displayfilter'} eq 'containing') {
994: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
995: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
996: foreach my $key (@changes) {
997: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
998: }
999: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1000: }
1001: my $count = 0;
1002: my $time =
1003: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1004: my $plainname =
1005: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1006: $docslog{$id}{'exe_udom'});
1007: my $about_me_link =
1008: &Apache::loncommon::aboutmewrapper($plainname,
1009: $docslog{$id}{'exe_uname'},
1010: $docslog{$id}{'exe_udom'});
1011: my $send_msg_link='';
1012: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1013: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1014: $send_msg_link ='<br />'.
1015: &Apache::loncommon::messagewrapper(&mt('Send message'),
1016: $docslog{$id}{'exe_uname'},
1017: $docslog{$id}{'exe_udom'});
1018: }
1019: $r->print(&Apache::loncommon::start_data_table_row());
1020: $r->print('<td>'.$time.'</td>
1021: <td>'.$about_me_link.
1022: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1023: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1024: $send_msg_link.'</td><td>'.
1025: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1026: my $is_supp = 0;
1027: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1028: $is_supp = 1;
1029: }
1030: # Before
1031: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1032: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1033: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1034: if ($oldname ne $newname) {
1035: my $shown = &LONCAPA::map::qtescape($oldname);
1036: if ($is_supp) {
1037: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1038: }
1039: $r->print($shown);
1040: }
1041: }
1042: $r->print('<ul>');
1043: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1044: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1045: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1046: if ($is_supp) {
1047: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1048: }
1049: $r->print('<li>'.$shown.'</li>');
1050: }
1051: }
1052: $r->print('</ul>');
1053: # After
1054: $r->print('</td><td>');
1055:
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1058: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1059: if ($oldname ne '' && $oldname ne $newname) {
1060: my $shown = &LONCAPA::map::qtescape($newname);
1061: if ($is_supp) {
1062: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1063: }
1064: $r->print($shown);
1065: }
1066: }
1067: $r->print('<ul>');
1068: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1069: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1070: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1071: if ($is_supp) {
1072: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1073: }
1074: $r->print('<li>'.$shown.'</li>');
1075: }
1076: }
1077: $r->print('</ul>');
1078: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1079: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1080: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1081: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1082: # FIXME: internationalization seems wrong here
1083: $r->print('<li>'.
1084: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1085: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1086: .'</li>');
1087: }
1088: }
1089: $r->print('</ul>');
1090: }
1091: # End
1092: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1093: $shown++;
1094: if (!($env{'form.show'} eq &mt('all')
1095: || $shown<=$env{'form.show'})) { last; }
1096: }
1097: $r->print(&Apache::loncommon::end_data_table()."\n".
1098: &makesimpleeditform($pathitem)."\n".
1099: '</div></div>');
1100: $r->print(&endContentScreen());
1101: }
1102:
1103: sub update_paste_buffer {
1104: my ($coursenum,$coursedom,$folder) = @_;
1105: my (@possibles,%removals,%cuts,$output);
1106: if ($env{'form.multiremove'}) {
1107: $env{'form.multiremove'} =~ s/,$//;
1108: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1109: }
1110: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1111: if ($env{'form.multicut'}) {
1112: $env{'form.multicut'} =~ s/,$//;
1113: foreach my $item (split(/,/,$env{'form.multicut'})) {
1114: unless ($removals{$item}) {
1115: $cuts{$item} = 1;
1116: push(@possibles,$item.':cut');
1117: }
1118: }
1119: }
1120: if ($env{'form.multicopy'}) {
1121: $env{'form.multicopy'} =~ s/,$//;
1122: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1123: unless ($removals{$item} || $cuts{$item}) {
1124: push(@possibles,$item.':copy');
1125: }
1126: }
1127: }
1128: } elsif ($env{'form.markcopy'}) {
1129: @possibles = split(/,/,$env{'form.markcopy'});
1130: }
1131:
1132: return if (@possibles == 0);
1133: return if (!defined($env{'form.copyfolder'}));
1134:
1135: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1136: $env{'form.copyfolder'});
1137: return if ($fatal);
1138:
1139: my %curr_groups = &Apache::longroup::coursegroups();
1140:
1141: # Retrieve current paste buffer suffixes.
1142: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1143: my (%pasteurls,@newpaste);
1144:
1145: # Construct identifiers for current contents of user's paste buffer
1146: if (@currpaste) {
1147: foreach my $suffix (@currpaste) {
1148: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1149: my $url = $env{'docs.markedcopy_url_'.$suffix};
1150: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1151: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1152: ($url ne '')) {
1153: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1154: }
1155: }
1156: }
1157:
1158: # Mark items for copying (skip any items already in user's paste buffer)
1159: my %addtoenv;
1160:
1161: my @pathitems = split(/\&/,$env{'form.folderpath'});
1162: my @folderconf = split(/\:/,$pathitems[-1]);
1163: my $ispage = $folderconf[4];
1164:
1165: foreach my $item (@possibles) {
1166: my ($orderidx,$cmd) = split(/:/,$item);
1167: next if ($orderidx =~ /\D/);
1168: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1169: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1170: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1171: my %denied = &action_restrictions($coursenum,$coursedom,
1172: &LONCAPA::map::qtescape($url),
1173: $env{'form.folderpath'},\%curr_groups);
1174: next if ($denied{'copy'});
1175: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1176: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1177: my ($suffix,$errortxt,$locknotfreed) =
1178: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1179: if ($suffix ne '') {
1180: push(@newpaste,$suffix);
1181: } else {
1182: if ($locknotfreed) {
1183: return $locknotfreed;
1184: }
1185: }
1186: if (&is_supplemental_title($title)) {
1187: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1188: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1189: }
1190:
1191: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1192: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1193: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1194: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1195: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1196: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1197: my $prefix = $1;
1198: my $subdir =$2;
1199: if ($subdir eq '') {
1200: $subdir = $prefix;
1201: }
1202: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1203: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1204: \%hierarchy,\%titles,\%allmaps);
1205: if (ref($hierarchy{$url}) eq 'HASH') {
1206: my ($nested,$nestednames);
1207: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1208: $nested =~ s/\&$//;
1209: $nestednames =~ s/\Q___&&&___\E$//;
1210: if ($nested ne '') {
1211: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1212: }
1213: if ($nestednames ne '') {
1214: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1215: }
1216: }
1217: }
1218: if ($locknotfreed) {
1219: $output = $locknotfreed;
1220: last;
1221: }
1222: }
1223: if (@newpaste) {
1224: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1225: }
1226: &Apache::lonnet::appenv(\%addtoenv);
1227: delete($env{'form.markcopy'});
1228: return $output;
1229: }
1230:
1231: sub recurse_uploaded_maps {
1232: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1233: if (ref($hierarchy->{$url}) eq 'HASH') {
1234: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1235: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1236: my (@uploaded,@names,%shorter);
1237: for (my $i=0; $i<@maps; $i++) {
1238: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1239: if ($inner ne '') {
1240: push(@uploaded,$inner);
1241: push(@names,&escape($titles[$i]));
1242: $shorter{$maps[$i]} = $inner;
1243: }
1244: }
1245: $$nestref .= "$dir:".join(',',@uploaded).'&';
1246: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1247: foreach my $map (@maps) {
1248: if ($shorter{$map} ne '') {
1249: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1250: }
1251: }
1252: }
1253: return;
1254: }
1255:
1256: sub print_paste_buffer {
1257: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1258: return if (!defined($env{'docs.markedcopies'}));
1259:
1260: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1261: return if ($env{'docs.markedcopies'} eq '');
1262: }
1263:
1264: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1265: my ($pasteitems,@pasteable);
1266: my $clipboardcount = 0;
1267:
1268: # Construct identifiers for current contents of user's paste buffer
1269: foreach my $suffix (@currpaste) {
1270: next if ($suffix =~ /\D/);
1271: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1272: my $url = $env{'docs.markedcopy_url_'.$suffix};
1273: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1274: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1275: ($url ne '')) {
1276: $clipboardcount ++;
1277: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1278: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1279: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1280: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1281: $is_external = 1;
1282: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1283: $is_exttool = 1;
1284: }
1285: if ($folder =~ /^supplemental/) {
1286: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1287: unless ($canpaste) {
1288: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1289: }
1290: } else {
1291: $canpaste = 1;
1292: }
1293: if ($canpaste) {
1294: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1295: my $srcdom = $1;
1296: my $srcnum = $2;
1297: my $rem = $3;
1298: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1299: $othercourse = 1;
1300: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1301: $othercrs = '<br />'.&mt('(from another course)');
1302: } else {
1303: $canpaste = 0;
1304: $nopaste = &mt('Paste from another course unavailable.');
1305: }
1306: }
1307: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1308: my $prefix = $1;
1309: $parent = $2;
1310: if ($folder !~ /^\Q$prefix\E/) {
1311: $areachange = 1;
1312: }
1313: $is_uploaded_map = 1;
1314: }
1315: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1316: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1317: if ($cid ne $env{'request.course.id'}) {
1318: my ($srcdom,$srcnum) = split(/_/,$cid);
1319: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1320: $othercrs = '<br />'.&mt('(from another course)');
1321: } else {
1322: $canpaste = 0;
1323: $nopaste = &mt('Paste from another course unavailable.');
1324: }
1325: }
1326: }
1327: if ($canpaste) {
1328: push(@pasteable,$suffix);
1329: }
1330: }
1331: my $buffer;
1332: if (($is_external) || ($is_exttool)) {
1333: $buffer = &mt('External Resource').': '.
1334: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1335: &LONCAPA::map::qtescape($url).')';
1336: } else {
1337: my $icon = &Apache::loncommon::icon($extension);
1338: if ($extension eq 'sequence' &&
1339: $url =~ m{/default_\d+\.sequence$}x) {
1340: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1341: $icon .= '/navmap.folder.closed.gif';
1342: }
1343: my $title = $env{'docs.markedcopy_title_'.$suffix};
1344: if ($title eq '') {
1345: ($title) = ($url =~ m{/([^/]+)$});
1346: }
1347: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1348: ': '.
1349: &Apache::loncommon::parse_supplemental_title(
1350: &LONCAPA::map::qtescape($title));
1351: }
1352: $pasteitems .= '<div class="LC_left_float">';
1353: my ($options,$onclick);
1354: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1355: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1356: if (($is_uploaded_map) ||
1357: ($url =~ /(bulletinboard|smppg)$/) ||
1358: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1359: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1360: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1361: }
1362: }
1363: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1364: if ($nopaste) {
1365: $pasteitems .= $nopaste;
1366: } else {
1367: if ($othercrs) {
1368: $pasteitems .= $othercrs;
1369: }
1370: if ($options) {
1371: $pasteitems .= $options;
1372: }
1373: }
1374: $pasteitems .= '</div>';
1375: }
1376: }
1377: if ($pasteitems eq '') {
1378: &Apache::lonnet::delenv('docs.markedcopies');
1379: }
1380: my ($pasteform,$form_start,$buttons,$form_end);
1381: if ($pasteitems) {
1382: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1383: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1384: if (@pasteable) {
1385: my $value = &mt('Paste to current folder');
1386: if ($container eq 'page') {
1387: $value = &mt('Paste to current page');
1388: }
1389: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1390: }
1391: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1392: if ($clipboardcount > 1) {
1393: $buttons .=
1394: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1395: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1396: (' 'x2).
1397: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1398: (' 'x2);
1399: }
1400: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1401: '</form>';
1402: } else {
1403: $pasteitems = &mt('Clipboard is empty');
1404: }
1405: $r->print($form_start
1406: .'<fieldset>'
1407: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1408: .$pasteitems
1409: .'</fieldset>'
1410: .$form_end);
1411: }
1412:
1413: sub paste_options {
1414: my ($suffix,$is_uploaded_map,$parent) = @_;
1415: my ($copytext,$movetext);
1416: if ($is_uploaded_map) {
1417: $copytext = &mt('Copy to new folder');
1418: $movetext = &mt('Move old');
1419: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1420: $copytext = &mt('Copy to new board');
1421: $movetext = &mt('Move (not posts)');
1422: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1423: $copytext = &mt('Copy to new page');
1424: $movetext = &mt('Move');
1425: } else {
1426: $copytext = &mt('Copy to new file');
1427: $movetext = &mt('Move');
1428: }
1429: my $output = '<br />'.
1430: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1431: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1432: '<label>'.
1433: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1434: $copytext.'</label></span>'.(' 'x2).' '.
1435: '<span class="LC_nobreak"><label>'.
1436: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1437: $movetext.'</label></span>';
1438: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1439: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1440: '</legend><table border="0">';
1441: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1442: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1443: my $lastdir = $parent;
1444: my %depths = (
1445: $lastdir => 0,
1446: );
1447: my (%display,%deps);
1448: for (my $i=0; $i<@pastemaps; $i++) {
1449: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1450: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1451: my @subfolders = split(/,/,$subfolderstr);
1452: $deps{$lastdir} = \@subfolders;
1453: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1454: my $depth = $depths{$lastdir} + 1;
1455: my $offset = int($depth * 4);
1456: my $indent = (' ' x $offset);
1457: for (my $j=0; $j<@subfolders; $j++) {
1458: $depths{$subfolders[$j]} = $depth;
1459: $display{$subfolders[$j]} =
1460: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1461: '<td><label>'.
1462: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1463: '<label>'.
1464: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1465: &mt('Move old').'</label>'.
1466: '</td></tr>';
1467: }
1468: }
1469: &recurse_print(\$output,$parent,\%deps,\%display);
1470: $output .= '</table></fieldset>';
1471: }
1472: $output .= '</div>';
1473: return $output;
1474: }
1475:
1476: sub recurse_print {
1477: my ($outputref,$dir,$deps,$display) = @_;
1478: $$outputref .= $display->{$dir}."\n";
1479: if (ref($deps->{$dir}) eq 'ARRAY') {
1480: foreach my $subdir (@{$deps->{$dir}}) {
1481: &recurse_print($outputref,$subdir,$deps,$display);
1482: }
1483: }
1484: }
1485:
1486: sub supp_pasteable {
1487: my ($url) = @_;
1488: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1489: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1490: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1491: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1492: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1493: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1494: return 1;
1495: }
1496: return;
1497: }
1498:
1499: sub paste_popup_js {
1500: my %html_js_lt = &Apache::lonlocal::texthash(
1501: show => 'Show Options',
1502: hide => 'Hide Options',
1503: );
1504: my %js_lt = &Apache::lonlocal::texthash(
1505: none => 'No items selected from clipboard.',
1506: );
1507: &html_escape(\%html_js_lt);
1508: &js_escape(\%html_js_lt);
1509: &js_escape(\%js_lt);
1510: return <<"END";
1511:
1512: function showPasteOptions(suffix) {
1513: document.getElementById('pasteoptions_'+suffix).style.display='block';
1514: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1515: return;
1516: }
1517:
1518: function hidePasteOptions(suffix) {
1519: document.getElementById('pasteoptions_'+suffix).style.display='none';
1520: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1521: return;
1522: }
1523:
1524: function showOptions(caller,suffix) {
1525: if (document.getElementById('pasteoptionstext_'+suffix)) {
1526: if (caller.checked) {
1527: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1528: } else {
1529: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1530: }
1531: if (document.getElementById('pasteoptions_'+suffix)) {
1532: document.getElementById('pasteoptions_'+suffix).style.display='none';
1533: }
1534: }
1535: return;
1536: }
1537:
1538: function validateClipboard() {
1539: var numchk = 0;
1540: if (document.pasteform.pasting.length > 1) {
1541: for (var i=0; i<document.pasteform.pasting.length; i++) {
1542: if (document.pasteform.pasting[i].checked) {
1543: numchk ++;
1544: }
1545: }
1546: } else {
1547: if (document.pasteform.pasting.type == 'checkbox') {
1548: if (document.pasteform.pasting.checked) {
1549: numchk ++;
1550: }
1551: }
1552: }
1553: if (numchk > 0) {
1554: return true;
1555: } else {
1556: alert("$js_lt{'none'}");
1557: return false;
1558: }
1559: }
1560:
1561: function checkClipboard() {
1562: if (document.pasteform.pasting.length > 1) {
1563: for (var i=0; i<document.pasteform.pasting.length; i++) {
1564: document.pasteform.pasting[i].checked = true;
1565: }
1566: }
1567: return;
1568: }
1569:
1570: function uncheckClipboard() {
1571: if (document.pasteform.pasting.length >1) {
1572: for (var i=0; i<document.pasteform.pasting.length; i++) {
1573: document.pasteform.pasting[i].checked = false;
1574: }
1575: }
1576: return;
1577: }
1578:
1579: END
1580:
1581: }
1582:
1583: sub do_paste_from_buffer {
1584: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1585:
1586: # Array of items in paste buffer
1587: my (@currpaste,%pastebuffer,%allerrors);
1588: @currpaste = split(/,/,$env{'docs.markedcopies'});
1589:
1590: # Early out if paste buffer is empty
1591: if (@currpaste == 0) {
1592: return ();
1593: }
1594: map { $pastebuffer{$_} = 1; } @currpaste;
1595:
1596: # Array of items selected items to paste
1597: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1598:
1599: # Early out if nothing selected to paste
1600: if (@reqpaste == 0) {
1601: return();
1602: }
1603: my @topaste;
1604: foreach my $suffix (@reqpaste) {
1605: next if ($suffix =~ /\D/);
1606: next unless (exists($pastebuffer{$suffix}));
1607: push(@topaste,$suffix);
1608: }
1609:
1610: # Early out if nothing available to paste
1611: if (@topaste == 0) {
1612: return();
1613: }
1614:
1615: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1616: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1617:
1618: foreach my $suffix (@topaste) {
1619: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1620: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1621: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1622: # Supplemental content may only include certain types of content
1623: # Early out if pasted content is not supported in Supplemental area
1624: if ($folder =~ /^supplemental/) {
1625: unless (&supp_pasteable($url)) {
1626: $notinsupp{$suffix} = 1;
1627: next;
1628: }
1629: }
1630: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1631: my $srcd = $1;
1632: my $srcn = $2;
1633: # When paste buffer was populated using an active role in a different course
1634: # check for mdc privilege in the course from which the resource was pasted
1635: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1636: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1637: $notincrs{$suffix} = 1;
1638: next;
1639: }
1640: }
1641: $srcdom{$suffix} = $srcd;
1642: $srcnum{$suffix} = $srcn;
1643: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1644: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1645: my ($srcd,$srcn) = split(/_/,$cid);
1646: # When paste buffer was populated using an active role in a different course
1647: # check for mdc privilege in the course from which the resource was pasted
1648: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1649: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1650: $notincrs{$suffix} = 1;
1651: next;
1652: }
1653: }
1654: $srcdom{$suffix} = $srcd;
1655: $srcnum{$suffix} = $srcn;
1656: }
1657: $srcmapidx{$suffix} = $mapidx;
1658: push(@dopaste,$suffix);
1659: if ($url=~/\.(page|sequence)$/) {
1660: $is_map{$suffix} = 1;
1661: }
1662:
1663: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1664: my $oldprefix = $1;
1665: # When pasting content from Main Content to Supplemental Content and vice versa
1666: # URLs will contain different paths (which depend on whether pasted item is
1667: # a folder/page or a document).
1668: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1669: $prefixchg{$suffix} = 'docstosupp';
1670: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1671: $prefixchg{$suffix} = 'supptodocs';
1672: }
1673:
1674: # If pasting an uploaded map, get list of contained uploaded maps.
1675: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1676: my @nested;
1677: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1678: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1679: my @deps = map { /\d+:([\d,]+$)/ } @items;
1680: foreach my $dep (@deps) {
1681: if ($dep =~ /,/) {
1682: push(@nested,split(/,/,$dep));
1683: } else {
1684: push(@nested,$dep);
1685: }
1686: }
1687: foreach my $item (@nested) {
1688: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1689: push(@{$marktomove{$suffix}},$type.'_'.$item);
1690: }
1691: }
1692: }
1693: }
1694: }
1695:
1696: # Early out if nothing available to paste
1697: if (@dopaste == 0) {
1698: return ();
1699: }
1700:
1701: # Populate message hash and hashes used for main content <=> supplemental content
1702: # changes
1703:
1704: %msgs = &Apache::lonlocal::texthash (
1705: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1706: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1707: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1708: );
1709:
1710: %before = (
1711: docstosupp => {
1712: map => 'default',
1713: doc => 'docs',
1714: },
1715: supptodocs => {
1716: map => 'supplemental',
1717: doc => 'supplemental',
1718: },
1719: );
1720:
1721: %after = (
1722: docstosupp => {
1723: map => 'supplemental',
1724: doc => 'supplemental'
1725: },
1726: supptodocs => {
1727: map => 'default',
1728: doc => 'docs',
1729: },
1730: );
1731:
1732: # Retrieve information about all course maps in main content area
1733:
1734: my $allmaps = {};
1735: if ($folder =~ /^default/) {
1736: $allmaps =
1737: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1738: $env{"course.$env{'request.course.id'}.home"},
1739: $env{'request.course.id'});
1740: }
1741:
1742: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1743:
1744: # Loop over the items to paste
1745: foreach my $suffix (@dopaste) {
1746: # Maps need to be copied first
1747: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1748: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1749: %newurls,%tomove,%resdatacopy);
1750: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1751: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1752: }
1753: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1754: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1755: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1756: my $oldurl = $url;
1757: if ($is_map{$suffix}) {
1758: # If pasting a map, check if map contains other maps
1759: my (%hierarchy,%titles);
1760: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1761: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1762: if ($url=~ m{^/uploaded/}) {
1763: my $newurl;
1764: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1765: ($newurl,my $error) =
1766: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1767: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1768: \$title,$allmaps,\%newurls);
1769: if ($error) {
1770: $allerrors{$suffix} = $error;
1771: next;
1772: }
1773: if ($newurl ne '') {
1774: if ($newurl ne $url) {
1775: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1776: $newsubdir{$url} = $1;
1777: }
1778: $mapchanges{$url} = 1;
1779: }
1780: }
1781: }
1782: if (($srcdom{$suffix} ne $coursedom) ||
1783: ($srcnum{$suffix} ne $coursenum) ||
1784: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1785: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1786: $coursedom,$coursenum,$srcdom{$suffix},
1787: $srcnum{$suffix},$allmaps,\%rewrites,
1788: \%retitles,\%copies,\%dbcopies,
1789: \%zombies,\%params,\%mapmoves,
1790: \%mapchanges,\%tomove,\%newsubdir,
1791: \%newurls,\%resdatacopy)) {
1792: $mapmoves{$url} = 1;
1793: }
1794: $url = $newurl;
1795: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1796: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1797: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1798: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1799: \%zombies,\%params,\%mapmoves,\%mapchanges,
1800: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1801: }
1802: } elsif ($url=~m {^/res/}) {
1803: # published map can only exist once, so remove from paste buffer when done
1804: push(@toclear,$suffix);
1805: # if pasting published map (main content area only) check map not already in course
1806: if ($folder =~ /^default/) {
1807: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1808: $duplicate{$suffix} = 1;
1809: next;
1810: }
1811: }
1812: }
1813: }
1814: if ($url=~ m{/(bulletinboard|smppg)$}) {
1815: my $prefix = $1;
1816: my $fromothercrs;
1817: #need to copy the db contents to a new one, unless this is a move.
1818: my %info = (
1819: src => $url,
1820: cdom => $coursedom,
1821: cnum => $coursenum,
1822: );
1823: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1824: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1825: $fromothercrs = 1;
1826: $info{'cdom'} = $srcdom{$suffix};
1827: $info{'cnum'} = $srcnum{$suffix};
1828: }
1829: }
1830: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1831: my (%lockerr,$msg);
1832: my ($newurl,$result,$errtext) =
1833: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1834: if ($result eq 'ok') {
1835: $url = $newurl;
1836: $title=&mt('Copy of').' '.$title;
1837: } else {
1838: if ($prefix eq 'smppg') {
1839: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1840: } elsif ($prefix eq 'bulletinboard') {
1841: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1842: }
1843: $results{$suffix} = $result;
1844: $msgerrs{$suffix} = $msg;
1845: $lockerrs{$suffix} = $lockerr{$prefix};
1846: next;
1847: }
1848: if ($lockerr{$prefix}) {
1849: $lockerrs{$suffix} = $lockerr{$prefix};
1850: }
1851: }
1852: }
1853: $title = &LONCAPA::map::qtunescape($title);
1854: my $ext='false';
1855: if ($url=~m{^http(|s)://}) { $ext='true'; }
1856: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1857: if ($folder !~ /^supplemental/) {
1858: (undef,undef,$title) =
1859: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1860: }
1861: } else {
1862: if ($folder=~/^supplemental/) {
1863: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1864: $env{'user.domain'}.'___&&&___'.$title;
1865: }
1866: }
1867:
1868: # For uploaded files (excluding pages/sequences) path in copied file is changed
1869: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1870: # courses.
1871:
1872: unless ($is_map{$suffix}) {
1873: my $newidx;
1874: # Now insert the URL at the bottom
1875: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1876: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1877: my $relpath = $1;
1878: if ($relpath ne '') {
1879: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1880: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1881: my $newprefix = $newloc;
1882: if ($newloc eq 'default') {
1883: $newprefix = 'docs';
1884: }
1885: if ($newdocsdir eq '') {
1886: $newdocsdir = 'default';
1887: }
1888: if (($prefixchg{$suffix}) ||
1889: ($srcdom{$suffix} ne $coursedom) ||
1890: ($srcnum{$suffix} ne $coursenum) ||
1891: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1892: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1893: $url =
1894: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1895: &Apache::lonnet::getfile($oldurl));
1896: if ($url eq '/adm/notfound.html') {
1897: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1898: next;
1899: } else {
1900: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1901: $newsubpath =~ s{/+$}{/};
1902: $docmoves{$oldurl} = $newsubpath;
1903: }
1904: }
1905: }
1906: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1907: my $template = $1;
1908: if ($newidx) {
1909: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1910: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1911: }
1912: }
1913: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1914: ':'.$ext.':normal:res';
1915: push(@LONCAPA::map::order,$newidx);
1916: # Store the result
1917: my ($errtext,$fatal) =
1918: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1919: if ($fatal) {
1920: $save_err .= $errtext;
1921: $allresult = 'fail';
1922: }
1923: }
1924:
1925: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1926: # resourcedata for simpleproblems copied from another course
1927: unless ($allresult eq 'fail') {
1928: my %updated = (
1929: rewrites => \%rewrites,
1930: zombies => \%zombies,
1931: removefrommap => \%removefrommap,
1932: removeparam => \%removeparam,
1933: dbcopies => \%dbcopies,
1934: resdatacopy => \%resdatacopy,
1935: retitles => \%retitles,
1936: );
1937: my %info = (
1938: newsubdir => \%newsubdir,
1939: params => \%params,
1940: );
1941: if ($prefixchg{$suffix}) {
1942: $info{'before'} = $before{$prefixchg{$suffix}};
1943: $info{'after'} = $after{$prefixchg{$suffix}};
1944: }
1945: my %moves = (
1946: copies => \%copies,
1947: docmoves => \%docmoves,
1948: mapmoves => \%mapmoves,
1949: );
1950: (my $result,$msgs{$suffix},my $lockerror) =
1951: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1952: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1953: $url,'paste');
1954: $lockerrors .= $lockerror;
1955: if ($result eq 'ok') {
1956: if ($is_map{$suffix}) {
1957: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1958: $folder.'.'.$container);
1959: if ($fatal) {
1960: $allresult = 'failread';
1961: } else {
1962: if ($#LONCAPA::map::order<1) {
1963: my $idx=&LONCAPA::map::getresidx();
1964: if ($idx<=0) { $idx=1; }
1965: $LONCAPA::map::order[0]=$idx;
1966: $LONCAPA::map::resources[$idx]='';
1967: }
1968: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1969: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1970: ':'.$ext.':normal:res';
1971: push(@LONCAPA::map::order,$newidx);
1972:
1973: # Store the result
1974: my ($errtext,$fatal) =
1975: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1976: if ($fatal) {
1977: $save_err .= $errtext;
1978: $allresult = 'failstore';
1979: }
1980: }
1981: }
1982: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1983: push(@toclear,$suffix);
1984: }
1985: }
1986: }
1987: }
1988: &clear_from_buffer(\@toclear,\@currpaste);
1989: my $msgsarray;
1990: foreach my $suffix (keys(%msgs)) {
1991: if (ref($msgs{$suffix}) eq 'ARRAY') {
1992: $msgsarray .= join(',',@{$msgs{$suffix}});
1993: }
1994: }
1995: return ($allresult,$save_err,$msgsarray,$lockerrors);
1996: }
1997:
1998: sub do_buffer_empty {
1999: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2000: if (@currpaste == 0) {
2001: return &mt('Clipboard is already empty');
2002: }
2003: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2004: if (@toclear == 0) {
2005: return &mt('Nothing selected to clear from clipboard');
2006: }
2007: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2008: if ($numdel) {
2009: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2010: } else {
2011: return &mt('Clipboard unchanged');
2012: }
2013: return;
2014: }
2015:
2016: sub clear_from_buffer {
2017: my ($toclear,$currpaste) = @_;
2018: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2019: my %pastebuffer;
2020: map { $pastebuffer{$_} = 1; } @{$currpaste};
2021: my $numdel = 0;
2022: foreach my $suffix (@{$toclear}) {
2023: next if ($suffix =~ /\D/);
2024: next unless (exists($pastebuffer{$suffix}));
2025: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2026: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2027: delete($pastebuffer{$suffix});
2028: $numdel ++;
2029: }
2030: }
2031: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2032: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2033: return $numdel;
2034: }
2035:
2036: sub get_newmap_url {
2037: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2038: $titleref,$allmaps,$newurls) = @_;
2039: my $newurl;
2040: if ($url=~ m{^/uploaded/}) {
2041: $$titleref=&mt('Copy of').' '.$$titleref;
2042: }
2043: my $now = time;
2044: my $suffix=$$.int(rand(100)).$now;
2045: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2046: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2047: my $path = $1;
2048: my $prefix = $2;
2049: my $ancestor = $3;
2050: if (length($ancestor) > 10) {
2051: $ancestor = substr($ancestor,-10,10);
2052: }
2053: my $newid;
2054: if ($prefixchg) {
2055: if ($folder =~ /^supplemental/) {
2056: $prefix =~ s/^default/supplemental/;
2057: } else {
2058: $prefix =~ s/^supplemental/default/;
2059: }
2060: }
2061: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2062: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2063: } else {
2064: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2065: }
2066: my $counter = 0;
2067: my $is_unique = &uniqueness_check($newurl);
2068: if ($folder =~ /^default/) {
2069: if ($allmaps->{$newurl}) {
2070: $is_unique = 0;
2071: }
2072: }
2073: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2074: $counter ++;
2075: $suffix ++;
2076: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2077: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2078: } else {
2079: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2080: }
2081: $is_unique = &uniqueness_check($newurl);
2082: }
2083: if ($is_unique) {
2084: $newurls->{$newurl} = 1;
2085: } else {
2086: if ($url=~/\.page$/) {
2087: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2088: } else {
2089: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2090: }
2091: }
2092: }
2093: return ($newurl);
2094: }
2095:
2096: sub dbcopy {
2097: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2098: my ($url,$result,$errtext);
2099: if (ref($dbref) eq 'HASH') {
2100: $url = $dbref->{'src'};
2101: if ($url =~ m{/(smppg|bulletinboard)$}) {
2102: my $prefix = $1;
2103: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2104: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2105: my $db_name;
2106: my $marker = (split(m{/},$url))[4];
2107: $marker=~s/\D//g;
2108: if ($dbref->{'src'} =~ m{/smppg$}) {
2109: $db_name =
2110: &Apache::lonsimplepage::get_db_name($url,$marker,
2111: $dbref->{'cdom'},
2112: $dbref->{'cnum'});
2113: } else {
2114: $db_name = 'bulletinpage_'.$marker;
2115: }
2116: my ($suffix,$freedlock,$error) =
2117: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2118: $coursedom,$coursenum,
2119: 'concat');
2120: if (!$suffix) {
2121: if ($prefix eq 'smppg') {
2122: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2123: } else {
2124: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2125: }
2126: if ($error) {
2127: $errtext .= '<br />'.$error;
2128: }
2129: } else {
2130: #need to copy the db contents to a new one.
2131: my %contents=&Apache::lonnet::dump($db_name,
2132: $dbref->{'cdom'},
2133: $dbref->{'cnum'});
2134: if (exists($contents{'uploaded.photourl'})) {
2135: my $photo = $contents{'uploaded.photourl'};
2136: my ($subdir,$fname) =
2137: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2138: my $newphoto;
2139: if ($fname ne '') {
2140: my $content = &Apache::lonnet::getfile($photo);
2141: unless ($content eq '-1') {
2142: $env{'form.'.$suffix.'.photourl'} = $content;
2143: $newphoto =
2144: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2145: delete($env{'form.'.$suffix.'.photourl'});
2146: }
2147: }
2148: if ($newphoto =~ m{^/uploaded/}) {
2149: $contents{'uploaded.photourl'} = $newphoto;
2150: }
2151: }
2152: $db_name =~ s{_\d*$ }{_$suffix}x;
2153: $result=&Apache::lonnet::put($db_name,\%contents,
2154: $coursedom,$coursenum);
2155: if ($result eq 'ok') {
2156: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2157: }
2158: }
2159: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2160: $lockerrorsref->{$prefix} =
2161: '<div class="LC_error">'.
2162: &mt('There was a problem removing a lockfile.');
2163: if ($prefix eq 'smppg') {
2164: $lockerrorsref->{$prefix} .=
2165: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2166: } else {
2167: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2168: }
2169: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2170: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2171: '</div>';
2172: }
2173: }
2174: } elsif ($url =~ m{/syllabus$}) {
2175: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2176: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2177: if (($dbref->{'cdom'} ne $coursedom) ||
2178: ($dbref->{'cnum'} ne $coursenum)) {
2179: my %contents=&Apache::lonnet::dump('syllabus',
2180: $dbref->{'cdom'},
2181: $dbref->{'cnum'});
2182: $result=&Apache::lonnet::put('syllabus',\%contents,
2183: $coursedom,$coursenum);
2184: }
2185: }
2186: }
2187: }
2188: return ($url,$result,$errtext);
2189: }
2190:
2191: sub copy_templated_files {
2192: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2193: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2194: my $srccontainer = 'sequence';
2195: if ($srcwaspage) {
2196: $srccontainer = 'page';
2197: }
2198: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2199: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2200: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2201: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2202: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2203: $template.'.problem';
2204: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2205: if ($template eq 'simpleproblem') {
2206: $srcprefix .= '.0.';
2207: my $weightprefix = $newprefix;
2208: $newprefix .= '.0.';
2209: my @simpleprobqtypes = qw(radio option string essay numerical);
2210: my $qtype=$srcparms{$srcprefix.'questiontype'};
2211: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2212: my %newdata;
2213: foreach my $type (@simpleprobqtypes) {
2214: if ($type eq $qtype) {
2215: $newdata{"$weightprefix.$type.weight"}=1;
2216: } else {
2217: $newdata{"$weightprefix.$type.weight"}=0;
2218: }
2219: }
2220: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2221: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2222: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2223: if ($qtype eq 'numerical') {
2224: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2225: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2226: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2227: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2228: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2229: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2230: unless (defined($maxfoils)) { $maxfoils=10; }
2231: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2232: if ($maxfoils<=0) { $maxfoils=10; }
2233: my $randomize=$srcparms{$srcprefix.'randomize'};
2234: unless (defined($randomize)) { $randomize='yes'; }
2235: unless ($randomize eq 'no') { $randomize='yes'; }
2236: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2237: $newdata{$newprefix.'randomize'} = $randomize;
2238: if ($qtype eq 'option') {
2239: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2240: }
2241: for (my $i=1; $i<=10; $i++) {
2242: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2243: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2244: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2245: }
2246:
2247: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2248: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2249: unless (defined($maxfoils)) { $maxfoils=10; }
2250: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2251: if ($maxfoils<=0) { $maxfoils=10; }
2252: my $randomize=$srcparms{$srcprefix.'randomize'};
2253: unless (defined($randomize)) { $randomize='yes'; }
2254: unless ($randomize eq 'no') { $randomize='yes'; }
2255: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2256: $newdata{$newprefix.'randomize'} = $randomize;
2257: if ($qtype eq 'option') {
2258: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2259: }
2260: for (my $i=1; $i<=10; $i++) {
2261: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2262: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2263: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2264: }
2265: } elsif ($qtype eq 'string') {
2266: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2267: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2268: }
2269: if (keys(%newdata)) {
2270: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2271: $coursenum);
2272: if ($putres eq 'ok') {
2273: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2274: }
2275: }
2276: }
2277: }
2278: }
2279:
2280: sub uniqueness_check {
2281: my ($newurl) = @_;
2282: my $unique = 1;
2283: foreach my $res (@LONCAPA::map::order) {
2284: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2285: $url=&LONCAPA::map::qtescape($url);
2286: if ($newurl eq $url) {
2287: $unique = 0;
2288: last;
2289: }
2290: }
2291: return $unique;
2292: }
2293:
2294: sub contained_map_check {
2295: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2296: $allmaps) = @_;
2297: my $content = &Apache::lonnet::getfile($url);
2298: unless ($content eq '-1') {
2299: my $parser = HTML::TokeParser->new(\$content);
2300: $parser->attr_encoded(1);
2301: while (my $token = $parser->get_token) {
2302: next if ($token->[0] ne 'S');
2303: if ($token->[1] eq 'resource') {
2304: next if ($token->[2]->{'type'} eq 'zombie');
2305: my $ressrc = $token->[2]->{'src'};
2306: if ($folder =~ /^supplemental/) {
2307: unless (&supp_pasteable($ressrc)) {
2308: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2309: next;
2310: }
2311: }
2312: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2313: if ($1 eq 'uploaded') {
2314: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2315: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2316: } else {
2317: if ($allmaps->{$ressrc}) {
2318: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2319: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2320: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2321: } else {
2322: $addedmaps->{$ressrc} = [$url];
2323: }
2324: }
2325: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2326: $addedmaps,$hierarchy,$titles,$allmaps);
2327: }
2328: } elsif ($token->[1] eq 'param') {
2329: if ($folder =~ /^supplemental/) {
2330: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2331: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2332: } else {
2333: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2334: }
2335: }
2336: }
2337: }
2338: }
2339: return;
2340: }
2341:
2342: sub url_paste_fixups {
2343: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2344: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2345: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2346: my $checktitle;
2347: if (($prefixchg) &&
2348: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2349: $checktitle = 1;
2350: }
2351: my $skip;
2352: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2353: my $mapid = $1.$2;
2354: if ($tomove->{$mapid}) {
2355: $skip = 1;
2356: }
2357: }
2358: my $file = &Apache::lonnet::getfile($oldurl);
2359: return if ($file eq '-1');
2360: my $parser = HTML::TokeParser->new(\$file);
2361: $parser->attr_encoded(1);
2362: my $changed = 0;
2363: while (my $token = $parser->get_token) {
2364: next if ($token->[0] ne 'S');
2365: if ($token->[1] eq 'resource') {
2366: my $ressrc = $token->[2]->{'src'};
2367: next if ($ressrc eq '');
2368: my $id = $token->[2]->{'id'};
2369: my $title = $token->[2]->{'title'};
2370: if ($checktitle) {
2371: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2372: $retitles->{$oldurl}{$id} = $ressrc;
2373: }
2374: }
2375: next if ($token->[2]->{'type'} eq 'external');
2376: if ($token->[2]->{'type'} eq 'zombie') {
2377: next if ($skip);
2378: $zombies->{$oldurl}{$id} = $ressrc;
2379: $changed = 1;
2380: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2381: my $srcdom = $1;
2382: my $srcnum = $2;
2383: my $rem = $3;
2384: my $newurl;
2385: my $mapname;
2386: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2387: my $prefix = $1;
2388: $mapname = $prefix.$2;
2389: if ($tomove->{$mapname}) {
2390: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2391: $srcdom,$srcnum,$allmaps,$rewrites,
2392: $retitles,$copies,$dbcopies,$zombies,
2393: $params,$mapmoves,$mapchanges,$tomove,
2394: $newsubdir,$newurls,$resdatacopy);
2395: next;
2396: } else {
2397: ($newurl,my $error) =
2398: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2399: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2400: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2401: $newsubdir->{$ressrc} = $1;
2402: }
2403: if ($error) {
2404: next;
2405: }
2406: }
2407: }
2408: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2409: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2410:
2411: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2412: $rewrites->{$oldurl}{$id} = $ressrc;
2413: $mapchanges->{$ressrc} = 1;
2414: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2415: $cnum,$srcdom,$srcnum,$allmaps,
2416: $rewrites,$retitles,$copies,$dbcopies,
2417: $zombies,$params,$mapmoves,$mapchanges,
2418: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2419: $mapmoves->{$ressrc} = 1;
2420: }
2421: $changed = 1;
2422: } else {
2423: $rewrites->{$oldurl}{$id} = $ressrc;
2424: $copies->{$oldurl}{$ressrc} = $id;
2425: $changed = 1;
2426: }
2427: }
2428: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2429: next if ($skip);
2430: my $srcdom = $1;
2431: my $srcnum = $2;
2432: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2433: $rewrites->{$oldurl}{$id} = $ressrc;
2434: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2435: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2436: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2437: $changed = 1;
2438: }
2439: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2440: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2441: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2442: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2443: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2444: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2445: $changed = 1;
2446: }
2447: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2448: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2449: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2450: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2451: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2452: }
2453: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2454: next if ($skip);
2455: my $srcdom = $1;
2456: my $srcnum = $2;
2457: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2458: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2459: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2460: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2461: $changed = 1;
2462: }
2463: }
2464: } elsif ($token->[1] eq 'param') {
2465: next if ($skip);
2466: my $to = $token->[2]->{'to'};
2467: if ($to ne '') {
2468: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2469: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2470: } else {
2471: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2472: }
2473: }
2474: }
2475: }
2476: return $changed;
2477: }
2478:
2479: sub apply_fixups {
2480: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2481: $oldurl,$url,$caller) = @_;
2482: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2483: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2484: %resdatacopy,%lockerrors,$lockmsg);
2485: if (ref($updated) eq 'HASH') {
2486: if (ref($updated->{'rewrites'}) eq 'HASH') {
2487: %rewrites = %{$updated->{'rewrites'}};
2488: }
2489: if (ref($updated->{'zombies'}) eq 'HASH') {
2490: %zombies = %{$updated->{'zombies'}};
2491: }
2492: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2493: %removefrommap = %{$updated->{'removefrommap'}};
2494: }
2495: if (ref($updated->{'removeparam'}) eq 'HASH') {
2496: %removeparam = %{$updated->{'removeparam'}};
2497: }
2498: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2499: %dbcopies = %{$updated->{'dbcopies'}};
2500: }
2501: if (ref($updated->{'retitles'}) eq 'HASH') {
2502: %retitles = %{$updated->{'retitles'}};
2503: }
2504: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2505: %resdatacopy = %{$updated->{'resdatacopy'}};
2506: }
2507: }
2508: if (ref($info) eq 'HASH') {
2509: if (ref($info->{'newsubdir'}) eq 'HASH') {
2510: %newsubdir = %{$info->{'newsubdir'}};
2511: }
2512: if (ref($info->{'params'}) eq 'HASH') {
2513: %params = %{$info->{'params'}};
2514: }
2515: if (ref($info->{'before'}) eq 'HASH') {
2516: %before = %{$info->{'before'}};
2517: }
2518: if (ref($info->{'after'}) eq 'HASH') {
2519: %after = %{$info->{'after'}};
2520: }
2521: }
2522: if (ref($moves) eq 'HASH') {
2523: if (ref($moves->{'copies'}) eq 'HASH') {
2524: %copies = %{$moves->{'copies'}};
2525: }
2526: if (ref($moves->{'docmoves'}) eq 'HASH') {
2527: %docmoves = %{$moves->{'docmoves'}};
2528: }
2529: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2530: %mapmoves = %{$moves->{'mapmoves'}};
2531: }
2532: }
2533: foreach my $key (keys(%copies),keys(%docmoves)) {
2534: my @allcopies;
2535: if (exists($copies{$key})) {
2536: if (ref($copies{$key}) eq 'HASH') {
2537: my %added;
2538: foreach my $innerkey (keys(%{$copies{$key}})) {
2539: if (($innerkey ne '') && (!$added{$innerkey})) {
2540: push(@allcopies,$innerkey);
2541: $added{$innerkey} = 1;
2542: }
2543: }
2544: undef(%added);
2545: }
2546: }
2547: if ($key eq $oldurl) {
2548: if ((exists($docmoves{$key}))) {
2549: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2550: push(@allcopies,$oldurl);
2551: }
2552: }
2553: }
2554: if (@allcopies > 0) {
2555: foreach my $item (@allcopies) {
2556: my ($relpath,$oldsubdir,$fname) =
2557: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2558: if ($fname ne '') {
2559: my $content = &Apache::lonnet::getfile($item);
2560: unless ($content eq '-1') {
2561: my $storefn;
2562: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2563: $storefn = $docmoves{$key};
2564: } else {
2565: $storefn = $relpath;
2566: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2567: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2568: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2569: }
2570: if ($newsubdir{$key}) {
2571: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2572: }
2573: }
2574: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2575: my $copyurl =
2576: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2577: $storefn.$fname,$content);
2578: if ($copyurl eq '/adm/notfound.html') {
2579: if (exists($docmoves{$oldurl})) {
2580: return &mt('Paste failed: an error occurred copying the file.');
2581: } elsif (ref($errors) eq 'HASH') {
2582: $errors->{$item} = 1;
2583: }
2584: }
2585: }
2586: }
2587: }
2588: }
2589: }
2590: foreach my $key (keys(%mapmoves)) {
2591: my $storefn=$key;
2592: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2593: if ($prefixchg && $before{'map'} && $after{'map'}) {
2594: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2595: }
2596: if ($newsubdir{$key}) {
2597: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2598: }
2599: my $mapcontent = &Apache::lonnet::getfile($key);
2600: if ($mapcontent eq '-1') {
2601: if (ref($errors) eq 'HASH') {
2602: $errors->{$key} = 1;
2603: }
2604: } else {
2605: my $newmap =
2606: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2607: $mapcontent);
2608: if ($newmap eq '/adm/notfound.html') {
2609: if (ref($errors) eq 'HASH') {
2610: $errors->{$key} = 1;
2611: }
2612: }
2613: }
2614: }
2615: my %updates;
2616: if ($is_map) {
2617: if (ref($updated) eq 'HASH') {
2618: foreach my $type (keys(%{$updated})) {
2619: if (ref($updated->{$type}) eq 'HASH') {
2620: foreach my $key (keys(%{$updated->{$type}})) {
2621: $updates{$key} = 1;
2622: }
2623: }
2624: }
2625: }
2626: foreach my $key (keys(%updates)) {
2627: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2628: if (ref($rewrites{$key}) eq 'HASH') {
2629: %torewrite = %{$rewrites{$key}};
2630: }
2631: if (ref($retitles{$key}) eq 'HASH') {
2632: %toretitle = %{$retitles{$key}};
2633: }
2634: if (ref($removefrommap{$key}) eq 'HASH') {
2635: %toremove = %{$removefrommap{$key}};
2636: }
2637: if (ref($removeparam{$key}) eq 'HASH') {
2638: %remparam = %{$removeparam{$key}};
2639: }
2640: if (ref($zombies{$key}) eq 'HASH') {
2641: %zombie = %{$zombies{$key}};
2642: }
2643: if (ref($dbcopies{$key}) eq 'HASH') {
2644: foreach my $idx (keys(%{$dbcopies{$key}})) {
2645: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2646: my ($newurl,$result,$errtext) =
2647: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2648: if ($result eq 'ok') {
2649: $newdb{$idx} = $newurl;
2650: } elsif (ref($errors) eq 'HASH') {
2651: $errors->{$key} = 1;
2652: }
2653: push(@msgs,$errtext);
2654: }
2655: }
2656: }
2657: if (ref($resdatacopy{$key}) eq 'HASH') {
2658: if ($newsubdir{$key}) {
2659:
2660: }
2661: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2662: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2663: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2664: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2665: my $template = $1;
2666: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2667: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2668: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2669: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2670: my ($newmapname) = ($key =~ m{/([^/]+)$});
2671: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2672: my $srcmapinfo = $srcfolder.':'.$idx;
2673: if ($srccontainer eq 'page') {
2674: $srcmapinfo .= ':1';
2675: }
2676: if ($newsubdir{$key}) {
2677: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2678: }
2679: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2680: $cnum,$template,$idx,$newmapname);
2681: }
2682: }
2683: }
2684: }
2685: }
2686: if (ref($params{$key}) eq 'HASH') {
2687: %currparam = %{$params{$key}};
2688: }
2689: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2690: if ($fatal) {
2691: return ($errtext);
2692: }
2693: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2694: if (defined($LONCAPA::map::zombies[$i])) {
2695: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2696: if ($zombie{$i} eq $src) {
2697: undef($LONCAPA::map::zombies[$i]);
2698: }
2699: }
2700: }
2701: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2702: my $idx = $LONCAPA::map::order[$i];
2703: if (defined($LONCAPA::map::resources[$idx])) {
2704: my $changed;
2705: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2706: if ((exists($toremove{$idx})) &&
2707: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2708: splice(@LONCAPA::map::order,$i,1);
2709: if (ref($currparam{$idx}) eq 'ARRAY') {
2710: foreach my $name (@{$currparam{$idx}}) {
2711: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2712: }
2713: }
2714: next;
2715: }
2716: my $origsrc = $src;
2717: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2718: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2719: $changed = 1;
2720: }
2721: }
2722: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2723: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2724: if ($origsrc =~ m{^/uploaded/}) {
2725: if ($prefixchg && $before{'map'} && $after{'map'}) {
2726: if ($src =~ /\.(page|sequence)$/) {
2727: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2728: } else {
2729: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2730: }
2731: }
2732: if ($origsrc =~ /\.(page|sequence)$/) {
2733: if ($newsubdir{$origsrc}) {
2734: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2735: }
2736: } elsif ($newsubdir{$key}) {
2737: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2738: }
2739: }
2740: $changed = 1;
2741: } elsif ($newdb{$idx} ne '') {
2742: $src = $newdb{$idx};
2743: $changed = 1;
2744: }
2745: if ($changed) {
2746: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2747: }
2748: }
2749: }
2750: foreach my $idx (keys(%remparam)) {
2751: if (ref($remparam{$idx}) eq 'ARRAY') {
2752: foreach my $name (@{$remparam{$idx}}) {
2753: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2754: }
2755: }
2756: }
2757: if (values(%lockerrors) > 0) {
2758: $lockmsg = join('<br />',values(%lockerrors));
2759: }
2760: my $storefn;
2761: if ($key eq $oldurl) {
2762: $storefn = $url;
2763: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2764: } else {
2765: $storefn = $key;
2766: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2767: if ($prefixchg && $before{'map'} && $after{'map'}) {
2768: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2769: }
2770: if ($newsubdir{$key}) {
2771: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2772: }
2773: }
2774: my $report;
2775: if ($folder !~ /^supplemental/) {
2776: $report = 1;
2777: }
2778: (my $outtext,$errtext) =
2779: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2780: if ($errtext) {
2781: if ($caller eq 'paste') {
2782: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2783: }
2784: }
2785: }
2786: }
2787: return ('ok',\@msgs,$lockmsg);
2788: }
2789:
2790: sub copy_dependencies {
2791: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2792: my $content;
2793: if (ref($contentref)) {
2794: $content = $$contentref;
2795: } else {
2796: $content = &Apache::lonnet::getfile($item);
2797: }
2798: unless ($content eq '-1') {
2799: my $mm = new File::MMagic;
2800: my $mimetype = $mm->checktype_contents($content);
2801: if ($mimetype eq 'text/html') {
2802: my (%allfiles,%codebase,$state);
2803: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2804: if ($res eq 'ok') {
2805: my ($numexisting,$numpathchanges,$existing);
2806: (undef,$numexisting,$numpathchanges,$existing) =
2807: &Apache::loncommon::ask_for_embedded_content(
2808: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2809: {'error_on_invalid_names' => 1,
2810: 'ignore_remote_references' => 1,
2811: 'docs_url' => $item,
2812: 'context' => 'paste'});
2813: if ($numexisting > 0) {
2814: if (ref($existing) eq 'HASH') {
2815: foreach my $dep (keys(%{$existing})) {
2816: my $depfile = $dep;
2817: unless ($depfile =~ m{^\Q$relpath\E}) {
2818: $depfile = $relpath.$dep;
2819: }
2820: my $depcontent = &Apache::lonnet::getfile($depfile);
2821: unless ($depcontent eq '-1') {
2822: my $storedep = $dep;
2823: $storedep =~ s{^\Q$relpath\E}{};
2824: my $dep_url =
2825: &Apache::lonclonecourse::writefile(
2826: $env{'request.course.id'},
2827: $storefn.$storedep,$depcontent);
2828: if ($dep_url eq '/adm/notfound.html') {
2829: if (ref($errors) eq 'HASH') {
2830: $errors->{$depfile} = 1;
2831: }
2832: } else {
2833: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2834: }
2835: }
2836: }
2837: }
2838: }
2839: }
2840: }
2841: }
2842: return;
2843: }
2844:
2845: my %parameter_type = ( 'randompick' => 'int_pos',
2846: 'hiddenresource' => 'string_yesno',
2847: 'encrypturl' => 'string_yesno',
2848: 'randomorder' => 'string_yesno',);
2849: my $valid_parameters_re = join('|',keys(%parameter_type));
2850: # set parameters
2851: sub update_parameter {
2852: if ($env{'form.changeparms'} eq 'all') {
2853: my (@allidx,@allmapidx,%allchecked,%currchecked);
2854: %allchecked = (
2855: 'hiddenresource' => {},
2856: 'encrypturl' => {},
2857: 'randompick' => {},
2858: 'randomorder' => {},
2859: );
2860: foreach my $which (keys(%allchecked)) {
2861: $env{'form.all'.$which} =~ s/,$//;
2862: if ($which eq 'randompick') {
2863: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2864: my ($res,$value) = split(/:/,$item);
2865: if ($value =~ /^\d+$/) {
2866: $allchecked{$which}{$res} = $value;
2867: }
2868: }
2869: } else {
2870: if ($env{'form.all'.$which}) {
2871: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2872: }
2873: }
2874: }
2875: my $haschanges = 0;
2876: foreach my $res (@LONCAPA::map::order) {
2877: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2878: $name=&LONCAPA::map::qtescape($name);
2879: $url=&LONCAPA::map::qtescape($url);
2880: next unless ($name && $url);
2881: my $is_map;
2882: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2883: $is_map = 1;
2884: }
2885: foreach my $which (keys(%allchecked)) {
2886: if (($which eq 'randompick' || $which eq 'randomorder')) {
2887: next if (!$is_map);
2888: }
2889: my $oldvalue = 0;
2890: my $newvalue = 0;
2891: if ($allchecked{$which}{$res}) {
2892: $newvalue = $allchecked{$which}{$res};
2893: }
2894: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2895: if ($which eq 'randompick') {
2896: if ($current =~ /^(\d+)$/) {
2897: $oldvalue = $1;
2898: }
2899: } else {
2900: if ($current =~ /^yes$/i) {
2901: $oldvalue = 1;
2902: }
2903: }
2904: if ($oldvalue ne $newvalue) {
2905: $haschanges = 1;
2906: if ($newvalue) {
2907: my $storeval = 'yes';
2908: if ($which eq 'randompick') {
2909: $storeval = $newvalue;
2910: }
2911: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2912: $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($res,$which,'set',$storeval);
2915: } elsif ($oldvalue) {
2916: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2917: &remember_parms($res,$which,'del');
2918: }
2919: }
2920: }
2921: }
2922: return $haschanges;
2923: } else {
2924: my $haschanges = 0;
2925: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
2926:
2927: my $which = $env{'form.changeparms'};
2928: my $idx = $env{'form.setparms'};
2929: my $oldvalue = 0;
2930: my $newvalue = 0;
2931: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2932: if ($which eq 'randompick') {
2933: if ($current =~ /^(\d+)$/) {
2934: $oldvalue = $1;
2935: }
2936: } elsif ($current =~ /^yes$/i) {
2937: $oldvalue = 1;
2938: }
2939: if ($env{'form.'.$which.'_'.$idx}) {
2940: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2941: : 1;
2942: }
2943: if ($oldvalue ne $newvalue) {
2944: $haschanges = 1;
2945: if ($newvalue) {
2946: my $storeval = 'yes';
2947: if ($which eq 'randompick') {
2948: $storeval = $newvalue;
2949: }
2950: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2951: $parameter_type{$which});
2952: &remember_parms($idx,$which,'set',$storeval);
2953: } else {
2954: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2955: &remember_parms($idx,$which,'del');
2956: }
2957: }
2958: return $haschanges;
2959: }
2960: }
2961:
2962: sub handle_edit_cmd {
2963: my ($coursenum,$coursedom) =@_;
2964: if ($env{'form.cmd'} eq '') {
2965: return 0;
2966: }
2967: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2968:
2969: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2970: my ($title, $url, @rrest) = split(':', $ratstr);
2971:
2972: if ($cmd eq 'remove') {
2973: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2974: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2975: &Apache::lonnet::removeuploadedurl($url);
2976: } else {
2977: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2978: }
2979: splice(@LONCAPA::map::order, $idx, 1);
2980:
2981: } elsif ($cmd eq 'cut') {
2982: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2983: splice(@LONCAPA::map::order, $idx, 1);
2984:
2985: } elsif ($cmd eq 'up'
2986: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2987: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2988:
2989: } elsif ($cmd eq 'down'
2990: && defined($LONCAPA::map::order[$idx+1])) {
2991: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2992:
2993: } elsif ($cmd eq 'rename') {
2994: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2995: if ($comment=~/\S/) {
2996: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2997: $comment.':'.join(':', $url, @rrest);
2998: }
2999: # Devalidate title cache
3000: my $renamed_url=&LONCAPA::map::qtescape($url);
3001: &Apache::lonnet::devalidate_title_cache($renamed_url);
3002:
3003: } else {
3004: return 0;
3005: }
3006: return 1;
3007: }
3008:
3009: sub editor {
3010: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3011: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3012: $canedit,$navmapref,$hiddentop)=@_;
3013: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3014: if ($allowed) {
3015: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3016: $is_random_order,$container) =
3017: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3018: $r->print($breadcrumbtrail);
3019: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3020: $container = 'page';
3021: } else {
3022: $container = 'sequence';
3023: }
3024:
3025: my $jumpto;
3026:
3027: unless ($supplementalflag) {
3028: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3029: }
3030:
3031: unless ($allowed) {
3032: $randompick = -1;
3033: }
3034:
3035: my ($errtext,$fatal);
3036: if (($folder eq '') && (!$supplementalflag)) {
3037: if (@LONCAPA::map::order) {
3038: undef(@LONCAPA::map::order);
3039: undef(@LONCAPA::map::resources);
3040: undef(@LONCAPA::map::resparms);
3041: undef(@LONCAPA::map::zombies);
3042: }
3043: $folder = 'default';
3044: $container = 'sequence';
3045: } else {
3046: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3047: $folder.'.'.$container);
3048: return $errtext if ($fatal);
3049: }
3050:
3051: if ($#LONCAPA::map::order<1) {
3052: my $idx=&LONCAPA::map::getresidx();
3053: if ($idx<=0) { $idx=1; }
3054: $LONCAPA::map::order[0]=$idx;
3055: $LONCAPA::map::resources[$idx]='';
3056: }
3057:
3058: # ------------------------------------------------------------ Process commands
3059:
3060: # ---------------- if they are for this folder and user allowed to make changes
3061: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3062: # set parameters and change order
3063: &snapshotbefore();
3064:
3065: if (&update_parameter()) {
3066: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3067: return $errtext if ($fatal);
3068: }
3069:
3070: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3071: # change order
3072: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3073: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3074:
3075: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3076: return $errtext if ($fatal);
3077: }
3078:
3079: if ($env{'form.pastemarked'}) {
3080: my %paste_errors;
3081: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3082: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3083: \%paste_errors);
3084: if (ref($pastemsgarray) eq 'ARRAY') {
3085: if (@{$pastemsgarray} > 0) {
3086: $r->print('<p class="LC_info">'.
3087: join('<br />',@{$pastemsgarray}).
3088: '</p>');
3089: }
3090: }
3091: if ($lockerror) {
3092: $r->print('<p class="LC_error">'.
3093: $lockerror.
3094: '</p>');
3095: }
3096: if ($save_error ne '') {
3097: return $save_error;
3098: }
3099: if ($paste_res) {
3100: my %errortext = &Apache::lonlocal::texthash (
3101: fail => 'Storage of folder contents failed',
3102: failread => 'Reading folder contents failed',
3103: failstore => 'Storage of folder contents failed',
3104: );
3105: if ($errortext{$paste_res}) {
3106: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3107: }
3108: }
3109: if (keys(%paste_errors) > 0) {
3110: $r->print('<p class="LC_warning">'."\n".
3111: &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".
3112: '<ul>'."\n");
3113: foreach my $key (sort(keys(%paste_errors))) {
3114: $r->print('<li>'.$key.'</li>'."\n");
3115: }
3116: $r->print('</ul></p>'."\n");
3117: }
3118: } elsif ($env{'form.clearmarked'}) {
3119: my $output = &do_buffer_empty();
3120: if ($output) {
3121: $r->print('<p class="LC_info">'.$output.'</p>');
3122: }
3123: }
3124:
3125: $r->print($upload_output);
3126:
3127: # Rename, cut, copy or remove a single resource
3128: if (&handle_edit_cmd($coursenum,$coursedom)) {
3129: my $contentchg;
3130: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
3131: $contentchg = 1;
3132: }
3133: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3134: return $errtext if ($fatal);
3135: }
3136:
3137: # Cut, copy and/or remove multiple resources
3138: if ($env{'form.multichange'}) {
3139: my %allchecked = (
3140: cut => {},
3141: remove => {},
3142: );
3143: my $needsupdate;
3144: foreach my $which (keys(%allchecked)) {
3145: $env{'form.multi'.$which} =~ s/,$//;
3146: if ($env{'form.multi'.$which}) {
3147: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3148: if (ref($allchecked{$which}) eq 'HASH') {
3149: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3150: }
3151: }
3152: }
3153: if ($needsupdate) {
3154: my $haschanges = 0;
3155: my %curr_groups = &Apache::longroup::coursegroups();
3156: my $total = scalar(@LONCAPA::map::order) - 1;
3157: for (my $i=$total; $i>=0; $i--) {
3158: my $res = $LONCAPA::map::order[$i];
3159: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3160: $name=&LONCAPA::map::qtescape($name);
3161: $url=&LONCAPA::map::qtescape($url);
3162: next unless $url;
3163: my %denied =
3164: &action_restrictions($coursenum,$coursedom,$url,
3165: $env{'form.folderpath'},\%curr_groups);
3166: foreach my $which (keys(%allchecked)) {
3167: next if ($denied{$which});
3168: next unless ($allchecked{$which}{$res});
3169: if ($which eq 'remove') {
3170: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3171: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3172: &Apache::lonnet::removeuploadedurl($url);
3173: } else {
3174: &LONCAPA::map::makezombie($res);
3175: }
3176: splice(@LONCAPA::map::order,$i,1);
3177: $haschanges ++;
3178: } elsif ($which eq 'cut') {
3179: &LONCAPA::map::makezombie($res);
3180: splice(@LONCAPA::map::order,$i,1);
3181: $haschanges ++;
3182: }
3183: }
3184: }
3185: if ($haschanges) {
3186: ($errtext,$fatal) =
3187: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3188: return $errtext if ($fatal);
3189: }
3190: }
3191: }
3192:
3193: # Group import/search
3194: if ($env{'form.importdetail'}) {
3195: my @imports;
3196: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3197: if (defined($item)) {
3198: my ($name,$url,$residx)=
3199: map { &unescape($_); } split(/\=/,$item);
3200: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3201: my ($suffix,$errortxt,$locknotfreed) =
3202: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3203: if ($locknotfreed) {
3204: $r->print($locknotfreed);
3205: }
3206: if ($suffix) {
3207: $url =~ s/_new\./_$suffix./;
3208: } else {
3209: return $errortxt;
3210: }
3211: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3212: my $type = $1;
3213: my ($suffix,$errortxt,$locknotfreed) =
3214: &new_timebased_suffix($coursedom,$coursenum,$type);
3215: if ($locknotfreed) {
3216: $r->print($locknotfreed);
3217: }
3218: if ($suffix) {
3219: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3220: } else {
3221: return $errortxt;
3222: }
3223: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3224: my ($suffix,$errortxt,$locknotfreed) =
3225: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3226: if ($locknotfreed) {
3227: $r->print($locknotfreed);
3228: }
3229: if ($suffix) {
3230: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3231: } else {
3232: return $errortxt;
3233: }
3234: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3235: if ($supplementalflag) {
3236: next unless ($1 eq 'supplemental');
3237: if ($folder eq 'supplemental') {
3238: next unless ($2 eq 'default');
3239: } else {
3240: next unless ($folder eq 'supplemental_'.$2);
3241: }
3242: } else {
3243: next unless ($1 eq 'docs');
3244: if ($folder eq 'default') {
3245: next unless ($2 eq 'default');
3246: } else {
3247: next unless ($folder eq 'default_'.$2);
3248: }
3249: }
3250: }
3251: push(@imports, [$name, $url, $residx]);
3252: }
3253: }
3254: ($errtext,$fatal,my $fixuperrors) =
3255: &group_import($coursenum, $coursedom, $folder,$container,
3256: 'londocs',$ltitoolsref,@imports);
3257: return $errtext if ($fatal);
3258: if ($fixuperrors) {
3259: $r->print($fixuperrors);
3260: }
3261: }
3262: # Loading a complete map
3263: if ($env{'form.loadmap'}) {
3264: if ($env{'form.importmap'}=~/\w/) {
3265: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3266: my ($title,$url,$ext,$type)=split(/\:/,$res);
3267: my $idx=&LONCAPA::map::getresidx($url);
3268: $LONCAPA::map::resources[$idx]=$res;
3269: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3270: }
3271: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3272: $folder.'.'.$container,1);
3273: return $errtext if ($fatal);
3274: } else {
3275: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3276:
3277: }
3278: }
3279: &log_differences($plain);
3280: }
3281: # ---------------------------------------------------------------- End commands
3282: # ---------------------------------------------------------------- Print screen
3283: my $idx=0;
3284: my $shown=0;
3285: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3286: $r->print('<div class="LC_Box">'.
3287: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3288: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3289: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3290: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3291: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3292: '</ol>');
3293: if ($randompick>=0) {
3294: $r->print('<p class="LC_warning">'
3295: .&mt('Caution: this folder is set to randomly pick a subset'
3296: .' of resources. Adding or removing resources from this'
3297: .' folder will change the set of resources that the'
3298: .' students see, resulting in spurious or missing credit'
3299: .' for completed problems, not limited to ones you'
3300: .' modify. Do not modify the contents of this folder if'
3301: .' it is in active student use.')
3302: .'</p>'
3303: );
3304: }
3305: if ($is_random_order) {
3306: $r->print('<p class="LC_warning">'
3307: .&mt('Caution: this folder is set to randomly order its'
3308: .' contents. Adding or removing resources from this folder'
3309: .' will change the order of resources shown.')
3310: .'</p>'
3311: );
3312: }
3313: $r->print('</div>');
3314: }
3315:
3316: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3317: %filters = (
3318: canremove => [],
3319: cancut => [],
3320: cancopy => [],
3321: hiddenresource => [],
3322: encrypturl => [],
3323: randomorder => [],
3324: randompick => [],
3325: );
3326: %curr_groups = &Apache::longroup::coursegroups();
3327: &Apache::loncommon::start_data_table_count(); #setup a row counter
3328: foreach my $res (@LONCAPA::map::order) {
3329: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3330: $name=&LONCAPA::map::qtescape($name);
3331: $url=&LONCAPA::map::qtescape($url);
3332: unless ($name) { $name=(split(/\//,$url))[-1]; }
3333: unless ($name) { $idx++; next; }
3334: push(@allidx,$res);
3335: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3336: push(@allmapidx,$res);
3337: }
3338:
3339: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3340: $coursenum,$coursedom,$crstype,
3341: $pathitem,$supplementalflag,$container,
3342: \%filters,\%curr_groups,$ltitoolsref,$canedit,$isencrypted,$navmapref);
3343: $idx++;
3344: $shown++;
3345: }
3346: &Apache::loncommon::end_data_table_count();
3347:
3348: my $need_save;
3349: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3350: my $toolslink;
3351: if ($allowed) {
3352: $toolslink = '<table><tr><td>'
3353: .&Apache::loncommon::help_open_menu('Navigation Screen',
3354: 'Navigation_Screen',undef,'RAT')
3355: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3356: .'<td align="left"><ul id="LC_toolbar">'
3357: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3358: .'id="LC_content_toolbar_edittoplevel" '
3359: .'class="LC_toolbarItem" '
3360: .'title="'.&mt('Supplemental Content Editor').'">'
3361: .'</a></li></ul></td></tr></table><br />';
3362: }
3363: if ($shown) {
3364: if ($allowed) {
3365: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3366: .&Apache::loncommon::start_data_table(undef,'contentlist')
3367: .&Apache::loncommon::start_data_table_header_row()
3368: .'<th colspan="2">'.&mt('Move').'</th>'
3369: .'<th colspan="2">'.&mt('Actions').'</th>'
3370: .'<th>'.&mt('Document').'</th>';
3371: if ($folder !~ /^supplemental/) {
3372: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3373: }
3374: $to_show .= &Apache::loncommon::end_data_table_header_row();
3375: if ($folder !~ /^supplemental/) {
3376: $lists{'canhide'} = join(',',@allidx);
3377: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3378: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3379: 'randomorder','randompick');
3380: foreach my $item (@possfilters) {
3381: if (ref($filters{$item}) eq 'ARRAY') {
3382: if (@{$filters{$item}} > 0) {
3383: $lists{$item} = join(',',@{$filters{$item}});
3384: }
3385: }
3386: }
3387: if (@allidx > 0) {
3388: my $path;
3389: if ($env{'form.folderpath'}) {
3390: $path =
3391: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3392: }
3393: if (@allidx > 1) {
3394: $to_show .=
3395: &Apache::loncommon::continue_data_table_row().
3396: '<td colspan="2"> </td>'.
3397: '<td>'.
3398: &multiple_check_form('actions',\%lists,$canedit).
3399: '</td>'.
3400: '<td> </td>'.
3401: '<td> </td>'.
3402: '<td colspan="4">'.
3403: &multiple_check_form('settings',\%lists,$canedit).
3404: '</td>'.
3405: &Apache::loncommon::end_data_table_row();
3406: $need_save = 1;
3407: }
3408: }
3409: }
3410: $to_show .= $output.' '
3411: .&Apache::loncommon::end_data_table()
3412: .'<br style="line-height:2px;" />'
3413: .&Apache::loncommon::end_scrollbox();
3414: } else {
3415: $to_show .= $toolslink
3416: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3417: .$output.' '
3418: .&Apache::loncommon::end_data_table();
3419: }
3420: } else {
3421: if (!$allowed) {
3422: $to_show .= $toolslink;
3423: }
3424: my $noresmsg;
3425: if ($allowed && $hiddentop && !$supplementalflag) {
3426: $noresmsg = &mt('Main Content Hidden');
3427: } else {
3428: $noresmsg = &mt('Currently empty');
3429: }
3430: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3431: .'<div class="LC_info" id="contentlist">'
3432: .$noresmsg
3433: .'</div>'
3434: .&Apache::loncommon::end_scrollbox();
3435: }
3436: } else {
3437: if ($shown) {
3438: $to_show = '<div>'
3439: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3440: .$output
3441: .&Apache::loncommon::end_data_table()
3442: .'</div>';
3443: } else {
3444: $to_show = '<div class="LC_info" id="contentlist">'
3445: .&mt('Currently empty')
3446: .'</div>'
3447: }
3448: }
3449: my $tid = 1;
3450: if ($supplementalflag) {
3451: $tid = 2;
3452: }
3453: if ($allowed) {
3454: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3455: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3456: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3457: if ($canedit) {
3458: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3459: }
3460: } else {
3461: $r->print($to_show);
3462: }
3463: return;
3464: }
3465:
3466: sub multiple_check_form {
3467: my ($caller,$listsref,$canedit) = @_;
3468: return unless (ref($listsref) eq 'HASH');
3469: my $disabled;
3470: unless ($canedit) {
3471: $disabled = 'disabled="disabled"';
3472: }
3473: my $output =
3474: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3475: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3476: '<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>'.
3477: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3478: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3479: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3480: if ($caller eq 'settings') {
3481: $output .=
3482: '<table><tr>'.
3483: '<td class="LC_docs_entry_parameter">'.
3484: '<span class="LC_nobreak"><label>'.
3485: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3486: '</label></span></td>'.
3487: '<td class="LC_docs_entry_parameter">'.
3488: '<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="" />'.
3489: '</span></td>'.
3490: '</tr>'."\n".
3491: '<tr>'.
3492: '<td class="LC_docs_entry_parameter">'.
3493: '<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').
3494: '</label></span>'.
3495: '</td></tr></table>'."\n";
3496: } else {
3497: $output .=
3498: '<table><tr>'.
3499: '<td class="LC_docs_entry_parameter">'.
3500: '<span class="LC_nobreak LC_docs_remove">'.
3501: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3502: '</label></span></td>'.
3503: '<td class="LC_docs_entry_parameter">'.
3504: '<span class="LC_nobreak LC_docs_cut">'.
3505: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3506: '</label></span></td>'."\n".
3507: '<td class="LC_docs_entry_parameter">'.
3508: '<span class="LC_nobreak LC_docs_copy">'.
3509: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3510: '</label></span></td>'.
3511: '</tr></table>'."\n";
3512: }
3513: $output .=
3514: '</fieldset>'.
3515: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3516: if ($caller eq 'settings') {
3517: $output .=
3518: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3519: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3520: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3521: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3522: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3523: } elsif ($caller eq 'actions') {
3524: $output .=
3525: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3526: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3527: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3528: }
3529: $output .=
3530: '</form>'.
3531: '</div>';
3532: return $output;
3533: }
3534:
3535: sub process_file_upload {
3536: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3537: # upload a file, if present
3538: my $filesize = length($env{'form.uploaddoc'});
3539: if (!$filesize) {
3540: $$upload_output = '<div class="LC_error">'.
3541: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3542: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3543: $filesize).'<br />'.
3544: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3545: '</div>';
3546: return;
3547: }
3548: my $quotatype = 'unofficial';
3549: if ($crstype eq 'Community') {
3550: $quotatype = 'community';
3551: } elsif ($crstype eq 'Placement') {
3552: $quotatype = 'placement';
3553: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3554: $quotatype = 'official';
3555: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3556: $quotatype = 'textbook';
3557: }
3558: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3559: $filesize = int($filesize/1000); #expressed in kb
3560: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3561: $env{'form.uploaddoc.filename'},$filesize,
3562: 'upload',$quotatype);
3563: return if ($$upload_output);
3564: }
3565: my ($parseaction,$showupload,$nextphase,$mimetype);
3566: if ($env{'form.parserflag'}) {
3567: $parseaction = 'parse';
3568: }
3569: my $folder=$env{'form.folder'};
3570: if ($folder eq '') {
3571: $folder='default';
3572: }
3573: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3574: my $errtext='';
3575: my $fatal=0;
3576: my $container='sequence';
3577: if ($env{'form.folderpath'} =~ /:1$/) {
3578: $container='page';
3579: }
3580: ($errtext,$fatal)=
3581: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3582: if ($#LONCAPA::map::order<1) {
3583: $LONCAPA::map::order[0]=1;
3584: $LONCAPA::map::resources[1]='';
3585: }
3586: my $destination = 'docs/';
3587: if ($folder =~ /^supplemental/) {
3588: $destination = 'supplemental/';
3589: }
3590: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3591: $destination .= 'default/';
3592: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3593: $destination .= $2.'/';
3594: }
3595: if ($fatal) {
3596: $$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>';
3597: return;
3598: }
3599: # this is for a course, not a user, so set context to coursedoc.
3600: my $newidx=&LONCAPA::map::getresidx();
3601: $destination .= $newidx;
3602: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3603: $parseaction,$allfiles,
3604: $codebase,undef,undef,undef,undef,
3605: undef,undef,\$mimetype);
3606: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3607: my $stored = $1;
3608: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3609: $stored.'</span>').'</p>';
3610: } else {
3611: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3612:
3613: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3614: return;
3615: }
3616: my $ext='false';
3617: if ($url=~m{^http://}) { $ext='true'; }
3618: $url = &LONCAPA::map::qtunescape($url);
3619: my $comment=$env{'form.comment'};
3620: $comment = &LONCAPA::map::qtunescape($comment);
3621: if ($folder=~/^supplemental/) {
3622: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3623: $env{'user.domain'}.'___&&&___'.$comment;
3624: }
3625:
3626: $LONCAPA::map::resources[$newidx]=
3627: $comment.':'.$url.':'.$ext.':normal:res';
3628: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3629: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3630: $folder.'.'.$container,1);
3631: if ($fatal) {
3632: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3633: return;
3634: } else {
3635: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3636: $$upload_output = $showupload;
3637: my $total_embedded = scalar(keys(%{$allfiles}));
3638: if ($total_embedded > 0) {
3639: my $uploadphase = 'upload_embedded';
3640: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3641: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3642: my ($embedded,$num) =
3643: &Apache::loncommon::ask_for_embedded_content(
3644: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3645: if ($embedded) {
3646: if ($num) {
3647: $$upload_output .=
3648: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3649: $nextphase = $uploadphase;
3650: } else {
3651: $$upload_output .= $embedded;
3652: }
3653: } else {
3654: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3655: }
3656: } else {
3657: $$upload_output .= &mt('No embedded items identified').'<br />';
3658: }
3659: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3660: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3661: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3662: $nextphase = 'decompress_uploaded';
3663: my $position = scalar(@LONCAPA::map::order)-1;
3664: my $noextract = &return_to_editor();
3665: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3666: my %archiveitems = (
3667: folderpath => $env{'form.folderpath'},
3668: cmd => $nextphase,
3669: newidx => $newidx,
3670: position => $position,
3671: phase => $nextphase,
3672: comment => $comment,
3673: );
3674: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3675: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3676: $$upload_output = $showupload.
3677: &Apache::loncommon::decompress_form($mimetype,
3678: $archiveurl,'/adm/coursedocs',$noextract,
3679: \%archiveitems,\@current);
3680: }
3681: }
3682: }
3683: return $nextphase;
3684: }
3685:
3686: sub get_dir_list {
3687: my ($url,$coursenum,$coursedom,$newidx) = @_;
3688: my ($destination,$dir_root) = &embedded_destination();
3689: my ($dirlistref,$listerror) =
3690: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3691: my @dir_lines;
3692: my $dirptr=16384;
3693: if (ref($dirlistref) eq 'ARRAY') {
3694: foreach my $dir_line (sort
3695: {
3696: my ($afile)=split('&',$a,2);
3697: my ($bfile)=split('&',$b,2);
3698: return (lc($afile) cmp lc($bfile));
3699: } (@{$dirlistref})) {
3700: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3701: $filename =~ s/\s+$//;
3702: next if ($filename =~ /^\.\.?$/);
3703: my $isdir = 0;
3704: if ($dirptr&$testdir) {
3705: $isdir = 1;
3706: }
3707: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3708: }
3709: }
3710: return @dir_lines;
3711: }
3712:
3713: sub is_supplemental_title {
3714: my ($title) = @_;
3715: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3716: }
3717:
3718: # --------------------------------------------------------------- An entry line
3719:
3720: sub entryline {
3721: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3722: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3723: $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
3724: my ($foldertitle,$renametitle,$oldtitle);
3725: if (&is_supplemental_title($title)) {
3726: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3727: } else {
3728: $title=&HTML::Entities::encode($title,'"<>&\'');
3729: $renametitle=$title;
3730: $foldertitle=$title;
3731: }
3732:
3733: my ($disabled,$readonly,$js_lt);
3734: unless ($canedit) {
3735: $disabled = 'disabled="disabled"';
3736: $readonly = 1;
3737: }
3738:
3739: my $orderidx=$LONCAPA::map::order[$index];
3740:
3741: $renametitle=~s/\\/\\\\/g;
3742: $renametitle=~s/\"\;/\\\"/g;
3743: $renametitle=~s/"/%22/g;
3744: $renametitle=~s/ /%20/g;
3745: $oldtitle = $renametitle;
3746: $renametitle=~s/\'/\\\'/g;
3747: my $line=&Apache::loncommon::start_data_table_row();
3748: my ($form_start,$form_end,$form_common,$form_param);
3749: # Edit commands
3750: my ($esc_path, $path, $symb);
3751: if ($env{'form.folderpath'}) {
3752: $esc_path=&escape($env{'form.folderpath'});
3753: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3754: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3755: }
3756: my $isexternal;
3757: if ($residx) {
3758: my $currurl = $url;
3759: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3760: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3761: $isexternal = 1;
3762: }
3763: if (!$supplementalflag) {
3764: my $path = 'uploaded/'.
3765: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3766: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3767: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3768: $residx,
3769: &Apache::lonnet::declutter($currurl));
3770: }
3771: }
3772: my ($renamelink,%lt,$ishash);
3773: if (ref($filtersref) eq 'HASH') {
3774: $ishash = 1;
3775: }
3776:
3777: if ($allowed) {
3778: $form_start = '
3779: <form action="/adm/coursedocs" method="post">
3780: ';
3781: $form_common=(<<END);
3782: <input type="hidden" name="folderpath" value="$path" />
3783: <input type="hidden" name="symb" value="$symb" />
3784: END
3785: $form_param=(<<END);
3786: <input type="hidden" name="setparms" value="$orderidx" />
3787: <input type="hidden" name="changeparms" value="0" />
3788: END
3789: $form_end = '</form>';
3790:
3791: my $incindex=$index+1;
3792: my $selectbox='';
3793: if (($#LONCAPA::map::order>0) &&
3794: ((split(/\:/,
3795: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3796: ne '') &&
3797: ((split(/\:/,
3798: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
3799: ne '')) {
3800: $selectbox=
3801: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
3802: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
3803: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3804: if ($i==$incindex) {
3805: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
3806: } else {
3807: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3808: }
3809: }
3810: $selectbox.='</select>';
3811: }
3812: %lt=&Apache::lonlocal::texthash(
3813: 'up' => 'Move Up',
3814: 'dw' => 'Move Down',
3815: 'rm' => 'Remove',
3816: 'ct' => 'Cut',
3817: 'rn' => 'Rename',
3818: 'cp' => 'Copy',
3819: 'ex' => 'External Resource',
3820: 'et' => 'External Tool',
3821: 'ed' => 'Edit',
3822: 'pr' => 'Preview',
3823: 'sv' => 'Save',
3824: 'ul' => 'URL',
3825: 'ti' => 'Title',
3826: 'er' => 'Editing rights unavailable for your current role',
3827: );
3828: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3829: $env{'form.folderpath'},
3830: $currgroups);
3831: my ($copylink,$cutlink,$removelink);
3832: my $skip_confirm = 0;
3833: my $confirm_removal = 0;
3834: if ( $folder =~ /^supplemental/
3835: || ($url =~ m{( /smppg$
3836: |/syllabus$
3837: |/aboutme$
3838: |/navmaps$
3839: |/bulletinboard$
3840: |/exttools?$
3841: |\.html$)}x)
3842: || $isexternal) {
3843: $skip_confirm = 1;
3844: }
3845: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3846: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3847: $confirm_removal = 1;
3848: }
3849:
3850: if ($denied{'copy'}) {
3851: $copylink=(<<ENDCOPY)
3852: <span style="visibility: hidden;">$lt{'cp'}</span>
3853: ENDCOPY
3854: } else {
3855: my $formname = 'edit_copy_'.$orderidx;
3856: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3857: $copylink=(<<ENDCOPY);
3858: <form name="$formname" method="post" action="/adm/coursedocs">
3859: $form_common
3860: <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>
3861: $form_end
3862: ENDCOPY
3863: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3864: push(@{$filtersref->{'cancopy'}},$orderidx);
3865: }
3866: }
3867: if ($denied{'cut'}) {
3868: $cutlink=(<<ENDCUT);
3869: <span style="visibility: hidden;">$lt{'ct'}</span>
3870: ENDCUT
3871: } else {
3872: my $formname = 'edit_cut_'.$orderidx;
3873: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3874: $cutlink=(<<ENDCUT);
3875: <form name="$formname" method="post" action="/adm/coursedocs">
3876: $form_common
3877: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
3878: <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>
3879: $form_end
3880: ENDCUT
3881: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3882: push(@{$filtersref->{'cancut'}},$orderidx);
3883: }
3884: }
3885: if ($denied{'remove'}) {
3886: $removelink=(<<ENDREM);
3887: <span style="visibility: hidden;">$lt{'rm'}</a>
3888: ENDREM
3889: } else {
3890: my $formname = 'edit_remove_'.$orderidx;
3891: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
3892: $removelink=(<<ENDREM);
3893: <form name="$formname" method="post" action="/adm/coursedocs">
3894: $form_common
3895: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
3896: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
3897: <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>
3898: $form_end
3899: ENDREM
3900: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3901: push(@{$filtersref->{'canremove'}},$orderidx);
3902: }
3903: }
3904: $renamelink=(<<ENDREN);
3905: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
3906: ENDREN
3907: my ($uplink,$downlink);
3908: if ($canedit) {
3909: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3910: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3911: } else {
3912: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3913: $downlink = $uplink;
3914: }
3915: $line.=(<<END);
3916: <td>
3917: <div class="LC_docs_entry_move">
3918: <a href="$uplink">
3919: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
3920: </a>
3921: </div>
3922: <div class="LC_docs_entry_move">
3923: <a href="$downlink">
3924: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
3925: </a>
3926: </div>
3927: </td>
3928: <td>
3929: $form_start
3930: $form_param
3931: $form_common
3932: $selectbox
3933: $form_end
3934: </td>
3935: <td class="LC_docs_entry_commands LC_nobreak">
3936: $removelink
3937: $cutlink
3938: $copylink
3939: </td>
3940: END
3941: }
3942: # Figure out what kind of a resource this is
3943: my ($extension)=($url=~/\.(\w+)$/);
3944: my $uploaded=($url=~/^\/*uploaded\//);
3945: my $icon=&Apache::loncommon::icon($url);
3946: my $isfolder;
3947: my $ispage;
3948: my $containerarg;
3949: my $folderurl;
3950: if ($uploaded) {
3951: if (($extension eq 'sequence') || ($extension eq 'page')) {
3952: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
3953: $containerarg = $1;
3954: if ($extension eq 'sequence') {
3955: $icon=$iconpath.'navmap.folder.closed.gif';
3956: $isfolder=1;
3957: } else {
3958: $icon=$iconpath.'page.gif';
3959: $ispage=1;
3960: }
3961: $folderurl = &Apache::lonnet::declutter($url);
3962: if ($allowed) {
3963: $url='/adm/coursedocs?';
3964: } else {
3965: $url='/adm/supplemental?';
3966: }
3967: } else {
3968: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3969: }
3970: }
3971:
3972: my ($editlink,$extresform,$anchor,$hiddenres);
3973: my $orig_url = $url;
3974: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
3975: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3976: if (!$supplementalflag && $residx && $symb) {
3977: if ((!$isfolder) && (!$ispage)) {
3978: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3979: $url=&Apache::lonnet::clutter($url);
3980: if ($url=~/^\/*uploaded\//) {
3981: $url=~/\.(\w+)$/;
3982: my $embstyle=&Apache::loncommon::fileembstyle($1);
3983: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3984: $url='/adm/wrapper'.$url;
3985: } elsif ($embstyle eq 'ssi') {
3986: #do nothing with these
3987: } elsif ($url!~/\.(sequence|page)$/) {
3988: $url='/adm/coursedocs/showdoc'.$url;
3989: }
3990: } elsif ($url=~m|^/ext/|) {
3991: $url='/adm/wrapper'.$url;
3992: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3993: $url='/adm/wrapper'.$url;
3994: }
3995: if (&Apache::lonnet::symbverify($symb,$url)) {
3996: my $shownsymb = $symb;
3997: if ($isexternal) {
3998: if ($url =~ /^([^#]+)#([^#]+)$/) {
3999: $url = $1;
4000: $anchor = $2;
4001: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4002: $shownsymb = $1.&escape('#').$anchor;
4003: }
4004: }
4005: }
4006: unless ($env{'request.role.adv'}) {
4007: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4008: $url = '';
4009: }
4010: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4011: $url = '';
4012: $hiddenres = 1;
4013: }
4014: }
4015: if ($url ne '') {
4016: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4017: }
4018: } elsif (!$env{'request.role.adv'}) {
4019: my $checkencrypt;
4020: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4021: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4022: $checkencrypt = 1;
4023: } else {
4024: unless (ref($$navmapref)) {
4025: $$navmapref = Apache::lonnavmaps::navmap->new();
4026: }
4027: if (ref($$navmapref)) {
4028: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4029: $checkencrypt = 1;
4030: }
4031: }
4032: }
4033: if ($checkencrypt) {
4034: my $shownsymb = &Apache::lonenc::encrypted($symb);
4035: my $shownurl = &Apache::lonenc::encrypted($url);
4036: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4037: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4038: if ($env{'request.enc'} ne '') {
4039: delete($env{'request.enc'});
4040: }
4041: } else {
4042: $url='';
4043: }
4044: } else {
4045: $url='';
4046: }
4047: } else {
4048: $url='';
4049: }
4050: }
4051: } elsif ($supplementalflag) {
4052: if ($isexternal) {
4053: if ($url =~ /^([^#]+)#([^#]+)$/) {
4054: $url = $1;
4055: $anchor = $2;
4056: }
4057: }
4058: }
4059: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4060: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4061: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4062: my $foldername=&escape($foldertitle);
4063: my $folderpath=$env{'form.folderpath'};
4064: if ($folderpath) { $folderpath.='&' };
4065: if (!$allowed && $supplementalflag) {
4066: $folderpath.=$containerarg.'&'.$foldername;
4067: $url.='folderpath='.&escape($folderpath);
4068: } else {
4069: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4070: 'parameter_randompick'))[0];
4071: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4072: 'parameter_randomorder'))[0]=~/^yes$/i);
4073: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4074: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4075: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4076: 'parameter_encrypturl'))[0]=~/^yes$/i);
4077: unless ($hiddenmap) {
4078: unless (ref($$navmapref)) {
4079: $$navmapref = Apache::lonnavmaps::navmap->new();
4080: }
4081: if (ref($$navmapref)) {
4082: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4083: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4084: unless (@resources) {
4085: $hiddenmap = 1;
4086: unless ($env{'request.role.adv'}) {
4087: $url = '';
4088: $hiddenfolder = 1;
4089: }
4090: }
4091: }
4092: }
4093: }
4094: unless ($encryptmap) {
4095: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4096: $encryptmap = 1;
4097: }
4098: }
4099:
4100: # Append randompick number, hidden, and encrypted with ":" to foldername,
4101: # so it gets transferred between levels
4102: $folderpath.=$containerarg.'&'.$foldername.
4103: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4104: unless ($url eq '') {
4105: $url.='folderpath='.&escape($folderpath);
4106: }
4107: my $rpckchk;
4108: if ($rpicknum) {
4109: $rpckchk = ' checked="checked"';
4110: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4111: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4112: }
4113: }
4114: my $formname = 'edit_randompick_'.$orderidx;
4115: $rand_pick_text =
4116: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4117: $form_param."\n".
4118: $form_common."\n".
4119: '<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.'">';
4120: if ($rpicknum ne '') {
4121: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4122: }
4123: $rand_pick_text .= '</span></span>'.
4124: $form_end;
4125: my $ro_set;
4126: if ($randorder) {
4127: $ro_set = 'checked="checked"';
4128: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4129: push(@{$filtersref->{'randomorder'}},$orderidx);
4130: }
4131: }
4132: $formname = 'edit_rorder_'.$orderidx;
4133: $rand_order_text =
4134: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4135: $form_param."\n".
4136: $form_common."\n".
4137: '<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>'.
4138: $form_end;
4139: }
4140: } elsif ($supplementalflag && !$allowed) {
4141: my $isexttool;
4142: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4143: $url='/adm/wrapper'.$url;
4144: $isexttool = 1;
4145: }
4146: $url .= ($url =~ /\?/) ? '&':'?';
4147: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4148: if ($title) {
4149: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4150: }
4151: if ((($isexternal) || ($isexttool)) && $orderidx) {
4152: $url .= '&idx='.$orderidx;
4153: }
4154: if ($anchor ne '') {
4155: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4156: }
4157: }
4158: my ($tdalign,$tdwidth);
4159: if ($allowed) {
4160: my $fileloc =
4161: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4162: if ($isexternal) {
4163: ($editlink,$extresform) =
4164: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4165: undef,undef,undef,undef,undef,undef,
4166: undef,$disabled);
4167: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4168: ($editlink,$extresform) =
4169: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4170: undef,undef,undef,'tool',$coursedom,
4171: $coursenum,$ltitoolsref,$disabled);
4172: } elsif (!$isfolder && !$ispage) {
4173: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4174: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4175: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4176: my $suppanchor;
4177: if ($supplementalflag) {
4178: $suppanchor = $anchor;
4179: }
4180: my $jscall =
4181: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4182: $switchserver,
4183: $forceedit,
4184: undef,$symb,
4185: &escape($env{'form.folderpath'}),
4186: $renametitle,'','',1,$suppanchor);
4187: if ($jscall) {
4188: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4189: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4190: }
4191: }
4192: }
4193: $tdalign = ' align="right" valign="top"';
4194: $tdwidth = ' width="80%"';
4195: }
4196: my $reinit;
4197: if ($crstype eq 'Community') {
4198: $reinit = &mt('(re-initialize community to access)');
4199: } else {
4200: $reinit = &mt('(re-initialize course to access)');
4201: }
4202: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4203: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4204: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4205: } elsif ($url) {
4206: if ($anchor ne '') {
4207: if ($supplementalflag) {
4208: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4209: } else {
4210: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4211: }
4212: }
4213: $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4214: (($anchor ne '')?$anchor:'')),
4215: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4216: } else {
4217: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4218: }
4219: $line.='</span></td><td'.$tdwidth.'>';
4220: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4221: $line.='<a href="'.$url.'">'.$title.'</a>';
4222: } elsif ($url) {
4223: $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4224: (($anchor ne '')?$anchor:'')),
4225: $title,600,500);
4226: } elsif (($hiddenfolder) || ($hiddenres)) {
4227: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
4228: } else {
4229: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4230: }
4231: $line.="$extresform</td>";
4232: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4233: $rand_order_text = ' ' if ($rand_order_text eq '');
4234: if (($allowed) && ($folder!~/^supplemental/)) {
4235: my %lt=&Apache::lonlocal::texthash(
4236: 'hd' => 'Hidden',
4237: 'ec' => 'URL hidden');
4238: my ($enctext,$hidtext);
4239: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4240: $enctext = ' checked="checked"';
4241: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4242: push(@{$filtersref->{'encrypturl'}},$orderidx);
4243: }
4244: }
4245: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4246: $hidtext = ' checked="checked"';
4247: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4248: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4249: }
4250: }
4251: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4252: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
4253: $line.=(<<ENDPARMS);
4254: <td class="LC_docs_entry_parameter">
4255: <form action="/adm/coursedocs" method="post" name="$formhidden">
4256: $form_param
4257: $form_common
4258: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4259: $form_end
4260: <br />
4261: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4262: $form_param
4263: $form_common
4264: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4265: $form_end
4266: </td>
4267: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4268: $rand_order_text</td>
4269: ENDPARMS
4270: }
4271: $line.=&Apache::loncommon::end_data_table_row();
4272: return $line;
4273: }
4274:
4275: sub action_restrictions {
4276: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4277: my %denied = (
4278: cut => 0,
4279: copy => 0,
4280: remove => 0,
4281: );
4282: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4283: # no copy for published maps
4284: $denied{'copy'} = 1;
4285: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4286: unless ($1 eq 'simpleproblem') {
4287: $denied{'copy'} = 1;
4288: }
4289: $denied{'cut'} = 1;
4290: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4291: if ($folderpath =~ /^default&[^\&]+$/) {
4292: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4293: $denied{'remove'} = 1;
4294: }
4295: $denied{'cut'} = 1;
4296: $denied{'copy'} = 1;
4297: }
4298: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4299: my $group = $1;
4300: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4301: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4302: $denied{'remove'} = 1;
4303: }
4304: }
4305: $denied{'cut'} = 1;
4306: $denied{'copy'} = 1;
4307: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4308: my $group = $1;
4309: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4310: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4311: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4312: if (keys(%groupsettings) > 0) {
4313: $denied{'remove'} = 1;
4314: }
4315: $denied{'cut'} = 1;
4316: $denied{'copy'} = 1;
4317: }
4318: }
4319: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4320: my $group = $1;
4321: if ($url =~ /group_boards_\Q$group\E/) {
4322: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4323: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4324: if (keys(%groupsettings) > 0) {
4325: if (ref($groupsettings{'functions'}) eq 'HASH') {
4326: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4327: $denied{'remove'} = 1;
4328: }
4329: }
4330: }
4331: $denied{'cut'} = 1;
4332: $denied{'copy'} = 1;
4333: }
4334: }
4335: }
4336: return %denied;
4337: }
4338:
4339: sub new_timebased_suffix {
4340: my ($dom,$num,$type,$area,$container) = @_;
4341: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4342: if ($type eq 'paste') {
4343: $prefix = $type;
4344: $namespace = 'courseeditor';
4345: $idtype = 'addcode';
4346: } elsif ($type eq 'map') {
4347: $prefix = 'docs';
4348: if ($area eq 'supplemental') {
4349: $prefix = 'supp';
4350: }
4351: $prefix .= $container;
4352: $namespace = 'uploadedmaps';
4353: } else {
4354: $prefix = $type;
4355: $namespace = 'templated';
4356: }
4357: my ($suffix,$freedlock,$error) =
4358: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4359: if (!$suffix) {
4360: if ($type eq 'paste') {
4361: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4362: } elsif ($type eq 'map') {
4363: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4364: } elsif ($type eq 'smppg') {
4365: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4366: } else {
4367: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4368: }
4369: if ($error) {
4370: $errtext .= '<br />'.$error;
4371: }
4372: }
4373: if ($freedlock ne 'ok') {
4374: $locknotfreed =
4375: '<div class="LC_error">'.
4376: &mt('There was a problem removing a lockfile.').' ';
4377: if ($type eq 'paste') {
4378: if ($freedlock eq 'nolock') {
4379: $locknotfreed =
4380: '<div class="LC_error">'.
4381: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4382:
4383: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4384: } else {
4385: $locknotfreed .=
4386: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4387: }
4388: } elsif ($type eq 'map') {
4389: $locknotfreed .=
4390: &mt('This will prevent creation of additional folders or composite pages in this course.');
4391: } elsif ($type eq 'smppg') {
4392: $locknotfreed .=
4393: &mt('This will prevent creation of additional simple pages in this course.');
4394: } else {
4395: $locknotfreed .=
4396: &mt('This will prevent creation of additional discussion boards in this course.');
4397: }
4398: unless ($type eq 'paste') {
4399: $locknotfreed .=
4400: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4401: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4402: }
4403: $locknotfreed .= '</div>';
4404: }
4405: return ($suffix,$errtext,$locknotfreed);
4406: }
4407:
4408: =pod
4409:
4410: =item tiehash()
4411:
4412: tie the hash
4413:
4414: =cut
4415:
4416: sub tiehash {
4417: my ($mode)=@_;
4418: $hashtied=0;
4419: if ($env{'request.course.fn'}) {
4420: if ($mode eq 'write') {
4421: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4422: &GDBM_WRCREAT(),0640)) {
4423: $hashtied=2;
4424: }
4425: } else {
4426: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4427: &GDBM_READER(),0640)) {
4428: $hashtied=1;
4429: }
4430: }
4431: }
4432: }
4433:
4434: sub untiehash {
4435: if ($hashtied) { untie %hash; }
4436: $hashtied=0;
4437: return OK;
4438: }
4439:
4440:
4441:
4442:
4443: sub checkonthis {
4444: my ($r,$url,$level,$title)=@_;
4445: $url=&unescape($url);
4446: $alreadyseen{$url}=1;
4447: $r->rflush();
4448: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4449: $r->print("\n<br />");
4450: if ($level==0) {
4451: $r->print("<br />");
4452: }
4453: for (my $i=0;$i<=$level*5;$i++) {
4454: $r->print(' ');
4455: }
4456: $r->print('<a href="'.$url.'" target="cat">'.
4457: ($title?$title:$url).'</a> ');
4458: if ($url=~/^\/res\//) {
4459: my $result=&Apache::lonnet::repcopy(
4460: &Apache::lonnet::filelocation('',$url));
4461: if ($result eq 'ok') {
4462: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4463: $r->rflush();
4464: &Apache::lonnet::countacc($url);
4465: $url=~/\.(\w+)$/;
4466: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4467: $r->print('<br />');
4468: $r->rflush();
4469: for (my $i=0;$i<=$level*5;$i++) {
4470: $r->print(' ');
4471: }
4472: $r->print('- '.&mt('Rendering:').' ');
4473: my ($errorcount,$warningcount)=split(/:/,
4474: &Apache::lonnet::ssi_body($url,
4475: ('grade_target'=>'web',
4476: 'return_only_error_and_warning_counts' => 1)));
4477: if (($errorcount) ||
4478: ($warningcount)) {
4479: if ($errorcount) {
4480: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4481: &mt('[quant,_1,error]',$errorcount).'</span>');
4482: }
4483: if ($warningcount) {
4484: $r->print('<span class="LC_warning">'.
4485: &mt('[quant,_1,warning]',$warningcount).'</span>');
4486: }
4487: } else {
4488: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4489: }
4490: $r->rflush();
4491: }
4492: my $dependencies=
4493: &Apache::lonnet::metadata($url,'dependencies');
4494: foreach my $dep (split(/\,/,$dependencies)) {
4495: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4496: &checkonthis($r,$dep,$level+1);
4497: }
4498: }
4499: } elsif ($result eq 'unavailable') {
4500: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4501: } elsif ($result eq 'not_found') {
4502: unless ($url=~/\$/) {
4503: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4504: } else {
4505: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4506: }
4507: } else {
4508: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4509: }
4510: }
4511: }
4512: }
4513:
4514:
4515:
4516: =pod
4517:
4518: =item list_symbs()
4519:
4520: List Content Identifiers
4521:
4522: =cut
4523:
4524: sub list_symbs {
4525: my ($r) = @_;
4526:
4527: my $crstype = &Apache::loncommon::course_type();
4528: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4529: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4530: $r->print(&startContentScreen('tools'));
4531: my $navmap = Apache::lonnavmaps::navmap->new();
4532: if (!defined($navmap)) {
4533: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4534: '<div class="LC_error">'.
4535: &mt('Unable to retrieve information about course contents').
4536: '</div>');
4537: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4538: } else {
4539: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4540: &Apache::loncommon::start_data_table().
4541: &Apache::loncommon::start_data_table_header_row().
4542: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4543: &Apache::loncommon::end_data_table_header_row()."\n");
4544: my $count;
4545: foreach my $res ($navmap->retrieveResources()) {
4546: $r->print(&Apache::loncommon::start_data_table_row().
4547: '<td>'.$res->compTitle().'</td>'.
4548: '<td>'.$res->symb().'</td>'.
4549: &Apache::loncommon::end_data_table_row());
4550: $count ++;
4551: }
4552: if (!$count) {
4553: $r->print(&Apache::loncommon::start_data_table_row().
4554: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4555: &Apache::loncommon::end_data_table_row());
4556: }
4557: $r->print(&Apache::loncommon::end_data_table());
4558: }
4559: $r->print(&endContentScreen());
4560: }
4561:
4562:
4563: sub verifycontent {
4564: my ($r) = @_;
4565: my $crstype = &Apache::loncommon::course_type();
4566: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4567: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4568: $r->print(&startContentScreen('tools'));
4569: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4570: $hashtied=0;
4571: undef %alreadyseen;
4572: %alreadyseen=();
4573: &tiehash();
4574:
4575: foreach my $key (keys(%hash)) {
4576: if ($hash{$key}=~/\.(page|sequence)$/) {
4577: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4578: $r->print('<hr /><span class="LC_error">'.
4579: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
4580: &unescape($hash{$key}).'</span><br />'.
4581: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
4582: }
4583: }
4584: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4585: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4586: }
4587: }
4588: &untiehash();
4589: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
4590: $r->print(&endContentScreen());
4591: }
4592:
4593:
4594: sub devalidateversioncache {
4595: my $src=shift;
4596: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4597: &Apache::lonnet::clutter($src));
4598: }
4599:
4600: sub checkversions {
4601: my ($r,$canedit) = @_;
4602: my $crstype = &Apache::loncommon::course_type();
4603: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4604: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
4605: $r->print(&startContentScreen('tools'));
4606:
4607: my $header='';
4608: my $startsel='';
4609: my $monthsel='';
4610: my $weeksel='';
4611: my $daysel='';
4612: my $allsel='';
4613: my %changes=();
4614: my $starttime=0;
4615: my $haschanged=0;
4616: my %setversions=&Apache::lonnet::dump('resourceversions',
4617: $env{'course.'.$env{'request.course.id'}.'.domain'},
4618: $env{'course.'.$env{'request.course.id'}.'.num'});
4619:
4620: $hashtied=0;
4621: &tiehash();
4622: if ($canedit) {
4623: my %newsetversions=();
4624: if ($env{'form.setmostrecent'}) {
4625: $haschanged=1;
4626: foreach my $key (keys(%hash)) {
4627: if ($key=~/^ids\_(\/res\/.+)$/) {
4628: $newsetversions{$1}='mostrecent';
4629: &devalidateversioncache($1);
4630: }
4631: }
4632: } elsif ($env{'form.setcurrent'}) {
4633: $haschanged=1;
4634: foreach my $key (keys(%hash)) {
4635: if ($key=~/^ids\_(\/res\/.+)$/) {
4636: my $getvers=&Apache::lonnet::getversion($1);
4637: if ($getvers>0) {
4638: $newsetversions{$1}=$getvers;
4639: &devalidateversioncache($1);
4640: }
4641: }
4642: }
4643: } elsif ($env{'form.setversions'}) {
4644: $haschanged=1;
4645: foreach my $key (keys(%env)) {
4646: if ($key=~/^form\.set_version_(.+)$/) {
4647: my $src=$1;
4648: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4649: $newsetversions{$src}=$env{$key};
4650: &devalidateversioncache($src);
4651: }
4652: }
4653: }
4654: }
4655: if ($haschanged) {
4656: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4657: $env{'course.'.$env{'request.course.id'}.'.domain'},
4658: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4659: $r->print(&Apache::loncommon::confirmwrapper(
4660: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4661: } else {
4662: $r->print(&Apache::loncommon::confirmwrapper(
4663: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4664: }
4665: &mark_hash_old();
4666: }
4667: &changewarning($r,'');
4668: }
4669: if ($env{'form.timerange'} eq 'all') {
4670: # show all documents
4671: $header=&mt('All content in '.$crstype);
4672: $allsel=' selected="selected"';
4673: foreach my $key (keys(%hash)) {
4674: if ($key=~/^ids\_(\/res\/.+)$/) {
4675: my $src=$1;
4676: $changes{$src}=1;
4677: }
4678: }
4679: } else {
4680: # show documents which changed
4681: %changes=&Apache::lonnet::dump
4682: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4683: $env{'course.'.$env{'request.course.id'}.'.num'});
4684: my $firstkey=(keys(%changes))[0];
4685: unless ($firstkey=~/^error\:/) {
4686: unless ($env{'form.timerange'}) {
4687: $env{'form.timerange'}=604800;
4688: }
4689: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4690: .&mt('seconds');
4691: if ($env{'form.timerange'}==-1) {
4692: $seltext='since start of course';
4693: $startsel=' selected="selected"';
4694: $env{'form.timerange'}=time;
4695: }
4696: $starttime=time-$env{'form.timerange'};
4697: if ($env{'form.timerange'}==2592000) {
4698: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4699: $monthsel=' selected="selected"';
4700: } elsif ($env{'form.timerange'}==604800) {
4701: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4702: $weeksel=' selected="selected"';
4703: } elsif ($env{'form.timerange'}==86400) {
4704: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4705: $daysel=' selected="selected"';
4706: }
4707: $header=&mt('Content changed').' '.$seltext;
4708: } else {
4709: $header=&mt('No content modifications yet.');
4710: }
4711: }
4712: %setversions=&Apache::lonnet::dump('resourceversions',
4713: $env{'course.'.$env{'request.course.id'}.'.domain'},
4714: $env{'course.'.$env{'request.course.id'}.'.num'});
4715: my %lt=&Apache::lonlocal::texthash
4716: ('st' => 'Version changes since start of '.$crstype,
4717: 'lm' => 'Version changes since last Month',
4718: 'lw' => 'Version changes since last Week',
4719: 'sy' => 'Version changes since Yesterday',
4720: 'al' => 'All Resources (possibly large output)',
4721: 'cd' => 'Change display',
4722: 'sd' => 'Display',
4723: 'fi' => 'File',
4724: 'md' => 'Modification Date',
4725: 'mr' => 'Most recently published Version',
4726: 've' => 'Version used in '.$crstype,
4727: 'vu' => 'Set Version to be used in '.$crstype,
4728: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
4729: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4730: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
4731: 'di' => 'Differences',
4732: 'save' => 'Save changes',
4733: 'vers' => 'Version choice(s) for specific resources',
4734: 'act' => 'Actions');
4735: my ($disabled,$readonly);
4736: unless ($canedit) {
4737: $disabled = 'disabled="disabled"';
4738: $readonly = 1;
4739: }
4740: $r->print(<<ENDHEADERS);
4741: <h4 class="LC_info">$header</h4>
4742: <form action="/adm/coursedocs" method="post">
4743: <input type="hidden" name="versions" value="1" />
4744: <div class="LC_left_float">
4745: <fieldset>
4746: <legend>$lt{'cd'}</legend>
4747: <select name="timerange">
4748: <option value='all'$allsel>$lt{'al'}</option>
4749: <option value="-1"$startsel>$lt{'st'}</option>
4750: <option value="2592000"$monthsel>$lt{'lm'}</option>
4751: <option value="604800"$weeksel>$lt{'lw'}</option>
4752: <option value="86400"$daysel>$lt{'sy'}</option>
4753: </select>
4754: <input type="submit" name="display" value="$lt{'sd'}" />
4755: </fieldset>
4756: </div>
4757: <div class="LC_left_float">
4758: <fieldset>
4759: <legend>$lt{'act'}</legend>
4760: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4761: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
4762: </fieldset>
4763: </div>
4764: <br clear="all" />
4765: <hr />
4766: <h4>$lt{'vers'}</h4>
4767: ENDHEADERS
4768: #number of columns for version history
4769: my %changedbytime;
4770: foreach my $key (keys(%changes)) {
4771: #excludes not versionable problems from resource version history:
4772: next if ($key =~ /^\/res\/lib\/templates/);
4773: my $chg;
4774: if ($env{'form.timerange'} eq 'all') {
4775: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4776: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4777: } else {
4778: $chg = $changes{$key};
4779: next if ($chg < $starttime);
4780: }
4781: push(@{$changedbytime{$chg}},$key);
4782: }
4783: if (keys(%changedbytime) == 0) {
4784: &untiehash();
4785: $r->print(&mt('No content changes in imported content in specified time frame').
4786: &endContentScreen());
4787: return;
4788: }
4789: $r->print(
4790: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
4791: &Apache::loncommon::start_data_table().
4792: &Apache::loncommon::start_data_table_header_row().
4793: '<th>'.&mt('Resources').'</th>'.
4794: "<th>$lt{'mr'}</th>".
4795: "<th>$lt{'ve'}</th>".
4796: "<th>$lt{'vu'}</th>".
4797: '<th>'.&mt('History').'</th>'.
4798: &Apache::loncommon::end_data_table_header_row()
4799: );
4800: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4801: foreach my $key (sort(@{$changedbytime{$chg}})) {
4802: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4803: my $currentversion=&Apache::lonnet::getversion($key);
4804: if ($currentversion<0) {
4805: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4806: }
4807: my $linkurl=&Apache::lonnet::clutter($key);
4808: $r->print(
4809: &Apache::loncommon::start_data_table_row().
4810: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4811: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4812: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4813: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4814: '<td align="right">'
4815: );
4816: # Used in course
4817: my $usedversion=$hash{'version_'.$linkurl};
4818: if (($usedversion) && ($usedversion ne 'mostrecent')) {
4819: if ($usedversion != $currentversion) {
4820: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
4821: } else {
4822: $r->print($usedversion);
4823: }
4824: } else {
4825: $r->print($currentversion);
4826: }
4827: $r->print('</td><td title="'.$lt{'vu'}.'">');
4828: # Set version
4829: $r->print(&Apache::loncommon::select_form(
4830: $setversions{$linkurl},
4831: 'set_version_'.$linkurl,
4832: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4833: '' => '',
4834: 'mostrecent' => &mt('most recent'),
4835: map {$_,$_} (1..$currentversion)},'',$readonly));
4836: my $lastold=1;
4837: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4838: my $url=$root.'.'.$prevvers.'.'.$extension;
4839: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4840: $lastold=$prevvers;
4841: }
4842: }
4843: $r->print('</td>');
4844: # List all available versions
4845: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4846: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4847: my $url=$root.'.'.$prevvers.'.'.$extension;
4848: $r->print(
4849: '<span class="LC_nobreak">'
4850: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4851: .&mt('Version [_1]',$prevvers).'</a>'
4852: .' ('.&Apache::lonlocal::locallocaltime(
4853: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4854: .')');
4855: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4856: $r->print(
4857: ' <a href="/adm/diff?filename='.
4858: &Apache::lonnet::clutter($root.'.'.$extension).
4859: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4860: '" target="diffs">'.&mt('Diffs').'</a>');
4861: }
4862: $r->print('</span><br />');
4863: }
4864: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
4865: }
4866: }
4867: $r->print(
4868: &Apache::loncommon::end_data_table().
4869: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
4870: '</form>'
4871: );
4872:
4873: &untiehash();
4874: $r->print(&endContentScreen());
4875: return;
4876: }
4877:
4878: sub mark_hash_old {
4879: my $retie_hash=0;
4880: if ($hashtied) {
4881: $retie_hash=1;
4882: &untiehash();
4883: }
4884: &tiehash('write');
4885: $hash{'old'}=1;
4886: &untiehash();
4887: if ($retie_hash) { &tiehash(); }
4888: }
4889:
4890: sub is_hash_old {
4891: my $untie_hash=0;
4892: if (!$hashtied) {
4893: $untie_hash=1;
4894: &tiehash();
4895: }
4896: my $return=$hash{'old'};
4897: if ($untie_hash) { &untiehash(); }
4898: return $return;
4899: }
4900:
4901: sub changewarning {
4902: my ($r,$postexec,$message,$url)=@_;
4903: if (!&is_hash_old()) { return; }
4904: my $pathvar='folderpath';
4905: my $path=&escape($env{'form.folderpath'});
4906: if (!defined($url)) {
4907: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4908: }
4909: my $course_type = &Apache::loncommon::course_type();
4910: if (!defined($message)) {
4911: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4912: }
4913: $r->print("\n\n".
4914: '<script type="text/javascript">'."\n".
4915: '// <![CDATA['."\n".
4916: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4917: '// ]]>'."\n".
4918: '</script>'."\n".
4919: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
4920: '<input type="hidden" name="orgurl" value="'.$url.
4921: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
4922: &mt($message,' <input type="hidden" name="'.
4923: $env{'request.role'}.'" value="1" /><input type="button" value="'.
4924: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
4925: $help{'Caching'}.'</p></form>'."\n\n");
4926: }
4927:
4928:
4929: sub init_breadcrumbs {
4930: my ($form,$text,$help)=@_;
4931: &Apache::lonhtmlcommon::clear_breadcrumbs();
4932: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
4933: text=>&Apache::loncommon::course_type().' Editor',
4934: faq=>273,
4935: bug=>'Instructor Interface',
4936: help => $help});
4937: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4938: text=>$text,
4939: faq=>273,
4940: bug=>'Instructor Interface'});
4941: }
4942:
4943: # subroutine to list form elements
4944: sub create_list_elements {
4945: my @formarr = @_;
4946: my $list = '';
4947: foreach my $button (@formarr){
4948: foreach my $picture (keys(%{$button})) {
4949: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
4950: }
4951: }
4952: return $list;
4953: }
4954:
4955: # subroutine to create ul from list elements
4956: sub create_form_ul {
4957: my $list = shift;
4958: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4959: return $ul;
4960: }
4961:
4962: #
4963: # Start tabs
4964: #
4965:
4966: sub startContentScreen {
4967: my ($mode) = @_;
4968: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
4969: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
4970: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4971: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4972: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4973: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4974: } else {
4975: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
4976: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4977: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4978: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4979: }
4980: $output .= "\n".'</ul>'."\n";
4981: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4982: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4983: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4984: return $output;
4985: }
4986:
4987: #
4988: # End tabs
4989: #
4990:
4991: sub endContentScreen {
4992: return '</div></div></div>';
4993: }
4994:
4995: sub supplemental_base {
4996: return 'supplemental&'.&escape(&mt('Supplemental Content'));
4997: }
4998:
4999: sub handler {
5000: my $r = shift;
5001: &Apache::loncommon::content_type($r,'text/html');
5002: $r->send_http_header;
5003: return OK if $r->header_only;
5004:
5005: # get course data
5006: my $crstype = &Apache::loncommon::course_type();
5007: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5008: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5009:
5010: # get docroot
5011: my $londocroot = $r->dir_config('lonDocRoot');
5012:
5013: # graphics settings
5014: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5015:
5016: #
5017: # --------------------------------------------- Initialize help topics for this
5018: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5019: 'Adding_External_Resource','Navigate_Content',
5020: 'Adding_Folders','Docs_Overview', 'Load_Map',
5021: 'Supplemental','Score_Upload_Form','Adding_Pages',
5022: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
5023: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5024: 'Dropbox','Simple_Problem') {
5025: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5026: }
5027: # Composite help files
5028: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5029: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5030: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5031: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5032: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5033: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5034: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5035: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5036: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5037: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5038:
5039: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5040: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5041: unless ($r->uri eq '/adm/supplemental') {
5042: # does this user have privileges to modify content.
5043: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5044: $allowed = 1;
5045: $canedit = 1;
5046: $canview = 1;
5047: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5048: $allowed = 1;
5049: $canview = 1;
5050: }
5051: }
5052: unless ($canedit) {
5053: $disabled = ' disabled="disabled"';
5054: }
5055: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5056: if ($allowed && $env{'form.verify'}) {
5057: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5058: &verifycontent($r);
5059: } elsif ($allowed && $env{'form.listsymbs'}) {
5060: &init_breadcrumbs('listsymbs','List Content IDs');
5061: &list_symbs($r);
5062: } elsif ($allowed && $env{'form.docslog'}) {
5063: &init_breadcrumbs('docslog','Show Log');
5064: my $folder = $env{'form.folder'};
5065: if ($folder eq '') {
5066: $folder='default';
5067: }
5068: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5069: } elsif ($allowed && $env{'form.versions'}) {
5070: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5071: &checkversions($r,$canedit);
5072: } elsif ($canedit && $env{'form.dumpcourse'}) {
5073: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5074: &dumpcourse($r);
5075: } elsif ($canedit && $env{'form.exportcourse'}) {
5076: &init_breadcrumbs('exportcourse','IMS Export');
5077: &Apache::imsexport::exportcourse($r);
5078: } else {
5079: if ($canedit && $env{'form.authorrole'}) {
5080: $noendpage = 1;
5081: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5082: if ($redirect) {
5083: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5084: my $container = 'sequence';
5085: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5086: $is_random_order,$container) =
5087: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5088: my (@folders)=split('&',$env{'form.folderpath'});
5089: $env{'form.foldername'}=&unescape(pop(@folders));
5090: my $folder=pop(@folders);
5091: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5092: $folder.'.'.$container);
5093: my $warning;
5094: if ($fatal) {
5095: if ($container eq 'page') {
5096: $warning = &mt('An error occurred retrieving the contents of the current page.');
5097: } else {
5098: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5099: }
5100: } else {
5101: my $url = $redirect;
5102: my $srcfile = $londocroot.$url;
5103: $url =~ s{^/priv/}{/res/};
5104: my $targetfile = $londocroot.$url;
5105: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5106: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5107: $env{'form.folder'} = $folder;
5108: &snapshotbefore();
5109: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5110: my $ext = 'false';
5111: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5112: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5113: ':'.$ext.':normal:res';
5114: push(@LONCAPA::map::order,$newidx);
5115: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5116: 'string_yesno');
5117: &remember_parms($newidx,'hiddenresource','set','yes');
5118: ($errtext,$fatal) =
5119: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5120: &log_differences($plain);
5121: &mark_hash_old();
5122: $r->internal_redirect($redirect);
5123: return OK;
5124: }
5125: }
5126: }
5127: }
5128: #
5129: # Done catching special calls
5130: # The whole rest is for course and supplemental documents and utilities menu
5131: # Get the parameters that may be needed
5132: #
5133: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5134: ['folderpath',
5135: 'forcesupplement','forcestandard',
5136: 'tools','symb','command','supppath']);
5137:
5138: # standard=1: this is a "new-style" course with an uploaded map as top level
5139: # standard=2: this is a "old-style" course, and there is nothing we can do
5140:
5141: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5142:
5143: # Decide whether this should display supplemental or main content or utilities
5144: # supplementalflag=1: show supplemental documents
5145: # supplementalflag=0: show standard documents
5146: # toolsflag=1: show utilities
5147:
5148: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5149: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5150: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5151: $supplementalflag=0;
5152: }
5153: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5154: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5155: unless ($allowed) { $supplementalflag=1; }
5156: unless ($standard) { $supplementalflag=1; }
5157: my $toolsflag=0;
5158: if ($env{'form.tools'}) { $toolsflag=1; }
5159:
5160: my $script='';
5161: my $showdoc=0;
5162: my $addentries = {};
5163: my $container;
5164: my $containertag;
5165: my $pathitem;
5166: my %ltitools;
5167: my $hiddentop;
5168: my $navmap;
5169: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5170:
5171: # Do we directly jump somewhere?
5172: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5173: if ($env{'form.symb'} ne '') {
5174: $env{'form.folderpath'}=
5175: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5176: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5177: $env{'form.command'}.'_'.$env{'form.symb'}});
5178: } elsif ($env{'form.supppath'} ne '') {
5179: $env{'form.folderpath'}=$env{'form.supppath'};
5180: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5181: $env{'form.command'}.'_'.$env{'form.supppath'}});
5182: }
5183: } elsif ($env{'form.command'} eq 'editdocs') {
5184: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5185: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5186: } elsif ($env{'form.command'} eq 'editsupp') {
5187: $env{'form.folderpath'} = &supplemental_base();
5188: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5189: } elsif ($env{'form.command'} eq 'contents') {
5190: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5191: } elsif ($env{'form.command'} eq 'home') {
5192: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5193: }
5194:
5195:
5196: # Where do we store these for when we come back?
5197: my $stored_folderpath='docs_folderpath';
5198: if ($supplementalflag) {
5199: $stored_folderpath='docs_sup_folderpath';
5200: }
5201:
5202: # No folderpath, and in edit mode, see if we have something stored
5203: if ((!$env{'form.folderpath'}) && $allowed) {
5204: &Apache::loncommon::restore_course_settings($stored_folderpath,
5205: {'folderpath' => 'scalar'});
5206:
5207: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5208: if ($supplementalflag) {
5209: undef($env{'form.folderpath'}) if ($1 eq 'default');
5210: } else {
5211: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5212: }
5213: } else {
5214: undef($env{'form.folderpath'});
5215: }
5216: }
5217:
5218: # If we are not allowed to make changes, all we can see are supplemental docs
5219: if (!$allowed) {
5220: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5221: $env{'form.folderpath'} = &supplemental_base();
5222: }
5223: }
5224: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5225: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5226: $env{'form.folderpath'} = &supplemental_base()
5227: .'&'.
5228: $env{'form.folderpath'};
5229: }
5230: # If allowed and user's role is not advanced check folderpath is not hidden
5231: if (($allowed) && (!$env{'request.role.adv'}) &&
5232: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5233: my $folderurl;
5234: my @pathitems = split(/\&/,$env{'form.folderpath'});
5235: my $folder = $pathitems[-2];
5236: if ($folder eq '') {
5237: undef($env{'form.folderpath'});
5238: } else {
5239: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5240: if ((split(/\:/,$pathitems[-1]))[4]) {
5241: $folderurl .= '.page';
5242: } else {
5243: $folderurl .= '.sequence';
5244: }
5245: unless (ref($navmap)) {
5246: $navmap = Apache::lonnavmaps::navmap->new();
5247: }
5248: if (ref($navmap)) {
5249: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5250: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5251: unless (@resources) {
5252: undef($env{'form.folderpath'});
5253: }
5254: }
5255: }
5256: }
5257: }
5258:
5259:
5260: # If after all of this, we still don't have any paths, make them
5261: unless ($env{'form.folderpath'}) {
5262: if ($supplementalflag) {
5263: $env{'form.folderpath'}=&supplemental_base();
5264: } elsif ($allowed) {
5265: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5266: }
5267: }
5268:
5269: # Store this
5270: unless ($toolsflag) {
5271: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5272: &Apache::loncommon::store_course_settings($stored_folderpath,
5273: {'folderpath' => 'scalar'});
5274: }
5275: my $folderpath;
5276: if ($env{'form.folderpath'}) {
5277: $folderpath = $env{'form.folderpath'};
5278: my (@folders)=split('&',$env{'form.folderpath'});
5279: $env{'form.foldername'}=&unescape(pop(@folders));
5280: if ($env{'form.foldername'} =~ /\:1$/) {
5281: $container = 'page';
5282: } else {
5283: $container = 'sequence';
5284: }
5285: $env{'form.folder'}=pop(@folders);
5286: } else {
5287: if ($env{'form.folder'} eq '' ||
5288: $env{'form.folder'} eq 'supplemental') {
5289: if ($env{'form.folder'} eq 'supplemental') {
5290: $folderpath=&supplemental_base();
5291: } elsif (!$hiddentop) {
5292: $folderpath='default&'.
5293: &escape(&mt('Main Content').':::::');
5294: }
5295: }
5296: }
5297: $containertag = '<input type="hidden" name="folderpath" value="" />';
5298: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5299: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5300: $showdoc='/'.$1;
5301: }
5302: if ($showdoc) { # got called in sequence from course
5303: $allowed=0;
5304: } else {
5305: if ($canedit) {
5306: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5307: $script=&Apache::lonratedt::editscript('simple');
5308: }
5309: }
5310: }
5311:
5312: # get personal data
5313: my $uname=$env{'user.name'};
5314: my $udom=$env{'user.domain'};
5315: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5316:
5317: if ($allowed) {
5318: if ($toolsflag) {
5319: $script .= &inject_data_js();
5320: my ($home,$other,%outhash)=&authorhosts();
5321: if (!$home && $other) {
5322: my @hosts;
5323: foreach my $aurole (keys(%outhash)) {
5324: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5325: push(@hosts,$outhash{$aurole});
5326: }
5327: }
5328: $script .= &dump_switchserver_js(@hosts);
5329: }
5330: } else {
5331: my $tid = 1;
5332: my @tabids;
5333: if ($supplementalflag) {
5334: @tabids = ('002','ee2','ff2');
5335: $tid = 2;
5336: } else {
5337: @tabids = ('aa1','bb1','cc1','ff1');
5338: unless ($env{'form.folderpath'} =~ /\:1$/) {
5339: unshift(@tabids,'001');
5340: push(@tabids,('dd1','ee1'));
5341: }
5342: }
5343: my $tabidstr = join("','",@tabids);
5344: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
5345: my $posslti = keys(%ltitools);
5346: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5347: $londocroot,$canedit,\$navmap).
5348: &history_tab_js().
5349: &inject_data_js().
5350: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5351: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5352: $addentries = {
5353: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5354: };
5355: }
5356: $script .= &paste_popup_js();
5357: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5358: &mt('Switch server?');
5359:
5360:
5361: }
5362: # -------------------------------------------------------------------- Body tag
5363: $script = '<script type="text/javascript">'."\n"
5364: .'// <![CDATA['."\n"
5365: .$script."\n"
5366: .'// ]]>'."\n"
5367: .'</script>'."\n"
5368: .'<script type="text/javascript"
5369: src="/res/adm/includes/file_upload.js"></script>'."\n";
5370:
5371: # Breadcrumbs
5372: &Apache::lonhtmlcommon::clear_breadcrumbs();
5373:
5374: if ($showdoc) {
5375: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5376: {'force_register' => $showdoc,}));
5377: } elsif ($toolsflag) {
5378: my ($breadtext,$breadtitle);
5379: $breadtext = "$crstype Editor";
5380: if ($canedit) {
5381: $breadtitle = 'Editing '.$crstype.' Contents';
5382: } else {
5383: $breadtext .= ' (View-only mode)';
5384: $breadtitle = 'Viewing '.$crstype.' Contents';
5385: }
5386: &Apache::lonhtmlcommon::add_breadcrumb({
5387: href=>"/adm/coursedocs",text=>$breadtext});
5388: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5389: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5390: .&Apache::lonhtmlcommon::breadcrumbs(
5391: $breadtitle)
5392: );
5393: } elsif ($r->uri eq '/adm/supplemental') {
5394: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5395: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5396: {'bread_crumbs' => $brcrum,}));
5397: } else {
5398: my ($breadtext,$breadtitle,$helpitem);
5399: $breadtext = "$crstype Editor";
5400: if ($canedit) {
5401: $breadtitle = 'Editing '.$crstype.' Contents';
5402: $helpitem = 'Docs_Adding_Course_Doc';
5403: } else {
5404: $breadtext .= ' (View-only mode)';
5405: $breadtitle = 'Viewing '.$crstype.' Contents';
5406: $helpitem = 'Docs_Viewing_Course_Doc';
5407: }
5408: &Apache::lonhtmlcommon::add_breadcrumb({
5409: href=>"/adm/coursedocs",text=>$breadtext});
5410: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5411: {'add_entries' => $addentries}
5412: )
5413: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5414: .&Apache::lonhtmlcommon::breadcrumbs(
5415: $breadtitle,
5416: $helpitem)
5417: );
5418: }
5419:
5420: my %allfiles = ();
5421: my %codebase = ();
5422: my ($upload_result,$upload_output,$uploadphase);
5423: if ($canedit) {
5424: if (($env{'form.uploaddoc.filename'}) &&
5425: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5426: my $context = $1;
5427: # Process file upload - phase one - upload and parse primary file.
5428: undef($hadchanges);
5429: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5430: \%allfiles,\%codebase,$context,$crstype);
5431: if ($hadchanges) {
5432: &mark_hash_old();
5433: }
5434: $r->print($upload_output);
5435: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5436: # Process file upload - phase two - upload embedded objects
5437: $uploadphase = 'check_embedded';
5438: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5439: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5440: $env{'form.newidx'});
5441: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5442: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5443: my ($destination,$dir_root) = &embedded_destination();
5444: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5445: my $actionurl = '/adm/coursedocs';
5446: my ($result,$flag) =
5447: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5448: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5449: $actionurl);
5450: $r->print($result.&return_to_editor());
5451: } elsif ($env{'form.phase'} eq 'check_embedded') {
5452: # Process file upload - phase three - modify references in HTML file
5453: $uploadphase = 'modified_orightml';
5454: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5455: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5456: my ($destination,$dir_root) = &embedded_destination();
5457: my $result =
5458: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5459: $docuname,$docudom,undef,
5460: $dir_root);
5461: $r->print($result.&return_to_editor());
5462: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5463: $uploadphase = 'decompress_phase_one';
5464: $r->print(&decompression_phase_one().
5465: &return_to_editor());
5466: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5467: $uploadphase = 'decompress_phase_two';
5468: $r->print(&decompression_phase_two().
5469: &return_to_editor());
5470: }
5471: }
5472:
5473: if ($allowed && $toolsflag) {
5474: $r->print(&startContentScreen('tools'));
5475: $r->print(&generate_admin_menu($crstype,$canedit));
5476: $r->print(&endContentScreen());
5477: } elsif ((!$showdoc) && (!$uploadphase)) {
5478: # -----------------------------------------------------------------------------
5479: my %lt=&Apache::lonlocal::texthash(
5480: 'copm' => 'All documents out of a published map into this folder',
5481: 'upfi' => 'Upload File',
5482: 'upld' => 'Upload Content',
5483: 'srch' => 'Search',
5484: 'impo' => 'Import',
5485: 'lnks' => 'Import from Stored Links',
5486: 'impm' => 'Import from Assembled Map',
5487: 'imcr' => 'Import from Course Resources',
5488: 'extr' => 'External Resource',
5489: 'extt' => 'External Tool',
5490: 'selm' => 'Select Map',
5491: 'load' => 'Load Map',
5492: 'newf' => 'New Folder',
5493: 'newp' => 'New Composite Page',
5494: 'syll' => 'Syllabus',
5495: 'navc' => 'Table of Contents',
5496: 'sipa' => 'Simple Course Page',
5497: 'sipr' => 'Simple Problem',
5498: 'webp' => 'Blank Web Page (editable)',
5499: 'stpr' => 'Standard Problem',
5500: 'news' => 'New sub-directory',
5501: 'crpr' => 'Create Problem',
5502: 'drbx' => 'Drop Box',
5503: 'scuf' => 'External Scores (handgrade, upload, clicker)',
5504: 'bull' => 'Discussion Board',
5505: 'mypi' => 'My Personal Information Page',
5506: 'grpo' => 'Group Portfolio',
5507: 'rost' => 'Course Roster',
5508: 'abou' => 'Personal Information Page for a User',
5509: 'imsf' => 'IMS Upload',
5510: 'imsl' => 'Upload IMS package',
5511: 'cms' => 'Origin of IMS package',
5512: 'se' => 'Select',
5513: 'file' => 'File',
5514: 'title' => 'Title',
5515: 'addp' => 'Add Placeholder to course?',
5516: 'uste' => 'Use Template?',
5517: 'fnam' => 'File Name:',
5518: 'loca' => 'Location:',
5519: 'dire' => 'Directory:',
5520: 'cate' => 'Category:',
5521: 'tmpl' => 'Template:',
5522: 'comment' => 'Comment',
5523: 'parse' => 'Upload embedded images/multimedia files if HTML file',
5524: 'bb5' => 'Blackboard 5',
5525: 'bb6' => 'Blackboard 6',
5526: 'angel5' => 'ANGEL 5.5',
5527: 'webctce4' => 'WebCT 4 Campus Edition',
5528: 'yes' => 'Yes',
5529: 'no' => 'No',
5530: 'er' => 'Editing rights unavailable for your current role',
5531: );
5532: # -----------------------------------------------------------------------------
5533:
5534: # Calculate free quota space for a user or course. A javascript function checks
5535: # file size to determine if upload should be allowed.
5536: my $quotatype = 'unofficial';
5537: if ($crstype eq 'Community') {
5538: $quotatype = 'community';
5539: } elsif ($crstype eq 'Placement') {
5540: $quotatype = 'placement';
5541: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5542: $quotatype = 'official';
5543: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5544: $quotatype = 'textbook';
5545: }
5546: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5547: 'course',$quotatype); # expressed in MB
5548: my $current_disk_usage = 0;
5549: foreach my $subdir ('docs','supplemental') {
5550: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5551: "userfiles/$subdir",1); # expressed in kB
5552: }
5553: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5554: my $usage = $current_disk_usage/1024; # in MB
5555: my $quota = $disk_quota;
5556: my $percent;
5557: if ($disk_quota == 0) {
5558: $percent = 100.0;
5559: } else {
5560: $percent = 100*($current_disk_usage/$disk_quota);
5561: }
5562: $usage = sprintf("%.2f",$usage);
5563: $quota = sprintf("%.2f",$quota);
5564: $percent = sprintf("%.0f",$percent);
5565: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5566: $percent.'%',$quota.' MB').'</p>';
5567:
5568: my $fileupload=(<<FIUP);
5569: $quotainfo
5570: $lt{'file'}:<br />
5571: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
5572: <input type="hidden" id="free_space" value="$free_space" />
5573: FIUP
5574:
5575: my $checkbox=(<<CHBO);
5576: <!-- <label>$lt{'parse'}?
5577: <input type="checkbox" name="parserflag" />
5578: </label> -->
5579: <label>
5580: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
5581: </label>
5582: CHBO
5583: my $imsfolder = $env{'form.folder'};
5584: if ($imsfolder eq '') {
5585: $imsfolder = 'default';
5586: }
5587: my $imspform=(<<IMSFORM);
5588: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5589: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5590: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
5591: <fieldset id="uploadimsform" style="display: none;">
5592: <legend>$lt{'imsf'}</legend>
5593: $fileupload
5594: <br />
5595: <p>
5596: $lt{'cms'}:
5597: <select name="source" $disabled>
5598: <option value="-1" selected="selected">$lt{'se'}</option>
5599: <option value="bb5">$lt{'bb5'}</option>
5600: <option value="bb6">$lt{'bb6'}</option>
5601: <option value="angel5">$lt{'angel5'}</option>
5602: <option value="webctce4">$lt{'webctce4'}</option>
5603: </select>
5604: <input type="hidden" name="folder" value="$imsfolder" />
5605: </p>
5606: <input type="hidden" name="phase" value="one" />
5607: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
5608: </fieldset>
5609: </form>
5610: IMSFORM
5611:
5612: my $fileuploadform=(<<FUFORM);
5613: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5614: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5615: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
5616: <fieldset id="uploaddocform" style="display: none;">
5617: <legend>$lt{'upfi'}</legend>
5618: <input type="hidden" name="active" value="aa" />
5619: $fileupload
5620: <br />
5621: $lt{'title'}:<br />
5622: <input type="text" size="60" name="comment" $disabled />
5623: $pathitem
5624: <input type="hidden" name="cmd" value="upload_default" />
5625: <br />
5626: <span class="LC_nobreak" style="float:left">
5627: $checkbox
5628: </span>
5629: <br clear="all" />
5630: <input type="submit" value="$lt{'upld'}" $disabled />
5631: </fieldset>
5632: </form>
5633: FUFORM
5634:
5635: my $mapimportjs;
5636: if ($canedit) {
5637: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5638: } else {
5639: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5640: }
5641: my $importpubform=(<<SEDFFORM);
5642: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
5643: $lt{'impm'}</a>$help{'Load_Map'}
5644: <form action="/adm/coursedocs" method="post" name="mapimportform">
5645: <fieldset id="importmapform" style="display: none;">
5646: <legend>$lt{'impm'}</legend>
5647: <input type="hidden" name="active" value="bb" />
5648: $lt{'copm'}<br />
5649: <span class="LC_nobreak">
5650: <input type="text" name="importmap" size="40" value=""
5651: onfocus="this.blur();$mapimportjs" $disabled />
5652: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5653: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
5654: </fieldset>
5655: </form>
5656:
5657: SEDFFORM
5658: my $importcrsresform;
5659: my ($numdirs,$pickfile) =
5660: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5661: "resize_scrollbox('contentscroll','1','0');",
5662: undef,'res');
5663: if ($pickfile) {
5664: $importcrsresform=(<<CRSFORM);
5665: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5666: $lt{'imcr'}</a>$help{'Course_Resources'}
5667: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5668: <fieldset id="importcrsresform" style="display: none;">
5669: <legend>$lt{'imcr'}</legend>
5670: <input type="hidden" name="active" value="bb" />
5671: $pickfile
5672: <p>
5673: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
5674: </p>
5675: <input type="hidden" name="importdetail" value="" />
5676: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
5677: </fieldset>
5678: </form>
5679: CRSFORM
5680: }
5681:
5682: my $fromstoredjs;
5683: if ($canedit) {
5684: $fromstoredjs = 'open_StoredLinks_Import()';
5685: } else {
5686: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5687: }
5688:
5689: my @importpubforma = (
5690: { '<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>" },
5691: { '<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'}" },
5692: { '<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>' },
5693: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5694: );
5695: if ($pickfile) {
5696: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5697: }
5698: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5699: my $extresourcesform =
5700: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5701: $help{'Adding_External_Resource'},
5702: undef,undef,undef,undef,undef,undef,$disabled);
5703: my $exttoolform =
5704: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5705: $help{'Adding_External_Tool'},undef,
5706: undef,'tool',$coursedom,$coursenum,
5707: \%ltitools,$disabled);
5708: if ($allowed) {
5709: my $folder = $env{'form.folder'};
5710: if ($folder eq '') {
5711: $folder='default';
5712: }
5713: if ($canedit) {
5714: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5715: if ($output) {
5716: $r->print($output);
5717: }
5718: }
5719: $r->print(<<HIDDENFORM);
5720: <form name="renameform" method="post" action="/adm/coursedocs">
5721: <input type="hidden" name="title" />
5722: <input type="hidden" name="cmd" />
5723: <input type="hidden" name="markcopy" />
5724: <input type="hidden" name="copyfolder" />
5725: $containertag
5726: </form>
5727:
5728: HIDDENFORM
5729: $r->print(&makesimpleeditform($pathitem)."\n".
5730: &makedocslogform($pathitem."\n".
5731: '<input type="hidden" name="folder" value="'.
5732: $env{'form.folder'}.'" />'."\n"));
5733: }
5734:
5735: # Generate the tabs
5736: my ($mode,$needs_end);
5737: if (($supplementalflag) && (!$allowed)) {
5738: my @folders = split('&',$env{'form.folderpath'});
5739: unless (@folders > 2) {
5740: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5741: $needs_end = 1;
5742: }
5743: } else {
5744: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
5745: $needs_end = 1;
5746: }
5747:
5748: #
5749:
5750: my $savefolderpath;
5751:
5752: if ($allowed) {
5753: my $folder=$env{'form.folder'};
5754: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
5755: $folder='default';
5756: $savefolderpath = $env{'form.folderpath'};
5757: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
5758: $pathitem = '<input type="hidden" name="folderpath" value="'.
5759: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5760: }
5761: my $postexec='';
5762: if ($folder eq 'default') {
5763: $r->print('<script type="text/javascript">'."\n"
5764: .'// <![CDATA['."\n"
5765: .'this.window.name="loncapaclient";'."\n"
5766: .'// ]]>'."\n"
5767: .'</script>'."\n"
5768: );
5769: } else {
5770: #$postexec='self.close();';
5771: }
5772: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5773: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
5774: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5775:
5776: my $newnavform=(<<NNFORM);
5777: <form action="/adm/coursedocs" method="post" name="newnav">
5778: <input type="hidden" name="active" value="ee" />
5779: $pathitem
5780: <input type="hidden" name="importdetail"
5781: value="$lt{'navc'}=/adm/navmaps" />
5782: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
5783: $help{'Navigate_Content'}
5784: </form>
5785: NNFORM
5786: my $newsmppageform=(<<NSPFORM);
5787: <form action="/adm/coursedocs" method="post" name="newsmppg">
5788: <input type="hidden" name="active" value="ee" />
5789: $pathitem
5790: <input type="hidden" name="importdetail" value="" />
5791: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
5792: $help{'Simple Page'}
5793: </form>
5794: NSPFORM
5795:
5796: my $newsmpproblemform=(<<NSPROBFORM);
5797: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
5798: <input type="hidden" name="active" value="cc" />
5799: $pathitem
5800: <input type="hidden" name="importdetail" value="" />
5801: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
5802: $help{'Simple_Problem'}
5803: </form>
5804:
5805: NSPROBFORM
5806:
5807: my $newdropboxform=(<<NDBFORM);
5808: <form action="/adm/coursedocs" method="post" name="newdropbox">
5809: <input type="hidden" name="active" value="cc" />
5810: $pathitem
5811: <input type="hidden" name="importdetail" value="" />
5812: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
5813: $help{'Dropbox'}
5814: </form>
5815: NDBFORM
5816:
5817: my $newexuploadform=(<<NEXUFORM);
5818: <form action="/adm/coursedocs" method="post" name="newexamupload">
5819: <input type="hidden" name="active" value="cc" />
5820: $pathitem
5821: <input type="hidden" name="importdetail" value="" />
5822: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
5823: $help{'Score_Upload_Form'}
5824: </form>
5825: NEXUFORM
5826:
5827: my $newbulform=(<<NBFORM);
5828: <form action="/adm/coursedocs" method="post" name="newbul">
5829: <input type="hidden" name="active" value="dd" />
5830: $pathitem
5831: <input type="hidden" name="importdetail" value="" />
5832: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
5833: $help{'Bulletin Board'}
5834: </form>
5835: NBFORM
5836:
5837: my $newaboutmeform=(<<NAMFORM);
5838: <form action="/adm/coursedocs" method="post" name="newaboutme">
5839: <input type="hidden" name="active" value="dd" />
5840: $pathitem
5841: <input type="hidden" name="importdetail"
5842: value="$plainname=/adm/$udom/$uname/aboutme" />
5843: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
5844: $help{'My Personal Information Page'}
5845: </form>
5846: NAMFORM
5847:
5848: my $newaboutsomeoneform=(<<NASOFORM);
5849: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
5850: <input type="hidden" name="active" value="dd" />
5851: $pathitem
5852: <input type="hidden" name="importdetail" value="" />
5853: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
5854: </form>
5855: NASOFORM
5856:
5857: my $newrosterform=(<<NROSTFORM);
5858: <form action="/adm/coursedocs" method="post" name="newroster">
5859: <input type="hidden" name="active" value="dd" />
5860: $pathitem
5861: <input type="hidden" name="importdetail"
5862: value="$lt{'rost'}=/adm/viewclasslist" />
5863: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
5864: $help{'Course_Roster'}
5865: </form>
5866: NROSTFORM
5867:
5868: my $newwebpage;
5869: if ($folder =~ /^default_?(\d*)$/) {
5870: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5871: if ($1) {
5872: $newwebpage .= $1;
5873: } else {
5874: $newwebpage .= 'default';
5875: }
5876: $newwebpage .= '/new.html';
5877: }
5878: my $newwebpageform =(<<NWEBFORM);
5879: <form action="/adm/coursedocs" method="post" name="newwebpage">
5880: <input type="hidden" name="active" value="ee" />
5881: $pathitem
5882: <input type="hidden" name="importdetail" value="$newwebpage" />
5883: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
5884: $help{'Web_Page'}
5885: </form>
5886: NWEBFORM
5887:
5888: my @ids=&Apache::lonnet::current_machine_ids();
5889: my %select_menus;
5890: my $numauthor = 0;
5891: my $numcrsdirs = 0;
5892: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5893: if ($env{'user.author'}) {
5894: $numauthor ++;
5895: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5896: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5897: my $is_home = 1;
5898: my %subdirs;
5899: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5900: $select_menus{'author'}->{'default'} = '/';
5901: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5902: my @ordered = ('/');
5903: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5904: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5905: push(@ordered,$relpath);
5906: }
5907: $select_menus{'author'}->{'order'} = \@ordered;
5908: } else {
5909: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5910: $select_menus{'author'}->{'default'} = 'switch';
5911: $select_menus{'author'}->{'order'} = ['switch'];
5912: }
5913: }
5914: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5915: ['active'],['ca','aa']);
5916: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5917: my %by_roletype;
5918: if (keys(%roleshash)) {
5919: foreach my $entry (keys(%roleshash)) {
5920: my ($auname,$audom,$roletype) = split(/:/,$entry);
5921: my $key = $entry;
5922: $key =~ s/:/___/g;
5923: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5924: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5925: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5926: if (grep(/^\Q$rolehome\E$/,@ids)) {
5927: my $is_home = 1;
5928: my (%subdirs,@ordered);
5929: my $toppath="/priv/$audom/$auname";
5930: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5931: $select_menus{$key}->{'default'} = '/';
5932: $select_menus{$key}->{'select2'}->{'/'} = '/';
5933: my @ordered = ('/');
5934: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5935: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5936: push(@ordered,$relpath);
5937: }
5938: $select_menus{$key}->{'order'} = \@ordered;
5939: } else {
5940: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5941: $select_menus{$key}->{'default'} = 'switch';
5942: $select_menus{$key}->{'order'} = ['switch'];
5943: }
5944: $numauthor ++;
5945: }
5946: }
5947: my ($pickdir,$showtitle);;
5948: if ($numauthor) {
5949: my @order;
5950: my $defrole;
5951: if ($env{'user.author'}) {
5952: push(@order,'author');
5953: $defrole = 'author';
5954: }
5955: if (keys(%by_roletype)) {
5956: foreach my $possrole ('ca','aa') {
5957: if (ref($by_roletype{$possrole}) eq 'HASH') {
5958: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5959: unless ($defrole) {
5960: $defrole = $author;
5961: }
5962: push(@order,$author.'___'.$possrole);
5963: }
5964: }
5965: }
5966: }
5967: $select_menus{'course'}->{'text'} = &mt('Course Resource');
5968: if (grep(/^\Q$crshome\E$/,@ids)) {
5969: my $is_home = 1;
5970: my %subdirs;
5971: my $toppath="/priv/$coursedom/$coursenum";
5972: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5973: $numcrsdirs = keys(%subdirs);
5974: $select_menus{'course'}->{'default'} = '/';
5975: $select_menus{'course'}->{'select2'}->{'/'} = '/';
5976: my @ordered = ('/');
5977: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5978: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
5979: push(@ordered,$relpath);
5980: }
5981: $select_menus{'course'}->{'order'} = \@ordered;
5982: } else {
5983: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
5984: $select_menus{'course'}->{'default'} = 'switch';
5985: $select_menus{'course'}->{'order'} = ['switch'];
5986: }
5987: push(@order,'course');
5988: $pickdir = $lt{'loca'}.
5989: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
5990: $defrole,'authorrole','authorpath',
5991: \%select_menus,\@order,'toggleCrsResTitle();',
5992: '','priv').'<br />';
5993: $showtitle = 'none';
5994: } else {
5995: my $is_home;
5996: $showtitle = 'inline';
5997: if (grep(/^\Q$crshome\E$/,@ids)) {
5998: $is_home = 1;
5999: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6000: my $toppath="/priv/$coursedom/$coursenum'}";
6001: my %subdirs;
6002: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6003: $numcrsdirs = keys(%subdirs);
6004: if ($numcrsdirs) {
6005: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6006: '<option value="/">/</option>'."\n";
6007: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6008: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
6009: }
6010: $pickdir .= '</select>';
6011: } else {
6012: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6013: }
6014: }
6015: }
6016:
6017: my %seltemplate_menus;
6018: my @files = &Apache::lonhomework::get_template_list('problem');
6019: my @noexamplelink = ('blank.problem','blank.library','script.library');
6020: my $currentcategory = '';
6021: my @ordered = ('');
6022: my %templatehelp;
6023: my $defcategory = '';
6024: my @catorder = ($defcategory);
6025: $seltemplate_menus{$defcategory}->{'order'} = [''];
6026: $seltemplate_menus{$defcategory}->{'text'} = '';
6027: foreach my $file (@files) {
6028: if (ref($file) eq 'ARRAY') {
6029: my ($path,$title,$category,$help) = @{$file};
6030: next if ($title !~ /\S/);
6031: if (&js_escape($category) ne $currentcategory) {
6032: $currentcategory = &js_escape($category);
6033: push(@catorder,&js_escape($currentcategory));
6034: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6035: $seltemplate_menus{$currentcategory}->{'default'} = '';
6036: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6037: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6038: }
6039: if ($path) {
6040: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6041: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6042: if ($help) {
6043: $templatehelp{$path} = $help;
6044: }
6045: }
6046: }
6047: }
6048:
6049: my $templates = $lt{'cate'}.' '.
6050: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6051: $defcategory,'tempcategory','template',
6052: \%seltemplate_menus,\@catorder,
6053: "resize_scrollbox('contentscroll','1','0');",
6054: "toggleExampleText();",'template').'<br />';
6055: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6056: '<span id="newresexample">'.&mt('Example').'<span></a>';
6057: my $crsresform=(<<RESFORM);
6058: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6059: $lt{'stpr'}</a>$help{'Course_Resource'}
6060: <form action="/adm/coursedocs" method="post" name="courseresform">
6061: <fieldset id="crsresform" style="display:none;">
6062: <legend>$lt{'stpr'}</legend>
6063: <input type="hidden" name="active" value="ee" />
6064: <p>
6065: $pickdir
6066: <span class="LC_nobreak">$lt{'news'}?
6067: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6068:
6069: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6070: </span><span id="newsubdir"></span>
6071: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6072: </p>
6073: $lt{'fnam'}
6074: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6075: <p>
6076: <div id="newresource" style="display:$showtitle">
6077: $lt{'addp'}
6078: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6079: $lt{'no'}</label>
6080: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6081: $lt{'yes'}</label>
6082: <span id="newrestitle"></span>
6083: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6084: </div>
6085: </p>
6086: <p>
6087: $lt{'uste'}
6088: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6089: $lt{'no'}</label>
6090: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6091: $lt{'yes'}</label>
6092: <div id="newrestemplate" style="display:none">
6093: $templates
6094: $templatepreview
6095: </div>
6096: </p>
6097: <span class="LC_nobreak">
6098: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6099: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6100: </span>
6101: </fieldset>
6102: </form>
6103:
6104: RESFORM
6105:
6106: my $specialdocumentsform;
6107: my @specialdocumentsforma;
6108: my $gradingform;
6109: my @gradingforma;
6110: my $communityform;
6111: my @communityforma;
6112: my $newfolderform;
6113: my $newfolderb;
6114:
6115: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6116:
6117: my $newpageform=(<<NPFORM);
6118: <form action="/adm/coursedocs" method="post" name="newpage">
6119: <input type="hidden" name="folderpath" value="$path" />
6120: <input type="hidden" name="importdetail" value="" />
6121: <input type="hidden" name="active" value="ee" />
6122: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6123: $help{'Adding_Pages'}
6124: </form>
6125: NPFORM
6126:
6127:
6128: $newfolderform=(<<NFFORM);
6129: <form action="/adm/coursedocs" method="post" name="newfolder">
6130: $pathitem
6131: <input type="hidden" name="importdetail" value="" />
6132: <input type="hidden" name="active" value="" />
6133: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6134: </form>
6135: NFFORM
6136:
6137: my $newsylform=(<<NSYLFORM);
6138: <form action="/adm/coursedocs" method="post" name="newsyl">
6139: <input type="hidden" name="active" value="ee" />
6140: $pathitem
6141: <input type="hidden" name="importdetail"
6142: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6143: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6144: $help{'Syllabus'}
6145:
6146: </form>
6147: NSYLFORM
6148:
6149: my $newgroupfileform=(<<NGFFORM);
6150: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6151: <input type="hidden" name="active" value="dd" />
6152: $pathitem
6153: <input type="hidden" name="importdetail"
6154: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6155: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6156: $help{'Group Portfolio'}
6157: </form>
6158: NGFFORM
6159: @specialdocumentsforma=(
6160: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6161: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="makenew(document.newsyl);" />'=>$newsylform},
6162: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6163: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6164: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6165: );
6166: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6167:
6168:
6169: my @importdoc = (
6170: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6171: );
6172: if (keys(%ltitools)) {
6173: push(@importdoc,
6174: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6175: );
6176: }
6177: unless ($container eq 'page') {
6178: push(@importdoc,
6179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6180: );
6181: }
6182: push(@importdoc,
6183: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6184: );
6185: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6186:
6187: @gradingforma=(
6188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6190: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6191: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6192: );
6193: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6194:
6195: @communityforma=(
6196: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6197: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6198: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6199: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6200: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6201: );
6202: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6203:
6204: my %orderhash = (
6205: 'aa' => ['Upload',$fileuploadform],
6206: 'bb' => ['Import',$importpubform],
6207: 'cc' => ['Grading',$gradingform],
6208: );
6209: unless ($container eq 'page') {
6210: $orderhash{'00'} = ['Newfolder',$newfolderform];
6211: $orderhash{'dd'} = ['Collaboration',$communityform];
6212: $orderhash{'ee'} = ['Other',$specialdocumentsform];
6213: }
6214:
6215: $hadchanges=0;
6216: unless (($supplementalflag || $toolsflag)) {
6217: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6218: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6219: \%ltitools,$canedit,\$navmap,$hiddentop);
6220: undef($navmap);
6221: if ($error) {
6222: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6223: }
6224: if ($hadchanges) {
6225: &mark_hash_old();
6226: }
6227:
6228: &changewarning($r,'');
6229: }
6230: }
6231:
6232: # Supplemental documents start here
6233:
6234: my $folder=$env{'form.folder'};
6235: unless ($supplementalflag) {
6236: $folder='supplemental';
6237: }
6238: if ($folder =~ /^supplemental$/ &&
6239: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6240: $env{'form.folderpath'} = &supplemental_base();
6241: } elsif ($allowed) {
6242: $env{'form.folderpath'} = $savefolderpath;
6243: }
6244: $pathitem = '<input type="hidden" name="folderpath" value="'.
6245: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6246: if ($allowed) {
6247: my $folderseq=
6248: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6249:
6250: my $supupdocform=(<<SUPDOCFORM);
6251: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6252: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6253: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6254: <fieldset id="uploadsuppdocform" style="display: none;">
6255: <legend>$lt{'upfi'}</legend>
6256: <input type="hidden" name="active" value="ee" />
6257: $fileupload
6258: <br />
6259: <br />
6260: <span class="LC_nobreak">
6261: $checkbox
6262: </span>
6263: <br /><br />
6264: $lt{'comment'}:<br />
6265: <textarea cols="50" rows="4" name="comment"></textarea>
6266: <br />
6267: $pathitem
6268: <input type="hidden" name="cmd" value="upload_supplemental" />
6269: <input type='submit' value="$lt{'upld'}" />
6270: </form>
6271: SUPDOCFORM
6272:
6273: my $supnewfolderform=(<<SNFFORM);
6274: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6275: <input type="hidden" name="active" value="" />
6276: $pathitem
6277: <input type="hidden" name="importdetail" value="" />
6278: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6279: $help{'Adding_Folders'}
6280: </form>
6281: SNFFORM
6282:
6283: my $supextform =
6284: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6285: $help{'Adding_External_Resource'},
6286: undef,undef,undef,undef,undef,undef,
6287: $disabled);
6288:
6289: my $supexttoolform =
6290: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6291: $help{'Adding_External_Tool'},
6292: undef,undef,'tool',$coursedom,
6293: $coursenum,\%ltitools,$disabled);
6294:
6295: my $supnewsylform=(<<SNSFORM);
6296: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6297: <input type="hidden" name="active" value="ff" />
6298: $pathitem
6299: <input type="hidden" name="importdetail"
6300: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6301: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6302: $help{'Syllabus'}
6303: </form>
6304: SNSFORM
6305:
6306: my $supnewaboutmeform=(<<SNAMFORM);
6307: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6308: <input type="hidden" name="active" value="ff" />
6309: $pathitem
6310: <input type="hidden" name="importdetail"
6311: value="$plainname=/adm/$udom/$uname/aboutme" />
6312: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6313: $help{'My Personal Information Page'}
6314: </form>
6315: SNAMFORM
6316:
6317: my $supwebpage;
6318: if ($folder =~ /^supplemental_?(\d*)$/) {
6319: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6320: if ($1) {
6321: $supwebpage .= $1;
6322: } else {
6323: $supwebpage .= 'default';
6324: }
6325: $supwebpage .= '/new.html';
6326: }
6327: my $supwebpageform =(<<SWEBFORM);
6328: <form action="/adm/coursedocs" method="post" name="supwebpage">
6329: <input type="hidden" name="active" value="cc" />
6330: $pathitem
6331: <input type="hidden" name="importdetail" value="$supwebpage" />
6332: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6333: $help{'Web_Page'}
6334: </form>
6335: SWEBFORM
6336:
6337:
6338: my @specialdocs = (
6339: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="makenew(document.supnewsyl);" />'
6340: =>$supnewsylform},
6341: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6342: =>$supnewaboutmeform},
6343: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6344:
6345: );
6346: my @supimportdoc = (
6347: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
6348: =>$supextform});
6349: if (keys(%ltitools)) {
6350: push(@supimportdoc,
6351: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6352: =>$supexttoolform});
6353: }
6354: push(@supimportdoc,
6355: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6356: =>$supupdocform},
6357: );
6358:
6359: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6360: my %suporderhash = (
6361: '00' => ['Supnewfolder', $supnewfolderform],
6362: 'ee' => ['Upload',$supupdocform],
6363: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6364: );
6365: if ($supplementalflag) {
6366: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6367: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6368: \%ltitools,$canedit);
6369: if ($error) {
6370: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6371: } else {
6372: if ($suppchanges) {
6373: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6374: my @ids=&Apache::lonnet::current_machine_ids();
6375: foreach my $server (keys(%servers)) {
6376: next if (grep(/^\Q$server\E$/,@ids));
6377: my $hashid=$coursenum.':'.$coursedom;
6378: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6379: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
6380: }
6381: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6382: undef($suppchanges);
6383: }
6384: }
6385: }
6386: } elsif ($supplementalflag) {
6387: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6388: $supplementalflag,'',$iconpath,$pathitem);
6389: if ($error) {
6390: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6391: }
6392: }
6393:
6394: if ($needs_end) {
6395: $r->print(&endContentScreen());
6396: }
6397:
6398: if ($allowed) {
6399: $r->print('
6400: <form method="post" name="extimport" action="/adm/coursedocs">
6401: <input type="hidden" name="title" />
6402: <input type="hidden" name="url" />
6403: <input type="hidden" name="useform" />
6404: <input type="hidden" name="residx" />
6405: </form>');
6406: }
6407: } elsif ($showdoc) {
6408: # -------------------------------------------------------- This is showdoc mode
6409: $r->print("<h1>".&mt('Uploaded Document').' - '.
6410: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6411: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6412: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6413: }
6414: }
6415: unless ($noendpage) {
6416: $r->print(&Apache::loncommon::end_page());
6417: }
6418: return OK;
6419: }
6420:
6421: sub embedded_form_elems {
6422: my ($phase,$primaryurl,$newidx) = @_;
6423: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6424: return <<STATE;
6425: <input type="hidden" name="folderpath" value="$folderpath" />
6426: <input type="hidden" name="cmd" value="upload_embedded" />
6427: <input type="hidden" name="newidx" value="$newidx" />
6428: <input type="hidden" name="phase" value="$phase" />
6429: <input type="hidden" name="primaryurl" value="$primaryurl" />
6430: STATE
6431: }
6432:
6433: sub embedded_destination {
6434: my $folder=$env{'form.folder'};
6435: my $destination = 'docs/';
6436: if ($folder =~ /^supplemental/) {
6437: $destination = 'supplemental/';
6438: }
6439: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6440: $destination .= 'default/';
6441: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6442: $destination .= $2.'/';
6443: }
6444: $destination .= $env{'form.newidx'};
6445: my $dir_root = '/userfiles';
6446: return ($destination,$dir_root);
6447: }
6448:
6449: sub return_to_editor {
6450: my $actionurl = '/adm/coursedocs';
6451: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6452: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6453: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6454: '</a></p>';
6455: }
6456:
6457: sub decompression_info {
6458: my ($destination,$dir_root) = &embedded_destination();
6459: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6460: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6461: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6462: my $container='sequence';
6463: my ($pathitem,$hiddenelem);
6464: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
6465: if ($env{'form.folderpath'} =~ /\:1$/) {
6466: $container='page';
6467: }
6468: unshift(@hiddens,$pathitem);
6469: foreach my $item (@hiddens) {
6470: if ($env{'form.'.$item}) {
6471: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
6472: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
6473: }
6474: }
6475: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6476: $hiddenelem);
6477: }
6478:
6479: sub decompression_phase_one {
6480: my ($dir,$file,$warning,$error,$output);
6481: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6482: &decompression_info();
6483: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
6484: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6485: } else {
6486: my $file = $1;
6487: $output =
6488: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6489: $destination,$dir_root,
6490: $hiddenelem);
6491: if ($env{'form.autoextract_camtasia'}) {
6492: $output .= &remove_archive($docudom,$docuname,$container);
6493: }
6494: }
6495: if ($error) {
6496: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6497: $error.'</p>'."\n";
6498: }
6499: if ($warning) {
6500: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6501: }
6502: return $output;
6503: }
6504:
6505: sub decompression_phase_two {
6506: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6507: &decompression_info();
6508: my $output;
6509: if ($env{'form.archivedelete'}) {
6510: $output = &remove_archive($docudom,$docuname,$container);
6511: }
6512: $output .=
6513: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
6514: $destination,$dir_root,$hiddenelem);
6515: return $output;
6516: }
6517:
6518: sub remove_archive {
6519: my ($docudom,$docuname,$container) = @_;
6520: my $map = $env{'form.folder'}.'.'.$container;
6521: my ($output,$delwarning,$delresult,$url);
6522: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6523: if ($fatal) {
6524: if ($container eq 'page') {
6525: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6526: } else {
6527: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6528: }
6529: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
6530: } else {
6531: my $currcmd = $env{'form.cmd'};
6532: my $position = $env{'form.position'};
6533: my $archiveidx = $position;
6534: if ($position > 0) {
6535: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6536: $archiveidx = $position-1;
6537: }
6538: $env{'form.cmd'} = 'remove_'.$archiveidx;
6539: my ($title,$url,@rrest) =
6540: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6541: if ($url eq $env{'form.archiveurl'}) {
6542: if (&handle_edit_cmd($docuname,$docudom)) {
6543: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6544: if ($fatal) {
6545: if ($container eq 'page') {
6546: $delwarning = &mt('An error occurred updating the contents of the current page.');
6547: } else {
6548: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6549: }
6550: } else {
6551: $delresult = &mt('Archive file removed.');
6552: }
6553: }
6554: } else {
6555: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6556: ' '.&mt('As a result the archive file has not been removed.');
6557: }
6558: }
6559: $env{'form.cmd'} = $currcmd;
6560: }
6561: if ($delwarning) {
6562: $output = '<p class="LC_warning">'.
6563: $delwarning.
6564: '</p>';
6565: }
6566: if ($delresult) {
6567: $output .= '<p class="LC_info">'.
6568: $delresult.
6569: '</p>';
6570: }
6571: return $output;
6572: }
6573:
6574: sub generate_admin_menu {
6575: my ($crstype,$canedit) = @_;
6576: my $lc_crstype = lc($crstype);
6577: my ($home,$other,%outhash)=&authorhosts();
6578: my %lt= ( # do not translate here
6579: 'vc' => 'Verify Content',
6580: 'cv' => 'Check/Set Resource Versions',
6581: 'ls' => 'List Resource Identifiers',
6582: 'imse' => 'Export contents to IMS Archive',
6583: 'dcd' => "Copy $crstype Content to Authoring Space",
6584: );
6585: my ($candump,$dumpurl);
6586: if ($home + $other > 0) {
6587: $candump = 'F';
6588: if ($home) {
6589: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6590: } else {
6591: my @hosts;
6592: foreach my $aurole (keys(%outhash)) {
6593: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6594: push(@hosts,$outhash{$aurole});
6595: }
6596: }
6597: if (@hosts == 1) {
6598: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6599: '&role='.
6600: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6601: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6602: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6603: } else {
6604: $dumpurl = "javascript:choose_switchserver_window()";
6605: }
6606: }
6607: }
6608: my @menu=
6609: ({ categorytitle=>'Administration',
6610: items =>[
6611: { linktext => $lt{'vc'},
6612: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6613: permission => 'F',
6614: help => 'Docs_Verify_Content',
6615: icon => 'verify.png',
6616: linktitle => 'Verify contents can be retrieved/rendered',
6617: },
6618: { linktext => $lt{'cv'},
6619: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6620: permission => 'F',
6621: help => 'Docs_Check_Resource_Versions',
6622: icon => 'resversion.png',
6623: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6624: },
6625: { linktext => $lt{'ls'},
6626: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6627: permission => 'F',
6628: #help => '',
6629: icon => 'symbs.png',
6630: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6631: },
6632: ]
6633: });
6634: if ($canedit) {
6635: push(@menu,
6636: { categorytitle=>'Export',
6637: items =>[
6638: { linktext => $lt{'imse'},
6639: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6640: permission => 'F',
6641: help => 'Docs_Export_Course_Docs',
6642: icon => 'imsexport.png',
6643: linktitle => $lt{'imse'},
6644: },
6645: { linktext => $lt{'dcd'},
6646: url => $dumpurl,
6647: permission => $candump,
6648: help => 'Docs_Dump_Course_Docs',
6649: icon => 'dump.png',
6650: linktitle => $lt{'dcd'},
6651: },
6652: ]
6653: });
6654: }
6655: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6656: '<input type="hidden" id="dummy" />'."\n".
6657: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6658: '</form>';
6659: }
6660:
6661: sub generate_edit_table {
6662: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
6663: $need_save,$copyfolder,$canedit) = @_;
6664: return unless(ref($orderhash_ref) eq 'HASH');
6665: my %orderhash = %{$orderhash_ref};
6666: my ($form, $activetab, $active, $disabled);
6667: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
6668: $activetab = $env{'form.active'};
6669: }
6670: unless ($canedit) {
6671: $disabled = ' disabled="disabled"';
6672: }
6673: my $backicon = $iconpath.'clickhere.gif';
6674: my $backtext = &mt('Exit Editor');
6675: $form = '<div class="LC_Box" style="margin:0;">'.
6676: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6677: '<li class="goback">'.
6678: '<a href="javascript:toContents('."'$jumpto'".');">'.
6679: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6680: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6681: '<li>'.
6682: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6683: &mt('Undo Delete').'</a></li>'."\n";
6684: if ($env{'form.docslog'}) {
6685: $form .= '<li class="active">';
6686: } else {
6687: $form .= '<li>';
6688: }
6689: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6690: &mt('History').'</a></li>'."\n";
6691: if ($env{'form.docslog'}) {
6692: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6693: &mt('Edit').'</a></li>'."\n";
6694: }
6695: foreach my $name (reverse(sort(keys(%orderhash)))) {
6696: if($name ne '00'){
6697: if($activetab eq '' || $activetab ne $name){
6698: $active = '';
6699: }elsif($activetab eq $name){
6700: $active = 'class="active"';
6701: }
6702: $form .= '<li style="float:right" '.$active
6703: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
6704: } else {
6705: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
6706:
6707: }
6708: }
6709: $form .= '</ul>'."\n";
6710: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
6711:
6712: if ($to_show ne '') {
6713: my $saveform;
6714: if ($need_save) {
6715: my $button = &mt('Make changes');
6716: my $path;
6717: if ($env{'form.folderpath'}) {
6718: $path =
6719: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6720: }
6721: $saveform = <<"END";
6722: <div id="multisave" style="display:none; clear:both;" >
6723: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6724: <input type="hidden" name="folderpath" value="$path" />
6725: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6726: <input type="hidden" name="allhiddenresource" value="" />
6727: <input type="hidden" name="allencrypturl" value="" />
6728: <input type="hidden" name="allrandompick" value="" />
6729: <input type="hidden" name="allrandomorder" value="" />
6730: <input type="hidden" name="changeparms" value="" />
6731: <input type="hidden" name="multiremove" value="" />
6732: <input type="hidden" name="multicut" value="" />
6733: <input type="hidden" name="multicopy" value="" />
6734: <input type="hidden" name="multichange" value="" />
6735: <input type="hidden" name="copyfolder" value="$copyfolder" />
6736: <input type="submit" name="savemultiples" value="$button" $disabled />
6737: </form>
6738: </div>
6739: END
6740: }
6741: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
6742: }
6743: foreach my $field (keys(%orderhash)){
6744: if($field ne '00'){
6745: if($activetab eq '' || $activetab ne $field){
6746: $active = 'style="display: none;float:left"';
6747: }elsif($activetab eq $field){
6748: $active = 'style="display:block;float:left"';
6749: }
6750: $form .= '<div id="'.$field.$tid.'"'
6751: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
6752: .'</div>'."\n";
6753: }
6754: }
6755: unless ($env{'form.docslog'}) {
6756: $form .= '</div></div>'."\n";
6757: }
6758: return $form;
6759: }
6760:
6761: sub editing_js {
6762: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit,$navmapref) = @_;
6763: my %js_lt = &Apache::lonlocal::texthash(
6764: p_mnf => 'Name of New Folder',
6765: t_mnf => 'New Folder',
6766: p_mnp => 'Name of New Page',
6767: t_mnp => 'New Page',
6768: p_mxu => 'Title for the External Score',
6769: p_msp => 'Name of Simple Course Page',
6770: p_msb => 'Title for the Problem',
6771: p_mdb => 'Title for the Drop Box',
6772: p_mbb => 'Title for the Discussion Board',
6773: p_mwp => 'Title for Web Page',
6774: p_mnr => 'Title for the Resource',
6775: p_mab => "Enter user:domain for User's Personal Information Page",
6776: p_mab2 => 'Personal Information Page of ',
6777: p_mab_alrt1 => 'Not a valid user:domain',
6778: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6779: p_chn => 'New Title',
6780: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
6781: p_rmr2a => 'Remove',
6782: p_rmr2b => '?',
6783: p_rmr3a => 'Remove those',
6784: p_rmr3b => 'items?',
6785: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6786: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
6787: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6788: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
6789: p_ctr2a => 'Cut',
6790: p_ctr2b => '?',
6791: p_ctr3a => 'Cut those',
6792: p_ctr3b => 'items?',
6793: rpck => 'Enter number to pick (e.g., 3)',
6794: imsfile => 'You must choose an IMS package for import',
6795: imscms => 'You must select which Course Management System was the source of the IMS package',
6796: invurl => 'Invalid URL',
6797: titbl => 'Title is blank',
6798: more => '(More ...)',
6799: less => '(Less ...)',
6800: noor => 'No actions selected or changes to settings specified.',
6801: noch => 'No changes to settings specified.',
6802: noac => 'No actions selected.',
6803: nofi => 'No file selected',
6804: tinc => 'Title in course',
6805: sunm => 'Sub-directory name',
6806: edri => 'Editing rights unavailable for your current role',
6807: );
6808: &js_escape(\%js_lt);
6809: my $crstype = &Apache::loncommon::course_type();
6810: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6811: my $main_container_page;
6812: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6813: $main_container_page = 1;
6814: }
6815: my $backtourl;
6816: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
6817: my $toplevelsupp = &supplemental_base();
6818:
6819: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6820: my $caller = $1;
6821: if ($caller =~ /^supplemental/) {
6822: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6823: } else {
6824: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6825: $res = &Apache::lonnet::clutter($res);
6826: if (&Apache::lonnet::is_on_map($res)) {
6827: my ($url,$anchor);
6828: if ($res =~ /^([^#]+)#([^#]+)$/) {
6829: $url = $1;
6830: $anchor = $2;
6831: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6832: $caller = $1.&escape('#').$anchor;
6833: }
6834: } else {
6835: $url = $res;
6836: }
6837: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
6838: &HTML::Entities::encode($caller,'<>&"');
6839: if ($anchor ne '') {
6840: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6841: }
6842: $backtourl = &Apache::loncommon::escape_single($backtourl);
6843: } else {
6844: $backtourl = '/adm/navmaps';
6845: }
6846: }
6847: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6848: $backtourl = '/adm/menu';
6849: } elsif ($supplementalflag) {
6850: $backtourl = '/adm/supplemental';
6851: } else {
6852: $backtourl = '/adm/navmaps';
6853: }
6854:
6855: my $fieldsets = "'ext','doc'";
6856: if ($posslti) {
6857: $fieldsets .= ",'tool'";
6858: }
6859: unless ($main_container_page) {
6860: $fieldsets .=",'ims'";
6861: }
6862: if ($supplementalflag) {
6863: $fieldsets = "'suppext','suppdoc'";
6864: if ($posslti) {
6865: $fieldsets .= ",'supptool'";
6866: }
6867: }
6868:
6869: my $jsmakefunctions;
6870: if ($canedit) {
6871: $jsmakefunctions = <<ENDNEWSCRIPT;
6872: function makenewfolder(targetform,folderseq) {
6873: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
6874: if (foldername) {
6875: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6876: targetform.submit();
6877: }
6878: }
6879:
6880: function makenewpage(targetform,folderseq) {
6881: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
6882: if (pagename) {
6883: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6884: targetform.submit();
6885: }
6886: }
6887:
6888: function makeexamupload() {
6889: var title=prompt('$js_lt{"p_mxu"}');
6890: if (title) {
6891: this.document.forms.newexamupload.importdetail.value=
6892: escape(title)+'=/res/lib/templates/examupload.problem';
6893: this.document.forms.newexamupload.submit();
6894: }
6895: }
6896:
6897: function makesmppage() {
6898: var title=prompt('$js_lt{"p_msp"}');
6899: if (title) {
6900: this.document.forms.newsmppg.importdetail.value=
6901: escape(title)+'=/adm/$udom/$uname/new/smppg';
6902: this.document.forms.newsmppg.submit();
6903: }
6904: }
6905:
6906: function makewebpage(type) {
6907: var title=prompt('$js_lt{"p_mwp"}');
6908: var formname;
6909: if (type == 'supp') {
6910: formname = this.document.forms.supwebpage;
6911: } else {
6912: formname = this.document.forms.newwebpage;
6913: }
6914: if (title) {
6915: var webpage = formname.importdetail.value;
6916: formname.importdetail.value = escape(title)+'='+webpage;
6917: formname.submit();
6918: }
6919: }
6920:
6921: function makesmpproblem() {
6922: var title=prompt('$js_lt{"p_msb"}');
6923: if (title) {
6924: this.document.forms.newsmpproblem.importdetail.value=
6925: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6926: this.document.forms.newsmpproblem.submit();
6927: }
6928: }
6929:
6930: function makedropbox() {
6931: var title=prompt('$js_lt{"p_mdb"}');
6932: if (title) {
6933: this.document.forms.newdropbox.importdetail.value=
6934: escape(title)+'=/res/lib/templates/DropBox.problem';
6935: this.document.forms.newdropbox.submit();
6936: }
6937: }
6938:
6939: function makebulboard() {
6940: var title=prompt('$js_lt{"p_mbb"}');
6941: if (title) {
6942: this.document.forms.newbul.importdetail.value=
6943: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
6944: this.document.forms.newbul.submit();
6945: }
6946: }
6947:
6948: function makeabout() {
6949: var user=prompt("$js_lt{'p_mab'}");
6950: if (user) {
6951: var comp=new Array();
6952: comp=user.split(':');
6953: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6954: if ((comp[0]) && (comp[1])) {
6955: this.document.forms.newaboutsomeone.importdetail.value=
6956: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
6957: this.document.forms.newaboutsomeone.submit();
6958: } else {
6959: alert("$js_lt{'p_mab_alrt1'}");
6960: }
6961: } else {
6962: alert("$js_lt{'p_mab_alrt2'}");
6963: }
6964: }
6965: }
6966:
6967: function makenew(targetform) {
6968: targetform.submit();
6969: }
6970:
6971: function changename(folderpath,index,oldtitle) {
6972: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6973: if (title) {
6974: this.document.forms.renameform.markcopy.value='';
6975: this.document.forms.renameform.title.value=title;
6976: this.document.forms.renameform.cmd.value='rename_'+index;
6977: this.document.forms.renameform.folderpath.value=folderpath;
6978: this.document.forms.renameform.submit();
6979: }
6980: }
6981:
6982: ENDNEWSCRIPT
6983: } else {
6984: $jsmakefunctions = <<ENDNEWSCRIPT;
6985:
6986: function makenewfolder() {
6987: alert("$js_lt{'edri'}");
6988: }
6989:
6990: function makenewpage() {
6991: alert("$js_lt{'edri'}");
6992: }
6993:
6994: function makeexamupload() {
6995: alert("$js_lt{'edri'}");
6996: }
6997:
6998: function makesmppage() {
6999: alert("$js_lt{'edri'}");
7000: }
7001:
7002: function makewebpage(type) {
7003: alert("$js_lt{'edri'}");
7004: }
7005:
7006: function makesmpproblem() {
7007: alert("$js_lt{'edri'}");
7008: }
7009:
7010: function makedropbox() {
7011: alert("$js_lt{'edri'}");
7012: }
7013:
7014: function makebulboard() {
7015: alert("$js_lt{'edri'}");
7016: }
7017:
7018: function makeabout() {
7019: alert("$js_lt{'edri'}");
7020: }
7021:
7022: function changename() {
7023: alert("$js_lt{'edri'}");
7024: }
7025:
7026: function makenew() {
7027: alert("$js_lt{'edri'}");
7028: }
7029:
7030: function groupimport() {
7031: alert("$js_lt{'edri'}");
7032: }
7033:
7034: function groupsearch() {
7035: alert("$js_lt{'edri'}");
7036: }
7037:
7038: function groupopen(url,recover) {
7039: var options="scrollbars=1,resizable=1,menubar=0";
7040: idxflag=1;
7041: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7042: idx.focus();
7043: }
7044:
7045: ENDNEWSCRIPT
7046:
7047: }
7048: return <<ENDSCRIPT;
7049:
7050: $jsmakefunctions
7051:
7052: function toggleUpload(caller) {
7053: var blocks = Array($fieldsets);
7054: for (var i=0; i<blocks.length; i++) {
7055: var disp = 'none';
7056: if (caller == blocks[i]) {
7057: var curr = document.getElementById('upload'+caller+'form').style.display;
7058: if (curr == 'none') {
7059: disp='block';
7060: }
7061: }
7062: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7063: if ((caller == 'tool') || (caller == 'supptool')) {
7064: if (disp == 'block') {
7065: if (document.getElementById('LC_exttoolid')) {
7066: var toolselector = document.getElementById('LC_exttoolid');
7067: var suppflag = 0;
7068: if (caller == 'supptool') {
7069: suppflag = 1;
7070: }
7071: currForm = document.getElementById('new'+caller);
7072: updateExttool(toolselector,currForm,suppflag);
7073: }
7074: }
7075: }
7076: }
7077: resize_scrollbox('contentscroll','1','1');
7078: return;
7079: }
7080:
7081: function toggleMap(caller) {
7082: var disp = 'none';
7083: if (document.getElementById('importmapform')) {
7084: if (caller == 'map') {
7085: var curr = document.getElementById('importmapform').style.display;
7086: if (curr == 'none') {
7087: disp='block';
7088: }
7089: }
7090: document.getElementById('importmapform').style.display=disp;
7091: resize_scrollbox('contentscroll','1','1');
7092: }
7093: return;
7094: }
7095:
7096: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7097: var disp = 'none';
7098: if (document.getElementById('crsresform')) {
7099: if (caller == 'res') {
7100: var curr = document.getElementById('crsresform').style.display;
7101: if (curr == 'none') {
7102: disp='block';
7103: numauthor = parseInt(numauthorrole);
7104: if (numauthor > 0) {
7105: document.courseresform.authorrole.selectedIndex = 0;
7106: select1priv_changed();
7107: document.courseresform.authorpath.selectedIndex = 0;
7108: document.courseresform.newresourceadd.selectedIndex = 0;
7109: toggleNewInCourse(document.courseresform);
7110: if (document.getElementById('newresource')) {
7111: document.getElementById('newresource').style.display = 'none';
7112: }
7113: } else {
7114: if (numcrsdirs) {
7115: document.courseresform.authorpath.selectedIndex = 0;
7116: }
7117: }
7118: if (document.courseresform.newresusetemp.length) {
7119: document.courseresform.newresusetemp[0].checked = true;
7120: toggleWithTemplate(document.courseresform);
7121: }
7122: document.courseresform.newresourcename.value = '';
7123: }
7124: }
7125: if (document.courseresform.newsubdir.length) {
7126: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7127: if (document.courseresform.newsubdir[j].value == 0) {
7128: document.courseresform.newsubdir[j].checked = true;
7129: }
7130: break;
7131: }
7132: if (document.getElementById('newsubdirname')) {
7133: document.getElementById('newsubdirname').type = "hidden";
7134: document.getElementById('newsubdirname').value = "";
7135: }
7136: if (document.getElementById('newsubdir')) {
7137: document.getElementById('newsubdir').innerHTML = "";
7138: }
7139: }
7140: document.getElementById('crsresform').style.display=disp;
7141: resize_scrollbox('contentscroll','1','0');
7142: }
7143: return;
7144: }
7145:
7146: function toggleNewsubdir(form) {
7147: if (form.newsubdir.length) {
7148: for (var j=0; j<form.newsubdir.length; j++) {
7149: if (form.newsubdir[j].checked) {
7150: if (document.getElementById('newsubdirname')) {
7151: if (form.newsubdir[j].value == '1') {
7152: document.getElementById('newsubdirname').type = "text";
7153: if (document.getElementById('newsubdir')) {
7154: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7155: }
7156: } else {
7157: document.getElementById('newsubdirname').type = "hidden";
7158: document.getElementById('newsubdirname').value = "";
7159: document.getElementById('newsubdir').innerHTML = "";
7160: }
7161: }
7162: break;
7163: }
7164: }
7165: }
7166: }
7167:
7168: function toggleCrsResTitle() {
7169: if (document.getElementById('newresource')) {
7170: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7171: document.getElementById('newresource').style.display = 'inline';
7172: document.courseresform.newresourceadd[0].checked = true;
7173: toggleNewInCourse(document.courseresform);
7174: } else {
7175: document.getElementById('newresource').style.display = 'none';
7176: }
7177: }
7178: }
7179:
7180: function toggleNewInCourse(form) {
7181: if (form.newresourceadd.length) {
7182: for (var i=0; i<form.newresourceadd.length; i++) {
7183: if (form.newresourceadd[i].checked) {
7184: if (document.getElementById('newresourcetitle')) {
7185: if (form.newresourceadd[i].value == '1') {
7186: document.getElementById('newresourcetitle').type = 'text';
7187: if (document.getElementById('newrestitle')) {
7188: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7189: }
7190: } else {
7191: document.getElementById('newresourcetitle').type = 'hidden';
7192: document.getElementById('newresourcetitle').value = '';
7193: if (document.getElementById('newrestitle')) {
7194: document.getElementById('newrestitle').innerHTML = '';
7195: }
7196: }
7197: }
7198: break;
7199: }
7200: }
7201: }
7202: }
7203:
7204: function toggleWithTemplate(form) {
7205: if (form.newresusetemp.length) {
7206: for (var i=0; i<form.newresusetemp.length; i++) {
7207: if (form.newresusetemp[i].checked) {
7208: if (document.getElementById('newrestemplate')) {
7209: if (form.newresusetemp[i].value == '1') {
7210: document.getElementById('newrestemplate').style.display = 'inline';
7211: toggleExampleText();
7212: } else {
7213: form.tempcategory.selectedIndex = 0;
7214: select1template_changed();
7215: document.getElementById('newrestemplate').style.display = 'none';
7216: }
7217: }
7218: }
7219: }
7220: }
7221: }
7222:
7223: function toggleExampleText() {
7224: if (document.getElementById('newresexample')) {
7225: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7226: if (url == '') {
7227: document.getElementById('newresexample').style.fontWeight = 'normal';
7228: } else {
7229: document.getElementById('newresexample').style.fontWeight = 'bold';
7230: }
7231: }
7232: }
7233:
7234: function getExample(width,height,scrolling,transparency) {
7235: var url;
7236: if (document.courseresform.newresusetemp.length) {
7237: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7238: if (document.courseresform.newresusetemp[i].checked) {
7239: if (document.courseresform.newresusetemp[i].value == '1') {
7240: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7241: if (url == '') {
7242: alert('Pick a category and template');
7243: } else {
7244: url = url.replace("$londocroot","");
7245: url += '?inhibitmenu=yes';
7246: }
7247: }
7248: break;
7249: }
7250: }
7251: }
7252: if (url != '') {
7253: openMyModal(url,width,height,scrolling,transparency,'');
7254: }
7255: }
7256:
7257: function toggleImportCrsres(caller,dircount) {
7258: var disp = 'none';
7259: if (document.getElementById('importcrsresform')) {
7260: if (caller == 'res') {
7261: var numdirs = parseInt(dircount);
7262: var curr = document.getElementById('importcrsresform').style.display;
7263: if (curr == 'none') {
7264: disp='block';
7265: if (numdirs > 1) {
7266: select1res_changed();
7267: }
7268: }
7269: }
7270: document.getElementById('importcrsresform').style.display=disp;
7271: resize_scrollbox('contentscroll','1','0');
7272: }
7273: return;
7274: }
7275:
7276: function makeims(imsform) {
7277: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7278: alert("$js_lt{'imsfile'}");
7279: return;
7280: }
7281: if (imsform.source.selectedIndex == 0) {
7282: alert("$js_lt{'imscms'}");
7283: return;
7284: }
7285: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7286: imsform.submit();
7287: }
7288:
7289: function updatePick(targetform,index,caller) {
7290: var pickitem;
7291: var picknumitem;
7292: var picknumtext;
7293: if (index == 'all') {
7294: pickitem = document.getElementById('randompickall');
7295: picknumitem = document.getElementById('rpicknumall');
7296: picknumtext = document.getElementById('rpicktextall');
7297: } else {
7298: pickitem = document.getElementById('randompick_'+index);
7299: picknumitem = document.getElementById('rpicknum_'+index);
7300: picknumtext = document.getElementById('randompicknum_'+index);
7301: }
7302: if (pickitem.checked) {
7303: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7304: if (picknum == '' || picknum == null) {
7305: if (caller == 'check') {
7306: pickitem.checked=false;
7307: if (index == 'all') {
7308: picknumtext.innerHTML = '';
7309: if (caller == 'link') {
7310: propagateState(targetform,'rpicknum');
7311: }
7312: } else {
7313: checkForSubmit(targetform,'randompick','settings');
7314: }
7315: }
7316: } else {
7317: picknum.toString();
7318: var regexdigit=/^\\d+\$/;
7319: if (regexdigit.test(picknum)) {
7320: picknumitem.value = picknum;
7321: if (index == 'all') {
7322: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7323: if (caller == 'link') {
7324: propagateState(targetform,'rpicknum');
7325: }
7326: } else {
7327: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7328: checkForSubmit(targetform,'randompick','settings');
7329: }
7330: } else {
7331: if (caller == 'check') {
7332: if (index == 'all') {
7333: picknumtext.innerHTML = '';
7334: if (caller == 'link') {
7335: propagateState(targetform,'rpicknum');
7336: }
7337: } else {
7338: pickitem.checked=false;
7339: checkForSubmit(targetform,'randompick','settings');
7340: }
7341: }
7342: return;
7343: }
7344: }
7345: } else {
7346: picknumitem.value = '';
7347: picknumtext.innerHTML = '';
7348: if (index == 'all') {
7349: if (caller == 'link') {
7350: propagateState(targetform,'rpicknum');
7351: }
7352: } else {
7353: checkForSubmit(targetform,'randompick','settings');
7354: }
7355: }
7356: }
7357:
7358: function propagateState(form,param) {
7359: if (document.getElementById(param+'all')) {
7360: var setcheck = 0;
7361: var rpick = 0;
7362: if (param == 'rpicknum') {
7363: if (document.getElementById('randompickall')) {
7364: if (document.getElementById('randompickall').checked) {
7365: if (document.getElementById('rpicknumall')) {
7366: rpick = document.getElementById('rpicknumall').value;
7367: }
7368: }
7369: }
7370: } else {
7371: if (document.getElementById(param+'all').checked) {
7372: setcheck = 1;
7373: }
7374: }
7375: var allidxlist;
7376: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7377: if (document.getElementById('all'+param+'idx')) {
7378: allidxlist = document.getElementById('all'+param+'idx').value;
7379: }
7380: var actions = new Array ('remove','cut','copy');
7381: for (var i=0; i<actions.length; i++) {
7382: if (actions[i] != param) {
7383: if (document.getElementById(actions[i]+'all')) {
7384: document.getElementById(actions[i]+'all').checked = false;
7385: }
7386: }
7387: }
7388: }
7389: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
7390: allidxlist = form.allidx.value;
7391: }
7392: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7393: allidxlist = form.allmapidx.value;
7394: }
7395: if ((allidxlist != '') && (allidxlist != null)) {
7396: var allidxs = allidxlist.split(',');
7397: if (allidxs.length > 1) {
7398: for (var i=0; i<allidxs.length; i++) {
7399: if (document.getElementById(param+'_'+allidxs[i])) {
7400: if (param == 'rpicknum') {
7401: if (document.getElementById('randompick_'+allidxs[i])) {
7402: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7403: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7404: if (rpick > 0) {
7405: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7406: } else {
7407: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7408: }
7409: }
7410: }
7411: } else {
7412: if (setcheck == 1) {
7413: document.getElementById(param+'_'+allidxs[i]).checked = true;
7414: } else {
7415: document.getElementById(param+'_'+allidxs[i]).checked = false;
7416: if (param == 'randompick') {
7417: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7418: }
7419: }
7420: }
7421: }
7422: }
7423: if (setcheck == 1) {
7424: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7425: var actions = new Array('copy','cut','remove');
7426: for (var i=0; i<actions.length; i++) {
7427: var otheractions;
7428: var otheridxs;
7429: if (actions[i] === param) {
7430: continue;
7431: } else {
7432: if (document.getElementById('all'+actions[i]+'idx')) {
7433: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7434: otheridxs = otheractions.split(',');
7435: if (otheridxs.length > 1) {
7436: for (var j=0; j<otheridxs.length; j++) {
7437: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7438: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7439: }
7440: }
7441: }
7442: }
7443: }
7444: }
7445: }
7446: }
7447: }
7448: }
7449: }
7450: return;
7451: }
7452:
7453: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
7454: var canedit = '$canedit';
7455: if (canedit == '') {
7456: alert("$js_lt{'edri'}");
7457: return;
7458: }
7459: var dosettings;
7460: var doaction;
7461: var control = document.togglemultsettings;
7462: if (context == 'actions') {
7463: control = document.togglemultactions;
7464: doaction = 1;
7465: } else {
7466: dosettings = 1;
7467: }
7468: if (control) {
7469: if (control.showmultpick.length) {
7470: for (var i=0; i<control.showmultpick.length; i++) {
7471: if (control.showmultpick[i].checked) {
7472: if (control.showmultpick[i].value == 1) {
7473: if (context == 'settings') {
7474: dosettings = 0;
7475: } else {
7476: doaction = 0;
7477: }
7478: }
7479: }
7480: }
7481: }
7482: }
7483: if (context == 'settings') {
7484: if (dosettings == 1) {
7485: targetform.changeparms.value=param;
7486: targetform.submit();
7487: }
7488: }
7489: if (context == 'actions') {
7490: if (doaction == 1) {
7491: targetform.cmd.value=param+'_'+index;
7492: targetform.folderpath.value=folderpath;
7493: targetform.markcopy.value=idx+':'+param;
7494: targetform.copyfolder.value=folder+'.'+container;
7495: if (param == 'remove') {
7496: var doremove = 0;
7497: if (skip_confirm) {
7498: if (confirm_removal) {
7499: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7500: doremove = 1;
7501: }
7502: } else {
7503: doremove = 1;
7504: }
7505: } else {
7506: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7507: doremove = 1;
7508: }
7509: }
7510: if (doremove) {
7511: targetform.markcopy.value='';
7512: targetform.copyfolder.value='';
7513: targetform.submit();
7514: }
7515: }
7516: if (param == 'cut') {
7517: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
7518: targetform.submit();
7519: return;
7520: }
7521: }
7522: if (param == 'copy') {
7523: targetform.submit();
7524: return;
7525: }
7526: targetform.markcopy.value='';
7527: targetform.copyfolder.value='';
7528: targetform.cmd.value='';
7529: targetform.folderpath.value='';
7530: return;
7531: } else {
7532: if (document.getElementById(param+'_'+idx)) {
7533: item = document.getElementById(param+'_'+idx);
7534: if (item.type == 'checkbox') {
7535: if (item.checked) {
7536: item.checked = false;
7537: } else {
7538: item.checked = true;
7539: singleCheck(item,idx,param);
7540: }
7541: }
7542: }
7543: }
7544: }
7545: return;
7546: }
7547:
7548: function singleCheck(caller,idx,action) {
7549: actions = new Array('cut','copy','remove');
7550: if (caller.checked) {
7551: for (var i=0; i<actions.length; i++) {
7552: if (actions[i] != action) {
7553: if (document.getElementById(actions[i]+'_'+idx)) {
7554: if (document.getElementById(actions[i]+'_'+idx).checked) {
7555: document.getElementById(actions[i]+'_'+idx).checked = false;
7556: }
7557: }
7558: }
7559: }
7560: }
7561: return;
7562: }
7563:
7564: function unselectInactive(nav) {
7565: currentNav = document.getElementById(nav);
7566: currentLis = currentNav.getElementsByTagName('LI');
7567: for (i = 0; i < currentLis.length; i++) {
7568: if (currentLis[i].className == 'goback') {
7569: currentLis[i].className = 'goback';
7570: } else {
7571: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
7572: currentLis[i].className = 'right';
7573: } else {
7574: currentLis[i].className = 'i';
7575: }
7576: }
7577: }
7578: }
7579:
7580: function hideAll(current, nav, data) {
7581: unselectInactive(nav);
7582: if (current) {
7583: if (current.className == 'right'){
7584: current.className = 'right active'
7585: } else {
7586: current.className = 'active';
7587: }
7588: }
7589: currentData = document.getElementById(data);
7590: currentDivs = currentData.getElementsByTagName('DIV');
7591: for (i = 0; i < currentDivs.length; i++) {
7592: if(currentDivs[i].className == 'LC_ContentBox'){
7593: currentDivs[i].style.display = 'none';
7594: }
7595: }
7596: }
7597:
7598: function openTabs(pageId) {
7599: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
7600: if(tabnav.length > 2 ){
7601: currentNav = document.getElementById(tabnav[1].id);
7602: currentLis = currentNav.getElementsByTagName('LI');
7603: for(i = 0; i< currentLis.length; i++){
7604: if(currentLis[i].className == 'active') {
7605: funcString = currentLis[i].onclick.toString();
7606: tab = funcString.split('"');
7607: if(tab.length < 2) {
7608: tab = funcString.split("'");
7609: }
7610: currentData = document.getElementById(tab[1]);
7611: currentData.style.display = 'block';
7612: }
7613: }
7614: }
7615: }
7616:
7617: function showPage(current, pageId, nav, data) {
7618: currstate = current.className;
7619: hideAll(current, nav, data);
7620: openTabs(pageId);
7621: unselectInactive(nav);
7622: if ((currstate == 'active') || (currstate == 'right active')) {
7623: if (currstate == 'active') {
7624: current.className = '';
7625: } else {
7626: current.className = 'right';
7627: }
7628: activeTab = '';
7629: toggleUpload();
7630: toggleMap();
7631: toggleCrsRes();
7632: toggleImportCrsres();
7633: resize_scrollbox('contentscroll','1','0');
7634: return;
7635: } else {
7636: current.className = 'active';
7637: }
7638: currentData = document.getElementById(pageId);
7639: currentData.style.display = 'block';
7640: activeTab = pageId;
7641: toggleUpload();
7642: toggleMap();
7643: toggleCrsRes();
7644: toggleImportCrsres();
7645: if (nav == 'mainnav') {
7646: var storedpath = "$docs_folderpath";
7647: var storedpage = "$main_container_page";
7648: var reg = new RegExp("^supplemental");
7649: if (pageId == 'mainCourseDocuments') {
7650: if (storedpage == 1) {
7651: document.simpleedit.folderpath.value = '';
7652: document.uploaddocument.folderpath.value = '';
7653: } else {
7654: if (reg.test(storedpath)) {
7655: document.simpleedit.folderpath.value = '$toplevelmain';
7656: document.uploaddocument.folderpath.value = '$toplevelmain';
7657: document.newext.folderpath.value = '$toplevelmain';
7658: } else {
7659: document.simpleedit.folderpath.value = storedpath;
7660: document.uploaddocument.folderpath.value = storedpath;
7661: document.newext.folderpath.value = storedpath;
7662: }
7663: }
7664: } else {
7665: if (reg.test(storedpath)) {
7666: document.simpleedit.folderpath.value = storedpath;
7667: document.supuploaddocument.folderpath.value = storedpath;
7668: document.supnewext.folderpath.value = storedpath;
7669: } else {
7670: document.simpleedit.folderpath.value = '$toplevelsupp';
7671: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7672: document.supnewext.folderpath.value = '$toplevelsupp';
7673: }
7674: }
7675: }
7676: resize_scrollbox('contentscroll','1','0');
7677: return false;
7678: }
7679:
7680: function toContents(jumpto) {
7681: var newurl = '$backtourl';
7682: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
7683: newurl = newurl+'?postdata='+jumpto;
7684: }
7685: location.href=newurl;
7686: }
7687:
7688: function togglePick(caller,value) {
7689: var disp = 'none';
7690: if (document.getElementById('multi'+caller)) {
7691: var curr = document.getElementById('multi'+caller).style.display;
7692: if (value == 1) {
7693: disp='block';
7694: }
7695: if (curr == disp) {
7696: return;
7697: }
7698: document.getElementById('multi'+caller).style.display=disp;
7699: if (value == 1) {
7700: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
7701: } else {
7702: document.getElementById('more'+caller).innerHTML = '';
7703: }
7704: if (caller == 'actions') {
7705: setClass(value);
7706: setBoxes(value);
7707: }
7708: }
7709: var showButton = multiSettings();
7710: if (showButton != 1) {
7711: showButton = multiActions();
7712: }
7713: if (document.getElementById('multisave')) {
7714: if (showButton == 1) {
7715: document.getElementById('multisave').style.display='block';
7716: } else {
7717: document.getElementById('multisave').style.display='none';
7718: }
7719: }
7720: resize_scrollbox('contentscroll','1','1');
7721: return;
7722: }
7723:
7724: function toggleCheckUncheck(caller,more) {
7725: if (more == 1) {
7726: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
7727: document.getElementById('allfields'+caller).style.display='block';
7728: } else {
7729: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
7730: document.getElementById('allfields'+caller).style.display='none';
7731: }
7732: resize_scrollbox('contentscroll','1','1');
7733: }
7734:
7735: function multiSettings() {
7736: var inuse = 0;
7737: var settingsform = document.togglemultsettings;
7738: if (settingsform.showmultpick.length > 1) {
7739: for (var i=0; i<settingsform.showmultpick.length; i++) {
7740: if (settingsform.showmultpick[i].checked) {
7741: if (settingsform.showmultpick[i].value == 1) {
7742: inuse = 1;
7743: }
7744: }
7745: }
7746: }
7747: return inuse;
7748: }
7749:
7750: function multiActions() {
7751: var inuse = 0;
7752: var actionsform = document.togglemultactions;
7753: if (actionsform.showmultpick.length > 1) {
7754: for (var i=0; i<actionsform.showmultpick.length; i++) {
7755: if (actionsform.showmultpick[i].checked) {
7756: if (actionsform.showmultpick[i].value == 1) {
7757: inuse = 1;
7758: }
7759: }
7760: }
7761: }
7762: return inuse;
7763: }
7764:
7765: function checkSubmits() {
7766: var numchanges = 0;
7767: var form = document.saveactions;
7768: var doactions = multiActions();
7769: var cutwarnings = 0;
7770: var remwarnings = 0;
7771: var removalinfo = 0;
7772: if (doactions == 1) {
7773: var remidxlist = document.cumulativeactions.allremoveidx.value;
7774: if ((remidxlist != '') && (remidxlist != null)) {
7775: var remidxs = remidxlist.split(',');
7776: for (var i=0; i<remidxs.length; i++) {
7777: if (document.getElementById('remove_'+remidxs[i])) {
7778: if (document.getElementById('remove_'+remidxs[i]).checked) {
7779: form.multiremove.value += remidxs[i]+',';
7780: numchanges ++;
7781: if (document.getElementById('skip_remove_'+remidxs[i])) {
7782: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7783: remwarnings ++;
7784: }
7785: }
7786: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7787: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7788: removalinfo ++;
7789: }
7790: }
7791: }
7792: }
7793: }
7794: }
7795: var cutidxlist = document.cumulativeactions.allcutidx.value;
7796: if ((cutidxlist != '') && (cutidxlist != null)) {
7797: var cutidxs = cutidxlist.split(',');
7798: for (var i=0; i<cutidxs.length; i++) {
7799: if (document.getElementById('cut_'+cutidxs[i])) {
7800: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7801: form.multicut.value += cutidxs[i]+',';
7802: numchanges ++;
7803: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7804: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7805: cutwarnings ++;
7806: }
7807: }
7808: }
7809: }
7810: }
7811: }
7812: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7813: if ((copyidxlist != '') && (copyidxlist != null)) {
7814: var copyidxs = copyidxlist.split(',');
7815: for (var i=0; i<copyidxs.length; i++) {
7816: if (document.getElementById('copy_'+copyidxs[i])) {
7817: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7818: form.multicopy.value += copyidxs[i]+',';
7819: numchanges ++;
7820: }
7821: }
7822: }
7823: }
7824: if (numchanges > 0) {
7825: form.multichange.value = numchanges;
7826: }
7827: }
7828: var dosettings = multiSettings();
7829: var haschanges = 0;
7830: if (dosettings == 1) {
7831: form.allencrypturl.value = '';
7832: form.allhiddenresource.value = '';
7833: form.changeparms.value = 'all';
7834: var patt=new RegExp(",\$");
7835: var allidxlist = document.cumulativesettings.allidx.value;
7836: if ((allidxlist != '') && (allidxlist != null)) {
7837: var allidxs = allidxlist.split(',');
7838: if (allidxs.length > 1) {
7839: for (var i=0; i<allidxs.length; i++) {
7840: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7841: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7842: form.allhiddenresource.value += allidxs[i]+',';
7843: }
7844: }
7845: if (document.getElementById('encrypturl_'+allidxs[i])) {
7846: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7847: form.allencrypturl.value += allidxs[i]+',';
7848: }
7849: }
7850: }
7851: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7852: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7853: }
7854: }
7855: form.allrandompick.value = '';
7856: form.allrandomorder.value = '';
7857: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7858: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7859: var allmapidxs = allmapidxlist.split(',');
7860: for (var i=0; i<allmapidxs.length; i++) {
7861: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7862: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7863: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7864: if ((randompick.checked) && (rpicknum.value != '')) {
7865: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7866: }
7867: if (randorder.checked) {
7868: form.allrandomorder.value += allmapidxs[i]+',';
7869: }
7870: }
7871: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7872: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7873: }
7874: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7875: haschanges = 1;
7876: }
7877: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7878: haschanges = 1;
7879: }
7880: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7881: haschanges = 1;
7882: }
7883: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7884: haschanges = 1;
7885: }
7886: }
7887: if (doactions == 1) {
7888: if (numchanges > 0) {
7889: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
7890: if (remwarnings > 0) {
7891: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
7892: return false;
7893: }
7894: }
7895: if (removalinfo > 0) {
7896: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7897: return false;
7898: }
7899: }
7900: if (cutwarnings > 0) {
7901: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
7902: return false;
7903: }
7904: }
7905: }
7906: form.submit();
7907: return true;
7908: }
7909: }
7910: if (dosettings == 1) {
7911: if (haschanges == 1) {
7912: form.submit();
7913: return true;
7914: }
7915: }
7916: if ((dosettings == 1) && (doactions == 1)) {
7917: alert("$js_lt{'noor'}");
7918: } else {
7919: if (dosettings == 1) {
7920: alert("$js_lt{'noch'}");
7921: } else {
7922: alert("$js_lt{'noac'}");
7923: }
7924: }
7925: return false;
7926: }
7927:
7928: function setClass(value) {
7929: var cutclass = 'LC_docs_cut';
7930: var copyclass = 'LC_docs_copy';
7931: var removeclass = 'LC_docs_remove';
7932: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7933: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7934: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7935: var links = document.getElementsByTagName('a');
7936: for (var i=0; i<links.length; i++) {
7937: var classes = links[i].className;
7938: if (cutreg.test(classes)) {
7939: links[i].className = cutclass;
7940: if (value == 1) {
7941: links[i].className += " LC_menubuttons_link";
7942: }
7943: } else {
7944: if (copyreg.test(classes)) {
7945: links[i].className = copyclass;
7946: if (value == 1) {
7947: links[i].className += " LC_menubuttons_link";
7948: }
7949: } else {
7950: if (removereg.test(classes)) {
7951: links[i].className = removeclass;
7952: if (value == 1) {
7953: links[i].className += " LC_menubuttons_link";
7954: }
7955: }
7956: }
7957: }
7958: }
7959: return;
7960: }
7961:
7962: function setBoxes(value) {
7963: var remidxlist = document.cumulativeactions.allremoveidx.value;
7964: if ((remidxlist != '') && (remidxlist != null)) {
7965: var remidxs = remidxlist.split(',');
7966: for (var i=0; i<remidxs.length; i++) {
7967: if (document.getElementById('remove_'+remidxs[i])) {
7968: var item = document.getElementById('remove_'+remidxs[i]);
7969: if (value == 1) {
7970: item.className = 'LC_docs_remove';
7971: } else {
7972: item.className = 'LC_hidden';
7973: }
7974: }
7975: }
7976: }
7977: var cutidxlist = document.cumulativeactions.allcutidx.value;
7978: if ((cutidxlist != '') && (cutidxlist != null)) {
7979: var cutidxs = cutidxlist.split(',');
7980: for (var i=0; i<cutidxs.length; i++) {
7981: if (document.getElementById('cut_'+cutidxs[i])) {
7982: var item = document.getElementById('cut_'+cutidxs[i]);
7983: if (value == 1) {
7984: item.className = 'LC_docs_cut';
7985: } else {
7986: item.className = 'LC_hidden';
7987: }
7988: }
7989: }
7990: }
7991: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7992: if ((copyidxlist != '') && (copyidxlist != null)) {
7993: var copyidxs = copyidxlist.split(',');
7994: for (var i=0; i<copyidxs.length; i++) {
7995: if (document.getElementById('copy_'+copyidxs[i])) {
7996: var item = document.getElementById('copy_'+copyidxs[i]);
7997: if (value == 1) {
7998: item.className = 'LC_docs_copy';
7999: } else {
8000: item.className = 'LC_hidden';
8001: }
8002: }
8003: }
8004: }
8005: return;
8006: }
8007:
8008: function validImportCrsRes() {
8009: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8010: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8011: if ((fname == '') || (fname == null)) {
8012: alert("$js_lt{'nofi'}");
8013: return false;
8014: }
8015: var url = '/res/$coursedom/$coursenum/';
8016: if (path && path != '/') {
8017: url += path+'/';
8018: }
8019: if (fname != '') {
8020: url += fname;
8021: }
8022: var title = document.crsresimportform.crsrestitle.value;
8023: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8024: return true;
8025: }
8026:
8027: function validateNewRes(caller) {
8028: if (caller == 'single') {
8029: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8030: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8031: var resname = document.courseresform.newresourcename.value;
8032: }
8033: }
8034:
8035: ENDSCRIPT
8036: }
8037:
8038: sub history_tab_js {
8039: return <<"ENDHIST";
8040: function toggleHistoryDisp(choice) {
8041: document.docslogform.docslog.value = choice;
8042: document.docslogform.submit();
8043: return;
8044: }
8045:
8046: ENDHIST
8047: }
8048:
8049: sub inject_data_js {
8050: return <<ENDINJECT;
8051:
8052: function injectData(current, hiddenField, name, value) {
8053: currentElement = document.getElementById(hiddenField);
8054: currentElement.name = name;
8055: currentElement.value = value;
8056: current.submit();
8057: }
8058:
8059: ENDINJECT
8060: }
8061:
8062: sub dump_switchserver_js {
8063: my @hosts = @_;
8064: my %js_lt = &Apache::lonlocal::texthash(
8065: dump => 'Copying content to Authoring Space requires switching server.',
8066: swit => 'Switch server?',
8067: );
8068: my %html_js_lt = &Apache::lonlocal::texthash(
8069: swit => 'Switch server?',
8070: duco => 'Copying Content to Authoring Space',
8071: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8072: chos => 'Choose server',
8073: );
8074: &js_escape(\%js_lt);
8075: &html_escape(\%html_js_lt);
8076: &js_escape(\%html_js_lt);
8077: my $role = $env{'request.role'};
8078: my $js = <<"ENDSWJS";
8079: <script type="text/javascript">
8080: function write_switchserver() {
8081: var server;
8082: if (document.setserver.posshosts.length > 0) {
8083: for (var i=0; i<document.setserver.posshosts.length; i++) {
8084: if (document.setserver.posshosts[i].checked) {
8085: server = document.setserver.posshosts[i].value;
8086: }
8087: }
8088: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8089: }
8090: window.close();
8091: }
8092: </script>
8093:
8094: ENDSWJS
8095:
8096: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8097: {'only_body' => 1,
8098: 'js_ready' => 1,});
8099: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8100:
8101: my $hostpicker;
8102: my $count = 0;
8103: foreach my $host (sort(@hosts)) {
8104: my $checked;
8105: if ($count == 0) {
8106: $checked = ' checked="checked"';
8107: }
8108: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8109: $host.'"'.$checked.' />'.$host.'</label> ';
8110: $count++;
8111: }
8112:
8113: return <<"ENDSWITCHJS";
8114:
8115: function dump_needs_switchserver(url) {
8116: if (url!='' && url!= null) {
8117: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8118: go(url);
8119: }
8120: }
8121: return;
8122: }
8123:
8124: function choose_switchserver_window() {
8125: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8126: newWindow.document.open();
8127: newWindow.document.writeln('$startpage');
8128: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8129: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8130: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8131: '<form name="setserver" method="post" action="" \\/>\\n'+
8132: '$hostpicker\\n'+
8133: '<br \\/><br \\/>\\n'+
8134: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8135: 'onclick="write_switchserver();" \\/>\\n'+
8136: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8137: newWindow.document.writeln('$endpage');
8138: newWindow.document.close();
8139: newWindow.focus();
8140: }
8141:
8142: ENDSWITCHJS
8143: }
8144:
8145: sub makedocslogform {
8146: my ($formelems,$docslog) = @_;
8147: return <<"LOGSFORM";
8148: <form action="/adm/coursedocs" method="post" name="docslogform">
8149: <input type="hidden" name="docslog" value="$docslog" />
8150: $formelems
8151: </form>
8152: LOGSFORM
8153: }
8154:
8155: sub makesimpleeditform {
8156: my ($formelems) = @_;
8157: return <<"SIMPFORM";
8158: <form name="simpleedit" method="post" action="/adm/coursedocs">
8159: <input type="hidden" name="importdetail" value="" />
8160: $formelems
8161: </form>
8162: SIMPFORM
8163: }
8164:
8165: sub makenewproblem {
8166: my ($r,$coursedom,$coursenum) = @_;
8167: # Creating a new problem
8168: my ($redirect,$error);
8169: if ($env{'form.authorrole'}) {
8170: my ($newsubdir,$filename);
8171: if ($env{'form.newsubdir'}) {
8172: if ($env{'form.newsubdirname'} ne '') {
8173: $newsubdir = $env{'form.newsubdirname'};
8174: }
8175: }
8176: if ($env{'form.newresourcename'}) {
8177: $filename = $env{'form.newresourcename'};
8178: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8179: $filename =~ s/`//g;
8180: $filename =~ s{/\.\./}{_}g;
8181: $filename =~ s/\.+/./g;
8182: $filename =~ s{/+}{_}g;
8183: if ($filename ne '') {
8184: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8185: if (($ext) && ($ext ne '.problem')) {
8186: $filename = $name.'.problem';
8187: } elsif ($ext eq '') {
8188: $filename .= '.problem';
8189: }
8190: my $docroot = $r->dir_config('lonDocRoot');
8191: my @ids=&Apache::lonnet::current_machine_ids();
8192: if ($env{'form.authorrole'} eq 'author') {
8193: if ($env{'user.author'}) {
8194: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8195: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8196: my $path = $docroot.$url;
8197: my $subdir = $env{'form.authorpath'};
8198: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8199: }
8200: }
8201: } elsif ($env{'form.authorrole'} eq 'course') {
8202: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8203: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8204: my $url = "/priv/$coursedom/$coursenum";
8205: my $path=$docroot.$url;
8206: my $subdir = $env{'form.authorpath'};
8207: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8208: if ($redirect) {
8209: my $rightsfile = 'default.rights';
8210: my $sourcerights = "$path/$rightsfile";
8211: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8212: my $now = time;
8213: if (!-e $sourcerights) {
8214: my $cid = $coursedom.'_'.$coursenum;
8215: if (open(my $fh,">$sourcerights")) {
8216: print $fh <<END;
8217: <accessrule effect="deny" realm="" type="course" role="" />
8218: <accessrule effect="allow" realm="$cid" type="course" role="" />
8219: END
8220: close($fh);
8221: }
8222: }
8223: if (!-e "$sourcerights.meta") {
8224: if (open(my $fh,">$sourcerights.meta")) {
8225: my $author=$env{'environment.firstname'}.' '.
8226: $env{'environment.middlename'}.' '.
8227: $env{'environment.lastname'}.' '.
8228: $env{'environment.generation'};
8229: $author =~ s/\s+$//;
8230: print $fh <<"END";
8231:
8232: <abstract></abstract>
8233: <author>$author</author>
8234: <authorspace>$coursenum:$coursedom</authorspace>
8235: <copyright>private</copyright>
8236: <creationdate>$now</creationdate>
8237: <customdistributionfile></customdistributionfile>
8238: <dependencies></dependencies>
8239: <domain>$coursedom</domain>
8240: <highestgradelevel>0</highestgradelevel>
8241: <keywords></keywords>
8242: <language>notset </language>
8243: <lastrevisiondate>$now</lastrevisiondate>
8244: <lowestgradelevel>0</lowestgradelevel>
8245: <mime>rights</mime>
8246: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8247: <notes></notes>
8248: <obsolete></obsolete>
8249: <obsoletereplacement></obsoletereplacement>
8250: <owner>$coursenum:$coursedom</owner>
8251: <rule>deny:::course,allow:$cid::course</rule>
8252: <sourceavail></sourceavail>
8253: <standards></standards>
8254: <subject></subject>
8255: <title></title>
8256: END
8257: close($fh);
8258: }
8259: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8260: if (!-e "$docroot/res/$coursedom") {
8261: mkdir("$docroot/res/$coursedom",0755);
8262: }
8263: if (!-e "$docroot/res/$coursedom/$coursenum") {
8264: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8265: }
8266: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8267: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8268: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8269: }
8270: }
8271: }
8272: if ($env{'form.newresourceadd'}) {
8273: my $template = $env{'form.template'};
8274: my $source = $docroot.$redirect;
8275: my $target = $redirect;
8276: $target =~ s{^/priv/}{/res/};
8277: $target = $docroot.$target;
8278: if (!-e $source) {
8279: my $copyfrom;
8280: if ($template) {
8281: my %templates;
8282: my @files = &Apache::lonhomework::get_template_list('problem');
8283: foreach my $poss (@files) {
8284: if (ref($poss) eq 'ARRAY') {
8285: if ($template eq $poss->[0]) {
8286: $templates{$template} = 1;
8287: last;
8288: }
8289: }
8290: }
8291: if ($templates{$template}) {
8292: $copyfrom = $template;
8293: }
8294: }
8295: unless ($copyfrom) {
8296: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8297: }
8298: &File::Copy::copy($copyfrom,$source);
8299: }
8300: if (!-e "$source.meta") {
8301: my $cid = $coursedom.'_'.$coursenum;
8302: my $now = time;
8303: if (open(my $fh,">$source.meta")) {
8304: my $author=$env{'environment.firstname'}.' '.
8305: $env{'environment.middlename'}.' '.
8306: $env{'environment.lastname'}.' '.
8307: $env{'environment.generation'};
8308: $author =~ s/\s+$//;
8309: my $title = $env{'form.newresourcetitle'};
8310: $title =~ s/^\s+|\s+$//g;
8311: print $fh <<END;
8312:
8313: <abstract></abstract>
8314: <author>$author</author>
8315: <authorspace>$coursenum:$coursedom</authorspace>
8316: <copyright>custom</copyright>
8317: <creationdate>$now</creationdate>
8318: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8319: <dependencies></dependencies>
8320: <domain>$coursedom</domain>
8321: <highestgradelevel>0</highestgradelevel>
8322: <keywords></keywords>
8323: <language>notset </language>
8324: <lastrevisiondate>$now</lastrevisiondate>
8325: <lowestgradelevel>0</lowestgradelevel>
8326: <mime>problem</mime>
8327: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8328: <notes></notes>
8329: <obsolete></obsolete>
8330: <obsoletereplacement></obsoletereplacement>
8331: <owner>$coursenum:$coursedom</owner>
8332: <sourceavail></sourceavail>
8333: <standards></standards>
8334: <subject></subject>
8335: <title>$title</title>
8336: END
8337: close($fh);
8338: }
8339: }
8340: }
8341: }
8342: }
8343: } else {
8344: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8345: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8346: if (grep(/^\Q$rolehome\E$/,@ids)) {
8347: my $now = time;
8348: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8349: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8350: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8351: my $url = "/priv/$audom/$auname";
8352: my $path = $r->dir_config('lonDocRoot').$url;
8353: my $subdir = $env{'form.authorpath'};
8354: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8355: }
8356: }
8357: }
8358: }
8359: }
8360: }
8361: }
8362: return ($redirect,$error);
8363: }
8364:
8365: sub finishnewprob {
8366: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
8367: unless (-d $path) {
8368: unless (mkdir($path,02770)) {
8369: return;
8370: }
8371: }
8372: my $redirect;
8373: if ($subdir ne '/') {
8374: $subdir = &cleandir($subdir);
8375: if (($subdir ne '') && (-d "$path/$subdir")) {
8376: $path .= "/$subdir";
8377: $url .= "/$subdir";
8378: }
8379: }
8380: my $dest;
8381: if ($newsubdir ne '') {
8382: $newsubdir = &cleandir($newsubdir);
8383: }
8384: if ($newsubdir ne '') {
8385: if (-d "$path/$newsubdir") {
8386: $dest = "$path/$newsubdir/$filename";
8387: } else {
8388: my $dirok;
8389: unless (-e "$path/$newsubdir") {
8390: if (mkdir("$path/$newsubdir",02770)) {
8391: if (chmod(02770,"$path/$newsubdir")) {
8392: $dirok = 1;
8393: }
8394: }
8395: }
8396: if ($dirok) {
8397: $dest = "$path/$newsubdir/$filename";
8398: }
8399: }
8400: if (($dest ne '') && (!-e $dest)) {
8401: $redirect = "$url/$newsubdir/$filename";
8402: }
8403: } else {
8404: $dest = "$path/$filename";
8405: if (($dest ne '') && (!-e $dest)) {
8406: $redirect = "$url/$filename";
8407: }
8408: }
8409: return $redirect;
8410: }
8411:
8412: sub cleandir {
8413: my ($dir) = @_;
8414: $dir =~ s/^\s+//;
8415: $dir =~ s/\s+$//;
8416: $dir =~ s/\.+//g;
8417: $dir =~ s/[\#\?&%\":]//g;
8418: return $dir;
8419: }
8420:
8421: 1;
8422: __END__
8423:
8424:
8425: =head1 NAME
8426:
8427: Apache::londocs.pm
8428:
8429: =head1 SYNOPSIS
8430:
8431: This is part of the LearningOnline Network with CAPA project
8432: described at http://www.lon-capa.org.
8433:
8434: =head1 SUBROUTINES
8435:
8436: =over
8437:
8438: =item %help=()
8439:
8440: Available help topics
8441:
8442: =item mapread()
8443:
8444: Mapread read maps into LONCAPA::map:: global arrays
8445: @order and @resources, determines status
8446: sets @order - pointer to resources in right order
8447: sets @resources - array with the resources with correct idx
8448:
8449: =item authorhosts()
8450:
8451: Return hash with valid author names
8452:
8453: =item clean()
8454:
8455: =item dumpcourse()
8456:
8457: Actually dump course
8458:
8459: =item group_import()
8460:
8461: Imports the given (name, url) resources into the course
8462: coursenum, coursedom, and folder must precede the list
8463:
8464: =item breadcrumbs()
8465:
8466: =item log_docs()
8467:
8468: =item docs_change_log()
8469:
8470: =item update_paste_buffer()
8471:
8472: =item print_paste_buffer()
8473:
8474: =item do_paste_from_buffer()
8475:
8476: =item do_buffer_empty()
8477:
8478: =item clear_from_buffer()
8479:
8480: =item get_newmap_url()
8481:
8482: =item dbcopy()
8483:
8484: =item uniqueness_check()
8485:
8486: =item contained_map_check()
8487:
8488: =item url_paste_fixups()
8489:
8490: =item apply_fixups()
8491:
8492: =item copy_dependencies()
8493:
8494: =item update_parameter()
8495:
8496: =item handle_edit_cmd()
8497:
8498: =item editor()
8499:
8500: =item process_file_upload()
8501:
8502: =item process_secondary_uploads()
8503:
8504: =item is_supplemental_title()
8505:
8506: =item entryline()
8507:
8508: =item tiehash()
8509:
8510: =item untiehash()
8511:
8512: =item checkonthis()
8513:
8514: check on this
8515:
8516: =item verifycontent()
8517:
8518: Verify Content
8519:
8520: =item devalidateversioncache() & checkversions()
8521:
8522: Check Versions
8523:
8524: =item mark_hash_old()
8525:
8526: =item is_hash_old()
8527:
8528: =item changewarning()
8529:
8530: =item init_breadcrumbs()
8531:
8532: Breadcrumbs for special functions
8533:
8534: =item create_list_elements()
8535:
8536: =item create_form_ul()
8537:
8538: =item startContentScreen()
8539:
8540: =item endContentScreen()
8541:
8542: =item supplemental_base()
8543:
8544: =item embedded_form_elems()
8545:
8546: =item embedded_destination()
8547:
8548: =item return_to_editor()
8549:
8550: =item decompression_info()
8551:
8552: =item decompression_phase_one()
8553:
8554: =item decompression_phase_two()
8555:
8556: =item remove_archive()
8557:
8558: =item generate_admin_menu()
8559:
8560: =item generate_edit_table()
8561:
8562: =item editing_js()
8563:
8564: =item history_tab_js()
8565:
8566: =item inject_data_js()
8567:
8568: =item dump_switchserver_js()
8569:
8570: =item resize_scrollbox_js()
8571:
8572: =item makedocslogform()
8573:
8574: =item makesimpleeditform()
8575:
8576: =back
8577:
8578: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>