File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.649:
download - view:
text,
annotated -
select for diffs
Fri Dec 29 16:01:33 2017 UTC (6 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Pasting resources from Clipboard in Course Editor.
- When a folder is copied, external tools within it (or in sub-folders)
are copied (and receive new unique instance identifiers).
- When an external tool is pasted into Supplemental Content, any gradable
setting is removed.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.649 2017/12/29 16:01:33 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 Apache::lonparmset();
49: use HTML::Entities;
50: use HTML::TokeParser;
51: use GDBM_File;
52: use File::MMagic;
53: use File::Copy;
54: use Apache::lonlocal;
55: use Cwd;
56: use UUID::Tiny ':std';
57: use LONCAPA qw(:DEFAULT :match);
58:
59: my $iconpath;
60:
61: my %hash;
62:
63: my $hashtied;
64: my %alreadyseen=();
65:
66: my $hadchanges;
67: my $suppchanges;
68:
69:
70: my %help=();
71:
72:
73: sub mapread {
74: my ($coursenum,$coursedom,$map)=@_;
75: return
76: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map);
78: }
79:
80: sub storemap {
81: my ($coursenum,$coursedom,$map,$contentchg)=@_;
82: my $report;
83: if (($contentchg) && ($map =~ /^default/)) {
84: $report = 1;
85: }
86: my ($outtext,$errtext)=
87: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
88: $map,1,$report);
89: if ($errtext) { return ($errtext,2); }
90:
91: if ($map =~ /^default/) {
92: $hadchanges=1;
93: } else {
94: $suppchanges=1;
95: }
96: return ($errtext,0);
97: }
98:
99:
100:
101: sub authorhosts {
102: my %outhash=();
103: my $home=0;
104: my $other=0;
105: foreach my $key (keys(%env)) {
106: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
107: my $role=$1;
108: my $realm=$2;
109: my ($start,$end)=split(/\./,$env{$key});
110: if (($start) && ($start>time)) { next; }
111: if (($end) && (time>$end)) { next; }
112: my ($ca,$cd);
113: if ($1 eq 'au') {
114: $ca=$env{'user.name'};
115: $cd=$env{'user.domain'};
116: } else {
117: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
118: }
119: my $allowed=0;
120: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
121: my @ids=&Apache::lonnet::current_machine_ids();
122: foreach my $id (@ids) {
123: if ($id eq $myhome) {
124: $allowed=1;
125: last;
126: }
127: }
128: if ($allowed) {
129: $home++;
130: $outhash{'home_'.$ca.':'.$cd}=1;
131: } else {
132: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
133: $other++;
134: }
135: }
136: }
137: return ($home,$other,%outhash);
138: }
139:
140:
141: sub clean {
142: my ($title)=@_;
143: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
144: return $title;
145: }
146:
147: sub default_folderpath {
148: my ($coursenum,$coursedom,$navmapref) = @_;
149: return unless ($coursenum && $coursedom && ref($navmapref));
150: # Check if entire course is hidden and/or encrypted
151: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
152: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
153: unless (ref($$navmapref)) {
154: $$navmapref = Apache::lonnavmaps::navmap->new();
155: }
156: if (ref($$navmapref)) {
157: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
158: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
159: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
160: unless (@resources) {
161: $hiddenmap = 1;
162: unless ($env{'request.role.adv'}) {
163: $hiddentop = 1;
164: if ($env{'form.folder'}) {
165: undef($env{'form.folder'});
166: }
167: }
168: }
169: }
170: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
171: $encryptmap = 1;
172: }
173: }
174: unless ($hiddentop) {
175: $folderpath='default&'.&escape(&mt('Main Content')).
176: '::'.$hiddenmap.':'.$encryptmap.'::';
177: }
178: if (wantarray) {
179: return ($folderpath,$hiddentop);
180: } else {
181: return $folderpath;
182: }
183: }
184:
185: sub dumpcourse {
186: my ($r) = @_;
187: my $crstype = &Apache::loncommon::course_type();
188: my ($starthash,$js);
189: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
190: $js = <<"ENDJS";
191: <script type="text/javascript">
192: // <![CDATA[
193:
194: function hide_searching() {
195: if (document.getElementById('searching')) {
196: document.getElementById('searching').style.display = 'none';
197: }
198: return;
199: }
200:
201: // ]]>
202: </script>
203: ENDJS
204: $starthash = {
205: add_entries => {'onload' => "hide_searching();"},
206: };
207: }
208: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
209: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
210: $r->print(&startContentScreen('tools'));
211: my ($home,$other,%outhash)=&authorhosts();
212: unless ($home) {
213: $r->print(&endContentScreen());
214: return '';
215: }
216: my $origcrsid=$env{'request.course.id'};
217: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
218: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
219: # Do the dumping
220: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
221: $r->print(&endContentScreen());
222: return '';
223: }
224: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
225: $r->print('<h3>'.&mt('Copying Files').'</h3>');
226: my $title=$env{'form.authorfolder'};
227: $title=&clean($title);
228: my ($navmap,$errormsg) =
229: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
230: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
231: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
232: my (%maps,%resources,%titles);
233: if (!ref($navmap)) {
234: $r->print($errormsg.
235: &endContentScreen());
236: return '';
237: } else {
238: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
239: 'dumpdocs',$cdom,$cnum);
240: }
241: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
242: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
243: %newcontent,%has_simpleprobs);
244: foreach my $item (sort {$a <=> $b} (@todump)) {
245: my $name = $env{'form.namefor_'.$item};
246: if ($resources{$item}) {
247: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
248: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
249: $tocopy{$1} = $name;
250: $display{$item} = $1;
251: $lookup{$1} = $item;
252: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
253: $simpleproblems{$item} = {
254: symb => $resources{$item},
255: name => $name,
256: };
257: $display{$item} = 'simpleproblem_'.$name;
258: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
259: $has_simpleprobs{$1}{$id} = $item;
260: }
261: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
262: my $marker = $1;
263: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
264: $simplepages{$item} = {
265: res => $res,
266: title => $titles{$item},
267: db => $db_name,
268: marker => $marker,
269: symb => $resources{$item},
270: name => $name,
271: };
272: $display{$item} = '/'.$res;
273: }
274: } elsif ($maps{$item}) {
275: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
276: $tocopy{$1} = $name;
277: $display{$item} = $1;
278: $lookup{$1} = $item;
279: }
280: } else {
281: next;
282: }
283: }
284: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
285: $crs=~s/\_/\//g;
286: my $mm = new File::MMagic;
287: my $prefix = "/uploaded/$cdom/$cnum/";
288: %replacehash = %tocopy;
289: foreach my $item (sort(keys(%simpleproblems))) {
290: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
291: $newcontent{$display{$item}} = $content;
292: }
293: my $gateway = Apache::lonhtmlgateway->new('web');
294: foreach my $item (sort(keys(%simplepages))) {
295: if (ref($simplepages{$item}) eq 'HASH') {
296: my $pagetitle = $simplepages{$item}{'title'};
297: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
298: my %contents;
299: foreach my $field (keys(%fields)) {
300: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
301: my $name = $1;
302: my $msg = $fields{$field};
303: if ($name eq 'webreferences') {
304: if ($msg =~ m{^https?://}) {
305: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
306: }
307: } else {
308: $msg = &Encode::decode('utf8',$msg);
309: $msg = $gateway->process_outgoing_html($msg,1);
310: $contents{$name} = $msg;
311: }
312: } elsif ($field eq 'uploaded.photourl') {
313: my $marker = $simplepages{$item}{marker};
314: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
315: my $filepath = $1;
316: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
317: if ($fname ne '') {
318: $fname=~s/\.(\w+)$//;
319: my $ext=$1;
320: $fname = &clean($fname);
321: $fname.='.'.$ext;
322: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
323: $replacehash{$filepath} = $relpath.$fname;
324: $deps{$item}{$filepath} = 1;
325: }
326: }
327: }
328: }
329: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
330: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
331: my $content = '
332: <html>
333: <head>
334: <title>'.$pagetitle.'</title>
335: </head>
336: <body bgcolor="#ffffff">';
337: if ($contents{title}) {
338: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
339: }
340: if ($contents{image}) {
341: $content .= "\n".$contents{image};
342: }
343: if ($contents{content}) {
344: $content .= '
345: <div class="LC_Box">
346: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
347: $contents{content}.'
348: </div>';
349: }
350: if ($contents{webreferences}) {
351: $content .= '
352: <div class="LC_Box">
353: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
354: $contents{webreferences}.'
355: </div>';
356: }
357: $content .= '
358: </body>
359: </html>
360: ';
361: $newcontent{'/'.$simplepages{$item}{res}} = $content;
362: }
363: }
364: foreach my $item (keys(%tocopy)) {
365: unless ($item=~/\.(sequence|page)$/) {
366: my $currurlpath = $prefix.$item;
367: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
368: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
369: }
370: }
371: foreach my $num (sort {$a <=> $b} (@todump)) {
372: my $src = $display{$num};
373: next if ($src eq '');
374: my @needcopy = ();
375: if ($replacehash{$src}) {
376: push(@needcopy,$src);
377: if (ref($deps{$num}) eq 'HASH') {
378: foreach my $dep (sort(keys(%{$deps{$num}}))) {
379: if ($replacehash{$dep}) {
380: push(@needcopy,$dep);
381: }
382: }
383: }
384: } elsif ($src =~ /^simpleproblem_/) {
385: push(@needcopy,$src);
386: }
387: next if (@needcopy == 0);
388: my ($result,$depresult);
389: for (my $i=0; $i<@needcopy; $i++) {
390: my $item = $needcopy[$i];
391: my $newfilename;
392: if ($simpleproblems{$num}) {
393: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
394: } else {
395: $newfilename=$title.'/'.$replacehash{$item};
396: }
397: $newfilename=~s/\.(\w+)$//;
398: my $ext=$1;
399: $newfilename=&clean($newfilename);
400: $newfilename.='.'.$ext;
401: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
402: if ($newrelpath ne $replacehash{$item}) {
403: $replacehash{$item} = $newrelpath;
404: }
405: my @dirs=split(/\//,$newfilename);
406: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
407: my $makepath=$path;
408: my $fail;
409: my $origin;
410: for (my $i=0;$i<$#dirs;$i++) {
411: $makepath.='/'.$dirs[$i];
412: unless (-e $makepath) {
413: unless(mkdir($makepath,0755)) {
414: $fail = &mt('Directory creation failed.');
415: }
416: }
417: }
418: if ($i == 0) {
419: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
420: } else {
421: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
422: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
423: &mt('(dependency)').'</span>: ';
424: }
425: if (-e $path.'/'.$newfilename) {
426: $fail = &mt('Destination already exists -- not overwriting.');
427: } else {
428: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
429: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
430: ($item =~ /^simpleproblem_/)) {
431: print $fh $newcontent{$item};
432: } else {
433: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
434: if (-e $fileloc) {
435: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
436: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
437: (ref($has_simpleprobs{$item}) eq 'HASH')) {
438: my %changes = %{$has_simpleprobs{$item}};
439: my $content = &Apache::lonclonecourse::rewritefile(
440: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
441: (%replacehash,$crs => '')
442: );
443: my $updatedcontent = '';
444: my $parser = HTML::TokeParser->new(\$content);
445: $parser->attr_encoded(1);
446: while (my $token = $parser->get_token) {
447: if ($token->[0] eq 'S') {
448: if (($token->[1] eq 'resource') &&
449: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
450: ($changes{$token->[2]->{'id'}})) {
451: my $id = $token->[2]->{'id'};
452: $updatedcontent .= '<'.$token->[1];
453: foreach my $attrib (@{$token->[3]}) {
454: next unless ($attrib =~ /^(src|type|title|id)$/);
455: if ($attrib eq 'src') {
456: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
457: if ($file) {
458: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
459: } else {
460: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
461: }
462: } else {
463: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
464: }
465: }
466: $updatedcontent .= ' />'."\n";
467: } else {
468: $updatedcontent .= $token->[4]."\n";
469: }
470: } else {
471: $updatedcontent .= $token->[2];
472: }
473: }
474: print $fh $updatedcontent;
475: } else {
476: print $fh &Apache::lonclonecourse::rewritefile(
477: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
478: (%replacehash,$crs => '')
479: );
480: }
481: } else {
482: print $fh
483: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
484: }
485: } else {
486: $fail = &mt('Source does not exist.');
487: }
488: }
489: $fh->close();
490: } else {
491: $fail = &mt('Could not write to destination.');
492: }
493: }
494: my $text;
495: if ($fail) {
496: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
497: } else {
498: $text = '<span class="LC_success">'.&mt('ok').'</span>';
499: }
500: if ($i == 0) {
501: $result .= $text;
502: } else {
503: $depresult .= $text.'</li>';
504: }
505: }
506: $r->print($result);
507: if ($depresult) {
508: $r->print('<ul>'.$depresult.'</ul>');
509: }
510: }
511: } else {
512: my ($navmap,$errormsg) =
513: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
514: if (!ref($navmap)) {
515: $r->print($errormsg);
516: } else {
517: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
518: $r->rflush();
519: my ($preamble,$formname);
520: $formname = 'dumpdoc';
521: unless ($home==1) {
522: $preamble = '<div class="LC_left_float">'.
523: '<fieldset><legend>'.
524: &mt('Select the Authoring Space').
525: '</legend><select name="authorspace">';
526: }
527: my @orderspaces = ();
528: foreach my $key (sort(keys(%outhash))) {
529: if ($key=~/^home_(.+)$/) {
530: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
531: unshift(@orderspaces,$1);
532: } else {
533: push(@orderspaces,$1);
534: }
535: }
536: }
537: if ($home>1) {
538: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
539: }
540: foreach my $user (@orderspaces) {
541: if ($home==1) {
542: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
543: } else {
544: $preamble .= '<option value="'.$user.'">'.$user.' - '.
545: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
546: }
547: }
548: unless ($home==1) {
549: $preamble .= '</select></fieldset></div>'."\n";
550: }
551: my $title=$origcrsdata{'description'};
552: $title=~s/[\/\s]+/\_/gs;
553: $title=&clean($title);
554: $preamble .= '<div class="LC_left_float">'.
555: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
556: '<input type="text" size="50" name="authorfolder" value="'.
557: $title.'" />'.
558: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
559: my %uploadedfiles;
560: &tiehash();
561: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
562: my ($ext)=($file=~/\.(\w+)$/);
563: # FIXME Check supplemental here
564: my $title=$hash{'title_'.$hash{
565: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
566: if (!$title) {
567: $title=$file;
568: } else {
569: $title=~s|/|_|g;
570: }
571: $title=~s/\.(\w+)$//;
572: $title=&clean($title);
573: $title.='.'.$ext;
574: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
575: $uploadedfiles{$file} = $title;
576: }
577: &untiehash();
578: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
579: undef,undef,$preamble,$home,\%uploadedfiles));
580: }
581: }
582: $r->print(&endContentScreen());
583: }
584:
585: sub recurse_html {
586: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
587: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
588: my (%allfiles,%codebase);
589: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
590: if (keys(%allfiles)) {
591: foreach my $dependency (keys(%allfiles)) {
592: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
593: my ($depurl,$relfile,$newcontainer);
594: if ($dependency =~ m{^/}) {
595: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
596: $relfile = $1;
597: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
598: $newcontainer = $1;
599: next if ($replacehash->{$newcontainer});
600: }
601: $depurl = $dependency;
602: } else {
603: next;
604: }
605: } else {
606: $relfile = $dependency;
607: $depurl = $currurlpath;
608: $depurl =~ s{[^/]+$}{};
609: $depurl .= $dependency;
610: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
611: }
612: next if ($relfile eq '');
613: my $newname = $replacehash->{$container};
614: $newname =~ s{[^/]+$}{};
615: $replacehash->{$newcontainer} = $newname.$relfile;
616: $deps->{$item}{$newcontainer} = 1;
617: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
618: my $depfile = &Apache::lonnet::filelocation('',$depurl);
619: my $type = $mm->checktype_filename($depfile);
620: if ($type eq 'text/html') {
621: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
622: }
623: }
624: }
625: }
626: return;
627: }
628:
629: sub group_import {
630: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
631: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
632: %removeparam,$importuploaded,$fixuperrors);
633: $allmaps = {};
634: while (@files) {
635: my ($name, $url, $residx) = @{ shift(@files) };
636: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
637: && ($caller eq 'londocs')
638: && (!&Apache::lonnet::stat_file($url))) {
639:
640: my $errtext = '';
641: my $fatal = 0;
642: my $newmapstr = '<map>'."\n".
643: '<resource id="1" src="" type="start"></resource>'."\n".
644: '<link from="1" to="2" index="1"></link>'."\n".
645: '<resource id="2" src="" type="finish"></resource>'."\n".
646: '</map>';
647: $env{'form.output'}=$newmapstr;
648: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
649: 'output',$1.$2);
650: if ($result !~ m{^/uploaded/}) {
651: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
652: $fatal = 2;
653: }
654: if ($fatal) {
655: return ($errtext,$fatal);
656: }
657: }
658: if ($url) {
659: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
660: $url = $1;
661: my $marker = $2;
662: my $info = $3;
663: my ($toolid,%toolhash,%toolsettings);
664: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
665: my @toolinfo = split(/:/,$info);
666: if ($residx) {
667: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
668: $toolid = $toolsettings{'id'};
669: } else {
670: $toolid = shift(@toolinfo);
671: }
672: $toolid =~ s/\D//g;
673: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
674: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
675: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
676: foreach my $item (@extras) {
677: $toolhash{$item} = &unescape($toolhash{$item});
678: }
679: if ($folder =~ /^supplemental/) {
680: delete($toolhash{'gradable'});
681: } else {
682: $toolhash{'gradable'} =~ s/\D+//g;
683: }
684: if (ref($ltitoolsref) eq 'HASH') {
685: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
686: my @deleted;
687: $toolhash{'id'} = $toolid;
688: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
689: ($toolhash{'target'} eq 'window')) {
690: if ($toolhash{'target'} eq 'window') {
691: foreach my $item ('width','height') {
692: $toolhash{$item} =~ s/^\s+//;
693: $toolhash{$item} =~ s/\s+$//;
694: if ($toolhash{$item} =~ /\D/) {
695: delete($toolhash{$item});
696: if ($residx) {
697: if ($toolsettings{$item}) {
698: push(@deleted,$item);
699: }
700: }
701: }
702: }
703: }
704: } elsif ($residx) {
705: $toolhash{'target'} = $toolsettings{'target'};
706: if ($toolhash{'target'} eq 'window') {
707: foreach my $item ('width','height') {
708: $toolhash{$item} = $toolsettings{$item};
709: }
710: }
711: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
712: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
713: if ($toolhash{'target'} eq 'window') {
714: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
715: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
716: }
717: }
718: if ($toolhash{'target'} eq 'iframe') {
719: foreach my $item ('width','height','linktext','explanation') {
720: delete($toolhash{$item});
721: if ($residx) {
722: if ($toolsettings{$item}) {
723: push(@deleted,$item);
724: }
725: }
726: }
727: } elsif ($toolhash{'target'} eq 'tab') {
728: foreach my $item ('width','height') {
729: delete($toolhash{$item});
730: if ($residx) {
731: if ($toolsettings{$item}) {
732: push(@deleted,$item);
733: }
734: }
735: }
736: }
737: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
738: foreach my $item ('label','title','linktext','explanation') {
739: my $crsitem;
740: if (($item eq 'label') || ($item eq 'title')) {
741: $crsitem = 'crs'.$item;
742: } else {
743: $crsitem = $item;
744: }
745: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
746: $toolhash{$crsitem} =~ s/^\s+//;
747: $toolhash{$crsitem} =~ s/\s+$//;
748: if ($toolhash{$crsitem} eq '') {
749: delete($toolhash{$crsitem});
750: }
751: } else {
752: delete($toolhash{$crsitem});
753: }
754: if (($residx) && (exists($toolsettings{$crsitem}))) {
755: unless (exists($toolhash{$crsitem})) {
756: push(@deleted,$crsitem);
757: }
758: }
759: }
760: }
761: if ($toolhash{'passback'}) {
762: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
763: $toolhash{'gradesecret'} = $gradesecret;
764: $toolhash{'gradesecretdate'} = time;
765: }
766: if ($toolhash{'roster'}) {
767: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
768: $toolhash{'rostersecret'} = $rostersecret;
769: $toolhash{'rostersecretdate'} = time;
770: }
771: my $changegradable;
772: if (($residx) && ($folder =~ /^default/)) {
773: if ($toolsettings{'gradable'}) {
774: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
775: push(@deleted,'gradable');
776: $changegradable = 1;
777: }
778: } elsif ($toolhash{'gradable'}) {
779: $changegradable = 1;
780: }
781: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
782: $changegradable = 1;
783: if ($toolsettings{'gradable'}) {
784: $toolhash{'gradable'} = 1;
785: }
786: }
787: }
788: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
789: if ($putres eq 'ok') {
790: if (@deleted) {
791: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
792: }
793: if (($changegradable) && ($folder =~ /^default/)) {
794: my $val;
795: if ($toolhash{'gradable'}) {
796: $val = 'yes';
797: } else {
798: $val = 'no';
799: }
800: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
801: 'string_yesno');
802: &remember_parms($residx,'gradable','set',$val);
803: }
804: } else {
805: return (&mt('Failed to save update to external tool.'),1);
806: }
807: }
808: }
809: }
810: if (($caller eq 'londocs') &&
811: ($folder =~ /^default/)) {
812: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
813: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
814: my $cid = $coursedom.'_'.$coursenum;
815: $allmaps =
816: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
817: $chome,$cid);
818: $donechk = 1;
819: }
820: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
821: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
822: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
823: $importuploaded = 1;
824: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
825: next if ($allmaps->{$url});
826: }
827: }
828: if (!$residx
829: || defined($LONCAPA::map::zombies[$residx])) {
830: $residx = &LONCAPA::map::getresidx($url,$residx);
831: push(@LONCAPA::map::order, $residx);
832: }
833: my $ext = 'false';
834: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
835: $name = &LONCAPA::map::qtunescape($name);
836: if ($name eq '') {
837: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
838: }
839: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
840: my $filepath = $1;
841: my $fname = $name;
842: if ($fname =~ /^\W+$/) {
843: $fname = 'web';
844: } else {
845: $fname =~ s/\W/_/g;
846: }
847: if (length($fname) > 15) {
848: $fname = substr($fname,0,14);
849: }
850: my $initialtext = &mt('Replace with your own content.');
851: my $newhtml = <<END;
852: <html>
853: <head>
854: <title>$name</title>
855: </head>
856: <body bgcolor="#ffffff">
857: $initialtext
858: </body>
859: </html>
860: END
861: $env{'form.output'}=$newhtml;
862: my $result =
863: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
864: 'output',
865: "$filepath/$residx/$fname.html");
866: if ($result =~ m{^/uploaded/}) {
867: $url = $result;
868: if ($filepath =~ /^supplemental/) {
869: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
870: $env{'user.domain'}.'___&&&___'.$name;
871: }
872: } else {
873: return (&mt('Failed to save new web page.'),1);
874: }
875: }
876: $url = &LONCAPA::map::qtunescape($url);
877: $LONCAPA::map::resources[$residx] =
878: join(':', ($name, $url, $ext, 'normal', 'res'));
879: }
880: }
881: if ($importuploaded) {
882: my %import_errors;
883: my %updated = (
884: removefrommap => \%removefrommap,
885: removeparam => \%removeparam,
886: );
887: my ($result,$msgsarray,$lockerror) =
888: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
889: if (keys(%import_errors) > 0) {
890: $fixuperrors =
891: '<p span class="LC_warning">'."\n".
892: &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".
893: '<ul>'."\n";
894: foreach my $key (sort(keys(%import_errors))) {
895: $fixuperrors .= '<li>'.$key.'</li>'."\n";
896: }
897: $fixuperrors .= '</ul></p>'."\n";
898: }
899: if (ref($msgsarray) eq 'ARRAY') {
900: if (@{$msgsarray} > 0) {
901: $fixuperrors .= '<p class="LC_info">'.
902: join('<br />',@{$msgsarray}).
903: '</p>';
904: }
905: }
906: if ($lockerror) {
907: $fixuperrors .= '<p class="LC_error">'.
908: $lockerror.
909: '</p>';
910: }
911: }
912: my ($errtext,$fatal) =
913: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
914: unless ($fatal) {
915: if ($folder =~ /^supplemental/) {
916: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
917: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
918: $folder.'.'.$container);
919: }
920: }
921: return ($errtext,$fatal,$fixuperrors);
922: }
923:
924: sub log_docs {
925: return &Apache::lonnet::write_log('course','docslog',@_);
926: }
927:
928: {
929: my @oldresources=();
930: my @oldorder=();
931: my $parmidx;
932: my %parmaction=();
933: my %parmvalue=();
934: my $changedflag;
935:
936: sub snapshotbefore {
937: @oldresources=@LONCAPA::map::resources;
938: @oldorder=@LONCAPA::map::order;
939: $parmidx=undef;
940: %parmaction=();
941: %parmvalue=();
942: $changedflag=0;
943: }
944:
945: sub remember_parms {
946: my ($idx,$parameter,$action,$value)=@_;
947: $parmidx=$idx;
948: $parmaction{$parameter}=$action;
949: $parmvalue{$parameter}=$value;
950: $changedflag=1;
951: }
952:
953: sub log_differences {
954: my ($plain)=@_;
955: my %storehash=('folder' => $plain,
956: 'currentfolder' => $env{'form.folder'});
957: if ($parmidx) {
958: $storehash{'parameter_res'}=$oldresources[$parmidx];
959: foreach my $parm (keys(%parmaction)) {
960: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
961: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
962: }
963: }
964: my $maxidx=$#oldresources;
965: if ($#LONCAPA::map::resources>$#oldresources) {
966: $maxidx=$#LONCAPA::map::resources;
967: }
968: for (my $idx=0; $idx<=$maxidx; $idx++) {
969: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
970: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
971: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
972: $changedflag=1;
973: }
974: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
975: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
976: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
977: $changedflag=1;
978: }
979: }
980: $storehash{'maxidx'}=$maxidx;
981: if ($changedflag) { &log_docs(\%storehash); }
982: }
983: }
984:
985: sub docs_change_log {
986: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
987: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
988: my $navmap;
989: my $js = '<script type="text/javascript">'."\n".
990: '// <![CDATA['."\n".
991: &Apache::loncommon::display_filter_js('docslog')."\n".
992: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
993: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
994: &history_tab_js()."\n".
995: &Apache::lonratedt::editscript('simple')."\n".
996: '// ]]>'."\n".
997: '</script>'."\n";
998: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
999: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1000: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1001: my %orderhash;
1002: my $container='sequence';
1003: my $pathitem;
1004: if ($env{'form.folderpath'} =~ /\:1$/) {
1005: $container='page';
1006: }
1007: my $folderpath=$env{'form.folderpath'};
1008: if ($folderpath eq '') {
1009: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1010: }
1011: undef($navmap);
1012: $pathitem = '<input type="hidden" name="folderpath" value="'.
1013: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1014: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1015: my $jumpto = $readfile;
1016: $jumpto =~ s{^/}{};
1017: my $tid = 1;
1018: if ($supplementalflag) {
1019: $tid = 2;
1020: }
1021: my ($breadcrumbtrail) =
1022: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1023: $r->print($breadcrumbtrail.
1024: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1025: $readfile));
1026: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1027: $env{'course.'.$env{'request.course.id'}.'.domain'},
1028: $env{'course.'.$env{'request.course.id'}.'.num'});
1029:
1030: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1031:
1032: my %saveable_parameters = ('show' => 'scalar',);
1033: &Apache::loncommon::store_course_settings('docs_log',
1034: \%saveable_parameters);
1035: &Apache::loncommon::restore_course_settings('docs_log',
1036: \%saveable_parameters);
1037: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1038: # FIXME: internationalization seems wrong here
1039: my %lt=('hiddenresource' => 'Resources hidden',
1040: 'encrypturl' => 'URL hidden',
1041: 'randompick' => 'Randomly pick',
1042: 'randomorder' => 'Randomly ordered',
1043: 'gradable' => 'Grade can be assigned to External Tool',
1044: 'set' => 'set to',
1045: 'del' => 'deleted');
1046: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1047: $pathitem."\n".
1048: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1049: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1050: $r->print('<div class="LC_left_float">'.
1051: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1052: &makedocslogform($filter,1).
1053: '</fieldset></div><br clear="all" />');
1054: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1055: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1056: &mt('After').'</th>'.
1057: &Apache::loncommon::end_data_table_header_row());
1058: my $shown=0;
1059: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1060: if ($env{'form.displayfilter'} eq 'currentfolder') {
1061: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1062: }
1063: my @changes=keys(%{$docslog{$id}{'logentry'}});
1064: if ($env{'form.displayfilter'} eq 'containing') {
1065: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1066: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1067: foreach my $key (@changes) {
1068: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1069: }
1070: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1071: }
1072: my $count = 0;
1073: my $time =
1074: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1075: my $plainname =
1076: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1077: $docslog{$id}{'exe_udom'});
1078: my $about_me_link =
1079: &Apache::loncommon::aboutmewrapper($plainname,
1080: $docslog{$id}{'exe_uname'},
1081: $docslog{$id}{'exe_udom'});
1082: my $send_msg_link='';
1083: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1084: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1085: $send_msg_link ='<br />'.
1086: &Apache::loncommon::messagewrapper(&mt('Send message'),
1087: $docslog{$id}{'exe_uname'},
1088: $docslog{$id}{'exe_udom'});
1089: }
1090: $r->print(&Apache::loncommon::start_data_table_row());
1091: $r->print('<td>'.$time.'</td>
1092: <td>'.$about_me_link.
1093: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1094: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1095: $send_msg_link.'</td><td>'.
1096: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1097: my $is_supp = 0;
1098: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1099: $is_supp = 1;
1100: }
1101: # Before
1102: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1103: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1104: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1105: if ($oldname ne $newname) {
1106: my $shown = &LONCAPA::map::qtescape($oldname);
1107: if ($is_supp) {
1108: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1109: }
1110: $r->print($shown);
1111: }
1112: }
1113: $r->print('<ul>');
1114: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1115: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1116: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1117: if ($is_supp) {
1118: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1119: }
1120: $r->print('<li>'.$shown.'</li>');
1121: }
1122: }
1123: $r->print('</ul>');
1124: # After
1125: $r->print('</td><td>');
1126:
1127: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1128: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1129: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1130: if ($oldname ne '' && $oldname ne $newname) {
1131: my $shown = &LONCAPA::map::qtescape($newname);
1132: if ($is_supp) {
1133: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1134: }
1135: $r->print($shown);
1136: }
1137: }
1138: $r->print('<ul>');
1139: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1140: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1141: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1142: if ($is_supp) {
1143: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1144: }
1145: $r->print('<li>'.$shown.'</li>');
1146: }
1147: }
1148: $r->print('</ul>');
1149: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1150: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1151: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1152: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1153: # FIXME: internationalization seems wrong here
1154: $r->print('<li>'.
1155: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1156: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1157: .'</li>');
1158: }
1159: }
1160: $r->print('</ul>');
1161: }
1162: # End
1163: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1164: $shown++;
1165: if (!($env{'form.show'} eq &mt('all')
1166: || $shown<=$env{'form.show'})) { last; }
1167: }
1168: $r->print(&Apache::loncommon::end_data_table()."\n".
1169: &makesimpleeditform($pathitem)."\n".
1170: '</div></div>');
1171: $r->print(&endContentScreen());
1172: }
1173:
1174: sub update_paste_buffer {
1175: my ($coursenum,$coursedom,$folder) = @_;
1176: my (@possibles,%removals,%cuts,$output);
1177: if ($env{'form.multiremove'}) {
1178: $env{'form.multiremove'} =~ s/,$//;
1179: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1180: }
1181: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1182: if ($env{'form.multicut'}) {
1183: $env{'form.multicut'} =~ s/,$//;
1184: foreach my $item (split(/,/,$env{'form.multicut'})) {
1185: unless ($removals{$item}) {
1186: $cuts{$item} = 1;
1187: push(@possibles,$item.':cut');
1188: }
1189: }
1190: }
1191: if ($env{'form.multicopy'}) {
1192: $env{'form.multicopy'} =~ s/,$//;
1193: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1194: unless ($removals{$item} || $cuts{$item}) {
1195: push(@possibles,$item.':copy');
1196: }
1197: }
1198: }
1199: } elsif ($env{'form.markcopy'}) {
1200: @possibles = split(/,/,$env{'form.markcopy'});
1201: }
1202:
1203: return if (@possibles == 0);
1204: return if (!defined($env{'form.copyfolder'}));
1205:
1206: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1207: $env{'form.copyfolder'});
1208: return if ($fatal);
1209:
1210: my %curr_groups = &Apache::longroup::coursegroups();
1211:
1212: # Retrieve current paste buffer suffixes.
1213: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1214: my (%pasteurls,@newpaste);
1215:
1216: # Construct identifiers for current contents of user's paste buffer
1217: if (@currpaste) {
1218: foreach my $suffix (@currpaste) {
1219: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1220: my $url = $env{'docs.markedcopy_url_'.$suffix};
1221: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1222: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1223: ($url ne '')) {
1224: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1225: }
1226: }
1227: }
1228:
1229: # Mark items for copying (skip any items already in user's paste buffer)
1230: my %addtoenv;
1231:
1232: my @pathitems = split(/\&/,$env{'form.folderpath'});
1233: my @folderconf = split(/\:/,$pathitems[-1]);
1234: my $ispage = $folderconf[4];
1235:
1236: foreach my $item (@possibles) {
1237: my ($orderidx,$cmd) = split(/:/,$item);
1238: next if ($orderidx =~ /\D/);
1239: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1240: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1241: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1242: my %denied = &action_restrictions($coursenum,$coursedom,
1243: &LONCAPA::map::qtescape($url),
1244: $env{'form.folderpath'},\%curr_groups);
1245: next if ($denied{'copy'});
1246: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1247: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1248: my ($suffix,$errortxt,$locknotfreed) =
1249: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1250: if ($suffix ne '') {
1251: push(@newpaste,$suffix);
1252: } else {
1253: if ($locknotfreed) {
1254: return $locknotfreed;
1255: }
1256: }
1257: if (&is_supplemental_title($title)) {
1258: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1259: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1260: }
1261:
1262: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1263: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1264: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1265: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1266: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1267: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1268: my $prefix = $1;
1269: my $subdir =$2;
1270: if ($subdir eq '') {
1271: $subdir = $prefix;
1272: }
1273: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1274: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1275: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1276: if (ref($hierarchy{$url}) eq 'HASH') {
1277: my ($nested,$nestednames);
1278: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1279: $nested =~ s/\&$//;
1280: $nestednames =~ s/\Q___&&&___\E$//;
1281: if ($nested ne '') {
1282: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1283: }
1284: if ($nestednames ne '') {
1285: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1286: }
1287: }
1288: }
1289: if ($locknotfreed) {
1290: $output = $locknotfreed;
1291: last;
1292: }
1293: }
1294: if (@newpaste) {
1295: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1296: }
1297: &Apache::lonnet::appenv(\%addtoenv);
1298: delete($env{'form.markcopy'});
1299: return $output;
1300: }
1301:
1302: sub recurse_uploaded_maps {
1303: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1304: if (ref($hierarchy->{$url}) eq 'HASH') {
1305: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1306: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1307: my (@uploaded,@names,%shorter);
1308: for (my $i=0; $i<@maps; $i++) {
1309: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1310: if ($inner ne '') {
1311: push(@uploaded,$inner);
1312: push(@names,&escape($titles[$i]));
1313: $shorter{$maps[$i]} = $inner;
1314: }
1315: }
1316: $$nestref .= "$dir:".join(',',@uploaded).'&';
1317: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1318: foreach my $map (@maps) {
1319: if ($shorter{$map} ne '') {
1320: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1321: }
1322: }
1323: }
1324: return;
1325: }
1326:
1327: sub print_paste_buffer {
1328: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1329: return if (!defined($env{'docs.markedcopies'}));
1330:
1331: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1332: return if ($env{'docs.markedcopies'} eq '');
1333: }
1334:
1335: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1336: my ($pasteitems,@pasteable);
1337: my $clipboardcount = 0;
1338:
1339: # Construct identifiers for current contents of user's paste buffer
1340: foreach my $suffix (@currpaste) {
1341: next if ($suffix =~ /\D/);
1342: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1343: my $url = $env{'docs.markedcopy_url_'.$suffix};
1344: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1345: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1346: ($url ne '')) {
1347: $clipboardcount ++;
1348: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1349: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1350: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1351: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1352: $is_external = 1;
1353: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1354: $is_exttool = 1;
1355: }
1356: if ($folder =~ /^supplemental/) {
1357: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1358: unless ($canpaste) {
1359: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1360: }
1361: } else {
1362: $canpaste = 1;
1363: }
1364: if ($canpaste) {
1365: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1366: my $srcdom = $1;
1367: my $srcnum = $2;
1368: my $rem = $3;
1369: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1370: $othercourse = 1;
1371: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1372: $othercrs = '<br />'.&mt('(from another course)');
1373: } else {
1374: $canpaste = 0;
1375: $nopaste = &mt('Paste from another course unavailable.');
1376: }
1377: }
1378: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1379: my $prefix = $1;
1380: $parent = $2;
1381: if ($folder !~ /^\Q$prefix\E/) {
1382: $areachange = 1;
1383: }
1384: $is_uploaded_map = 1;
1385: }
1386: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1387: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1388: if ($cid ne $env{'request.course.id'}) {
1389: my ($srcdom,$srcnum) = split(/_/,$cid);
1390: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1391: if (($is_exttool) && ($srcdom ne $coursedom)) {
1392: $canpaste = 0;
1393: $nopaste = &mt('Paste from another domain unavailable.');
1394: } else {
1395: $othercrs = '<br />'.&mt('(from another course)');
1396: }
1397: } else {
1398: $canpaste = 0;
1399: $nopaste = &mt('Paste from another course unavailable.');
1400: }
1401: }
1402: }
1403: if ($canpaste) {
1404: push(@pasteable,$suffix);
1405: }
1406: }
1407: my $buffer;
1408: if ($is_external) {
1409: $buffer = &mt('External Resource').': '.
1410: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1411: &LONCAPA::map::qtescape($url).')';
1412: } elsif ($is_exttool) {
1413: $buffer = &mt('External Tool').': '.
1414: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1415: } else {
1416: my $icon = &Apache::loncommon::icon($extension);
1417: if ($extension eq 'sequence' &&
1418: $url =~ m{/default_\d+\.sequence$}x) {
1419: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1420: $icon .= '/navmap.folder.closed.gif';
1421: }
1422: my $title = $env{'docs.markedcopy_title_'.$suffix};
1423: if ($title eq '') {
1424: ($title) = ($url =~ m{/([^/]+)$});
1425: }
1426: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1427: ': '.
1428: &Apache::loncommon::parse_supplemental_title(
1429: &LONCAPA::map::qtescape($title));
1430: }
1431: $pasteitems .= '<div class="LC_left_float">';
1432: my ($options,$onclick);
1433: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1434: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1435: if (($is_uploaded_map) ||
1436: ($url =~ /(bulletinboard|smppg)$/) ||
1437: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1438: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1439: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1440: }
1441: }
1442: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1443: if ($nopaste) {
1444: $pasteitems .= $nopaste;
1445: } else {
1446: if ($othercrs) {
1447: $pasteitems .= $othercrs;
1448: }
1449: if ($options) {
1450: $pasteitems .= $options;
1451: }
1452: }
1453: $pasteitems .= '</div>';
1454: }
1455: }
1456: if ($pasteitems eq '') {
1457: &Apache::lonnet::delenv('docs.markedcopies');
1458: }
1459: my ($pasteform,$form_start,$buttons,$form_end);
1460: if ($pasteitems) {
1461: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1462: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1463: if (@pasteable) {
1464: my $value = &mt('Paste to current folder');
1465: if ($container eq 'page') {
1466: $value = &mt('Paste to current page');
1467: }
1468: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1469: }
1470: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1471: if ($clipboardcount > 1) {
1472: $buttons .=
1473: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1474: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1475: (' 'x2).
1476: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1477: (' 'x2);
1478: }
1479: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1480: '</form>';
1481: } else {
1482: $pasteitems = &mt('Clipboard is empty');
1483: }
1484: $r->print($form_start
1485: .'<fieldset>'
1486: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1487: .$pasteitems
1488: .'</fieldset>'
1489: .$form_end);
1490: }
1491:
1492: sub paste_options {
1493: my ($suffix,$is_uploaded_map,$parent) = @_;
1494: my ($copytext,$movetext);
1495: if ($is_uploaded_map) {
1496: $copytext = &mt('Copy to new folder');
1497: $movetext = &mt('Move old');
1498: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1499: $copytext = &mt('Copy to new board');
1500: $movetext = &mt('Move (not posts)');
1501: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1502: $copytext = &mt('Copy to new page');
1503: $movetext = &mt('Move');
1504: } else {
1505: $copytext = &mt('Copy to new file');
1506: $movetext = &mt('Move');
1507: }
1508: my $output = '<br />'.
1509: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1510: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1511: '<label>'.
1512: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1513: $copytext.'</label></span>'.(' 'x2).' '.
1514: '<span class="LC_nobreak"><label>'.
1515: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1516: $movetext.'</label></span>';
1517: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1518: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1519: '</legend><table border="0">';
1520: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1521: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1522: my $lastdir = $parent;
1523: my %depths = (
1524: $lastdir => 0,
1525: );
1526: my (%display,%deps);
1527: for (my $i=0; $i<@pastemaps; $i++) {
1528: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1529: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1530: my @subfolders = split(/,/,$subfolderstr);
1531: $deps{$lastdir} = \@subfolders;
1532: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1533: my $depth = $depths{$lastdir} + 1;
1534: my $offset = int($depth * 4);
1535: my $indent = (' ' x $offset);
1536: for (my $j=0; $j<@subfolders; $j++) {
1537: $depths{$subfolders[$j]} = $depth;
1538: $display{$subfolders[$j]} =
1539: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1540: '<td><label>'.
1541: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1542: '<label>'.
1543: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1544: &mt('Move old').'</label>'.
1545: '</td></tr>';
1546: }
1547: }
1548: &recurse_print(\$output,$parent,\%deps,\%display);
1549: $output .= '</table></fieldset>';
1550: }
1551: $output .= '</div>';
1552: return $output;
1553: }
1554:
1555: sub recurse_print {
1556: my ($outputref,$dir,$deps,$display) = @_;
1557: $$outputref .= $display->{$dir}."\n";
1558: if (ref($deps->{$dir}) eq 'ARRAY') {
1559: foreach my $subdir (@{$deps->{$dir}}) {
1560: &recurse_print($outputref,$subdir,$deps,$display);
1561: }
1562: }
1563: }
1564:
1565: sub supp_pasteable {
1566: my ($url) = @_;
1567: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1568: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1569: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1570: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1571: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1572: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1573: return 1;
1574: }
1575: return;
1576: }
1577:
1578: sub paste_popup_js {
1579: my %html_js_lt = &Apache::lonlocal::texthash(
1580: show => 'Show Options',
1581: hide => 'Hide Options',
1582: );
1583: my %js_lt = &Apache::lonlocal::texthash(
1584: none => 'No items selected from clipboard.',
1585: );
1586: &html_escape(\%html_js_lt);
1587: &js_escape(\%html_js_lt);
1588: &js_escape(\%js_lt);
1589: return <<"END";
1590:
1591: function showPasteOptions(suffix) {
1592: document.getElementById('pasteoptions_'+suffix).style.display='block';
1593: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1594: return;
1595: }
1596:
1597: function hidePasteOptions(suffix) {
1598: document.getElementById('pasteoptions_'+suffix).style.display='none';
1599: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1600: return;
1601: }
1602:
1603: function showOptions(caller,suffix) {
1604: if (document.getElementById('pasteoptionstext_'+suffix)) {
1605: if (caller.checked) {
1606: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1607: } else {
1608: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1609: }
1610: if (document.getElementById('pasteoptions_'+suffix)) {
1611: document.getElementById('pasteoptions_'+suffix).style.display='none';
1612: }
1613: }
1614: return;
1615: }
1616:
1617: function validateClipboard() {
1618: var numchk = 0;
1619: if (document.pasteform.pasting.length > 1) {
1620: for (var i=0; i<document.pasteform.pasting.length; i++) {
1621: if (document.pasteform.pasting[i].checked) {
1622: numchk ++;
1623: }
1624: }
1625: } else {
1626: if (document.pasteform.pasting.type == 'checkbox') {
1627: if (document.pasteform.pasting.checked) {
1628: numchk ++;
1629: }
1630: }
1631: }
1632: if (numchk > 0) {
1633: return true;
1634: } else {
1635: alert("$js_lt{'none'}");
1636: return false;
1637: }
1638: }
1639:
1640: function checkClipboard() {
1641: if (document.pasteform.pasting.length > 1) {
1642: for (var i=0; i<document.pasteform.pasting.length; i++) {
1643: document.pasteform.pasting[i].checked = true;
1644: }
1645: }
1646: return;
1647: }
1648:
1649: function uncheckClipboard() {
1650: if (document.pasteform.pasting.length >1) {
1651: for (var i=0; i<document.pasteform.pasting.length; i++) {
1652: document.pasteform.pasting[i].checked = false;
1653: }
1654: }
1655: return;
1656: }
1657:
1658: END
1659:
1660: }
1661:
1662: sub do_paste_from_buffer {
1663: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1664:
1665: # Array of items in paste buffer
1666: my (@currpaste,%pastebuffer,%allerrors);
1667: @currpaste = split(/,/,$env{'docs.markedcopies'});
1668:
1669: # Early out if paste buffer is empty
1670: if (@currpaste == 0) {
1671: return ();
1672: }
1673: map { $pastebuffer{$_} = 1; } @currpaste;
1674:
1675: # Array of items selected items to paste
1676: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1677:
1678: # Early out if nothing selected to paste
1679: if (@reqpaste == 0) {
1680: return();
1681: }
1682: my @topaste;
1683: foreach my $suffix (@reqpaste) {
1684: next if ($suffix =~ /\D/);
1685: next unless (exists($pastebuffer{$suffix}));
1686: push(@topaste,$suffix);
1687: }
1688:
1689: # Early out if nothing available to paste
1690: if (@topaste == 0) {
1691: return();
1692: }
1693:
1694: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1695: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1696:
1697: foreach my $suffix (@topaste) {
1698: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1699: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1700: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1701: # Supplemental content may only include certain types of content
1702: # Early out if pasted content is not supported in Supplemental area
1703: if ($folder =~ /^supplemental/) {
1704: unless (&supp_pasteable($url)) {
1705: $notinsupp{$suffix} = 1;
1706: next;
1707: }
1708: }
1709: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1710: my $srcd = $1;
1711: my $srcn = $2;
1712: # When paste buffer was populated using an active role in a different course
1713: # check for mdc privilege in the course from which the resource was pasted
1714: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1715: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1716: $notincrs{$suffix} = 1;
1717: next;
1718: }
1719: }
1720: $srcdom{$suffix} = $srcd;
1721: $srcnum{$suffix} = $srcn;
1722: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1723: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1724: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1725: my ($srcd,$srcn) = split(/_/,$cid);
1726: # When paste buffer was populated using an active role in a different course
1727: # check for mdc privilege in the course from which the resource was pasted
1728: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1729: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1730: $notincrs{$suffix} = 1;
1731: next;
1732: }
1733: }
1734: # When buffer was populated using an active role in a different course
1735: # disallow pasting of External Tool if course is in a different domain.
1736: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1737: $notindom{$suffix} = 1;
1738: next;
1739: }
1740: $srcdom{$suffix} = $srcd;
1741: $srcnum{$suffix} = $srcn;
1742: }
1743: $srcmapidx{$suffix} = $mapidx;
1744: push(@dopaste,$suffix);
1745: if ($url=~/\.(page|sequence)$/) {
1746: $is_map{$suffix} = 1;
1747: }
1748: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1749: my $oldprefix = $1;
1750: # When pasting content from Main Content to Supplemental Content and vice versa
1751: # URLs will contain different paths (which depend on whether pasted item is
1752: # a folder/page or a document).
1753: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1754: $prefixchg{$suffix} = 'docstosupp';
1755: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1756: $prefixchg{$suffix} = 'supptodocs';
1757: }
1758:
1759: # If pasting an uploaded map, get list of contained uploaded maps.
1760: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1761: my @nested;
1762: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1763: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1764: my @deps = map { /\d+:([\d,]+$)/ } @items;
1765: foreach my $dep (@deps) {
1766: if ($dep =~ /,/) {
1767: push(@nested,split(/,/,$dep));
1768: } else {
1769: push(@nested,$dep);
1770: }
1771: }
1772: foreach my $item (@nested) {
1773: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1774: push(@{$marktomove{$suffix}},$type.'_'.$item);
1775: }
1776: }
1777: }
1778: }
1779: }
1780:
1781: # Early out if nothing available to paste
1782: if (@dopaste == 0) {
1783: return ();
1784: }
1785:
1786: # Populate message hash and hashes used for main content <=> supplemental content
1787: # changes
1788:
1789: %msgs = &Apache::lonlocal::texthash (
1790: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1791: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1792: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1793: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1794: );
1795:
1796: %before = (
1797: docstosupp => {
1798: map => 'default',
1799: doc => 'docs',
1800: },
1801: supptodocs => {
1802: map => 'supplemental',
1803: doc => 'supplemental',
1804: },
1805: );
1806:
1807: %after = (
1808: docstosupp => {
1809: map => 'supplemental',
1810: doc => 'supplemental'
1811: },
1812: supptodocs => {
1813: map => 'default',
1814: doc => 'docs',
1815: },
1816: );
1817:
1818: # Retrieve information about all course maps in main content area
1819:
1820: my $allmaps = {};
1821: if ($folder =~ /^default/) {
1822: $allmaps =
1823: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1824: $env{"course.$env{'request.course.id'}.home"},
1825: $env{'request.course.id'});
1826: }
1827:
1828: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1829:
1830: # Loop over the items to paste
1831: foreach my $suffix (@dopaste) {
1832: # Maps need to be copied first
1833: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1834: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1835: %newurls,%tomove,%resdatacopy);
1836: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1837: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1838: }
1839: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1840: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1841: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1842: my $oldurl = $url;
1843: if ($is_map{$suffix}) {
1844: # If pasting a map, check if map contains other maps
1845: my (%hierarchy,%titles);
1846: &contained_map_check($url,$folder,$coursenum,$coursedom,
1847: \%removefrommap,\%removeparam,\%addedmaps,
1848: \%hierarchy,\%titles,$allmaps);
1849: if ($url=~ m{^/uploaded/}) {
1850: my $newurl;
1851: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1852: ($newurl,my $error) =
1853: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1854: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1855: \$title,$allmaps,\%newurls);
1856: if ($error) {
1857: $allerrors{$suffix} = $error;
1858: next;
1859: }
1860: if ($newurl ne '') {
1861: if ($newurl ne $url) {
1862: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1863: $newsubdir{$url} = $1;
1864: }
1865: $mapchanges{$url} = 1;
1866: }
1867: }
1868: }
1869: if (($srcdom{$suffix} ne $coursedom) ||
1870: ($srcnum{$suffix} ne $coursenum) ||
1871: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1872: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1873: $coursedom,$coursenum,$srcdom{$suffix},
1874: $srcnum{$suffix},$allmaps,\%rewrites,
1875: \%retitles,\%copies,\%dbcopies,
1876: \%zombies,\%params,\%mapmoves,
1877: \%mapchanges,\%tomove,\%newsubdir,
1878: \%newurls,\%resdatacopy)) {
1879: $mapmoves{$url} = 1;
1880: }
1881: $url = $newurl;
1882: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1883: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1884: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1885: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1886: \%zombies,\%params,\%mapmoves,\%mapchanges,
1887: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1888: }
1889: } elsif ($url=~m {^/res/}) {
1890: # published map can only exist once, so remove from paste buffer when done
1891: push(@toclear,$suffix);
1892: # if pasting published map (main content area only) check map not already in course
1893: if ($folder =~ /^default/) {
1894: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1895: $duplicate{$suffix} = 1;
1896: next;
1897: }
1898: }
1899: }
1900: }
1901: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1902: my $prefix = $1;
1903: my $fromothercrs;
1904: #need to copy the db contents to a new one, unless this is a move.
1905: my %info = (
1906: src => $url,
1907: cdom => $coursedom,
1908: cnum => $coursenum,
1909: );
1910: if ($prefix eq 'ext.tool') {
1911: if ($prefixchg{$suffix} eq 'docstosupp') {
1912: $info{'delgradable'} = 1;
1913: }
1914: }
1915: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1916: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1917: $fromothercrs = 1;
1918: $info{'cdom'} = $srcdom{$suffix};
1919: $info{'cnum'} = $srcnum{$suffix};
1920: }
1921: }
1922: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1923: my (%lockerr,$msg);
1924: my ($newurl,$result,$errtext) =
1925: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1926: if ($result eq 'ok') {
1927: $url = $newurl;
1928: $title=&mt('Copy of').' '.$title;
1929: } else {
1930: if ($prefix eq 'smppg') {
1931: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1932: } elsif ($prefix eq 'bulletinboard') {
1933: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1934: } elsif ($prefix eq 'ext.tool') {
1935: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1936: }
1937: $results{$suffix} = $result;
1938: $msgerrs{$suffix} = $msg;
1939: $lockerrs{$suffix} = $lockerr{$prefix};
1940: next;
1941: }
1942: if ($lockerr{$prefix}) {
1943: $lockerrs{$suffix} = $lockerr{$prefix};
1944: }
1945: }
1946: }
1947: $title = &LONCAPA::map::qtunescape($title);
1948: my $ext='false';
1949: if ($url=~m{^http(|s)://}) { $ext='true'; }
1950: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1951: if ($folder !~ /^supplemental/) {
1952: (undef,undef,$title) =
1953: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1954: }
1955: } else {
1956: if ($folder=~/^supplemental/) {
1957: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1958: $env{'user.domain'}.'___&&&___'.$title;
1959: }
1960: }
1961:
1962: # For uploaded files (excluding pages/sequences) path in copied file is changed
1963: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1964: # courses.
1965:
1966: unless ($is_map{$suffix}) {
1967: my $newidx;
1968: # Now insert the URL at the bottom
1969: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1970: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1971: my $relpath = $1;
1972: if ($relpath ne '') {
1973: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1974: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1975: my $newprefix = $newloc;
1976: if ($newloc eq 'default') {
1977: $newprefix = 'docs';
1978: }
1979: if ($newdocsdir eq '') {
1980: $newdocsdir = 'default';
1981: }
1982: if (($prefixchg{$suffix}) ||
1983: ($srcdom{$suffix} ne $coursedom) ||
1984: ($srcnum{$suffix} ne $coursenum) ||
1985: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1986: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1987: $url =
1988: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1989: &Apache::lonnet::getfile($oldurl));
1990: if ($url eq '/adm/notfound.html') {
1991: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1992: next;
1993: } else {
1994: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1995: $newsubpath =~ s{/+$}{/};
1996: $docmoves{$oldurl} = $newsubpath;
1997: }
1998: }
1999: }
2000: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2001: my $template = $1;
2002: if ($newidx) {
2003: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2004: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2005: }
2006: } elsif ($url =~ /ext\.tool$/) {
2007: if (($newidx) && ($folder=~/^default/)) {
2008: my $marker = (split(m{/},$url))[4];
2009: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2010: my $val = 'no';
2011: if ($toolsettings{'gradable'}) {
2012: $val = 'yes';
2013: }
2014: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2015: 'string_yesno');
2016: &remember_parms($newidx,'gradable','set',$val);
2017: }
2018: }
2019: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2020: ':'.$ext.':normal:res';
2021: push(@LONCAPA::map::order,$newidx);
2022: # Store the result
2023: my ($errtext,$fatal) =
2024: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2025: if ($fatal) {
2026: $save_err .= $errtext;
2027: $allresult = 'fail';
2028: }
2029: }
2030:
2031: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2032: # resourcedata for simpleproblems copied from another course
2033: unless ($allresult eq 'fail') {
2034: my %updated = (
2035: rewrites => \%rewrites,
2036: zombies => \%zombies,
2037: removefrommap => \%removefrommap,
2038: removeparam => \%removeparam,
2039: dbcopies => \%dbcopies,
2040: resdatacopy => \%resdatacopy,
2041: retitles => \%retitles,
2042: );
2043: my %info = (
2044: newsubdir => \%newsubdir,
2045: params => \%params,
2046: );
2047: if ($prefixchg{$suffix}) {
2048: $info{'before'} = $before{$prefixchg{$suffix}};
2049: $info{'after'} = $after{$prefixchg{$suffix}};
2050: }
2051: my %moves = (
2052: copies => \%copies,
2053: docmoves => \%docmoves,
2054: mapmoves => \%mapmoves,
2055: );
2056: (my $result,$msgs{$suffix},my $lockerror) =
2057: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2058: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2059: $url,'paste');
2060: $lockerrors .= $lockerror;
2061: if ($result eq 'ok') {
2062: if ($is_map{$suffix}) {
2063: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2064: $folder.'.'.$container);
2065: if ($fatal) {
2066: $allresult = 'failread';
2067: } else {
2068: if ($#LONCAPA::map::order<1) {
2069: my $idx=&LONCAPA::map::getresidx();
2070: if ($idx<=0) { $idx=1; }
2071: $LONCAPA::map::order[0]=$idx;
2072: $LONCAPA::map::resources[$idx]='';
2073: }
2074: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2075: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2076: ':'.$ext.':normal:res';
2077: push(@LONCAPA::map::order,$newidx);
2078:
2079: # Store the result
2080: my ($errtext,$fatal) =
2081: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2082: if ($fatal) {
2083: $save_err .= $errtext;
2084: $allresult = 'failstore';
2085: }
2086: }
2087: }
2088: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2089: push(@toclear,$suffix);
2090: }
2091: }
2092: }
2093: }
2094: &clear_from_buffer(\@toclear,\@currpaste);
2095: my $msgsarray;
2096: foreach my $suffix (keys(%msgs)) {
2097: if (ref($msgs{$suffix}) eq 'ARRAY') {
2098: $msgsarray .= join(',',@{$msgs{$suffix}});
2099: }
2100: }
2101: return ($allresult,$save_err,$msgsarray,$lockerrors);
2102: }
2103:
2104: sub do_buffer_empty {
2105: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2106: if (@currpaste == 0) {
2107: return &mt('Clipboard is already empty');
2108: }
2109: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2110: if (@toclear == 0) {
2111: return &mt('Nothing selected to clear from clipboard');
2112: }
2113: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2114: if ($numdel) {
2115: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2116: } else {
2117: return &mt('Clipboard unchanged');
2118: }
2119: return;
2120: }
2121:
2122: sub clear_from_buffer {
2123: my ($toclear,$currpaste) = @_;
2124: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2125: my %pastebuffer;
2126: map { $pastebuffer{$_} = 1; } @{$currpaste};
2127: my $numdel = 0;
2128: foreach my $suffix (@{$toclear}) {
2129: next if ($suffix =~ /\D/);
2130: next unless (exists($pastebuffer{$suffix}));
2131: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2132: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2133: delete($pastebuffer{$suffix});
2134: $numdel ++;
2135: }
2136: }
2137: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2138: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2139: return $numdel;
2140: }
2141:
2142: sub get_newmap_url {
2143: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2144: $titleref,$allmaps,$newurls) = @_;
2145: my $newurl;
2146: if ($url=~ m{^/uploaded/}) {
2147: $$titleref=&mt('Copy of').' '.$$titleref;
2148: }
2149: my $now = time;
2150: my $suffix=$$.int(rand(100)).$now;
2151: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2152: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2153: my $path = $1;
2154: my $prefix = $2;
2155: my $ancestor = $3;
2156: if (length($ancestor) > 10) {
2157: $ancestor = substr($ancestor,-10,10);
2158: }
2159: my $newid;
2160: if ($prefixchg) {
2161: if ($folder =~ /^supplemental/) {
2162: $prefix =~ s/^default/supplemental/;
2163: } else {
2164: $prefix =~ s/^supplemental/default/;
2165: }
2166: }
2167: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2168: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2169: } else {
2170: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2171: }
2172: my $counter = 0;
2173: my $is_unique = &uniqueness_check($newurl);
2174: if ($folder =~ /^default/) {
2175: if ($allmaps->{$newurl}) {
2176: $is_unique = 0;
2177: }
2178: }
2179: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2180: $counter ++;
2181: $suffix ++;
2182: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2183: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2184: } else {
2185: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2186: }
2187: $is_unique = &uniqueness_check($newurl);
2188: }
2189: if ($is_unique) {
2190: $newurls->{$newurl} = 1;
2191: } else {
2192: if ($url=~/\.page$/) {
2193: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2194: } else {
2195: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2196: }
2197: }
2198: }
2199: return ($newurl);
2200: }
2201:
2202: sub dbcopy {
2203: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2204: my ($url,$result,$errtext);
2205: if (ref($dbref) eq 'HASH') {
2206: $url = $dbref->{'src'};
2207: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
2208: my $prefix = $1;
2209: if ($prefix eq 'ext.tool') {
2210: $prefix = 'exttool';
2211: }
2212: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2213: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2214: my $db_name;
2215: my $marker = (split(m{/},$url))[4];
2216: $marker=~s/\D//g;
2217: if ($dbref->{'src'} =~ m{/smppg$}) {
2218: $db_name =
2219: &Apache::lonsimplepage::get_db_name($url,$marker,
2220: $dbref->{'cdom'},
2221: $dbref->{'cnum'});
2222: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2223: $db_name = 'exttool_'.$marker;
2224: } else {
2225: $db_name = 'bulletinpage_'.$marker;
2226: }
2227: my ($suffix,$freedlock,$error) =
2228: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2229: $coursedom,$coursenum,
2230: 'concat');
2231: if (!$suffix) {
2232: if ($prefix eq 'smppg') {
2233: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2234: } elsif ($prefix eq 'exttool') {
2235: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
2236: } else {
2237: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2238: }
2239: if ($error) {
2240: $errtext .= '<br />'.$error;
2241: }
2242: } else {
2243: #need to copy the db contents to a new one.
2244: my %contents=&Apache::lonnet::dump($db_name,
2245: $dbref->{'cdom'},
2246: $dbref->{'cnum'});
2247: if (exists($contents{'uploaded.photourl'})) {
2248: my $photo = $contents{'uploaded.photourl'};
2249: my ($subdir,$fname) =
2250: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2251: my $newphoto;
2252: if ($fname ne '') {
2253: my $content = &Apache::lonnet::getfile($photo);
2254: unless ($content eq '-1') {
2255: $env{'form.'.$suffix.'.photourl'} = $content;
2256: $newphoto =
2257: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2258: delete($env{'form.'.$suffix.'.photourl'});
2259: }
2260: }
2261: if ($newphoto =~ m{^/uploaded/}) {
2262: $contents{'uploaded.photourl'} = $newphoto;
2263: }
2264: }
2265: $db_name =~ s{_\d*$ }{_$suffix}x;
2266: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2267: delete($contents{'gradable'});
2268: }
2269: $result=&Apache::lonnet::put($db_name,\%contents,
2270: $coursedom,$coursenum);
2271: if ($result eq 'ok') {
2272: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2273: }
2274: }
2275: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2276: $lockerrorsref->{$prefix} =
2277: '<div class="LC_error">'.
2278: &mt('There was a problem removing a lockfile.');
2279: if ($prefix eq 'smppg') {
2280: $lockerrorsref->{$prefix} .=
2281: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2282: } elsif ($prefix eq 'exttool') {
2283: $lockerrorsref->{$prefix} .=
2284: ' '.&mt('This will prevent addition of more external tools to this course.');
2285: } else {
2286: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2287: }
2288: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2289: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2290: '</div>';
2291: }
2292: }
2293: } elsif ($url =~ m{/syllabus$}) {
2294: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2295: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2296: if (($dbref->{'cdom'} ne $coursedom) ||
2297: ($dbref->{'cnum'} ne $coursenum)) {
2298: my %contents=&Apache::lonnet::dump('syllabus',
2299: $dbref->{'cdom'},
2300: $dbref->{'cnum'});
2301: $result=&Apache::lonnet::put('syllabus',\%contents,
2302: $coursedom,$coursenum);
2303: }
2304: }
2305: }
2306: }
2307: return ($url,$result,$errtext);
2308: }
2309:
2310: sub copy_templated_files {
2311: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2312: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2313: my $srccontainer = 'sequence';
2314: if ($srcwaspage) {
2315: $srccontainer = 'page';
2316: }
2317: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2318: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2319: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2320: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2321: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2322: $template.'.problem';
2323: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2324: if ($template eq 'simpleproblem') {
2325: $srcprefix .= '.0.';
2326: my $weightprefix = $newprefix;
2327: $newprefix .= '.0.';
2328: my @simpleprobqtypes = qw(radio option string essay numerical);
2329: my $qtype=$srcparms{$srcprefix.'questiontype'};
2330: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2331: my %newdata;
2332: foreach my $type (@simpleprobqtypes) {
2333: if ($type eq $qtype) {
2334: $newdata{"$weightprefix.$type.weight"}=1;
2335: } else {
2336: $newdata{"$weightprefix.$type.weight"}=0;
2337: }
2338: }
2339: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2340: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2341: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2342: if ($qtype eq 'numerical') {
2343: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2344: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2345: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2346: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2347: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2348: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2349: unless (defined($maxfoils)) { $maxfoils=10; }
2350: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2351: if ($maxfoils<=0) { $maxfoils=10; }
2352: my $randomize=$srcparms{$srcprefix.'randomize'};
2353: unless (defined($randomize)) { $randomize='yes'; }
2354: unless ($randomize eq 'no') { $randomize='yes'; }
2355: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2356: $newdata{$newprefix.'randomize'} = $randomize;
2357: if ($qtype eq 'option') {
2358: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2359: }
2360: for (my $i=1; $i<=10; $i++) {
2361: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2362: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2363: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2364: }
2365:
2366: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2367: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2368: unless (defined($maxfoils)) { $maxfoils=10; }
2369: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2370: if ($maxfoils<=0) { $maxfoils=10; }
2371: my $randomize=$srcparms{$srcprefix.'randomize'};
2372: unless (defined($randomize)) { $randomize='yes'; }
2373: unless ($randomize eq 'no') { $randomize='yes'; }
2374: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2375: $newdata{$newprefix.'randomize'} = $randomize;
2376: if ($qtype eq 'option') {
2377: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2378: }
2379: for (my $i=1; $i<=10; $i++) {
2380: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2381: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2382: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2383: }
2384: } elsif ($qtype eq 'string') {
2385: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2386: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2387: }
2388: if (keys(%newdata)) {
2389: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2390: $coursenum);
2391: if ($putres eq 'ok') {
2392: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2393: }
2394: }
2395: }
2396: }
2397: }
2398:
2399: sub uniqueness_check {
2400: my ($newurl) = @_;
2401: my $unique = 1;
2402: foreach my $res (@LONCAPA::map::order) {
2403: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2404: $url=&LONCAPA::map::qtescape($url);
2405: if ($newurl eq $url) {
2406: $unique = 0;
2407: last;
2408: }
2409: }
2410: return $unique;
2411: }
2412:
2413: sub contained_map_check {
2414: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2415: $hierarchy,$titles,$allmaps) = @_;
2416: my $content = &Apache::lonnet::getfile($url);
2417: unless ($content eq '-1') {
2418: my $parser = HTML::TokeParser->new(\$content);
2419: $parser->attr_encoded(1);
2420: while (my $token = $parser->get_token) {
2421: next if ($token->[0] ne 'S');
2422: if ($token->[1] eq 'resource') {
2423: next if ($token->[2]->{'type'} eq 'zombie');
2424: my $ressrc = $token->[2]->{'src'};
2425: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2426: my $srcdom = $1;
2427: unless ($srcdom eq $coursedom) {
2428: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2429: next;
2430: }
2431: } elsif ($folder =~ /^supplemental/) {
2432: unless (&supp_pasteable($ressrc)) {
2433: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2434: next;
2435: }
2436: }
2437: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2438: if ($1 eq 'uploaded') {
2439: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2440: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2441: } else {
2442: if ($allmaps->{$ressrc}) {
2443: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2444: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2445: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2446: } else {
2447: $addedmaps->{$ressrc} = [$url];
2448: }
2449: }
2450: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2451: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
2452: }
2453: } elsif ($token->[1] eq 'param') {
2454: if ($folder =~ /^supplemental/) {
2455: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2456: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2457: } else {
2458: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2459: }
2460: }
2461: }
2462: }
2463: }
2464: return;
2465: }
2466:
2467: sub url_paste_fixups {
2468: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2469: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2470: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2471: my $checktitle;
2472: if (($prefixchg) &&
2473: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2474: $checktitle = 1;
2475: }
2476: my $skip;
2477: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2478: my $mapid = $1.$2;
2479: if ($tomove->{$mapid}) {
2480: $skip = 1;
2481: }
2482: }
2483: my $file = &Apache::lonnet::getfile($oldurl);
2484: return if ($file eq '-1');
2485: my $parser = HTML::TokeParser->new(\$file);
2486: $parser->attr_encoded(1);
2487: my $changed = 0;
2488: while (my $token = $parser->get_token) {
2489: next if ($token->[0] ne 'S');
2490: if ($token->[1] eq 'resource') {
2491: my $ressrc = $token->[2]->{'src'};
2492: next if ($ressrc eq '');
2493: my $id = $token->[2]->{'id'};
2494: my $title = $token->[2]->{'title'};
2495: if ($checktitle) {
2496: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2497: $retitles->{$oldurl}{$id} = $ressrc;
2498: }
2499: }
2500: next if ($token->[2]->{'type'} eq 'external');
2501: if ($token->[2]->{'type'} eq 'zombie') {
2502: next if ($skip);
2503: $zombies->{$oldurl}{$id} = $ressrc;
2504: $changed = 1;
2505: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2506: my $srcdom = $1;
2507: my $srcnum = $2;
2508: my $rem = $3;
2509: my $newurl;
2510: my $mapname;
2511: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2512: my $prefix = $1;
2513: $mapname = $prefix.$2;
2514: if ($tomove->{$mapname}) {
2515: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2516: $srcdom,$srcnum,$allmaps,$rewrites,
2517: $retitles,$copies,$dbcopies,$zombies,
2518: $params,$mapmoves,$mapchanges,$tomove,
2519: $newsubdir,$newurls,$resdatacopy);
2520: next;
2521: } else {
2522: ($newurl,my $error) =
2523: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2524: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2525: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2526: $newsubdir->{$ressrc} = $1;
2527: }
2528: if ($error) {
2529: next;
2530: }
2531: }
2532: }
2533: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2534: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2535:
2536: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2537: $rewrites->{$oldurl}{$id} = $ressrc;
2538: $mapchanges->{$ressrc} = 1;
2539: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2540: $cnum,$srcdom,$srcnum,$allmaps,
2541: $rewrites,$retitles,$copies,$dbcopies,
2542: $zombies,$params,$mapmoves,$mapchanges,
2543: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2544: $mapmoves->{$ressrc} = 1;
2545: }
2546: $changed = 1;
2547: } else {
2548: $rewrites->{$oldurl}{$id} = $ressrc;
2549: $copies->{$oldurl}{$ressrc} = $id;
2550: $changed = 1;
2551: }
2552: }
2553: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
2554: next if ($skip);
2555: my $srcdom = $1;
2556: my $srcnum = $2;
2557: my $rem = $3;
2558: my ($is_exttool,$exttoolchg);
2559: if ($rem =~ m{\d+/ext\.tool$}) {
2560: $is_exttool = 1;
2561: }
2562: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2563: $rewrites->{$oldurl}{$id} = $ressrc;
2564: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2565: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2566: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2567: $changed = 1;
2568: if ($is_exttool) {
2569: $exttoolchg = 1;
2570: }
2571: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2572: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2573: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2574: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2575: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2576: $changed = 1;
2577: $exttoolchg = 1;
2578: }
2579: if (($is_exttool) && ($prefixchg)) {
2580: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2581: if ($exttoolchg) {
2582: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2583: }
2584: }
2585: }
2586: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2587: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2588: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2589: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2590: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2591: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2592: $changed = 1;
2593: }
2594: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2595: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2596: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2597: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2598: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2599: }
2600: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2601: next if ($skip);
2602: my $srcdom = $1;
2603: my $srcnum = $2;
2604: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2605: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2606: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2607: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2608: $changed = 1;
2609: }
2610: }
2611: } elsif ($token->[1] eq 'param') {
2612: next if ($skip);
2613: my $to = $token->[2]->{'to'};
2614: if ($to ne '') {
2615: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2616: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2617: } else {
2618: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2619: }
2620: }
2621: }
2622: }
2623: return $changed;
2624: }
2625:
2626: sub apply_fixups {
2627: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2628: $oldurl,$url,$caller) = @_;
2629: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2630: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2631: %resdatacopy,%lockerrors,$lockmsg);
2632: if (ref($updated) eq 'HASH') {
2633: if (ref($updated->{'rewrites'}) eq 'HASH') {
2634: %rewrites = %{$updated->{'rewrites'}};
2635: }
2636: if (ref($updated->{'zombies'}) eq 'HASH') {
2637: %zombies = %{$updated->{'zombies'}};
2638: }
2639: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2640: %removefrommap = %{$updated->{'removefrommap'}};
2641: }
2642: if (ref($updated->{'removeparam'}) eq 'HASH') {
2643: %removeparam = %{$updated->{'removeparam'}};
2644: }
2645: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2646: %dbcopies = %{$updated->{'dbcopies'}};
2647: }
2648: if (ref($updated->{'retitles'}) eq 'HASH') {
2649: %retitles = %{$updated->{'retitles'}};
2650: }
2651: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2652: %resdatacopy = %{$updated->{'resdatacopy'}};
2653: }
2654: }
2655: if (ref($info) eq 'HASH') {
2656: if (ref($info->{'newsubdir'}) eq 'HASH') {
2657: %newsubdir = %{$info->{'newsubdir'}};
2658: }
2659: if (ref($info->{'params'}) eq 'HASH') {
2660: %params = %{$info->{'params'}};
2661: }
2662: if (ref($info->{'before'}) eq 'HASH') {
2663: %before = %{$info->{'before'}};
2664: }
2665: if (ref($info->{'after'}) eq 'HASH') {
2666: %after = %{$info->{'after'}};
2667: }
2668: }
2669: if (ref($moves) eq 'HASH') {
2670: if (ref($moves->{'copies'}) eq 'HASH') {
2671: %copies = %{$moves->{'copies'}};
2672: }
2673: if (ref($moves->{'docmoves'}) eq 'HASH') {
2674: %docmoves = %{$moves->{'docmoves'}};
2675: }
2676: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2677: %mapmoves = %{$moves->{'mapmoves'}};
2678: }
2679: }
2680: foreach my $key (keys(%copies),keys(%docmoves)) {
2681: my @allcopies;
2682: if (exists($copies{$key})) {
2683: if (ref($copies{$key}) eq 'HASH') {
2684: my %added;
2685: foreach my $innerkey (keys(%{$copies{$key}})) {
2686: if (($innerkey ne '') && (!$added{$innerkey})) {
2687: push(@allcopies,$innerkey);
2688: $added{$innerkey} = 1;
2689: }
2690: }
2691: undef(%added);
2692: }
2693: }
2694: if ($key eq $oldurl) {
2695: if ((exists($docmoves{$key}))) {
2696: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2697: push(@allcopies,$oldurl);
2698: }
2699: }
2700: }
2701: if (@allcopies > 0) {
2702: foreach my $item (@allcopies) {
2703: my ($relpath,$oldsubdir,$fname) =
2704: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2705: if ($fname ne '') {
2706: my $content = &Apache::lonnet::getfile($item);
2707: unless ($content eq '-1') {
2708: my $storefn;
2709: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2710: $storefn = $docmoves{$key};
2711: } else {
2712: $storefn = $relpath;
2713: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2714: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2715: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2716: }
2717: if ($newsubdir{$key}) {
2718: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2719: }
2720: }
2721: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2722: my $copyurl =
2723: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2724: $storefn.$fname,$content);
2725: if ($copyurl eq '/adm/notfound.html') {
2726: if (exists($docmoves{$oldurl})) {
2727: return &mt('Paste failed: an error occurred copying the file.');
2728: } elsif (ref($errors) eq 'HASH') {
2729: $errors->{$item} = 1;
2730: }
2731: }
2732: }
2733: }
2734: }
2735: }
2736: }
2737: foreach my $key (keys(%mapmoves)) {
2738: my $storefn=$key;
2739: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2740: if ($prefixchg && $before{'map'} && $after{'map'}) {
2741: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2742: }
2743: if ($newsubdir{$key}) {
2744: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2745: }
2746: my $mapcontent = &Apache::lonnet::getfile($key);
2747: if ($mapcontent eq '-1') {
2748: if (ref($errors) eq 'HASH') {
2749: $errors->{$key} = 1;
2750: }
2751: } else {
2752: my $newmap =
2753: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2754: $mapcontent);
2755: if ($newmap eq '/adm/notfound.html') {
2756: if (ref($errors) eq 'HASH') {
2757: $errors->{$key} = 1;
2758: }
2759: }
2760: }
2761: }
2762: my %updates;
2763: if ($is_map) {
2764: if (ref($updated) eq 'HASH') {
2765: foreach my $type (keys(%{$updated})) {
2766: if (ref($updated->{$type}) eq 'HASH') {
2767: foreach my $key (keys(%{$updated->{$type}})) {
2768: $updates{$key} = 1;
2769: }
2770: }
2771: }
2772: }
2773: foreach my $key (keys(%updates)) {
2774: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2775: if (ref($rewrites{$key}) eq 'HASH') {
2776: %torewrite = %{$rewrites{$key}};
2777: }
2778: if (ref($retitles{$key}) eq 'HASH') {
2779: %toretitle = %{$retitles{$key}};
2780: }
2781: if (ref($removefrommap{$key}) eq 'HASH') {
2782: %toremove = %{$removefrommap{$key}};
2783: }
2784: if (ref($removeparam{$key}) eq 'HASH') {
2785: %remparam = %{$removeparam{$key}};
2786: }
2787: if (ref($zombies{$key}) eq 'HASH') {
2788: %zombie = %{$zombies{$key}};
2789: }
2790: if (ref($dbcopies{$key}) eq 'HASH') {
2791: foreach my $idx (keys(%{$dbcopies{$key}})) {
2792: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2793: my ($newurl,$result,$errtext) =
2794: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2795: if ($result eq 'ok') {
2796: $newdb{$idx} = $newurl;
2797: } elsif (ref($errors) eq 'HASH') {
2798: $errors->{$key} = 1;
2799: }
2800: push(@msgs,$errtext);
2801: }
2802: }
2803: }
2804: if (ref($resdatacopy{$key}) eq 'HASH') {
2805: if ($newsubdir{$key}) {
2806:
2807: }
2808: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2809: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2810: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2811: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2812: my $template = $1;
2813: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2814: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2815: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2816: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2817: my ($newmapname) = ($key =~ m{/([^/]+)$});
2818: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2819: my $srcmapinfo = $srcfolder.':'.$idx;
2820: if ($srccontainer eq 'page') {
2821: $srcmapinfo .= ':1';
2822: }
2823: if ($newsubdir{$key}) {
2824: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2825: }
2826: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2827: $cnum,$template,$idx,$newmapname);
2828: }
2829: }
2830: }
2831: }
2832: }
2833: if (ref($params{$key}) eq 'HASH') {
2834: %currparam = %{$params{$key}};
2835: }
2836: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2837: if ($fatal) {
2838: return ($errtext);
2839: }
2840: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2841: if (defined($LONCAPA::map::zombies[$i])) {
2842: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2843: if ($zombie{$i} eq $src) {
2844: undef($LONCAPA::map::zombies[$i]);
2845: }
2846: }
2847: }
2848: my $total = scalar(@LONCAPA::map::order) - 1;
2849: for (my $i=$total; $i>=0; $i--) {
2850: my $idx = $LONCAPA::map::order[$i];
2851: if (defined($LONCAPA::map::resources[$idx])) {
2852: my $changed;
2853: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2854: if ((exists($toremove{$idx})) &&
2855: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2856: splice(@LONCAPA::map::order,$i,1);
2857: if (ref($currparam{$idx}) eq 'ARRAY') {
2858: foreach my $name (@{$currparam{$idx}}) {
2859: &LONCAPA::map::delparameter($idx,$name);
2860: }
2861: }
2862: next;
2863: }
2864: my $origsrc = $src;
2865: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2866: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2867: $changed = 1;
2868: }
2869: }
2870: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2871: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2872: if ($origsrc =~ m{^/uploaded/}) {
2873: if ($prefixchg && $before{'map'} && $after{'map'}) {
2874: if ($src =~ /\.(page|sequence)$/) {
2875: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2876: } else {
2877: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2878: }
2879: }
2880: if ($origsrc =~ /\.(page|sequence)$/) {
2881: if ($newsubdir{$origsrc}) {
2882: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2883: }
2884: } elsif ($newsubdir{$key}) {
2885: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2886: }
2887: }
2888: $changed = 1;
2889: } elsif ($newdb{$idx} ne '') {
2890: $src = $newdb{$idx};
2891: $changed = 1;
2892: }
2893: if ($changed) {
2894: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2895: }
2896: }
2897: }
2898: foreach my $idx (keys(%remparam)) {
2899: if (ref($remparam{$idx}) eq 'ARRAY') {
2900: foreach my $name (@{$remparam{$idx}}) {
2901: &LONCAPA::map::delparameter($idx,$name);
2902: }
2903: }
2904: }
2905: if (values(%lockerrors) > 0) {
2906: $lockmsg = join('<br />',values(%lockerrors));
2907: }
2908: my $storefn;
2909: if ($key eq $oldurl) {
2910: $storefn = $url;
2911: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2912: } else {
2913: $storefn = $key;
2914: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2915: if ($prefixchg && $before{'map'} && $after{'map'}) {
2916: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2917: }
2918: if ($newsubdir{$key}) {
2919: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2920: }
2921: }
2922: my $report;
2923: if ($folder !~ /^supplemental/) {
2924: $report = 1;
2925: }
2926: (my $outtext,$errtext) =
2927: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2928: if ($errtext) {
2929: if ($caller eq 'paste') {
2930: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2931: }
2932: }
2933: }
2934: }
2935: return ('ok',\@msgs,$lockmsg);
2936: }
2937:
2938: sub copy_dependencies {
2939: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2940: my $content;
2941: if (ref($contentref)) {
2942: $content = $$contentref;
2943: } else {
2944: $content = &Apache::lonnet::getfile($item);
2945: }
2946: unless ($content eq '-1') {
2947: my $mm = new File::MMagic;
2948: my $mimetype = $mm->checktype_contents($content);
2949: if ($mimetype eq 'text/html') {
2950: my (%allfiles,%codebase,$state);
2951: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2952: if ($res eq 'ok') {
2953: my ($numexisting,$numpathchanges,$existing);
2954: (undef,$numexisting,$numpathchanges,$existing) =
2955: &Apache::loncommon::ask_for_embedded_content(
2956: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2957: {'error_on_invalid_names' => 1,
2958: 'ignore_remote_references' => 1,
2959: 'docs_url' => $item,
2960: 'context' => 'paste'});
2961: if ($numexisting > 0) {
2962: if (ref($existing) eq 'HASH') {
2963: foreach my $dep (keys(%{$existing})) {
2964: my $depfile = $dep;
2965: unless ($depfile =~ m{^\Q$relpath\E}) {
2966: $depfile = $relpath.$dep;
2967: }
2968: my $depcontent = &Apache::lonnet::getfile($depfile);
2969: unless ($depcontent eq '-1') {
2970: my $storedep = $dep;
2971: $storedep =~ s{^\Q$relpath\E}{};
2972: my $dep_url =
2973: &Apache::lonclonecourse::writefile(
2974: $env{'request.course.id'},
2975: $storefn.$storedep,$depcontent);
2976: if ($dep_url eq '/adm/notfound.html') {
2977: if (ref($errors) eq 'HASH') {
2978: $errors->{$depfile} = 1;
2979: }
2980: } else {
2981: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2982: }
2983: }
2984: }
2985: }
2986: }
2987: }
2988: }
2989: }
2990: return;
2991: }
2992:
2993: my %parameter_type = ( 'randompick' => 'int_pos',
2994: 'hiddenresource' => 'string_yesno',
2995: 'encrypturl' => 'string_yesno',
2996: 'randomorder' => 'string_yesno',);
2997: my $valid_parameters_re = join('|',keys(%parameter_type));
2998: # set parameters
2999: sub update_parameter {
3000: if ($env{'form.changeparms'} eq 'all') {
3001: my (@allidx,@allmapidx,%allchecked,%currchecked);
3002: %allchecked = (
3003: 'hiddenresource' => {},
3004: 'encrypturl' => {},
3005: 'randompick' => {},
3006: 'randomorder' => {},
3007: );
3008: foreach my $which (keys(%allchecked)) {
3009: $env{'form.all'.$which} =~ s/,$//;
3010: if ($which eq 'randompick') {
3011: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3012: my ($res,$value) = split(/:/,$item);
3013: if ($value =~ /^\d+$/) {
3014: $allchecked{$which}{$res} = $value;
3015: }
3016: }
3017: } else {
3018: if ($env{'form.all'.$which}) {
3019: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3020: }
3021: }
3022: }
3023: my $haschanges = 0;
3024: foreach my $res (@LONCAPA::map::order) {
3025: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3026: $name=&LONCAPA::map::qtescape($name);
3027: $url=&LONCAPA::map::qtescape($url);
3028: next unless ($name && $url);
3029: my $is_map;
3030: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3031: $is_map = 1;
3032: }
3033: foreach my $which (keys(%allchecked)) {
3034: if (($which eq 'randompick' || $which eq 'randomorder')) {
3035: next if (!$is_map);
3036: }
3037: my $oldvalue = 0;
3038: my $newvalue = 0;
3039: if ($allchecked{$which}{$res}) {
3040: $newvalue = $allchecked{$which}{$res};
3041: }
3042: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3043: if ($which eq 'randompick') {
3044: if ($current =~ /^(\d+)$/) {
3045: $oldvalue = $1;
3046: }
3047: } else {
3048: if ($current =~ /^yes$/i) {
3049: $oldvalue = 1;
3050: }
3051: }
3052: if ($oldvalue ne $newvalue) {
3053: $haschanges = 1;
3054: if ($newvalue) {
3055: my $storeval = 'yes';
3056: if ($which eq 'randompick') {
3057: $storeval = $newvalue;
3058: }
3059: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3060: $storeval,
3061: $parameter_type{$which});
3062: &remember_parms($res,$which,'set',$storeval);
3063: } elsif ($oldvalue) {
3064: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3065: &remember_parms($res,$which,'del');
3066: }
3067: }
3068: }
3069: }
3070: return $haschanges;
3071: } else {
3072: my $haschanges = 0;
3073: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
3074:
3075: my $which = $env{'form.changeparms'};
3076: my $idx = $env{'form.setparms'};
3077: my $oldvalue = 0;
3078: my $newvalue = 0;
3079: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3080: if ($which eq 'randompick') {
3081: if ($current =~ /^(\d+)$/) {
3082: $oldvalue = $1;
3083: }
3084: } elsif ($current =~ /^yes$/i) {
3085: $oldvalue = 1;
3086: }
3087: if ($env{'form.'.$which.'_'.$idx}) {
3088: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3089: : 1;
3090: }
3091: if ($oldvalue ne $newvalue) {
3092: $haschanges = 1;
3093: if ($newvalue) {
3094: my $storeval = 'yes';
3095: if ($which eq 'randompick') {
3096: $storeval = $newvalue;
3097: }
3098: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3099: $parameter_type{$which});
3100: &remember_parms($idx,$which,'set',$storeval);
3101: } else {
3102: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3103: &remember_parms($idx,$which,'del');
3104: }
3105: }
3106: return $haschanges;
3107: }
3108: }
3109:
3110: sub handle_edit_cmd {
3111: my ($coursenum,$coursedom) =@_;
3112: my $haschanges = 0;
3113: if ($env{'form.cmd'} eq '') {
3114: return $haschanges;
3115: }
3116: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3117:
3118: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3119: my ($title, $url, @rrest) = split(':', $ratstr);
3120:
3121: if ($cmd eq 'remove') {
3122: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3123: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3124: &Apache::lonnet::removeuploadedurl($url);
3125: } else {
3126: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3127: }
3128: splice(@LONCAPA::map::order, $idx, 1);
3129: $haschanges = 1;
3130: } elsif ($cmd eq 'cut') {
3131: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3132: splice(@LONCAPA::map::order, $idx, 1);
3133: $haschanges = 1;
3134: } elsif ($cmd eq 'up'
3135: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3136: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3137: $haschanges = 1;
3138: } elsif ($cmd eq 'down'
3139: && defined($LONCAPA::map::order[$idx+1])) {
3140: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3141: $haschanges = 1;
3142: } elsif ($cmd eq 'rename') {
3143: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3144: if ($comment=~/\S/) {
3145: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3146: $comment.':'.join(':', $url, @rrest);
3147: }
3148: # Devalidate title cache
3149: my $renamed_url=&LONCAPA::map::qtescape($url);
3150: &Apache::lonnet::devalidate_title_cache($renamed_url);
3151: $haschanges = 1;
3152: } elsif ($cmd eq 'setalias') {
3153: my $newvalue = $env{'form.alias'};
3154: if ($newvalue ne '') {
3155: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3156: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3157: 'string');
3158: &remember_parms($idx,'mapalias','set',$newvalue);
3159: $haschanges = 1;
3160: }
3161: }
3162: } elsif ($cmd eq 'delalias') {
3163: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3164: if ($current ne '') {
3165: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3166: &remember_parms($idx,'mapalias','del');
3167: $haschanges = 1;
3168: }
3169: }
3170: return $haschanges;
3171: }
3172:
3173: sub editor {
3174: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3175: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3176: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3177: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3178: if ($allowed) {
3179: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3180: $is_random_order,$container) =
3181: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3182: $r->print($breadcrumbtrail);
3183: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3184: $container = 'page';
3185: } else {
3186: $container = 'sequence';
3187: }
3188:
3189: my $jumpto;
3190:
3191: unless ($supplementalflag) {
3192: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3193: }
3194:
3195: unless ($allowed) {
3196: $randompick = -1;
3197: }
3198:
3199: my ($errtext,$fatal);
3200: if (($folder eq '') && (!$supplementalflag)) {
3201: if (@LONCAPA::map::order) {
3202: undef(@LONCAPA::map::order);
3203: undef(@LONCAPA::map::resources);
3204: undef(@LONCAPA::map::resparms);
3205: undef(@LONCAPA::map::zombies);
3206: }
3207: $folder = 'default';
3208: $container = 'sequence';
3209: } else {
3210: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3211: $folder.'.'.$container);
3212: return $errtext if ($fatal);
3213: }
3214:
3215: if ($#LONCAPA::map::order<1) {
3216: my $idx=&LONCAPA::map::getresidx();
3217: if ($idx<=0) { $idx=1; }
3218: $LONCAPA::map::order[0]=$idx;
3219: $LONCAPA::map::resources[$idx]='';
3220: }
3221:
3222: # ------------------------------------------------------------ Process commands
3223:
3224: # ---------------- if they are for this folder and user allowed to make changes
3225: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3226: # set parameters and change order
3227: &snapshotbefore();
3228:
3229: if (&update_parameter()) {
3230: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3231: return $errtext if ($fatal);
3232: }
3233:
3234: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3235: # change order
3236: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3237: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3238:
3239: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3240: return $errtext if ($fatal);
3241: }
3242:
3243: if ($env{'form.pastemarked'}) {
3244: my %paste_errors;
3245: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3246: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3247: \%paste_errors);
3248: if (ref($pastemsgarray) eq 'ARRAY') {
3249: if (@{$pastemsgarray} > 0) {
3250: $r->print('<p class="LC_info">'.
3251: join('<br />',@{$pastemsgarray}).
3252: '</p>');
3253: }
3254: }
3255: if ($lockerror) {
3256: $r->print('<p class="LC_error">'.
3257: $lockerror.
3258: '</p>');
3259: }
3260: if ($save_error ne '') {
3261: return $save_error;
3262: }
3263: if ($paste_res) {
3264: my %errortext = &Apache::lonlocal::texthash (
3265: fail => 'Storage of folder contents failed',
3266: failread => 'Reading folder contents failed',
3267: failstore => 'Storage of folder contents failed',
3268: );
3269: if ($errortext{$paste_res}) {
3270: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3271: }
3272: }
3273: if (keys(%paste_errors) > 0) {
3274: $r->print('<p class="LC_warning">'."\n".
3275: &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".
3276: '<ul>'."\n");
3277: foreach my $key (sort(keys(%paste_errors))) {
3278: $r->print('<li>'.$key.'</li>'."\n");
3279: }
3280: $r->print('</ul></p>'."\n");
3281: }
3282: } elsif ($env{'form.clearmarked'}) {
3283: my $output = &do_buffer_empty();
3284: if ($output) {
3285: $r->print('<p class="LC_info">'.$output.'</p>');
3286: }
3287: }
3288:
3289: $r->print($upload_output);
3290:
3291: # Rename, cut, copy or remove a single resource
3292: if (&handle_edit_cmd($coursenum,$coursedom)) {
3293: my $contentchg;
3294: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
3295: $contentchg = 1;
3296: }
3297: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3298: return $errtext if ($fatal);
3299: }
3300:
3301: # Cut, copy and/or remove multiple resources
3302: if ($env{'form.multichange'}) {
3303: my %allchecked = (
3304: cut => {},
3305: remove => {},
3306: );
3307: my $needsupdate;
3308: foreach my $which (keys(%allchecked)) {
3309: $env{'form.multi'.$which} =~ s/,$//;
3310: if ($env{'form.multi'.$which}) {
3311: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3312: if (ref($allchecked{$which}) eq 'HASH') {
3313: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3314: }
3315: }
3316: }
3317: if ($needsupdate) {
3318: my $haschanges = 0;
3319: my %curr_groups = &Apache::longroup::coursegroups();
3320: my $total = scalar(@LONCAPA::map::order) - 1;
3321: for (my $i=$total; $i>=0; $i--) {
3322: my $res = $LONCAPA::map::order[$i];
3323: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3324: $name=&LONCAPA::map::qtescape($name);
3325: $url=&LONCAPA::map::qtescape($url);
3326: next unless $url;
3327: my %denied =
3328: &action_restrictions($coursenum,$coursedom,$url,
3329: $env{'form.folderpath'},\%curr_groups);
3330: foreach my $which (keys(%allchecked)) {
3331: next if ($denied{$which});
3332: next unless ($allchecked{$which}{$res});
3333: if ($which eq 'remove') {
3334: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3335: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3336: &Apache::lonnet::removeuploadedurl($url);
3337: } else {
3338: &LONCAPA::map::makezombie($res);
3339: }
3340: splice(@LONCAPA::map::order,$i,1);
3341: $haschanges ++;
3342: } elsif ($which eq 'cut') {
3343: &LONCAPA::map::makezombie($res);
3344: splice(@LONCAPA::map::order,$i,1);
3345: $haschanges ++;
3346: }
3347: }
3348: }
3349: if ($haschanges) {
3350: ($errtext,$fatal) =
3351: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3352: return $errtext if ($fatal);
3353: }
3354: }
3355: }
3356:
3357: # Group import/search
3358: if ($env{'form.importdetail'}) {
3359: my @imports;
3360: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3361: if (defined($item)) {
3362: my ($name,$url,$residx)=
3363: map { &unescape($_); } split(/\=/,$item);
3364: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3365: my ($suffix,$errortxt,$locknotfreed) =
3366: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3367: if ($locknotfreed) {
3368: $r->print($locknotfreed);
3369: }
3370: if ($suffix) {
3371: $url =~ s/_new\./_$suffix./;
3372: } else {
3373: return $errortxt;
3374: }
3375: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3376: my $type = $1;
3377: my ($suffix,$errortxt,$locknotfreed) =
3378: &new_timebased_suffix($coursedom,$coursenum,$type);
3379: if ($locknotfreed) {
3380: $r->print($locknotfreed);
3381: }
3382: if ($suffix) {
3383: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3384: } else {
3385: return $errortxt;
3386: }
3387: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3388: my ($suffix,$errortxt,$locknotfreed) =
3389: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3390: if ($locknotfreed) {
3391: $r->print($locknotfreed);
3392: }
3393: if ($suffix) {
3394: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3395: } else {
3396: return $errortxt;
3397: }
3398: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3399: if ($supplementalflag) {
3400: next unless ($1 eq 'supplemental');
3401: if ($folder eq 'supplemental') {
3402: next unless ($2 eq 'default');
3403: } else {
3404: next unless ($folder eq 'supplemental_'.$2);
3405: }
3406: } else {
3407: next unless ($1 eq 'docs');
3408: if ($folder eq 'default') {
3409: next unless ($2 eq 'default');
3410: } else {
3411: next unless ($folder eq 'default_'.$2);
3412: }
3413: }
3414: }
3415: push(@imports, [$name, $url, $residx]);
3416: }
3417: }
3418: ($errtext,$fatal,my $fixuperrors) =
3419: &group_import($coursenum, $coursedom, $folder,$container,
3420: 'londocs',$ltitoolsref,@imports);
3421: return $errtext if ($fatal);
3422: if ($fixuperrors) {
3423: $r->print($fixuperrors);
3424: }
3425: }
3426: # Loading a complete map
3427: if ($env{'form.loadmap'}) {
3428: if ($env{'form.importmap'}=~/\w/) {
3429: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3430: my ($title,$url,$ext,$type)=split(/\:/,$res);
3431: my $idx=&LONCAPA::map::getresidx($url);
3432: $LONCAPA::map::resources[$idx]=$res;
3433: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3434: }
3435: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3436: $folder.'.'.$container,1);
3437: return $errtext if ($fatal);
3438: } else {
3439: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3440:
3441: }
3442: }
3443: &log_differences($plain);
3444: }
3445: # ---------------------------------------------------------------- End commands
3446: # ---------------------------------------------------------------- Print screen
3447: my $idx=0;
3448: my $shown=0;
3449: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3450: $r->print('<div class="LC_Box">'.
3451: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3452: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3453: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3454: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3455: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3456: '</ol>');
3457: if ($randompick>=0) {
3458: $r->print('<p class="LC_warning">'
3459: .&mt('Caution: this folder is set to randomly pick a subset'
3460: .' of resources. Adding or removing resources from this'
3461: .' folder will change the set of resources that the'
3462: .' students see, resulting in spurious or missing credit'
3463: .' for completed problems, not limited to ones you'
3464: .' modify. Do not modify the contents of this folder if'
3465: .' it is in active student use.')
3466: .'</p>'
3467: );
3468: }
3469: if ($is_random_order) {
3470: $r->print('<p class="LC_warning">'
3471: .&mt('Caution: this folder is set to randomly order its'
3472: .' contents. Adding or removing resources from this folder'
3473: .' will change the order of resources shown.')
3474: .'</p>'
3475: );
3476: }
3477: $r->print('</div>');
3478: }
3479:
3480: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3481: %filters = (
3482: canremove => [],
3483: cancut => [],
3484: cancopy => [],
3485: hiddenresource => [],
3486: encrypturl => [],
3487: randomorder => [],
3488: randompick => [],
3489: );
3490: %curr_groups = &Apache::longroup::coursegroups();
3491: &Apache::loncommon::start_data_table_count(); #setup a row counter
3492: foreach my $res (@LONCAPA::map::order) {
3493: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3494: $name=&LONCAPA::map::qtescape($name);
3495: $url=&LONCAPA::map::qtescape($url);
3496: unless ($name) { $name=(split(/\//,$url))[-1]; }
3497: unless ($name) { $idx++; next; }
3498: push(@allidx,$res);
3499: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3500: push(@allmapidx,$res);
3501: }
3502:
3503: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3504: $coursenum,$coursedom,$crstype,
3505: $pathitem,$supplementalflag,$container,
3506: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3507: $isencrypted,$navmapref,$hostname);
3508: $idx++;
3509: $shown++;
3510: }
3511: &Apache::loncommon::end_data_table_count();
3512:
3513: my $need_save;
3514: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3515: my $toolslink;
3516: if ($allowed) {
3517: $toolslink = '<table><tr><td>'
3518: .&Apache::loncommon::help_open_menu('Navigation Screen',
3519: 'Navigation_Screen',undef,'RAT')
3520: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3521: .'<td align="left"><ul id="LC_toolbar">'
3522: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3523: .'id="LC_content_toolbar_edittoplevel" '
3524: .'class="LC_toolbarItem" '
3525: .'title="'.&mt('Supplemental Content Editor').'">'
3526: .'</a></li></ul></td></tr></table><br />';
3527: }
3528: if ($shown) {
3529: if ($allowed) {
3530: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3531: .&Apache::loncommon::start_data_table(undef,'contentlist')
3532: .&Apache::loncommon::start_data_table_header_row()
3533: .'<th colspan="2">'.&mt('Move').'</th>'
3534: .'<th colspan="3">'.&mt('Actions').'</th>'
3535: .'<th>'.&mt('Document').'</th>';
3536: if ($folder !~ /^supplemental/) {
3537: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
3538: }
3539: $to_show .= &Apache::loncommon::end_data_table_header_row();
3540: if ($folder !~ /^supplemental/) {
3541: $lists{'canhide'} = join(',',@allidx);
3542: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3543: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3544: 'randomorder','randompick');
3545: foreach my $item (@possfilters) {
3546: if (ref($filters{$item}) eq 'ARRAY') {
3547: if (@{$filters{$item}} > 0) {
3548: $lists{$item} = join(',',@{$filters{$item}});
3549: }
3550: }
3551: }
3552: if (@allidx > 0) {
3553: my $path;
3554: if ($env{'form.folderpath'}) {
3555: $path =
3556: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3557: }
3558: if (@allidx > 1) {
3559: $to_show .=
3560: &Apache::loncommon::continue_data_table_row().
3561: '<td colspan="2"> </td>'.
3562: '<td>'.
3563: &multiple_check_form('actions',\%lists,$canedit).
3564: '</td>'.
3565: '<td colspan="3"> </td>'.
3566: '<td colspan="2">'.
3567: &multiple_check_form('settings',\%lists,$canedit).
3568: '</td>'.
3569: &Apache::loncommon::end_data_table_row();
3570: $need_save = 1;
3571: }
3572: }
3573: }
3574: $to_show .= $output.' '
3575: .&Apache::loncommon::end_data_table()
3576: .'<br style="line-height:2px;" />'
3577: .&Apache::loncommon::end_scrollbox();
3578: } else {
3579: $to_show .= $toolslink
3580: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3581: .$output.' '
3582: .&Apache::loncommon::end_data_table();
3583: }
3584: } else {
3585: if (!$allowed) {
3586: $to_show .= $toolslink;
3587: }
3588: my $noresmsg;
3589: if ($allowed && $hiddentop && !$supplementalflag) {
3590: $noresmsg = &mt('Main Content Hidden');
3591: } else {
3592: $noresmsg = &mt('Currently empty');
3593: }
3594: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3595: .'<div class="LC_info" id="contentlist">'
3596: .$noresmsg
3597: .'</div>'
3598: .&Apache::loncommon::end_scrollbox();
3599: }
3600: } else {
3601: if ($shown) {
3602: $to_show = '<div>'
3603: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3604: .$output
3605: .&Apache::loncommon::end_data_table()
3606: .'</div>';
3607: } else {
3608: $to_show = '<div class="LC_info" id="contentlist">'
3609: .&mt('Currently empty')
3610: .'</div>'
3611: }
3612: }
3613: my $tid = 1;
3614: if ($supplementalflag) {
3615: $tid = 2;
3616: }
3617: if ($allowed) {
3618: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3619: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3620: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3621: if ($canedit) {
3622: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3623: }
3624: } else {
3625: $r->print($to_show);
3626: }
3627: return;
3628: }
3629:
3630: sub multiple_check_form {
3631: my ($caller,$listsref,$canedit) = @_;
3632: return unless (ref($listsref) eq 'HASH');
3633: my $disabled;
3634: unless ($canedit) {
3635: $disabled = 'disabled="disabled"';
3636: }
3637: my $output =
3638: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3639: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3640: '<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>'.
3641: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3642: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3643: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3644: if ($caller eq 'settings') {
3645: $output .=
3646: '<table><tr>'.
3647: '<td class="LC_docs_entry_parameter">'.
3648: '<span class="LC_nobreak"><label>'.
3649: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3650: '</label></span></td>'.
3651: '<td class="LC_docs_entry_parameter">'.
3652: '<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="" />'.
3653: '</span></td>'.
3654: '</tr>'."\n".
3655: '<tr>'.
3656: '<td class="LC_docs_entry_parameter">'.
3657: '<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').
3658: '</label></span>'.
3659: '</td></tr></table>'."\n";
3660: } else {
3661: $output .=
3662: '<table><tr>'.
3663: '<td class="LC_docs_entry_parameter">'.
3664: '<span class="LC_nobreak LC_docs_remove">'.
3665: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3666: '</label></span></td>'.
3667: '<td class="LC_docs_entry_parameter">'.
3668: '<span class="LC_nobreak LC_docs_cut">'.
3669: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3670: '</label></span></td>'."\n".
3671: '<td class="LC_docs_entry_parameter">'.
3672: '<span class="LC_nobreak LC_docs_copy">'.
3673: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3674: '</label></span></td>'.
3675: '</tr></table>'."\n";
3676: }
3677: $output .=
3678: '</fieldset>'.
3679: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3680: if ($caller eq 'settings') {
3681: $output .=
3682: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3683: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3684: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3685: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3686: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3687: } elsif ($caller eq 'actions') {
3688: $output .=
3689: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3690: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3691: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3692: }
3693: $output .=
3694: '</form>'.
3695: '</div>';
3696: return $output;
3697: }
3698:
3699: sub process_file_upload {
3700: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3701: # upload a file, if present
3702: my $filesize = length($env{'form.uploaddoc'});
3703: if (!$filesize) {
3704: $$upload_output = '<div class="LC_error">'.
3705: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3706: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3707: $filesize).'<br />'.
3708: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3709: '</div>';
3710: return;
3711: }
3712: my $quotatype = 'unofficial';
3713: if ($crstype eq 'Community') {
3714: $quotatype = 'community';
3715: } elsif ($crstype eq 'Placement') {
3716: $quotatype = 'placement';
3717: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3718: $quotatype = 'official';
3719: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3720: $quotatype = 'textbook';
3721: }
3722: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3723: $filesize = int($filesize/1000); #expressed in kb
3724: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3725: $env{'form.uploaddoc.filename'},$filesize,
3726: 'upload',$quotatype);
3727: return if ($$upload_output);
3728: }
3729: my ($parseaction,$showupload,$nextphase,$mimetype);
3730: if ($env{'form.parserflag'}) {
3731: $parseaction = 'parse';
3732: }
3733: my $folder=$env{'form.folder'};
3734: if ($folder eq '') {
3735: $folder='default';
3736: }
3737: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3738: my $errtext='';
3739: my $fatal=0;
3740: my $container='sequence';
3741: if ($env{'form.folderpath'} =~ /:1$/) {
3742: $container='page';
3743: }
3744: ($errtext,$fatal)=
3745: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3746: if ($#LONCAPA::map::order<1) {
3747: $LONCAPA::map::order[0]=1;
3748: $LONCAPA::map::resources[1]='';
3749: }
3750: my $destination = 'docs/';
3751: if ($folder =~ /^supplemental/) {
3752: $destination = 'supplemental/';
3753: }
3754: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3755: $destination .= 'default/';
3756: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3757: $destination .= $2.'/';
3758: }
3759: if ($fatal) {
3760: $$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>';
3761: return;
3762: }
3763: # this is for a course, not a user, so set context to coursedoc.
3764: my $newidx=&LONCAPA::map::getresidx();
3765: $destination .= $newidx;
3766: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3767: $parseaction,$allfiles,
3768: $codebase,undef,undef,undef,undef,
3769: undef,undef,\$mimetype);
3770: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3771: my $stored = $1;
3772: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3773: $stored.'</span>').'</p>';
3774: } else {
3775: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3776:
3777: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3778: return;
3779: }
3780: my $ext='false';
3781: if ($url=~m{^http://}) { $ext='true'; }
3782: $url = &LONCAPA::map::qtunescape($url);
3783: my $comment=$env{'form.comment'};
3784: $comment = &LONCAPA::map::qtunescape($comment);
3785: if ($folder=~/^supplemental/) {
3786: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3787: $env{'user.domain'}.'___&&&___'.$comment;
3788: }
3789:
3790: $LONCAPA::map::resources[$newidx]=
3791: $comment.':'.$url.':'.$ext.':normal:res';
3792: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3793: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3794: $folder.'.'.$container,1);
3795: if ($fatal) {
3796: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3797: return;
3798: } else {
3799: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3800: $$upload_output = $showupload;
3801: my $total_embedded = scalar(keys(%{$allfiles}));
3802: if ($total_embedded > 0) {
3803: my $uploadphase = 'upload_embedded';
3804: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3805: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3806: my ($embedded,$num) =
3807: &Apache::loncommon::ask_for_embedded_content(
3808: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3809: if ($embedded) {
3810: if ($num) {
3811: $$upload_output .=
3812: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3813: $nextphase = $uploadphase;
3814: } else {
3815: $$upload_output .= $embedded;
3816: }
3817: } else {
3818: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3819: }
3820: } else {
3821: $$upload_output .= &mt('No embedded items identified').'<br />';
3822: }
3823: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3824: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3825: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3826: $nextphase = 'decompress_uploaded';
3827: my $position = scalar(@LONCAPA::map::order)-1;
3828: my $noextract = &return_to_editor();
3829: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3830: my %archiveitems = (
3831: folderpath => $env{'form.folderpath'},
3832: cmd => $nextphase,
3833: newidx => $newidx,
3834: position => $position,
3835: phase => $nextphase,
3836: comment => $comment,
3837: );
3838: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3839: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3840: $$upload_output = $showupload.
3841: &Apache::loncommon::decompress_form($mimetype,
3842: $archiveurl,'/adm/coursedocs',$noextract,
3843: \%archiveitems,\@current);
3844: }
3845: }
3846: }
3847: return $nextphase;
3848: }
3849:
3850: sub get_dir_list {
3851: my ($url,$coursenum,$coursedom,$newidx) = @_;
3852: my ($destination,$dir_root) = &embedded_destination();
3853: my ($dirlistref,$listerror) =
3854: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3855: my @dir_lines;
3856: my $dirptr=16384;
3857: if (ref($dirlistref) eq 'ARRAY') {
3858: foreach my $dir_line (sort
3859: {
3860: my ($afile)=split('&',$a,2);
3861: my ($bfile)=split('&',$b,2);
3862: return (lc($afile) cmp lc($bfile));
3863: } (@{$dirlistref})) {
3864: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3865: $filename =~ s/\s+$//;
3866: next if ($filename =~ /^\.\.?$/);
3867: my $isdir = 0;
3868: if ($dirptr&$testdir) {
3869: $isdir = 1;
3870: }
3871: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3872: }
3873: }
3874: return @dir_lines;
3875: }
3876:
3877: sub is_supplemental_title {
3878: my ($title) = @_;
3879: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3880: }
3881:
3882: # --------------------------------------------------------------- An entry line
3883:
3884: sub entryline {
3885: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3886: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3887: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
3888: my ($foldertitle,$renametitle,$oldtitle);
3889: if (&is_supplemental_title($title)) {
3890: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3891: } else {
3892: $title=&HTML::Entities::encode($title,'"<>&\'');
3893: $renametitle=$title;
3894: $foldertitle=$title;
3895: }
3896:
3897: my ($disabled,$readonly,$js_lt);
3898: unless ($canedit) {
3899: $disabled = 'disabled="disabled"';
3900: $readonly = 1;
3901: }
3902:
3903: my $orderidx=$LONCAPA::map::order[$index];
3904:
3905: $renametitle=~s/\\/\\\\/g;
3906: $renametitle=~s/\"\;/\\\"/g;
3907: $renametitle=~s/"/%22/g;
3908: $renametitle=~s/ /%20/g;
3909: $oldtitle = $renametitle;
3910: $renametitle=~s/\'/\\\'/g;
3911: my $line=&Apache::loncommon::start_data_table_row();
3912: my ($form_start,$form_end,$form_common,$form_param);
3913: # Edit commands
3914: my ($esc_path, $path, $symb, $curralias);
3915: if ($env{'form.folderpath'}) {
3916: $esc_path=&escape($env{'form.folderpath'});
3917: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3918: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3919: }
3920: my $isexternal;
3921: if ($residx) {
3922: my $currurl = $url;
3923: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3924: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3925: $isexternal = 1;
3926: }
3927: if (!$supplementalflag) {
3928: my $path = 'uploaded/'.
3929: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3930: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3931: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3932: $residx,
3933: &Apache::lonnet::declutter($currurl));
3934: }
3935: }
3936: my ($renamelink,%lt,$ishash);
3937: if (ref($filtersref) eq 'HASH') {
3938: $ishash = 1;
3939: }
3940:
3941: if ($allowed) {
3942: $form_start = '
3943: <form action="/adm/coursedocs" method="post">
3944: ';
3945: $form_common=(<<END);
3946: <input type="hidden" name="folderpath" value="$path" />
3947: <input type="hidden" name="symb" value="$symb" />
3948: END
3949: $form_param=(<<END);
3950: <input type="hidden" name="setparms" value="$orderidx" />
3951: <input type="hidden" name="changeparms" value="0" />
3952: END
3953: $form_end = '</form>';
3954:
3955: my $incindex=$index+1;
3956: my $selectbox='';
3957: if (($#LONCAPA::map::order>0) &&
3958: ((split(/\:/,
3959: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3960: ne '') &&
3961: ((split(/\:/,
3962: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
3963: ne '')) {
3964: $selectbox=
3965: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
3966: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
3967: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3968: if ($i==$incindex) {
3969: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
3970: } else {
3971: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3972: }
3973: }
3974: $selectbox.='</select>';
3975: }
3976: %lt=&Apache::lonlocal::texthash(
3977: 'up' => 'Move Up',
3978: 'dw' => 'Move Down',
3979: 'rm' => 'Remove',
3980: 'ct' => 'Cut',
3981: 'rn' => 'Rename',
3982: 'cp' => 'Copy',
3983: 'da' => 'Unset alias',
3984: 'sa' => 'Set alias',
3985: 'ex' => 'External Resource',
3986: 'et' => 'External Tool',
3987: 'ed' => 'Edit',
3988: 'pr' => 'Preview',
3989: 'sv' => 'Save',
3990: 'ul' => 'URL',
3991: 'ti' => 'Title',
3992: 'er' => 'Editing rights unavailable for your current role.',
3993: );
3994: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3995: $env{'form.folderpath'},
3996: $currgroups);
3997: my ($copylink,$cutlink,$removelink);
3998: my $skip_confirm = 0;
3999: my $confirm_removal = 0;
4000: if ( $folder =~ /^supplemental/
4001: || ($url =~ m{( /smppg$
4002: |/syllabus$
4003: |/aboutme$
4004: |/navmaps$
4005: |/bulletinboard$
4006: |/ext\.tool$
4007: |\.html$)}x)
4008: || $isexternal) {
4009: $skip_confirm = 1;
4010: }
4011: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4012: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4013: $confirm_removal = 1;
4014: }
4015: if ($url =~ /$LONCAPA::assess_re/) {
4016: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4017: }
4018:
4019: if ($denied{'copy'}) {
4020: $copylink=(<<ENDCOPY)
4021: <span style="visibility: hidden;">$lt{'cp'}</span>
4022: ENDCOPY
4023: } else {
4024: my $formname = 'edit_copy_'.$orderidx;
4025: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4026: $copylink=(<<ENDCOPY);
4027: <form name="$formname" method="post" action="/adm/coursedocs">
4028: $form_common
4029: <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>
4030: $form_end
4031: ENDCOPY
4032: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4033: push(@{$filtersref->{'cancopy'}},$orderidx);
4034: }
4035: }
4036: if ($denied{'cut'}) {
4037: $cutlink=(<<ENDCUT);
4038: <span style="visibility: hidden;">$lt{'ct'}</span>
4039: ENDCUT
4040: } else {
4041: my $formname = 'edit_cut_'.$orderidx;
4042: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4043: $cutlink=(<<ENDCUT);
4044: <form name="$formname" method="post" action="/adm/coursedocs">
4045: $form_common
4046: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
4047: <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>
4048: $form_end
4049: ENDCUT
4050: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4051: push(@{$filtersref->{'cancut'}},$orderidx);
4052: }
4053: }
4054: if ($denied{'remove'}) {
4055: $removelink=(<<ENDREM);
4056: <span style="visibility: hidden;">$lt{'rm'}</a>
4057: ENDREM
4058: } else {
4059: my $formname = 'edit_remove_'.$orderidx;
4060: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
4061: $removelink=(<<ENDREM);
4062: <form name="$formname" method="post" action="/adm/coursedocs">
4063: $form_common
4064: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
4065: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
4066: <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>
4067: $form_end
4068: ENDREM
4069: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4070: push(@{$filtersref->{'canremove'}},$orderidx);
4071: }
4072: }
4073: $renamelink=(<<ENDREN);
4074: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
4075: ENDREN
4076: my ($uplink,$downlink);
4077: if ($canedit) {
4078: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4079: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4080: } else {
4081: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4082: $downlink = $uplink;
4083: }
4084: $line.=(<<END);
4085: <td>
4086: <div class="LC_docs_entry_move">
4087: <a href="$uplink">
4088: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
4089: </a>
4090: </div>
4091: <div class="LC_docs_entry_move">
4092: <a href="$downlink">
4093: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
4094: </a>
4095: </div>
4096: </td>
4097: <td>
4098: $form_start
4099: $form_param
4100: $form_common
4101: $selectbox
4102: $form_end
4103: </td>
4104: <td class="LC_docs_entry_commands LC_nobreak">
4105: $removelink
4106: $cutlink
4107: $copylink
4108: </td>
4109: END
4110: }
4111: # Figure out what kind of a resource this is
4112: my ($extension)=($url=~/\.(\w+)$/);
4113: my $uploaded=($url=~/^\/*uploaded\//);
4114: my $icon=&Apache::loncommon::icon($url);
4115: my $isfolder;
4116: my $ispage;
4117: my $containerarg;
4118: my $folderurl;
4119: if ($uploaded) {
4120: if (($extension eq 'sequence') || ($extension eq 'page')) {
4121: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
4122: $containerarg = $1;
4123: if ($extension eq 'sequence') {
4124: $icon=$iconpath.'navmap.folder.closed.gif';
4125: $isfolder=1;
4126: } else {
4127: $icon=$iconpath.'page.gif';
4128: $ispage=1;
4129: }
4130: $folderurl = &Apache::lonnet::declutter($url);
4131: if ($allowed) {
4132: $url='/adm/coursedocs?';
4133: } else {
4134: $url='/adm/supplemental?';
4135: }
4136: } else {
4137: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4138: }
4139: }
4140:
4141: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
4142: my $orig_url = $url;
4143: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
4144: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4145: if (!$supplementalflag && $residx && $symb) {
4146: if ((!$isfolder) && (!$ispage)) {
4147: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4148: $url=&Apache::lonnet::clutter($url);
4149: if ($url=~/^\/*uploaded\//) {
4150: $url=~/\.(\w+)$/;
4151: my $embstyle=&Apache::loncommon::fileembstyle($1);
4152: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4153: $url='/adm/wrapper'.$url;
4154: } elsif ($embstyle eq 'ssi') {
4155: #do nothing with these
4156: } elsif ($url!~/\.(sequence|page)$/) {
4157: $url='/adm/coursedocs/showdoc'.$url;
4158: }
4159: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4160: my $wrapped = $1;
4161: my $exturl = $2;
4162: if ($wrapped eq '') {
4163: $url='/adm/wrapper'.$url;
4164: }
4165: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4166: $nomodal = 1;
4167: }
4168: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4169: $url='/adm/wrapper'.$url;
4170: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4171: if (($ENV{'SERVER_PORT'} == 443) &&
4172: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4173: $url .= '?usehttp=1';
4174: $nomodal = 1;
4175: }
4176: }
4177: if (&Apache::lonnet::symbverify($symb,$url)) {
4178: my $shownsymb = $symb;
4179: if ($isexternal) {
4180: if ($url =~ /^([^#]+)#([^#]+)$/) {
4181: $url = $1;
4182: $anchor = $2;
4183: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4184: $shownsymb = $1.&escape('#').$anchor;
4185: }
4186: }
4187: }
4188: unless ($env{'request.role.adv'}) {
4189: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4190: $url = '';
4191: }
4192: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4193: $url = '';
4194: $hiddenres = 1;
4195: }
4196: }
4197: if ($url ne '') {
4198: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4199: }
4200: } elsif (!$env{'request.role.adv'}) {
4201: my $checkencrypt;
4202: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4203: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4204: $checkencrypt = 1;
4205: } elsif (ref($navmapref)) {
4206: unless (ref($$navmapref)) {
4207: $$navmapref = Apache::lonnavmaps::navmap->new();
4208: }
4209: if (ref($$navmapref)) {
4210: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4211: $checkencrypt = 1;
4212: }
4213: }
4214: }
4215: if ($checkencrypt) {
4216: my $shownsymb = &Apache::lonenc::encrypted($symb);
4217: my $shownurl = &Apache::lonenc::encrypted($url);
4218: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4219: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4220: if ($env{'request.enc'} ne '') {
4221: delete($env{'request.enc'});
4222: }
4223: } else {
4224: $url='';
4225: }
4226: } else {
4227: $url='';
4228: }
4229: } else {
4230: $url='';
4231: }
4232: }
4233: } elsif ($supplementalflag) {
4234: if ($isexternal) {
4235: if ($url =~ /^([^#]+)#([^#]+)$/) {
4236: $url = $1;
4237: $anchor = $2;
4238: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4239: if ($hostname ne '') {
4240: $url = 'http://'.$hostname.$url;
4241: }
4242: $nomodal = 1;
4243: }
4244: }
4245: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4246: if (($ENV{'SERVER_PORT'} == 443) &&
4247: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4248: if ($hostname ne '') {
4249: $url = 'http://'.$hostname.$url;
4250: }
4251: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4252: $nomodal = 1;
4253: }
4254: }
4255: }
4256: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4257: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4258: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4259: my $foldername=&escape($foldertitle);
4260: my $folderpath=$env{'form.folderpath'};
4261: if ($folderpath) { $folderpath.='&' };
4262: if (!$allowed && $supplementalflag) {
4263: $folderpath.=$containerarg.'&'.$foldername;
4264: $url.='folderpath='.&escape($folderpath);
4265: } else {
4266: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4267: 'parameter_randompick'))[0];
4268: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4269: 'parameter_randomorder'))[0]=~/^yes$/i);
4270: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4271: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4272: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4273: 'parameter_encrypturl'))[0]=~/^yes$/i);
4274: unless ($hiddenmap) {
4275: if (ref($navmapref)) {
4276: unless (ref($$navmapref)) {
4277: $$navmapref = Apache::lonnavmaps::navmap->new();
4278: }
4279: if (ref($$navmapref)) {
4280: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4281: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4282: unless (@resources) {
4283: $hiddenmap = 1;
4284: unless ($env{'request.role.adv'}) {
4285: $url = '';
4286: $hiddenfolder = 1;
4287: }
4288: }
4289: }
4290: }
4291: }
4292: }
4293: unless ($encryptmap) {
4294: if ((ref($navmapref)) && (ref($$navmapref))) {
4295: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4296: $encryptmap = 1;
4297: }
4298: }
4299: }
4300:
4301: # Append randompick number, hidden, and encrypted with ":" to foldername,
4302: # so it gets transferred between levels
4303: $folderpath.=$containerarg.'&'.$foldername.
4304: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4305: unless ($url eq '') {
4306: $url.='folderpath='.&escape($folderpath);
4307: }
4308: my $rpckchk;
4309: if ($rpicknum) {
4310: $rpckchk = ' checked="checked"';
4311: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4312: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4313: }
4314: }
4315: my $formname = 'edit_randompick_'.$orderidx;
4316: $rand_pick_text =
4317: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4318: $form_param."\n".
4319: $form_common."\n".
4320: '<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.'">';
4321: if ($rpicknum ne '') {
4322: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4323: }
4324: $rand_pick_text .= '</span></span>'.
4325: $form_end;
4326: my $ro_set;
4327: if ($randorder) {
4328: $ro_set = 'checked="checked"';
4329: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4330: push(@{$filtersref->{'randomorder'}},$orderidx);
4331: }
4332: }
4333: $formname = 'edit_rorder_'.$orderidx;
4334: $rand_order_text =
4335: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4336: $form_param."\n".
4337: $form_common."\n".
4338: '<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>'.
4339: $form_end;
4340: }
4341: } elsif ($supplementalflag && !$allowed) {
4342: my $isexttool;
4343: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4344: $url='/adm/wrapper'.$url;
4345: $isexttool = 1;
4346: }
4347: $url .= ($url =~ /\?/) ? '&':'?';
4348: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4349: if ($title) {
4350: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4351: }
4352: if ((($isexternal) || ($isexttool)) && $orderidx) {
4353: $url .= '&idx='.$orderidx;
4354: }
4355: if ($anchor ne '') {
4356: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4357: }
4358: }
4359: my ($tdalign,$tdwidth);
4360: if ($allowed) {
4361: my $fileloc =
4362: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4363: if ($isexternal) {
4364: ($editlink,$extresform) =
4365: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4366: undef,undef,undef,undef,undef,undef,
4367: undef,$disabled);
4368: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4369: ($editlink,$extresform) =
4370: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4371: undef,undef,undef,'tool',$coursedom,
4372: $coursenum,$ltitoolsref,$disabled);
4373: } elsif (!$isfolder && !$ispage) {
4374: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4375: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4376: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4377: my $suppanchor;
4378: if ($supplementalflag) {
4379: $suppanchor = $anchor;
4380: }
4381: my $jscall =
4382: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4383: $switchserver,
4384: $forceedit,
4385: undef,$symb,
4386: &escape($env{'form.folderpath'}),
4387: $renametitle,$hostname,
4388: '','',1,$suppanchor);
4389: if ($jscall) {
4390: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4391: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4392: }
4393: }
4394: }
4395: $tdalign = ' align="right" valign="top"';
4396: $tdwidth = ' width="80%"';
4397: }
4398: my $reinit;
4399: if ($crstype eq 'Community') {
4400: $reinit = &mt('(re-initialize community to access)');
4401: } else {
4402: $reinit = &mt('(re-initialize course to access)');
4403: }
4404: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4405: if ($url =~ /$LONCAPA::assess_re/) {
4406: $line.= '<br />';
4407: if ($curralias ne '') {
4408: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4409: $lt{'da'}.'</a></span>';
4410: } else {
4411: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4412: $lt{'sa'}.'</a></span>';
4413: }
4414: }
4415: $line.='</td><td>';
4416: my $link;
4417: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4418: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4419: } elsif ($url) {
4420: if ($anchor ne '') {
4421: if ($supplementalflag) {
4422: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4423: } else {
4424: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4425: }
4426: }
4427: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4428: $link = 'http://'.$hostname.$url;
4429: } else {
4430: $link = $url;
4431: }
4432: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4433: (($anchor ne '')?$anchor:''));
4434: if ($nomodal) {
4435: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4436: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4437: } else {
4438: $line.=&Apache::loncommon::modal_link($link,
4439: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4440: }
4441: } else {
4442: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4443: }
4444: $line.='</span></td><td'.$tdwidth.'>';
4445: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4446: $line.='<a href="'.$url.'">'.$title.'</a>';
4447: } elsif ($url) {
4448: if ($nomodal) {
4449: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4450: $title.'</a>';
4451: } else {
4452: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4453: }
4454: } elsif (($hiddenfolder) || ($hiddenres)) {
4455: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
4456: } else {
4457: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4458: }
4459: if (($allowed) && ($curralias ne '')) {
4460: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4461: } else {
4462: $line .= $extresform;
4463: }
4464: $line .= '</td>';
4465: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4466: $rand_order_text = ' ' if ($rand_order_text eq '');
4467: if (($allowed) && ($folder!~/^supplemental/)) {
4468: my %lt=&Apache::lonlocal::texthash(
4469: 'hd' => 'Hidden',
4470: 'ec' => 'URL hidden');
4471: my ($enctext,$hidtext);
4472: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4473: $enctext = ' checked="checked"';
4474: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4475: push(@{$filtersref->{'encrypturl'}},$orderidx);
4476: }
4477: }
4478: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4479: $hidtext = ' checked="checked"';
4480: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4481: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4482: }
4483: }
4484: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4485: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
4486: $line.=(<<ENDPARMS);
4487: <td class="LC_docs_entry_parameter">
4488: <form action="/adm/coursedocs" method="post" name="$formhidden">
4489: $form_param
4490: $form_common
4491: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4492: $form_end
4493: <br />
4494: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4495: $form_param
4496: $form_common
4497: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4498: $form_end
4499: </td>
4500: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4501: $rand_order_text</td>
4502: ENDPARMS
4503: }
4504: $line.=&Apache::loncommon::end_data_table_row();
4505: return $line;
4506: }
4507:
4508: sub action_restrictions {
4509: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4510: my %denied = (
4511: cut => 0,
4512: copy => 0,
4513: remove => 0,
4514: );
4515: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4516: # no copy for published maps
4517: $denied{'copy'} = 1;
4518: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4519: unless ($1 eq 'simpleproblem') {
4520: $denied{'copy'} = 1;
4521: }
4522: $denied{'cut'} = 1;
4523: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4524: if ($folderpath =~ /^default&[^\&]+$/) {
4525: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4526: $denied{'remove'} = 1;
4527: }
4528: $denied{'cut'} = 1;
4529: $denied{'copy'} = 1;
4530: }
4531: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4532: my $group = $1;
4533: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4534: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4535: $denied{'remove'} = 1;
4536: }
4537: }
4538: $denied{'cut'} = 1;
4539: $denied{'copy'} = 1;
4540: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4541: my $group = $1;
4542: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4543: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4544: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4545: if (keys(%groupsettings) > 0) {
4546: $denied{'remove'} = 1;
4547: }
4548: $denied{'cut'} = 1;
4549: $denied{'copy'} = 1;
4550: }
4551: }
4552: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4553: my $group = $1;
4554: if ($url =~ /group_boards_\Q$group\E/) {
4555: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4556: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4557: if (keys(%groupsettings) > 0) {
4558: if (ref($groupsettings{'functions'}) eq 'HASH') {
4559: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4560: $denied{'remove'} = 1;
4561: }
4562: }
4563: }
4564: $denied{'cut'} = 1;
4565: $denied{'copy'} = 1;
4566: }
4567: }
4568: }
4569: return %denied;
4570: }
4571:
4572: sub new_timebased_suffix {
4573: my ($dom,$num,$type,$area,$container) = @_;
4574: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4575: if ($type eq 'paste') {
4576: $prefix = $type;
4577: $namespace = 'courseeditor';
4578: $idtype = 'addcode';
4579: } elsif ($type eq 'map') {
4580: $prefix = 'docs';
4581: if ($area eq 'supplemental') {
4582: $prefix = 'supp';
4583: }
4584: $prefix .= $container;
4585: $namespace = 'uploadedmaps';
4586: } else {
4587: $prefix = $type;
4588: $namespace = 'templated';
4589: }
4590: my ($suffix,$freedlock,$error) =
4591: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4592: if (!$suffix) {
4593: if ($type eq 'paste') {
4594: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4595: } elsif ($type eq 'map') {
4596: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4597: } elsif ($type eq 'smppg') {
4598: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4599: } elsif ($type eq 'exttool') {
4600: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
4601: } else {
4602: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4603: }
4604: if ($error) {
4605: $errtext .= '<br />'.$error;
4606: }
4607: }
4608: if ($freedlock ne 'ok') {
4609: $locknotfreed =
4610: '<div class="LC_error">'.
4611: &mt('There was a problem removing a lockfile.').' ';
4612: if ($type eq 'paste') {
4613: if ($freedlock eq 'nolock') {
4614: $locknotfreed =
4615: '<div class="LC_error">'.
4616: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4617:
4618: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4619: } else {
4620: $locknotfreed .=
4621: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4622: }
4623: } elsif ($type eq 'map') {
4624: $locknotfreed .=
4625: &mt('This will prevent creation of additional folders or composite pages in this course.');
4626: } elsif ($type eq 'smppg') {
4627: $locknotfreed .=
4628: &mt('This will prevent creation of additional simple pages in this course.');
4629: } elsif ($type eq 'exttool') {
4630: $locknotfreed .=
4631: &mt('This will prevent creation of additional external tools in this course.');
4632: } else {
4633: $locknotfreed .=
4634: &mt('This will prevent creation of additional discussion boards in this course.');
4635: }
4636: unless ($type eq 'paste') {
4637: $locknotfreed .=
4638: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4639: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4640: }
4641: $locknotfreed .= '</div>';
4642: }
4643: return ($suffix,$errtext,$locknotfreed);
4644: }
4645:
4646: =pod
4647:
4648: =item tiehash()
4649:
4650: tie the hash
4651:
4652: =cut
4653:
4654: sub tiehash {
4655: my ($mode)=@_;
4656: $hashtied=0;
4657: if ($env{'request.course.fn'}) {
4658: if ($mode eq 'write') {
4659: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4660: &GDBM_WRCREAT(),0640)) {
4661: $hashtied=2;
4662: }
4663: } else {
4664: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4665: &GDBM_READER(),0640)) {
4666: $hashtied=1;
4667: }
4668: }
4669: }
4670: }
4671:
4672: sub untiehash {
4673: if ($hashtied) { untie %hash; }
4674: $hashtied=0;
4675: return OK;
4676: }
4677:
4678:
4679:
4680:
4681: sub checkonthis {
4682: my ($r,$url,$level,$title,$checkstale)=@_;
4683: $url=&unescape($url);
4684: $alreadyseen{$url}=1;
4685: $r->rflush();
4686: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4687: $r->print("\n<br />");
4688: if ($level==0) {
4689: $r->print("<br />");
4690: }
4691: for (my $i=0;$i<=$level*5;$i++) {
4692: $r->print(' ');
4693: }
4694: $r->print('<a href="'.$url.'" target="cat">'.
4695: ($title?$title:$url).'</a> ');
4696: if ($url=~/^\/res\//) {
4697: my $updated;
4698: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4699: ($url !~ /\.\d+\.\w+$/)) {
4700: $updated = &Apache::lonnet::remove_stale_resfile($url);
4701: }
4702: my $result=&Apache::lonnet::repcopy(
4703: &Apache::lonnet::filelocation('',$url));
4704: if ($result eq 'ok') {
4705: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4706: if ($updated) {
4707: $r->print('<br />');
4708: for (my $i=0;$i<=$level*5;$i++) {
4709: $r->print(' ');
4710: }
4711: $r->print('- '.&mt('Outdated copy removed'));
4712: }
4713: $r->rflush();
4714: &Apache::lonnet::countacc($url);
4715: $url=~/\.(\w+)$/;
4716: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4717: $r->print('<br />');
4718: $r->rflush();
4719: for (my $i=0;$i<=$level*5;$i++) {
4720: $r->print(' ');
4721: }
4722: $r->print('- '.&mt('Rendering:').' ');
4723: my ($errorcount,$warningcount)=split(/:/,
4724: &Apache::lonnet::ssi_body($url,
4725: ('grade_target'=>'web',
4726: 'return_only_error_and_warning_counts' => 1)));
4727: if (($errorcount) ||
4728: ($warningcount)) {
4729: if ($errorcount) {
4730: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4731: &mt('[quant,_1,error]',$errorcount).'</span>');
4732: }
4733: if ($warningcount) {
4734: $r->print('<span class="LC_warning">'.
4735: &mt('[quant,_1,warning]',$warningcount).'</span>');
4736: }
4737: } else {
4738: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4739: }
4740: $r->rflush();
4741: }
4742: my $dependencies=
4743: &Apache::lonnet::metadata($url,'dependencies');
4744: foreach my $dep (split(/\,/,$dependencies)) {
4745: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4746: &checkonthis($r,$dep,$level+1,'',$checkstale);
4747: }
4748: }
4749: } elsif ($result eq 'unavailable') {
4750: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4751: } elsif ($result eq 'not_found') {
4752: unless ($url=~/\$/) {
4753: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4754: } else {
4755: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4756: }
4757: } else {
4758: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4759: }
4760: if (($updated) && ($result ne 'ok')) {
4761: $r->print('<br />'.&mt('Outdated copy removed'));
4762: }
4763: }
4764: }
4765: }
4766:
4767:
4768:
4769: =pod
4770:
4771: =item list_symbs()
4772:
4773: List Content Identifiers
4774:
4775: =cut
4776:
4777: sub list_symbs {
4778: my ($r) = @_;
4779:
4780: my $crstype = &Apache::loncommon::course_type();
4781: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4782: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4783: $r->print(&startContentScreen('tools'));
4784: my $navmap = Apache::lonnavmaps::navmap->new();
4785: if (!defined($navmap)) {
4786: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4787: '<div class="LC_error">'.
4788: &mt('Unable to retrieve information about course contents').
4789: '</div>');
4790: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4791: } else {
4792: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4793: &Apache::loncommon::start_data_table().
4794: &Apache::loncommon::start_data_table_header_row().
4795: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4796: &Apache::loncommon::end_data_table_header_row()."\n");
4797: my $count;
4798: foreach my $res ($navmap->retrieveResources()) {
4799: $r->print(&Apache::loncommon::start_data_table_row().
4800: '<td>'.$res->compTitle().'</td>'.
4801: '<td>'.$res->symb().'</td>'.
4802: &Apache::loncommon::end_data_table_row());
4803: $count ++;
4804: }
4805: if (!$count) {
4806: $r->print(&Apache::loncommon::start_data_table_row().
4807: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4808: &Apache::loncommon::end_data_table_row());
4809: }
4810: $r->print(&Apache::loncommon::end_data_table());
4811: }
4812: $r->print(&endContentScreen());
4813: }
4814:
4815: sub contentverifyform {
4816: my ($r) = @_;
4817: my $crstype = &Apache::loncommon::course_type();
4818: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4819: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4820: $r->print(&startContentScreen('tools'));
4821: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4822: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4823: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4824: ' <span class="LC_nobreak">'.
4825: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4826: &mt('No').'</label>'.(' 'x2).
4827: '<label><input type="radio" name="checkstale" value="1" />'.
4828: &mt('Yes').'</label></span></p><p>'.
4829: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4830: '<input type="hidden" value="1" name="tools" />'.
4831: '<input type="hidden" value="1" name="verify" /></p></form>');
4832: $r->print(&endContentScreen());
4833: return;
4834: }
4835:
4836: sub verifycontent {
4837: my ($r,$checkstale) = @_;
4838: my $crstype = &Apache::loncommon::course_type();
4839: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4840: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4841: $r->print(&startContentScreen('tools'));
4842: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4843: $hashtied=0;
4844: undef %alreadyseen;
4845: %alreadyseen=();
4846: &tiehash();
4847:
4848: foreach my $key (keys(%hash)) {
4849: if ($hash{$key}=~/\.(page|sequence)$/) {
4850: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4851: $r->print('<hr /><span class="LC_error">'.
4852: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
4853: &unescape($hash{$key}).'</span><br />'.
4854: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
4855: }
4856: }
4857: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4858: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
4859: }
4860: }
4861: &untiehash();
4862: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
4863: $r->print(&endContentScreen());
4864: }
4865:
4866: sub devalidateversioncache {
4867: my $src=shift;
4868: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4869: &Apache::lonnet::clutter($src));
4870: }
4871:
4872: sub checkversions {
4873: my ($r,$canedit) = @_;
4874: my $crstype = &Apache::loncommon::course_type();
4875: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4876: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
4877: $r->print(&startContentScreen('tools'));
4878:
4879: my $header='';
4880: my $startsel='';
4881: my $monthsel='';
4882: my $weeksel='';
4883: my $daysel='';
4884: my $allsel='';
4885: my %changes=();
4886: my $starttime=0;
4887: my $haschanged=0;
4888: my %setversions=&Apache::lonnet::dump('resourceversions',
4889: $env{'course.'.$env{'request.course.id'}.'.domain'},
4890: $env{'course.'.$env{'request.course.id'}.'.num'});
4891:
4892: $hashtied=0;
4893: &tiehash();
4894: if ($canedit) {
4895: my %newsetversions=();
4896: if ($env{'form.setmostrecent'}) {
4897: $haschanged=1;
4898: foreach my $key (keys(%hash)) {
4899: if ($key=~/^ids\_(\/res\/.+)$/) {
4900: $newsetversions{$1}='mostrecent';
4901: &devalidateversioncache($1);
4902: }
4903: }
4904: } elsif ($env{'form.setcurrent'}) {
4905: $haschanged=1;
4906: foreach my $key (keys(%hash)) {
4907: if ($key=~/^ids\_(\/res\/.+)$/) {
4908: my $getvers=&Apache::lonnet::getversion($1);
4909: if ($getvers>0) {
4910: $newsetversions{$1}=$getvers;
4911: &devalidateversioncache($1);
4912: }
4913: }
4914: }
4915: } elsif ($env{'form.setversions'}) {
4916: $haschanged=1;
4917: foreach my $key (keys(%env)) {
4918: if ($key=~/^form\.set_version_(.+)$/) {
4919: my $src=$1;
4920: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4921: $newsetversions{$src}=$env{$key};
4922: &devalidateversioncache($src);
4923: }
4924: }
4925: }
4926: }
4927: if ($haschanged) {
4928: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4929: $env{'course.'.$env{'request.course.id'}.'.domain'},
4930: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4931: $r->print(&Apache::loncommon::confirmwrapper(
4932: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4933: } else {
4934: $r->print(&Apache::loncommon::confirmwrapper(
4935: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4936: }
4937: &mark_hash_old();
4938: }
4939: &changewarning($r,'');
4940: }
4941: if ($env{'form.timerange'} eq 'all') {
4942: # show all documents
4943: $header=&mt('All content in '.$crstype);
4944: $allsel=' selected="selected"';
4945: foreach my $key (keys(%hash)) {
4946: if ($key=~/^ids\_(\/res\/.+)$/) {
4947: my $src=$1;
4948: $changes{$src}=1;
4949: }
4950: }
4951: } else {
4952: # show documents which changed
4953: %changes=&Apache::lonnet::dump
4954: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4955: $env{'course.'.$env{'request.course.id'}.'.num'});
4956: my $firstkey=(keys(%changes))[0];
4957: unless ($firstkey=~/^error\:/) {
4958: unless ($env{'form.timerange'}) {
4959: $env{'form.timerange'}=604800;
4960: }
4961: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4962: .&mt('seconds');
4963: if ($env{'form.timerange'}==-1) {
4964: $seltext='since start of course';
4965: $startsel=' selected="selected"';
4966: $env{'form.timerange'}=time;
4967: }
4968: $starttime=time-$env{'form.timerange'};
4969: if ($env{'form.timerange'}==2592000) {
4970: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4971: $monthsel=' selected="selected"';
4972: } elsif ($env{'form.timerange'}==604800) {
4973: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4974: $weeksel=' selected="selected"';
4975: } elsif ($env{'form.timerange'}==86400) {
4976: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4977: $daysel=' selected="selected"';
4978: }
4979: $header=&mt('Content changed').' '.$seltext;
4980: } else {
4981: $header=&mt('No content modifications yet.');
4982: }
4983: }
4984: %setversions=&Apache::lonnet::dump('resourceversions',
4985: $env{'course.'.$env{'request.course.id'}.'.domain'},
4986: $env{'course.'.$env{'request.course.id'}.'.num'});
4987: my %lt=&Apache::lonlocal::texthash
4988: ('st' => 'Version changes since start of '.$crstype,
4989: 'lm' => 'Version changes since last Month',
4990: 'lw' => 'Version changes since last Week',
4991: 'sy' => 'Version changes since Yesterday',
4992: 'al' => 'All Resources (possibly large output)',
4993: 'cd' => 'Change display',
4994: 'sd' => 'Display',
4995: 'fi' => 'File',
4996: 'md' => 'Modification Date',
4997: 'mr' => 'Most recently published Version',
4998: 've' => 'Version used in '.$crstype,
4999: 'vu' => 'Set Version to be used in '.$crstype,
5000: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
5001: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5002: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
5003: 'di' => 'Differences',
5004: 'save' => 'Save changes',
5005: 'vers' => 'Version choice(s) for specific resources',
5006: 'act' => 'Actions');
5007: my ($disabled,$readonly);
5008: unless ($canedit) {
5009: $disabled = 'disabled="disabled"';
5010: $readonly = 1;
5011: }
5012: $r->print(<<ENDHEADERS);
5013: <h4 class="LC_info">$header</h4>
5014: <form action="/adm/coursedocs" method="post">
5015: <input type="hidden" name="versions" value="1" />
5016: <div class="LC_left_float">
5017: <fieldset>
5018: <legend>$lt{'cd'}</legend>
5019: <select name="timerange">
5020: <option value='all'$allsel>$lt{'al'}</option>
5021: <option value="-1"$startsel>$lt{'st'}</option>
5022: <option value="2592000"$monthsel>$lt{'lm'}</option>
5023: <option value="604800"$weeksel>$lt{'lw'}</option>
5024: <option value="86400"$daysel>$lt{'sy'}</option>
5025: </select>
5026: <input type="submit" name="display" value="$lt{'sd'}" />
5027: </fieldset>
5028: </div>
5029: <div class="LC_left_float">
5030: <fieldset>
5031: <legend>$lt{'act'}</legend>
5032: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5033: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
5034: </fieldset>
5035: </div>
5036: <br clear="all" />
5037: <hr />
5038: <h4>$lt{'vers'}</h4>
5039: ENDHEADERS
5040: #number of columns for version history
5041: my %changedbytime;
5042: foreach my $key (keys(%changes)) {
5043: #excludes not versionable problems from resource version history:
5044: next if ($key =~ /^\/res\/lib\/templates/);
5045: my $chg;
5046: if ($env{'form.timerange'} eq 'all') {
5047: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5048: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5049: } else {
5050: $chg = $changes{$key};
5051: next if ($chg < $starttime);
5052: }
5053: push(@{$changedbytime{$chg}},$key);
5054: }
5055: if (keys(%changedbytime) == 0) {
5056: &untiehash();
5057: $r->print(&mt('No content changes in imported content in specified time frame').
5058: &endContentScreen());
5059: return;
5060: }
5061: $r->print(
5062: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5063: &Apache::loncommon::start_data_table().
5064: &Apache::loncommon::start_data_table_header_row().
5065: '<th>'.&mt('Resources').'</th>'.
5066: "<th>$lt{'mr'}</th>".
5067: "<th>$lt{'ve'}</th>".
5068: "<th>$lt{'vu'}</th>".
5069: '<th>'.&mt('History').'</th>'.
5070: &Apache::loncommon::end_data_table_header_row()
5071: );
5072: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5073: foreach my $key (sort(@{$changedbytime{$chg}})) {
5074: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5075: my $currentversion=&Apache::lonnet::getversion($key);
5076: if ($currentversion<0) {
5077: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5078: }
5079: my $linkurl=&Apache::lonnet::clutter($key);
5080: $r->print(
5081: &Apache::loncommon::start_data_table_row().
5082: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5083: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5084: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5085: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5086: '<td align="right">'
5087: );
5088: # Used in course
5089: my $usedversion=$hash{'version_'.$linkurl};
5090: if (($usedversion) && ($usedversion ne 'mostrecent')) {
5091: if ($usedversion != $currentversion) {
5092: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
5093: } else {
5094: $r->print($usedversion);
5095: }
5096: } else {
5097: $r->print($currentversion);
5098: }
5099: $r->print('</td><td title="'.$lt{'vu'}.'">');
5100: # Set version
5101: $r->print(&Apache::loncommon::select_form(
5102: $setversions{$linkurl},
5103: 'set_version_'.$linkurl,
5104: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5105: '' => '',
5106: 'mostrecent' => &mt('most recent'),
5107: map {$_,$_} (1..$currentversion)},'',$readonly));
5108: my $lastold=1;
5109: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5110: my $url=$root.'.'.$prevvers.'.'.$extension;
5111: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5112: $lastold=$prevvers;
5113: }
5114: }
5115: $r->print('</td>');
5116: # List all available versions
5117: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5118: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5119: my $url=$root.'.'.$prevvers.'.'.$extension;
5120: $r->print(
5121: '<span class="LC_nobreak">'
5122: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5123: .&mt('Version [_1]',$prevvers).'</a>'
5124: .' ('.&Apache::lonlocal::locallocaltime(
5125: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5126: .')');
5127: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5128: $r->print(
5129: ' <a href="/adm/diff?filename='.
5130: &Apache::lonnet::clutter($root.'.'.$extension).
5131: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5132: '" target="diffs">'.&mt('Diffs').'</a>');
5133: }
5134: $r->print('</span><br />');
5135: }
5136: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
5137: }
5138: }
5139: $r->print(
5140: &Apache::loncommon::end_data_table().
5141: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5142: '</form>'
5143: );
5144:
5145: &untiehash();
5146: $r->print(&endContentScreen());
5147: return;
5148: }
5149:
5150: sub mark_hash_old {
5151: my $retie_hash=0;
5152: if ($hashtied) {
5153: $retie_hash=1;
5154: &untiehash();
5155: }
5156: &tiehash('write');
5157: $hash{'old'}=1;
5158: &untiehash();
5159: if ($retie_hash) { &tiehash(); }
5160: }
5161:
5162: sub is_hash_old {
5163: my $untie_hash=0;
5164: if (!$hashtied) {
5165: $untie_hash=1;
5166: &tiehash();
5167: }
5168: my $return=$hash{'old'};
5169: if ($untie_hash) { &untiehash(); }
5170: return $return;
5171: }
5172:
5173: sub changewarning {
5174: my ($r,$postexec,$message,$url)=@_;
5175: if (!&is_hash_old()) { return; }
5176: my $pathvar='folderpath';
5177: my $path=&escape($env{'form.folderpath'});
5178: if (!defined($url)) {
5179: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5180: }
5181: my $course_type = &Apache::loncommon::course_type();
5182: if (!defined($message)) {
5183: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5184: }
5185: $r->print("\n\n".
5186: '<script type="text/javascript">'."\n".
5187: '// <![CDATA['."\n".
5188: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5189: '// ]]>'."\n".
5190: '</script>'."\n".
5191: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
5192: '<input type="hidden" name="orgurl" value="'.$url.
5193: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
5194: &mt($message,' <input type="hidden" name="'.
5195: $env{'request.role'}.'" value="1" /><input type="button" value="'.
5196: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
5197: $help{'Caching'}.'</p></form>'."\n\n");
5198: }
5199:
5200:
5201: sub init_breadcrumbs {
5202: my ($form,$text,$help)=@_;
5203: &Apache::lonhtmlcommon::clear_breadcrumbs();
5204: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
5205: text=>&Apache::loncommon::course_type().' Editor',
5206: faq=>273,
5207: bug=>'Instructor Interface',
5208: help => $help});
5209: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5210: text=>$text,
5211: faq=>273,
5212: bug=>'Instructor Interface'});
5213: }
5214:
5215: # subroutine to list form elements
5216: sub create_list_elements {
5217: my @formarr = @_;
5218: my $list = '';
5219: foreach my $button (@formarr){
5220: foreach my $picture (keys(%{$button})) {
5221: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5222: }
5223: }
5224: return $list;
5225: }
5226:
5227: # subroutine to create ul from list elements
5228: sub create_form_ul {
5229: my $list = shift;
5230: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5231: return $ul;
5232: }
5233:
5234: #
5235: # Start tabs
5236: #
5237:
5238: sub startContentScreen {
5239: my ($mode) = @_;
5240: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5241: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5242: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5243: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5244: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5245: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5246: } else {
5247: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5248: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5249: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5250: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5251: }
5252: $output .= "\n".'</ul>'."\n";
5253: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5254: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5255: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5256: return $output;
5257: }
5258:
5259: #
5260: # End tabs
5261: #
5262:
5263: sub endContentScreen {
5264: return '</div></div></div>';
5265: }
5266:
5267: sub supplemental_base {
5268: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5269: }
5270:
5271: sub handler {
5272: my $r = shift;
5273: &Apache::loncommon::content_type($r,'text/html');
5274: $r->send_http_header;
5275: return OK if $r->header_only;
5276:
5277: # get course data
5278: my $crstype = &Apache::loncommon::course_type();
5279: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5280: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5281:
5282: # get docroot
5283: my $londocroot = $r->dir_config('lonDocRoot');
5284:
5285: # graphics settings
5286: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5287:
5288: #
5289: # --------------------------------------------- Initialize help topics for this
5290: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5291: 'Adding_External_Resource','Adding_External_Tool',
5292: 'Navigate_Content','Adding_Folders','Docs_Overview',
5293: 'Load_Map','Supplemental','Score_Upload_Form',
5294: 'Adding_Pages','Importing_LON-CAPA_Resource',
5295: 'Importing_IMS_Course','Uploading_From_Harddrive',
5296: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
5297: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5298: }
5299: # Composite help files
5300: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5301: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5302: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5303: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5304: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5305: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5306: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5307: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5308: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5309: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5310:
5311: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5312: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5313: unless ($r->uri eq '/adm/supplemental') {
5314: # does this user have privileges to modify content.
5315: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5316: $allowed = 1;
5317: $canedit = 1;
5318: $canview = 1;
5319: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5320: $allowed = 1;
5321: $canview = 1;
5322: }
5323: }
5324: unless ($canedit) {
5325: $disabled = ' disabled="disabled"';
5326: }
5327: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5328: if ($env{'form.inhibitmenu'}) {
5329: unless ($env{'form.inhibitmenu'} eq 'yes') {
5330: delete($env{'form.inhibitmenu'});
5331: }
5332: }
5333:
5334: if ($allowed && $env{'form.verify'}) {
5335: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5336: if (!$canedit) {
5337: &verifycontent($r);
5338: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5339: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5340: text=>'Results',
5341: faq=>273,
5342: bug=>'Instructor Interface'});
5343: &verifycontent($r,$env{'form.checkstale'});
5344: } else {
5345: &contentverifyform($r);
5346: }
5347: } elsif ($allowed && $env{'form.listsymbs'}) {
5348: &init_breadcrumbs('listsymbs','List Content IDs');
5349: &list_symbs($r);
5350: } elsif ($allowed && $env{'form.docslog'}) {
5351: &init_breadcrumbs('docslog','Show Log');
5352: my $folder = $env{'form.folder'};
5353: if ($folder eq '') {
5354: $folder='default';
5355: }
5356: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5357: } elsif ($allowed && $env{'form.versions'}) {
5358: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5359: &checkversions($r,$canedit);
5360: } elsif ($canedit && $env{'form.dumpcourse'}) {
5361: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5362: &dumpcourse($r);
5363: } elsif ($canedit && $env{'form.exportcourse'}) {
5364: &init_breadcrumbs('exportcourse','IMS Export');
5365: &Apache::imsexport::exportcourse($r);
5366: } else {
5367: if ($canedit && $env{'form.authorrole'}) {
5368: $noendpage = 1;
5369: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5370: if ($redirect) {
5371: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5372: my $container = 'sequence';
5373: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5374: $is_random_order,$container) =
5375: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5376: my (@folders)=split('&',$env{'form.folderpath'});
5377: $env{'form.foldername'}=&unescape(pop(@folders));
5378: my $folder=pop(@folders);
5379: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5380: $folder.'.'.$container);
5381: my $warning;
5382: if ($fatal) {
5383: if ($container eq 'page') {
5384: $warning = &mt('An error occurred retrieving the contents of the current page.');
5385: } else {
5386: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5387: }
5388: } else {
5389: my $url = $redirect;
5390: my $srcfile = $londocroot.$url;
5391: $url =~ s{^/priv/}{/res/};
5392: my $targetfile = $londocroot.$url;
5393: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5394: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5395: $env{'form.folder'} = $folder;
5396: &snapshotbefore();
5397: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5398: my $ext = 'false';
5399: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5400: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5401: ':'.$ext.':normal:res';
5402: push(@LONCAPA::map::order,$newidx);
5403: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5404: 'string_yesno');
5405: &remember_parms($newidx,'hiddenresource','set','yes');
5406: ($errtext,$fatal) =
5407: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5408: &log_differences($plain);
5409: &mark_hash_old();
5410: $r->internal_redirect($redirect);
5411: return OK;
5412: }
5413: }
5414: }
5415: }
5416: #
5417: # Done catching special calls
5418: # The whole rest is for course and supplemental documents and utilities menu
5419: # Get the parameters that may be needed
5420: #
5421: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5422: ['folderpath',
5423: 'forcesupplement','forcestandard',
5424: 'tools','symb','command','supppath']);
5425:
5426: foreach my $item ('forcesupplement','forcestandard','tools') {
5427: next if ($env{'form.'.$item} eq '');
5428: unless ($env{'form.'.$item} eq '1') {
5429: delete($env{'form.'.$item});
5430: }
5431: }
5432:
5433: if ($env{'form.command'}) {
5434: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5435: delete($env{'form.command'});
5436: }
5437: }
5438:
5439: if ($env{'form.symb'}) {
5440: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5441: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5442: delete($env{'form.symb'});
5443: }
5444: }
5445:
5446: # standard=1: this is a "new-style" course with an uploaded map as top level
5447: # standard=2: this is a "old-style" course, and there is nothing we can do
5448:
5449: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5450:
5451: # Decide whether this should display supplemental or main content or utilities
5452: # supplementalflag=1: show supplemental documents
5453: # supplementalflag=0: show standard documents
5454: # toolsflag=1: show utilities
5455:
5456: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5457: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5458: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5459: $supplementalflag=0;
5460: }
5461: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5462: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5463: unless ($allowed) { $supplementalflag=1; }
5464: unless ($standard) { $supplementalflag=1; }
5465: my $toolsflag=0;
5466: if ($env{'form.tools'}) { $toolsflag=1; }
5467:
5468: if ($env{'form.folderpath'} ne '') {
5469: my @items = split(/\&/,$env{'form.folderpath'});
5470: my $badpath;
5471: for (my $i=0; $i<@items; $i++) {
5472: my $odd = $i%2;
5473: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5474: $badpath = 1;
5475: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5476: $badpath = 1;
5477: }
5478: last if ($badpath);
5479: }
5480: if ($badpath) {
5481: delete($env{'form.folderpath'});
5482: }
5483: }
5484:
5485: if ($env{'form.supppath'} ne '') {
5486: my @items = split(/\&/,$env{'form.supppath'});
5487: my $badpath;
5488: for (my $i=0; $i<@items; $i++) {
5489: my $odd = $i%2;
5490: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5491: $badpath = 1;
5492: }
5493: last if ($badpath);
5494: }
5495: if ($badpath) {
5496: delete($env{'form.supppath'});
5497: }
5498: }
5499:
5500: my $script='';
5501: my $showdoc=0;
5502: my $addentries = {};
5503: my $container;
5504: my $containertag;
5505: my $pathitem;
5506: my %ltitools;
5507: my $hiddentop;
5508: my $navmap;
5509: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5510:
5511: # Do we directly jump somewhere?
5512: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5513: if ($env{'form.symb'} ne '') {
5514: $env{'form.folderpath'}=
5515: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5516: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5517: $env{'form.command'}.'_'.$env{'form.symb'}});
5518: } elsif ($env{'form.supppath'} ne '') {
5519: $env{'form.folderpath'}=$env{'form.supppath'};
5520: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5521: $env{'form.command'}.'_'.$env{'form.supppath'}});
5522: }
5523: } elsif ($env{'form.command'} eq 'editdocs') {
5524: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5525: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5526: } elsif ($env{'form.command'} eq 'editsupp') {
5527: $env{'form.folderpath'} = &supplemental_base();
5528: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5529: } elsif ($env{'form.command'} eq 'contents') {
5530: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5531: } elsif ($env{'form.command'} eq 'home') {
5532: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5533: }
5534:
5535:
5536: # Where do we store these for when we come back?
5537: my $stored_folderpath='docs_folderpath';
5538: if ($supplementalflag) {
5539: $stored_folderpath='docs_sup_folderpath';
5540: }
5541:
5542: # No folderpath, and in edit mode, see if we have something stored
5543: if ((!$env{'form.folderpath'}) && $allowed) {
5544: &Apache::loncommon::restore_course_settings($stored_folderpath,
5545: {'folderpath' => 'scalar'});
5546:
5547: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5548: if ($supplementalflag) {
5549: undef($env{'form.folderpath'}) if ($1 eq 'default');
5550: } else {
5551: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5552: }
5553: } else {
5554: undef($env{'form.folderpath'});
5555: }
5556: }
5557:
5558: # If we are not allowed to make changes, all we can see are supplemental docs
5559: if (!$allowed) {
5560: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5561: $env{'form.folderpath'} = &supplemental_base();
5562: }
5563: }
5564: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5565: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5566: $env{'form.folderpath'} = &supplemental_base()
5567: .'&'.
5568: $env{'form.folderpath'};
5569: }
5570: # If allowed and user's role is not advanced check folderpath is not hidden
5571: if (($allowed) && (!$env{'request.role.adv'}) &&
5572: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5573: my $folderurl;
5574: my @pathitems = split(/\&/,$env{'form.folderpath'});
5575: my $folder = $pathitems[-2];
5576: if ($folder eq '') {
5577: undef($env{'form.folderpath'});
5578: } else {
5579: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5580: if ((split(/\:/,$pathitems[-1]))[4]) {
5581: $folderurl .= '.page';
5582: } else {
5583: $folderurl .= '.sequence';
5584: }
5585: unless (ref($navmap)) {
5586: $navmap = Apache::lonnavmaps::navmap->new();
5587: }
5588: if (ref($navmap)) {
5589: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5590: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5591: unless (@resources) {
5592: undef($env{'form.folderpath'});
5593: }
5594: }
5595: }
5596: }
5597: }
5598:
5599:
5600: # If after all of this, we still don't have any paths, make them
5601: unless ($env{'form.folderpath'}) {
5602: if ($supplementalflag) {
5603: $env{'form.folderpath'}=&supplemental_base();
5604: } elsif ($allowed) {
5605: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5606: }
5607: }
5608:
5609: # Store this
5610: unless ($toolsflag) {
5611: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5612: &Apache::loncommon::store_course_settings($stored_folderpath,
5613: {'folderpath' => 'scalar'});
5614: }
5615: my $folderpath;
5616: if ($env{'form.folderpath'}) {
5617: $folderpath = $env{'form.folderpath'};
5618: my (@folders)=split('&',$env{'form.folderpath'});
5619: $env{'form.foldername'}=&unescape(pop(@folders));
5620: if ($env{'form.foldername'} =~ /\:1$/) {
5621: $container = 'page';
5622: } else {
5623: $container = 'sequence';
5624: }
5625: $env{'form.folder'}=pop(@folders);
5626: } else {
5627: if ($env{'form.folder'} eq '' ||
5628: $env{'form.folder'} eq 'supplemental') {
5629: if ($env{'form.folder'} eq 'supplemental') {
5630: $folderpath=&supplemental_base();
5631: } elsif (!$hiddentop) {
5632: $folderpath='default&'.
5633: &escape(&mt('Main Content').':::::');
5634: }
5635: }
5636: }
5637: $containertag = '<input type="hidden" name="folderpath" value="" />';
5638: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5639: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5640: $showdoc='/'.$1;
5641: }
5642: if ($showdoc) { # got called in sequence from course
5643: $allowed=0;
5644: } else {
5645: if ($canedit) {
5646: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5647: $script=&Apache::lonratedt::editscript('simple');
5648: }
5649: }
5650: }
5651:
5652: # get personal data
5653: my $uname=$env{'user.name'};
5654: my $udom=$env{'user.domain'};
5655: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5656:
5657: if ($allowed) {
5658: if ($toolsflag) {
5659: $script .= &inject_data_js();
5660: my ($home,$other,%outhash)=&authorhosts();
5661: if (!$home && $other) {
5662: my @hosts;
5663: foreach my $aurole (keys(%outhash)) {
5664: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5665: push(@hosts,$outhash{$aurole});
5666: }
5667: }
5668: $script .= &dump_switchserver_js(@hosts);
5669: }
5670: } else {
5671: my $tid = 1;
5672: my @tabids;
5673: if ($supplementalflag) {
5674: @tabids = ('002','ee2','ff2');
5675: $tid = 2;
5676: } else {
5677: @tabids = ('aa1','bb1','cc1','ff1');
5678: unless ($env{'form.folderpath'} =~ /\:1$/) {
5679: unshift(@tabids,'001');
5680: push(@tabids,('dd1','ee1'));
5681: }
5682: }
5683: my $tabidstr = join("','",@tabids);
5684: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5685: my $posslti = keys(%ltitools);
5686: my $hostname = $r->hostname();
5687: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5688: $londocroot,$canedit,$hostname,\$navmap).
5689: &history_tab_js().
5690: &inject_data_js().
5691: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5692: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5693: $addentries = {
5694: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5695: };
5696: }
5697: $script .= &paste_popup_js();
5698: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5699: &mt('Switch server?');
5700:
5701:
5702: }
5703: # -------------------------------------------------------------------- Body tag
5704: $script = '<script type="text/javascript">'."\n"
5705: .'// <![CDATA['."\n"
5706: .$script."\n"
5707: .'// ]]>'."\n"
5708: .'</script>'."\n"
5709: .'<script type="text/javascript"
5710: src="/res/adm/includes/file_upload.js"></script>'."\n";
5711:
5712: # Breadcrumbs
5713: &Apache::lonhtmlcommon::clear_breadcrumbs();
5714:
5715: if ($showdoc) {
5716: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5717: {'force_register' => $showdoc,}));
5718: } elsif ($toolsflag) {
5719: my ($breadtext,$breadtitle);
5720: $breadtext = "$crstype Editor";
5721: if ($canedit) {
5722: $breadtitle = 'Editing '.$crstype.' Contents';
5723: } else {
5724: $breadtext .= ' (View-only mode)';
5725: $breadtitle = 'Viewing '.$crstype.' Contents';
5726: }
5727: &Apache::lonhtmlcommon::add_breadcrumb({
5728: href=>"/adm/coursedocs",text=>$breadtext});
5729: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5730: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5731: .&Apache::lonhtmlcommon::breadcrumbs(
5732: $breadtitle)
5733: );
5734: } elsif ($r->uri eq '/adm/supplemental') {
5735: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5736: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5737: {'bread_crumbs' => $brcrum,}));
5738: } else {
5739: my ($breadtext,$breadtitle,$helpitem);
5740: $breadtext = "$crstype Editor";
5741: if ($canedit) {
5742: $breadtitle = 'Editing '.$crstype.' Contents';
5743: $helpitem = 'Docs_Adding_Course_Doc';
5744: } else {
5745: $breadtext .= ' (View-only mode)';
5746: $breadtitle = 'Viewing '.$crstype.' Contents';
5747: $helpitem = 'Docs_Viewing_Course_Doc';
5748: }
5749: &Apache::lonhtmlcommon::add_breadcrumb({
5750: href=>"/adm/coursedocs",text=>$breadtext});
5751: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5752: {'add_entries' => $addentries}
5753: )
5754: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5755: .&Apache::lonhtmlcommon::breadcrumbs(
5756: $breadtitle,
5757: $helpitem)
5758: );
5759: }
5760:
5761: my %allfiles = ();
5762: my %codebase = ();
5763: my ($upload_result,$upload_output,$uploadphase);
5764: if ($canedit) {
5765: if (($env{'form.uploaddoc.filename'}) &&
5766: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5767: my $context = $1;
5768: # Process file upload - phase one - upload and parse primary file.
5769: undef($hadchanges);
5770: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5771: \%allfiles,\%codebase,$context,$crstype);
5772: undef($navmap);
5773: if ($hadchanges) {
5774: &mark_hash_old();
5775: }
5776: $r->print($upload_output);
5777: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5778: # Process file upload - phase two - upload embedded objects
5779: $uploadphase = 'check_embedded';
5780: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5781: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5782: $env{'form.newidx'});
5783: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5784: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5785: my ($destination,$dir_root) = &embedded_destination();
5786: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5787: my $actionurl = '/adm/coursedocs';
5788: my ($result,$flag) =
5789: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5790: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5791: $actionurl);
5792: $r->print($result.&return_to_editor());
5793: } elsif ($env{'form.phase'} eq 'check_embedded') {
5794: # Process file upload - phase three - modify references in HTML file
5795: $uploadphase = 'modified_orightml';
5796: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5797: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5798: my ($destination,$dir_root) = &embedded_destination();
5799: my $result =
5800: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5801: $docuname,$docudom,undef,
5802: $dir_root);
5803: $r->print($result.&return_to_editor());
5804: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5805: $uploadphase = 'decompress_phase_one';
5806: $r->print(&decompression_phase_one().
5807: &return_to_editor());
5808: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5809: $uploadphase = 'decompress_phase_two';
5810: $r->print(&decompression_phase_two().
5811: &return_to_editor());
5812: }
5813: }
5814:
5815: if ($allowed && $toolsflag) {
5816: $r->print(&startContentScreen('tools'));
5817: $r->print(&generate_admin_menu($crstype,$canedit));
5818: $r->print(&endContentScreen());
5819: } elsif ((!$showdoc) && (!$uploadphase)) {
5820: # -----------------------------------------------------------------------------
5821: my %lt=&Apache::lonlocal::texthash(
5822: 'copm' => 'All documents out of a published map into this folder',
5823: 'upfi' => 'Upload File',
5824: 'upld' => 'Upload Content',
5825: 'srch' => 'Search',
5826: 'impo' => 'Import',
5827: 'lnks' => 'Import from Stored Links',
5828: 'impm' => 'Import from Assembled Map',
5829: 'imcr' => 'Import from Course Resources',
5830: 'extr' => 'External Resource',
5831: 'extt' => 'External Tool',
5832: 'selm' => 'Select Map',
5833: 'load' => 'Load Map',
5834: 'newf' => 'New Folder',
5835: 'newp' => 'New Composite Page',
5836: 'syll' => 'Syllabus',
5837: 'navc' => 'Table of Contents',
5838: 'sipa' => 'Simple Course Page',
5839: 'sipr' => 'Simple Problem',
5840: 'webp' => 'Blank Web Page (editable)',
5841: 'stpr' => 'Standard Problem',
5842: 'news' => 'New sub-directory',
5843: 'crpr' => 'Create Problem',
5844: 'drbx' => 'Drop Box',
5845: 'scuf' => 'External Scores (handgrade, upload, clicker)',
5846: 'bull' => 'Discussion Board',
5847: 'mypi' => 'My Personal Information Page',
5848: 'grpo' => 'Group Portfolio',
5849: 'rost' => 'Course Roster',
5850: 'abou' => 'Personal Information Page for a User',
5851: 'imsf' => 'IMS Upload',
5852: 'imsl' => 'Upload IMS package',
5853: 'cms' => 'Origin of IMS package',
5854: 'se' => 'Select',
5855: 'file' => 'File',
5856: 'title' => 'Title',
5857: 'addp' => 'Add Placeholder to course?',
5858: 'uste' => 'Use Template?',
5859: 'fnam' => 'File Name:',
5860: 'loca' => 'Location:',
5861: 'dire' => 'Directory:',
5862: 'cate' => 'Category:',
5863: 'tmpl' => 'Template:',
5864: 'comment' => 'Comment',
5865: 'parse' => 'Upload embedded images/multimedia files if HTML file',
5866: 'bb5' => 'Blackboard 5',
5867: 'bb6' => 'Blackboard 6',
5868: 'angel5' => 'ANGEL 5.5',
5869: 'webctce4' => 'WebCT 4 Campus Edition',
5870: 'yes' => 'Yes',
5871: 'no' => 'No',
5872: 'er' => 'Editing rights unavailable for your current role.',
5873: );
5874: # -----------------------------------------------------------------------------
5875:
5876: # Calculate free quota space for a user or course. A javascript function checks
5877: # file size to determine if upload should be allowed.
5878: my $quotatype = 'unofficial';
5879: if ($crstype eq 'Community') {
5880: $quotatype = 'community';
5881: } elsif ($crstype eq 'Placement') {
5882: $quotatype = 'placement';
5883: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5884: $quotatype = 'official';
5885: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5886: $quotatype = 'textbook';
5887: }
5888: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5889: 'course',$quotatype); # expressed in MB
5890: my $current_disk_usage = 0;
5891: foreach my $subdir ('docs','supplemental') {
5892: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5893: "userfiles/$subdir",1); # expressed in kB
5894: }
5895: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5896: my $usage = $current_disk_usage/1024; # in MB
5897: my $quota = $disk_quota;
5898: my $percent;
5899: if ($disk_quota == 0) {
5900: $percent = 100.0;
5901: } else {
5902: $percent = 100*($usage/$disk_quota);
5903: }
5904: $usage = sprintf("%.2f",$usage);
5905: $quota = sprintf("%.2f",$quota);
5906: $percent = sprintf("%.0f",$percent);
5907: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5908: $percent.'%',$quota.' MB').'</p>';
5909:
5910: my $fileupload=(<<FIUP);
5911: $quotainfo
5912: $lt{'file'}:<br />
5913: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
5914: <input type="hidden" id="free_space" value="$free_space" />
5915: FIUP
5916:
5917: my $checkbox=(<<CHBO);
5918: <!-- <label>$lt{'parse'}?
5919: <input type="checkbox" name="parserflag" />
5920: </label> -->
5921: <label>
5922: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
5923: </label>
5924: CHBO
5925: my $imsfolder = $env{'form.folder'};
5926: if ($imsfolder eq '') {
5927: $imsfolder = 'default';
5928: }
5929: my $imspform=(<<IMSFORM);
5930: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5931: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5932: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
5933: <fieldset id="uploadimsform" style="display: none;">
5934: <legend>$lt{'imsf'}</legend>
5935: $fileupload
5936: <br />
5937: <p>
5938: $lt{'cms'}:
5939: <select name="source" $disabled>
5940: <option value="-1" selected="selected">$lt{'se'}</option>
5941: <option value="bb5">$lt{'bb5'}</option>
5942: <option value="bb6">$lt{'bb6'}</option>
5943: <option value="angel5">$lt{'angel5'}</option>
5944: <option value="webctce4">$lt{'webctce4'}</option>
5945: </select>
5946: <input type="hidden" name="folder" value="$imsfolder" />
5947: </p>
5948: <input type="hidden" name="phase" value="one" />
5949: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
5950: </fieldset>
5951: </form>
5952: IMSFORM
5953:
5954: my $fileuploadform=(<<FUFORM);
5955: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5956: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5957: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
5958: <fieldset id="uploaddocform" style="display: none;">
5959: <legend>$lt{'upfi'}</legend>
5960: <input type="hidden" name="active" value="aa" />
5961: $fileupload
5962: <br />
5963: $lt{'title'}:<br />
5964: <input type="text" size="60" name="comment" $disabled />
5965: $pathitem
5966: <input type="hidden" name="cmd" value="upload_default" />
5967: <br />
5968: <span class="LC_nobreak" style="float:left">
5969: $checkbox
5970: </span>
5971: <br clear="all" />
5972: <input type="submit" value="$lt{'upld'}" $disabled />
5973: </fieldset>
5974: </form>
5975: FUFORM
5976:
5977: my $mapimportjs;
5978: if ($canedit) {
5979: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5980: } else {
5981: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5982: }
5983: my $importpubform=(<<SEDFFORM);
5984: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
5985: $lt{'impm'}</a>$help{'Load_Map'}
5986: <form action="/adm/coursedocs" method="post" name="mapimportform">
5987: <fieldset id="importmapform" style="display: none;">
5988: <legend>$lt{'impm'}</legend>
5989: <input type="hidden" name="active" value="bb" />
5990: $lt{'copm'}<br />
5991: <span class="LC_nobreak">
5992: <input type="text" name="importmap" size="40" value=""
5993: onfocus="this.blur();$mapimportjs" $disabled />
5994: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5995: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
5996: </fieldset>
5997: </form>
5998:
5999: SEDFFORM
6000: my $importcrsresform;
6001: my ($numdirs,$pickfile) =
6002: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6003: "resize_scrollbox('contentscroll','1','0');",
6004: undef,'res');
6005: if ($pickfile) {
6006: $importcrsresform=(<<CRSFORM);
6007: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6008: $lt{'imcr'}</a>$help{'Course_Resources'}
6009: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6010: <fieldset id="importcrsresform" style="display: none;">
6011: <legend>$lt{'imcr'}</legend>
6012: <input type="hidden" name="active" value="bb" />
6013: $pickfile
6014: <p>
6015: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
6016: </p>
6017: <input type="hidden" name="importdetail" value="" />
6018: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
6019: </fieldset>
6020: </form>
6021: CRSFORM
6022: }
6023:
6024: my $fromstoredjs;
6025: if ($canedit) {
6026: $fromstoredjs = 'open_StoredLinks_Import()';
6027: } else {
6028: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6029: }
6030:
6031: my @importpubforma = (
6032: { '<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>" },
6033: { '<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'}" },
6034: { '<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>' },
6035: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6036: );
6037: if ($pickfile) {
6038: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6039: }
6040: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6041: my $extresourcesform =
6042: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6043: $help{'Adding_External_Resource'},
6044: undef,undef,undef,undef,undef,undef,$disabled);
6045: my $exttoolform =
6046: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6047: $help{'Adding_External_Tool'},undef,
6048: undef,'tool',$coursedom,$coursenum,
6049: \%ltitools,$disabled);
6050: if ($allowed) {
6051: my $folder = $env{'form.folder'};
6052: if ($folder eq '') {
6053: $folder='default';
6054: }
6055: if ($canedit) {
6056: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6057: if ($output) {
6058: $r->print($output);
6059: }
6060: }
6061: $r->print(<<HIDDENFORM);
6062: <form name="renameform" method="post" action="/adm/coursedocs">
6063: <input type="hidden" name="title" />
6064: <input type="hidden" name="cmd" />
6065: <input type="hidden" name="markcopy" />
6066: <input type="hidden" name="copyfolder" />
6067: $containertag
6068: </form>
6069: <form name="aliasform" method="post" action="/adm/coursedocs">
6070: <input type="hidden" name="alias" />
6071: <input type="hidden" name="cmd" />
6072: $containertag
6073: </form>
6074:
6075: HIDDENFORM
6076: $r->print(&makesimpleeditform($pathitem)."\n".
6077: &makedocslogform($pathitem."\n".
6078: '<input type="hidden" name="folder" value="'.
6079: $env{'form.folder'}.'" />'."\n"));
6080: }
6081:
6082: # Generate the tabs
6083: my ($mode,$needs_end);
6084: if (($supplementalflag) && (!$allowed)) {
6085: my @folders = split('&',$env{'form.folderpath'});
6086: unless (@folders > 2) {
6087: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6088: $needs_end = 1;
6089: }
6090: } else {
6091: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
6092: $needs_end = 1;
6093: }
6094:
6095: #
6096: my $hostname = $r->hostname();
6097: my $savefolderpath;
6098:
6099: if ($allowed) {
6100: my $folder=$env{'form.folder'};
6101: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
6102: $folder='default';
6103: $savefolderpath = $env{'form.folderpath'};
6104: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
6105: $pathitem = '<input type="hidden" name="folderpath" value="'.
6106: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6107: }
6108: my $postexec='';
6109: if ($folder eq 'default') {
6110: $r->print('<script type="text/javascript">'."\n"
6111: .'// <![CDATA['."\n"
6112: .'this.window.name="loncapaclient";'."\n"
6113: .'// ]]>'."\n"
6114: .'</script>'."\n"
6115: );
6116: } else {
6117: #$postexec='self.close();';
6118: }
6119: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6120: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
6121: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6122:
6123: my $newnavform=(<<NNFORM);
6124: <form action="/adm/coursedocs" method="post" name="newnav">
6125: <input type="hidden" name="active" value="ee" />
6126: $pathitem
6127: <input type="hidden" name="importdetail"
6128: value="$lt{'navc'}=/adm/navmaps" />
6129: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
6130: $help{'Navigate_Content'}
6131: </form>
6132: NNFORM
6133: my $newsmppageform=(<<NSPFORM);
6134: <form action="/adm/coursedocs" method="post" name="newsmppg">
6135: <input type="hidden" name="active" value="ee" />
6136: $pathitem
6137: <input type="hidden" name="importdetail" value="" />
6138: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
6139: $help{'Simple Page'}
6140: </form>
6141: NSPFORM
6142:
6143: my $newsmpproblemform=(<<NSPROBFORM);
6144: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
6145: <input type="hidden" name="active" value="cc" />
6146: $pathitem
6147: <input type="hidden" name="importdetail" value="" />
6148: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
6149: $help{'Simple_Problem'}
6150: </form>
6151:
6152: NSPROBFORM
6153:
6154: my $newdropboxform=(<<NDBFORM);
6155: <form action="/adm/coursedocs" method="post" name="newdropbox">
6156: <input type="hidden" name="active" value="cc" />
6157: $pathitem
6158: <input type="hidden" name="importdetail" value="" />
6159: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
6160: $help{'Dropbox'}
6161: </form>
6162: NDBFORM
6163:
6164: my $newexuploadform=(<<NEXUFORM);
6165: <form action="/adm/coursedocs" method="post" name="newexamupload">
6166: <input type="hidden" name="active" value="cc" />
6167: $pathitem
6168: <input type="hidden" name="importdetail" value="" />
6169: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
6170: $help{'Score_Upload_Form'}
6171: </form>
6172: NEXUFORM
6173:
6174: my $newbulform=(<<NBFORM);
6175: <form action="/adm/coursedocs" method="post" name="newbul">
6176: <input type="hidden" name="active" value="dd" />
6177: $pathitem
6178: <input type="hidden" name="importdetail" value="" />
6179: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
6180: $help{'Bulletin Board'}
6181: </form>
6182: NBFORM
6183:
6184: my $newaboutmeform=(<<NAMFORM);
6185: <form action="/adm/coursedocs" method="post" name="newaboutme">
6186: <input type="hidden" name="active" value="dd" />
6187: $pathitem
6188: <input type="hidden" name="importdetail"
6189: value="$plainname=/adm/$udom/$uname/aboutme" />
6190: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
6191: $help{'My Personal Information Page'}
6192: </form>
6193: NAMFORM
6194:
6195: my $newaboutsomeoneform=(<<NASOFORM);
6196: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
6197: <input type="hidden" name="active" value="dd" />
6198: $pathitem
6199: <input type="hidden" name="importdetail" value="" />
6200: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
6201: </form>
6202: NASOFORM
6203:
6204: my $newrosterform=(<<NROSTFORM);
6205: <form action="/adm/coursedocs" method="post" name="newroster">
6206: <input type="hidden" name="active" value="dd" />
6207: $pathitem
6208: <input type="hidden" name="importdetail"
6209: value="$lt{'rost'}=/adm/viewclasslist" />
6210: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
6211: $help{'Course_Roster'}
6212: </form>
6213: NROSTFORM
6214:
6215: my $newwebpage;
6216: if ($folder =~ /^default_?(\d*)$/) {
6217: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6218: if ($1) {
6219: $newwebpage .= $1;
6220: } else {
6221: $newwebpage .= 'default';
6222: }
6223: $newwebpage .= '/new.html';
6224: }
6225: my $newwebpageform =(<<NWEBFORM);
6226: <form action="/adm/coursedocs" method="post" name="newwebpage">
6227: <input type="hidden" name="active" value="ee" />
6228: $pathitem
6229: <input type="hidden" name="importdetail" value="$newwebpage" />
6230: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
6231: $help{'Web_Page'}
6232: </form>
6233: NWEBFORM
6234:
6235: my @ids=&Apache::lonnet::current_machine_ids();
6236: my %select_menus;
6237: my $numauthor = 0;
6238: my $numcrsdirs = 0;
6239: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6240: if ($env{'user.author'}) {
6241: $numauthor ++;
6242: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6243: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6244: my $is_home = 1;
6245: my %subdirs;
6246: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6247: $select_menus{'author'}->{'default'} = '/';
6248: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6249: my @ordered = ('/');
6250: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6251: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6252: push(@ordered,$relpath);
6253: }
6254: $select_menus{'author'}->{'order'} = \@ordered;
6255: } else {
6256: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6257: $select_menus{'author'}->{'default'} = 'switch';
6258: $select_menus{'author'}->{'order'} = ['switch'];
6259: }
6260: }
6261: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6262: ['active'],['ca','aa']);
6263: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6264: my %by_roletype;
6265: if (keys(%roleshash)) {
6266: foreach my $entry (keys(%roleshash)) {
6267: my ($auname,$audom,$roletype) = split(/:/,$entry);
6268: my $key = $entry;
6269: $key =~ s/:/___/g;
6270: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6271: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6272: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6273: if (grep(/^\Q$rolehome\E$/,@ids)) {
6274: my $is_home = 1;
6275: my (%subdirs,@ordered);
6276: my $toppath="/priv/$audom/$auname";
6277: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6278: $select_menus{$key}->{'default'} = '/';
6279: $select_menus{$key}->{'select2'}->{'/'} = '/';
6280: my @ordered = ('/');
6281: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6282: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6283: push(@ordered,$relpath);
6284: }
6285: $select_menus{$key}->{'order'} = \@ordered;
6286: } else {
6287: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6288: $select_menus{$key}->{'default'} = 'switch';
6289: $select_menus{$key}->{'order'} = ['switch'];
6290: }
6291: $numauthor ++;
6292: }
6293: }
6294: my ($pickdir,$showtitle);
6295: if ($numauthor) {
6296: my @order;
6297: my $defrole;
6298: if ($env{'user.author'}) {
6299: push(@order,'author');
6300: $defrole = 'author';
6301: }
6302: if (keys(%by_roletype)) {
6303: foreach my $possrole ('ca','aa') {
6304: if (ref($by_roletype{$possrole}) eq 'HASH') {
6305: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6306: unless ($defrole) {
6307: $defrole = $author;
6308: }
6309: push(@order,$author.'___'.$possrole);
6310: }
6311: }
6312: }
6313: }
6314: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6315: if (grep(/^\Q$crshome\E$/,@ids)) {
6316: my $is_home = 1;
6317: my %subdirs;
6318: my $toppath="/priv/$coursedom/$coursenum";
6319: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6320: $numcrsdirs = keys(%subdirs);
6321: $select_menus{'course'}->{'default'} = '/';
6322: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6323: my @ordered = ('/');
6324: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6325: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6326: push(@ordered,$relpath);
6327: }
6328: $select_menus{'course'}->{'order'} = \@ordered;
6329: } else {
6330: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6331: $select_menus{'course'}->{'default'} = 'switch';
6332: $select_menus{'course'}->{'order'} = ['switch'];
6333: }
6334: push(@order,'course');
6335: $pickdir = $lt{'loca'}.
6336: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6337: $defrole,'authorrole','authorpath',
6338: \%select_menus,\@order,'toggleCrsResTitle();',
6339: '','priv').'<br />';
6340: $showtitle = 'none';
6341: } else {
6342: my $is_home;
6343: $showtitle = 'inline';
6344: if (grep(/^\Q$crshome\E$/,@ids)) {
6345: $is_home = 1;
6346: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6347: my $toppath="/priv/$coursedom/$coursenum'}";
6348: my %subdirs;
6349: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6350: $numcrsdirs = keys(%subdirs);
6351: if ($numcrsdirs) {
6352: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6353: '<option value="/">/</option>'."\n";
6354: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6355: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
6356: }
6357: $pickdir .= '</select>';
6358: } else {
6359: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6360: }
6361: }
6362: }
6363:
6364: my %seltemplate_menus;
6365: my @files = &Apache::lonhomework::get_template_list('problem');
6366: my @noexamplelink = ('blank.problem','blank.library','script.library');
6367: my $currentcategory = '';
6368: my @ordered = ('');
6369: my %templatehelp;
6370: my $defcategory = '';
6371: my @catorder = ($defcategory);
6372: $seltemplate_menus{$defcategory}->{'order'} = [''];
6373: $seltemplate_menus{$defcategory}->{'text'} = '';
6374: foreach my $file (@files) {
6375: if (ref($file) eq 'ARRAY') {
6376: my ($path,$title,$category,$help) = @{$file};
6377: next if ($title !~ /\S/);
6378: if (&js_escape($category) ne $currentcategory) {
6379: $currentcategory = &js_escape($category);
6380: push(@catorder,&js_escape($currentcategory));
6381: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6382: $seltemplate_menus{$currentcategory}->{'default'} = '';
6383: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6384: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6385: }
6386: if ($path) {
6387: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6388: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6389: if ($help) {
6390: $templatehelp{$path} = $help;
6391: }
6392: }
6393: }
6394: }
6395:
6396: my $templates = $lt{'cate'}.' '.
6397: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6398: $defcategory,'tempcategory','template',
6399: \%seltemplate_menus,\@catorder,
6400: "resize_scrollbox('contentscroll','1','0');",
6401: "toggleExampleText();",'template').'<br />';
6402: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6403: '<span id="newresexample">'.&mt('Example').'<span></a>';
6404: my $crsresform=(<<RESFORM);
6405: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6406: $lt{'stpr'}</a>$help{'Course_Resource'}
6407: <form action="/adm/coursedocs" method="post" name="courseresform">
6408: <fieldset id="crsresform" style="display:none;">
6409: <legend>$lt{'stpr'}</legend>
6410: <input type="hidden" name="active" value="ee" />
6411: <p>
6412: $pickdir
6413: <span class="LC_nobreak">$lt{'news'}?
6414: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6415:
6416: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6417: </span><span id="newsubdir"></span>
6418: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6419: </p>
6420: $lt{'fnam'}
6421: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6422: <p>
6423: <div id="newresource" style="display:$showtitle">
6424: $lt{'addp'}
6425: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6426: $lt{'no'}</label>
6427: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6428: $lt{'yes'}</label>
6429: <span id="newrestitle"></span>
6430: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6431: </div>
6432: </p>
6433: <p>
6434: $lt{'uste'}
6435: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6436: $lt{'no'}</label>
6437: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6438: $lt{'yes'}</label>
6439: <div id="newrestemplate" style="display:none">
6440: $templates
6441: $templatepreview
6442: </div>
6443: </p>
6444: <span class="LC_nobreak">
6445: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6446: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6447: </span>
6448: </fieldset>
6449: </form>
6450:
6451: RESFORM
6452:
6453: my $specialdocumentsform;
6454: my @specialdocumentsforma;
6455: my $gradingform;
6456: my @gradingforma;
6457: my $communityform;
6458: my @communityforma;
6459: my $newfolderform;
6460: my $newfolderb;
6461:
6462: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6463:
6464: my $newpageform=(<<NPFORM);
6465: <form action="/adm/coursedocs" method="post" name="newpage">
6466: <input type="hidden" name="folderpath" value="$path" />
6467: <input type="hidden" name="importdetail" value="" />
6468: <input type="hidden" name="active" value="ee" />
6469: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6470: $help{'Adding_Pages'}
6471: </form>
6472: NPFORM
6473:
6474:
6475: $newfolderform=(<<NFFORM);
6476: <form action="/adm/coursedocs" method="post" name="newfolder">
6477: $pathitem
6478: <input type="hidden" name="importdetail" value="" />
6479: <input type="hidden" name="active" value="" />
6480: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6481: </form>
6482: NFFORM
6483:
6484: my $newsylform=(<<NSYLFORM);
6485: <form action="/adm/coursedocs" method="post" name="newsyl">
6486: <input type="hidden" name="active" value="ee" />
6487: $pathitem
6488: <input type="hidden" name="importdetail"
6489: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6490: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6491: $help{'Syllabus'}
6492:
6493: </form>
6494: NSYLFORM
6495:
6496: my $newgroupfileform=(<<NGFFORM);
6497: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6498: <input type="hidden" name="active" value="dd" />
6499: $pathitem
6500: <input type="hidden" name="importdetail"
6501: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6502: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6503: $help{'Group Portfolio'}
6504: </form>
6505: NGFFORM
6506: @specialdocumentsforma=(
6507: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6508: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6509: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6510: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6511: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6512: );
6513: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6514:
6515:
6516: my @importdoc = (
6517: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6518: );
6519: if (keys(%ltitools)) {
6520: push(@importdoc,
6521: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6522: );
6523: }
6524: unless ($container eq 'page') {
6525: push(@importdoc,
6526: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6527: );
6528: }
6529: push(@importdoc,
6530: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6531: );
6532: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6533:
6534: @gradingforma=(
6535: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6536: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6537: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6538: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6539: );
6540: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6541:
6542: @communityforma=(
6543: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6544: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6545: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6546: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6547: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6548: );
6549: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6550:
6551: my %orderhash = (
6552: 'aa' => ['Upload',$fileuploadform],
6553: 'bb' => ['Import',$importpubform],
6554: 'cc' => ['Grading',$gradingform],
6555: );
6556: unless ($container eq 'page') {
6557: $orderhash{'00'} = ['Newfolder',$newfolderform];
6558: $orderhash{'dd'} = ['Collaboration',$communityform];
6559: $orderhash{'ee'} = ['Other',$specialdocumentsform];
6560: }
6561:
6562: $hadchanges=0;
6563: unless (($supplementalflag || $toolsflag)) {
6564: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6565: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6566: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
6567: undef($navmap);
6568: if ($error) {
6569: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6570: }
6571: if ($hadchanges) {
6572: unless (&is_hash_old()) {
6573: &mark_hash_old();
6574: }
6575: }
6576:
6577: &changewarning($r,'');
6578: }
6579: }
6580:
6581: # Supplemental documents start here
6582:
6583: my $folder=$env{'form.folder'};
6584: unless ($supplementalflag) {
6585: $folder='supplemental';
6586: }
6587: if ($folder =~ /^supplemental$/ &&
6588: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6589: $env{'form.folderpath'} = &supplemental_base();
6590: } elsif ($allowed) {
6591: $env{'form.folderpath'} = $savefolderpath;
6592: }
6593: $pathitem = '<input type="hidden" name="folderpath" value="'.
6594: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6595: if ($allowed) {
6596: my $folderseq=
6597: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6598:
6599: my $supupdocform=(<<SUPDOCFORM);
6600: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6601: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6602: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6603: <fieldset id="uploadsuppdocform" style="display: none;">
6604: <legend>$lt{'upfi'}</legend>
6605: <input type="hidden" name="active" value="ee" />
6606: $fileupload
6607: <br />
6608: <br />
6609: <span class="LC_nobreak">
6610: $checkbox
6611: </span>
6612: <br /><br />
6613: $lt{'comment'}:<br />
6614: <textarea cols="50" rows="4" name="comment"></textarea>
6615: <br />
6616: $pathitem
6617: <input type="hidden" name="cmd" value="upload_supplemental" />
6618: <input type='submit' value="$lt{'upld'}" />
6619: </form>
6620: SUPDOCFORM
6621:
6622: my $supnewfolderform=(<<SNFFORM);
6623: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6624: <input type="hidden" name="active" value="" />
6625: $pathitem
6626: <input type="hidden" name="importdetail" value="" />
6627: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6628: $help{'Adding_Folders'}
6629: </form>
6630: SNFFORM
6631:
6632: my $supextform =
6633: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6634: $help{'Adding_External_Resource'},
6635: undef,undef,undef,undef,undef,undef,
6636: $disabled);
6637:
6638: my $supexttoolform =
6639: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6640: $help{'Adding_External_Tool'},
6641: undef,undef,'tool',$coursedom,
6642: $coursenum,\%ltitools,$disabled);
6643:
6644: my $supnewsylform=(<<SNSFORM);
6645: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6646: <input type="hidden" name="active" value="ff" />
6647: $pathitem
6648: <input type="hidden" name="importdetail"
6649: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6650: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6651: $help{'Syllabus'}
6652: </form>
6653: SNSFORM
6654:
6655: my $supnewaboutmeform=(<<SNAMFORM);
6656: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6657: <input type="hidden" name="active" value="ff" />
6658: $pathitem
6659: <input type="hidden" name="importdetail"
6660: value="$plainname=/adm/$udom/$uname/aboutme" />
6661: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6662: $help{'My Personal Information Page'}
6663: </form>
6664: SNAMFORM
6665:
6666: my $supwebpage;
6667: if ($folder =~ /^supplemental_?(\d*)$/) {
6668: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6669: if ($1) {
6670: $supwebpage .= $1;
6671: } else {
6672: $supwebpage .= 'default';
6673: }
6674: $supwebpage .= '/new.html';
6675: }
6676: my $supwebpageform =(<<SWEBFORM);
6677: <form action="/adm/coursedocs" method="post" name="supwebpage">
6678: <input type="hidden" name="active" value="cc" />
6679: $pathitem
6680: <input type="hidden" name="importdetail" value="$supwebpage" />
6681: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6682: $help{'Web_Page'}
6683: </form>
6684: SWEBFORM
6685:
6686:
6687: my @specialdocs = (
6688: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
6689: =>$supnewsylform},
6690: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6691: =>$supnewaboutmeform},
6692: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6693:
6694: );
6695: my @supimportdoc = (
6696: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
6697: =>$supextform});
6698: if (keys(%ltitools)) {
6699: push(@supimportdoc,
6700: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6701: =>$supexttoolform});
6702: }
6703: push(@supimportdoc,
6704: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6705: =>$supupdocform},
6706: );
6707:
6708: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6709: my %suporderhash = (
6710: '00' => ['Supnewfolder', $supnewfolderform],
6711: 'ee' => ['Upload',$supupdocform],
6712: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6713: );
6714: if ($supplementalflag) {
6715: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6716: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6717: \%ltitools,$canedit,$hostname);
6718: if ($error) {
6719: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6720: } else {
6721: if ($suppchanges) {
6722: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6723: my @ids=&Apache::lonnet::current_machine_ids();
6724: foreach my $server (keys(%servers)) {
6725: next if (grep(/^\Q$server\E$/,@ids));
6726: my $hashid=$coursenum.':'.$coursedom;
6727: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6728: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
6729: }
6730: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6731: undef($suppchanges);
6732: }
6733: }
6734: }
6735: } elsif ($supplementalflag) {
6736: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6737: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
6738: if ($error) {
6739: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6740: }
6741: }
6742:
6743: if ($needs_end) {
6744: $r->print(&endContentScreen());
6745: }
6746:
6747: if ($allowed) {
6748: $r->print('
6749: <form method="post" name="extimport" action="/adm/coursedocs">
6750: <input type="hidden" name="title" />
6751: <input type="hidden" name="url" />
6752: <input type="hidden" name="useform" />
6753: <input type="hidden" name="residx" />
6754: </form>');
6755: }
6756: } elsif ($showdoc) {
6757: # -------------------------------------------------------- This is showdoc mode
6758: $r->print("<h1>".&mt('Uploaded Document').' - '.
6759: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6760: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6761: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6762: }
6763: }
6764: unless ($noendpage) {
6765: $r->print(&Apache::loncommon::end_page());
6766: }
6767: return OK;
6768: }
6769:
6770: sub embedded_form_elems {
6771: my ($phase,$primaryurl,$newidx) = @_;
6772: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6773: $newidx =~s /\D+//g;
6774: return <<STATE;
6775: <input type="hidden" name="folderpath" value="$folderpath" />
6776: <input type="hidden" name="cmd" value="upload_embedded" />
6777: <input type="hidden" name="newidx" value="$newidx" />
6778: <input type="hidden" name="phase" value="$phase" />
6779: <input type="hidden" name="primaryurl" value="$primaryurl" />
6780: STATE
6781: }
6782:
6783: sub embedded_destination {
6784: my $folder=$env{'form.folder'};
6785: my $destination = 'docs/';
6786: if ($folder =~ /^supplemental/) {
6787: $destination = 'supplemental/';
6788: }
6789: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6790: $destination .= 'default/';
6791: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6792: $destination .= $2.'/';
6793: }
6794: my $newidx = $env{'form.newidx'};
6795: $newidx =~s /\D+//g;
6796: if ($newidx) {
6797: $destination .= $newidx;
6798: }
6799: my $dir_root = '/userfiles';
6800: return ($destination,$dir_root);
6801: }
6802:
6803: sub return_to_editor {
6804: my $actionurl = '/adm/coursedocs';
6805: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6806: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6807: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6808: '</a></p>';
6809: }
6810:
6811: sub decompression_info {
6812: my ($destination,$dir_root) = &embedded_destination();
6813: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6814: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6815: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6816: my $container='sequence';
6817: my ($pathitem,$hiddenelem);
6818: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
6819: if ($env{'form.folderpath'} =~ /\:1$/) {
6820: $container='page';
6821: }
6822: unshift(@hiddens,$pathitem);
6823: foreach my $item (@hiddens) {
6824: if ($item eq 'newidx') {
6825: next if ($env{'form.'.$item} =~ /\D/);
6826: }
6827: if ($env{'form.'.$item}) {
6828: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
6829: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
6830: }
6831: }
6832: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6833: $hiddenelem);
6834: }
6835:
6836: sub decompression_phase_one {
6837: my ($dir,$file,$warning,$error,$output);
6838: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6839: &decompression_info();
6840: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
6841: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6842: } else {
6843: my $file = $1;
6844: $output =
6845: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6846: $destination,$dir_root,
6847: $hiddenelem);
6848: if ($env{'form.autoextract_camtasia'}) {
6849: $output .= &remove_archive($docudom,$docuname,$container);
6850: }
6851: }
6852: if ($error) {
6853: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6854: $error.'</p>'."\n";
6855: }
6856: if ($warning) {
6857: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6858: }
6859: return $output;
6860: }
6861:
6862: sub decompression_phase_two {
6863: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6864: &decompression_info();
6865: my $output;
6866: if ($env{'form.archivedelete'}) {
6867: $output = &remove_archive($docudom,$docuname,$container);
6868: }
6869: $output .=
6870: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
6871: $destination,$dir_root,$hiddenelem);
6872: return $output;
6873: }
6874:
6875: sub remove_archive {
6876: my ($docudom,$docuname,$container) = @_;
6877: my $map = $env{'form.folder'}.'.'.$container;
6878: my ($output,$delwarning,$delresult,$url);
6879: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6880: if ($fatal) {
6881: if ($container eq 'page') {
6882: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6883: } else {
6884: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6885: }
6886: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
6887: } else {
6888: my $currcmd = $env{'form.cmd'};
6889: my $position = $env{'form.position'};
6890: my $archiveidx = $position;
6891: if ($position > 0) {
6892: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6893: $archiveidx = $position-1;
6894: }
6895: $env{'form.cmd'} = 'remove_'.$archiveidx;
6896: my ($title,$url,@rrest) =
6897: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6898: if ($url eq $env{'form.archiveurl'}) {
6899: if (&handle_edit_cmd($docuname,$docudom)) {
6900: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6901: if ($fatal) {
6902: if ($container eq 'page') {
6903: $delwarning = &mt('An error occurred updating the contents of the current page.');
6904: } else {
6905: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6906: }
6907: } else {
6908: $delresult = &mt('Archive file removed.');
6909: }
6910: }
6911: } else {
6912: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6913: ' '.&mt('As a result the archive file has not been removed.');
6914: }
6915: }
6916: $env{'form.cmd'} = $currcmd;
6917: }
6918: if ($delwarning) {
6919: $output = '<p class="LC_warning">'.
6920: $delwarning.
6921: '</p>';
6922: }
6923: if ($delresult) {
6924: $output .= '<p class="LC_info">'.
6925: $delresult.
6926: '</p>';
6927: }
6928: return $output;
6929: }
6930:
6931: sub generate_admin_menu {
6932: my ($crstype,$canedit) = @_;
6933: my $lc_crstype = lc($crstype);
6934: my ($home,$other,%outhash)=&authorhosts();
6935: my %lt= ( # do not translate here
6936: 'vc' => 'Verify Content',
6937: 'cv' => 'Check/Set Resource Versions',
6938: 'ls' => 'List Resource Identifiers',
6939: 'imse' => 'Export contents to IMS Archive',
6940: 'dcd' => "Copy $crstype Content to Authoring Space",
6941: );
6942: my ($candump,$dumpurl);
6943: if ($home + $other > 0) {
6944: $candump = 'F';
6945: if ($home) {
6946: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6947: } else {
6948: my @hosts;
6949: foreach my $aurole (keys(%outhash)) {
6950: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6951: push(@hosts,$outhash{$aurole});
6952: }
6953: }
6954: if (@hosts == 1) {
6955: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6956: '&role='.
6957: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6958: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6959: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6960: } else {
6961: $dumpurl = "javascript:choose_switchserver_window()";
6962: }
6963: }
6964: }
6965: my @menu=
6966: ({ categorytitle=>'Administration',
6967: items =>[
6968: { linktext => $lt{'vc'},
6969: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6970: permission => 'F',
6971: help => 'Docs_Verify_Content',
6972: icon => 'verify.png',
6973: linktitle => 'Verify contents can be retrieved/rendered',
6974: },
6975: { linktext => $lt{'cv'},
6976: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6977: permission => 'F',
6978: help => 'Docs_Check_Resource_Versions',
6979: icon => 'resversion.png',
6980: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6981: },
6982: { linktext => $lt{'ls'},
6983: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6984: permission => 'F',
6985: #help => '',
6986: icon => 'symbs.png',
6987: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6988: },
6989: ]
6990: });
6991: if ($canedit) {
6992: push(@menu,
6993: { categorytitle=>'Export',
6994: items =>[
6995: { linktext => $lt{'imse'},
6996: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6997: permission => 'F',
6998: help => 'Docs_Export_Course_Docs',
6999: icon => 'imsexport.png',
7000: linktitle => $lt{'imse'},
7001: },
7002: { linktext => $lt{'dcd'},
7003: url => $dumpurl,
7004: permission => $candump,
7005: help => 'Docs_Dump_Course_Docs',
7006: icon => 'dump.png',
7007: linktitle => $lt{'dcd'},
7008: },
7009: ]
7010: });
7011: }
7012: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7013: '<input type="hidden" id="dummy" />'."\n".
7014: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7015: '</form>';
7016: }
7017:
7018: sub generate_edit_table {
7019: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
7020: $need_save,$copyfolder,$canedit) = @_;
7021: return unless(ref($orderhash_ref) eq 'HASH');
7022: my %orderhash = %{$orderhash_ref};
7023: my ($form, $activetab, $active, $disabled);
7024: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
7025: $activetab = $env{'form.active'};
7026: }
7027: unless ($canedit) {
7028: $disabled = ' disabled="disabled"';
7029: }
7030: my $backicon = $iconpath.'clickhere.gif';
7031: my $backtext = &mt('Exit Editor');
7032: $form = '<div class="LC_Box" style="margin:0;">'.
7033: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7034: '<li class="goback">'.
7035: '<a href="javascript:toContents('."'$jumpto'".');">'.
7036: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7037: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7038: '<li>'.
7039: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7040: &mt('Undo Delete').'</a></li>'."\n";
7041: if ($env{'form.docslog'}) {
7042: $form .= '<li class="active">';
7043: } else {
7044: $form .= '<li>';
7045: }
7046: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7047: &mt('History').'</a></li>'."\n";
7048: if ($env{'form.docslog'}) {
7049: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7050: &mt('Edit').'</a></li>'."\n";
7051: }
7052: foreach my $name (reverse(sort(keys(%orderhash)))) {
7053: if($name ne '00'){
7054: if($activetab eq '' || $activetab ne $name){
7055: $active = '';
7056: }elsif($activetab eq $name){
7057: $active = 'class="active"';
7058: }
7059: $form .= '<li style="float:right" '.$active
7060: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
7061: } else {
7062: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
7063:
7064: }
7065: }
7066: $form .= '</ul>'."\n";
7067: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
7068:
7069: if ($to_show ne '') {
7070: my $saveform;
7071: if ($need_save) {
7072: my $button = &mt('Make changes');
7073: my $path;
7074: if ($env{'form.folderpath'}) {
7075: $path =
7076: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7077: }
7078: $saveform = <<"END";
7079: <div id="multisave" style="display:none; clear:both;" >
7080: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7081: <input type="hidden" name="folderpath" value="$path" />
7082: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7083: <input type="hidden" name="allhiddenresource" value="" />
7084: <input type="hidden" name="allencrypturl" value="" />
7085: <input type="hidden" name="allrandompick" value="" />
7086: <input type="hidden" name="allrandomorder" value="" />
7087: <input type="hidden" name="changeparms" value="" />
7088: <input type="hidden" name="multiremove" value="" />
7089: <input type="hidden" name="multicut" value="" />
7090: <input type="hidden" name="multicopy" value="" />
7091: <input type="hidden" name="multichange" value="" />
7092: <input type="hidden" name="copyfolder" value="$copyfolder" />
7093: <input type="submit" name="savemultiples" value="$button" $disabled />
7094: </form>
7095: </div>
7096: END
7097: }
7098: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
7099: }
7100: foreach my $field (keys(%orderhash)){
7101: if($field ne '00'){
7102: if($activetab eq '' || $activetab ne $field){
7103: $active = 'style="display: none;float:left"';
7104: }elsif($activetab eq $field){
7105: $active = 'style="display:block;float:left"';
7106: }
7107: $form .= '<div id="'.$field.$tid.'"'
7108: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
7109: .'</div>'."\n";
7110: }
7111: }
7112: unless ($env{'form.docslog'}) {
7113: $form .= '</div></div>'."\n";
7114: }
7115: return $form;
7116: }
7117:
7118: sub editing_js {
7119: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7120: $londocroot,$canedit,$hostname,$navmapref) = @_;
7121: my %js_lt = &Apache::lonlocal::texthash(
7122: p_mnf => 'Name of New Folder',
7123: t_mnf => 'New Folder',
7124: p_mnp => 'Name of New Page',
7125: t_mnp => 'New Page',
7126: p_mxu => 'Title for the External Score',
7127: p_msp => 'Name of Simple Course Page',
7128: p_msb => 'Title for the Problem',
7129: p_mdb => 'Title for the Drop Box',
7130: p_mbb => 'Title for the Discussion Board',
7131: p_mwp => 'Title for Web Page',
7132: p_mnr => 'Title for the Resource',
7133: p_mab => "Enter user:domain for User's Personal Information Page",
7134: p_mab2 => 'Personal Information Page of ',
7135: p_mab_alrt1 => 'Not a valid user:domain',
7136: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7137: p_chn => 'New Title',
7138: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
7139: p_rmr2a => 'Remove',
7140: p_rmr2b => '?',
7141: p_rmr3a => 'Remove those',
7142: p_rmr3b => 'items?',
7143: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7144: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
7145: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7146: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
7147: p_ctr2a => 'Cut',
7148: p_ctr2b => '?',
7149: p_ctr3a => 'Cut those',
7150: p_ctr3b => 'items?',
7151: setal => 'Enter a (unique) alias',
7152: delal => 'Are you sure you want to eliminate the alias?',
7153: rpck => 'Enter number to pick (e.g., 3)',
7154: imsfile => 'You must choose an IMS package for import',
7155: imscms => 'You must select which Course Management System was the source of the IMS package',
7156: invurl => 'Invalid URL',
7157: titbl => 'Title is blank',
7158: more => '(More ...)',
7159: less => '(Less ...)',
7160: noor => 'No actions selected or changes to settings specified.',
7161: noch => 'No changes to settings specified.',
7162: noac => 'No actions selected.',
7163: nofi => 'No file selected',
7164: tinc => 'Title in course',
7165: sunm => 'Sub-directory name',
7166: edri => 'Editing rights unavailable for your current role.',
7167: );
7168: &js_escape(\%js_lt);
7169: my $crstype = &Apache::loncommon::course_type();
7170: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7171: my $main_container_page;
7172: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7173: $main_container_page = 1;
7174: }
7175: my $backtourl;
7176: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
7177: my $toplevelsupp = &supplemental_base();
7178:
7179: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7180: my $caller = $1;
7181: if ($caller =~ /^supplemental/) {
7182: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7183: } else {
7184: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7185: $res = &Apache::lonnet::clutter($res);
7186: if (&Apache::lonnet::is_on_map($res)) {
7187: my ($url,$anchor);
7188: if ($res =~ /^([^#]+)#([^#]+)$/) {
7189: $url = $1;
7190: $anchor = $2;
7191: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7192: $caller = $1.&escape('#').$anchor;
7193: }
7194: } else {
7195: $url = $res;
7196: }
7197: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7198: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7199: $backtourl .= '?navmap=1';
7200: } else {
7201: $backtourl .= '?symb='.
7202: &HTML::Entities::encode($caller,'<>&"');
7203: }
7204: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7205: if (($ENV{'SERVER_PORT'} == 443) &&
7206: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7207: if ($hostname ne '') {
7208: $backtourl = 'http://'.$hostname.$backtourl;
7209: }
7210: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7211: }
7212: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7213: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7214: $backtourl = 'http://'.$hostname.$backtourl;
7215: }
7216: }
7217: if ($anchor ne '') {
7218: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7219: }
7220: $backtourl = &Apache::loncommon::escape_single($backtourl);
7221: } else {
7222: $backtourl = '/adm/navmaps';
7223: }
7224: }
7225: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7226: $backtourl = '/adm/menu';
7227: } elsif ($supplementalflag) {
7228: $backtourl = '/adm/supplemental';
7229: } else {
7230: $backtourl = '/adm/navmaps';
7231: }
7232:
7233: my $fieldsets = "'ext','doc'";
7234: if ($posslti) {
7235: $fieldsets .= ",'tool'";
7236: }
7237: unless ($main_container_page) {
7238: $fieldsets .=",'ims'";
7239: }
7240: if ($supplementalflag) {
7241: $fieldsets = "'suppext','suppdoc'";
7242: if ($posslti) {
7243: $fieldsets .= ",'supptool'";
7244: }
7245: }
7246:
7247: my $jsmakefunctions;
7248: if ($canedit) {
7249: $jsmakefunctions = <<ENDNEWSCRIPT;
7250: function makenewfolder(targetform,folderseq) {
7251: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
7252: if (foldername) {
7253: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7254: targetform.submit();
7255: }
7256: }
7257:
7258: function makenewpage(targetform,folderseq) {
7259: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
7260: if (pagename) {
7261: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7262: targetform.submit();
7263: }
7264: }
7265:
7266: function makeexamupload() {
7267: var title=prompt('$js_lt{"p_mxu"}');
7268: if (title) {
7269: this.document.forms.newexamupload.importdetail.value=
7270: escape(title)+'=/res/lib/templates/examupload.problem';
7271: this.document.forms.newexamupload.submit();
7272: }
7273: }
7274:
7275: function makesmppage() {
7276: var title=prompt('$js_lt{"p_msp"}');
7277: if (title) {
7278: this.document.forms.newsmppg.importdetail.value=
7279: escape(title)+'=/adm/$udom/$uname/new/smppg';
7280: this.document.forms.newsmppg.submit();
7281: }
7282: }
7283:
7284: function makewebpage(type) {
7285: var title=prompt('$js_lt{"p_mwp"}');
7286: var formname;
7287: if (type == 'supp') {
7288: formname = this.document.forms.supwebpage;
7289: } else {
7290: formname = this.document.forms.newwebpage;
7291: }
7292: if (title) {
7293: var webpage = formname.importdetail.value;
7294: formname.importdetail.value = escape(title)+'='+webpage;
7295: formname.submit();
7296: }
7297: }
7298:
7299: function makesmpproblem() {
7300: var title=prompt('$js_lt{"p_msb"}');
7301: if (title) {
7302: this.document.forms.newsmpproblem.importdetail.value=
7303: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7304: this.document.forms.newsmpproblem.submit();
7305: }
7306: }
7307:
7308: function makedropbox() {
7309: var title=prompt('$js_lt{"p_mdb"}');
7310: if (title) {
7311: this.document.forms.newdropbox.importdetail.value=
7312: escape(title)+'=/res/lib/templates/DropBox.problem';
7313: this.document.forms.newdropbox.submit();
7314: }
7315: }
7316:
7317: function makebulboard() {
7318: var title=prompt('$js_lt{"p_mbb"}');
7319: if (title) {
7320: this.document.forms.newbul.importdetail.value=
7321: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
7322: this.document.forms.newbul.submit();
7323: }
7324: }
7325:
7326: function makeabout() {
7327: var user=prompt("$js_lt{'p_mab'}");
7328: if (user) {
7329: var comp=new Array();
7330: comp=user.split(':');
7331: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7332: if ((comp[0]) && (comp[1])) {
7333: this.document.forms.newaboutsomeone.importdetail.value=
7334: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7335: this.document.forms.newaboutsomeone.submit();
7336: } else {
7337: alert("$js_lt{'p_mab_alrt1'}");
7338: }
7339: } else {
7340: alert("$js_lt{'p_mab_alrt2'}");
7341: }
7342: }
7343: }
7344:
7345: function makenew(targetform) {
7346: targetform.submit();
7347: }
7348:
7349: function changename(folderpath,index,oldtitle) {
7350: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7351: if (title) {
7352: this.document.forms.renameform.markcopy.value='';
7353: this.document.forms.renameform.title.value=title;
7354: this.document.forms.renameform.cmd.value='rename_'+index;
7355: this.document.forms.renameform.folderpath.value=folderpath;
7356: this.document.forms.renameform.submit();
7357: }
7358: }
7359:
7360: function setalias(folderpath,index) {
7361: var alias = prompt('$js_lt{"setal"}');
7362: if ((alias != null) && (alias != '')) {
7363: this.document.forms.aliasform.alias.value=alias;
7364: this.document.forms.aliasform.cmd.value='setalias_'+index;
7365: this.document.forms.aliasform.folderpath.value=folderpath;
7366: this.document.forms.aliasform.submit();
7367: }
7368: }
7369:
7370: function delalias(folderpath,index) {
7371: if (confirm('$js_lt{"delal"}')) {
7372: this.document.forms.aliasform.cmd.value='delalias_'+index;
7373: this.document.forms.aliasform.folderpath.value=folderpath;
7374: this.document.forms.aliasform.submit();
7375: }
7376: }
7377:
7378: ENDNEWSCRIPT
7379: } else {
7380: $jsmakefunctions = <<ENDNEWSCRIPT;
7381:
7382: function makenewfolder() {
7383: alert("$js_lt{'edri'}");
7384: }
7385:
7386: function makenewpage() {
7387: alert("$js_lt{'edri'}");
7388: }
7389:
7390: function makeexamupload() {
7391: alert("$js_lt{'edri'}");
7392: }
7393:
7394: function makesmppage() {
7395: alert("$js_lt{'edri'}");
7396: }
7397:
7398: function makewebpage(type) {
7399: alert("$js_lt{'edri'}");
7400: }
7401:
7402: function makesmpproblem() {
7403: alert("$js_lt{'edri'}");
7404: }
7405:
7406: function makedropbox() {
7407: alert("$js_lt{'edri'}");
7408: }
7409:
7410: function makebulboard() {
7411: alert("$js_lt{'edri'}");
7412: }
7413:
7414: function makeabout() {
7415: alert("$js_lt{'edri'}");
7416: }
7417:
7418: function changename() {
7419: alert("$js_lt{'edri'}");
7420: }
7421:
7422: function setalias() {
7423: alert("$js_lt{'edri'}");
7424: }
7425:
7426: function delalias() {
7427: alert("$js_lt{'edri'}");
7428: }
7429:
7430: function makenew() {
7431: alert("$js_lt{'edri'}");
7432: }
7433:
7434: function groupimport() {
7435: alert("$js_lt{'edri'}");
7436: }
7437:
7438: function groupsearch() {
7439: alert("$js_lt{'edri'}");
7440: }
7441:
7442: function groupopen(url,recover) {
7443: var options="scrollbars=1,resizable=1,menubar=0";
7444: idxflag=1;
7445: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7446: idx.focus();
7447: }
7448:
7449: ENDNEWSCRIPT
7450:
7451: }
7452: return <<ENDSCRIPT;
7453:
7454: $jsmakefunctions
7455:
7456: function toggleUpload(caller) {
7457: var blocks = Array($fieldsets);
7458: for (var i=0; i<blocks.length; i++) {
7459: var disp = 'none';
7460: if (caller == blocks[i]) {
7461: var curr = document.getElementById('upload'+caller+'form').style.display;
7462: if (curr == 'none') {
7463: disp='block';
7464: }
7465: }
7466: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7467: if ((caller == 'tool') || (caller == 'supptool')) {
7468: if (disp == 'block') {
7469: if (document.getElementById('LC_exttoolid')) {
7470: var toolselector = document.getElementById('LC_exttoolid');
7471: var suppflag = 0;
7472: if (caller == 'supptool') {
7473: suppflag = 1;
7474: }
7475: currForm = document.getElementById('new'+caller);
7476: updateExttool(toolselector,currForm,suppflag);
7477: }
7478: }
7479: }
7480: }
7481: resize_scrollbox('contentscroll','1','1');
7482: return;
7483: }
7484:
7485: function toggleMap(caller) {
7486: var disp = 'none';
7487: if (document.getElementById('importmapform')) {
7488: if (caller == 'map') {
7489: var curr = document.getElementById('importmapform').style.display;
7490: if (curr == 'none') {
7491: disp='block';
7492: }
7493: }
7494: document.getElementById('importmapform').style.display=disp;
7495: resize_scrollbox('contentscroll','1','1');
7496: }
7497: return;
7498: }
7499:
7500: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7501: var disp = 'none';
7502: if (document.getElementById('crsresform')) {
7503: if (caller == 'res') {
7504: var curr = document.getElementById('crsresform').style.display;
7505: if (curr == 'none') {
7506: disp='block';
7507: numauthor = parseInt(numauthorrole);
7508: if (numauthor > 0) {
7509: document.courseresform.authorrole.selectedIndex = 0;
7510: select1priv_changed();
7511: document.courseresform.authorpath.selectedIndex = 0;
7512: document.courseresform.newresourceadd.selectedIndex = 0;
7513: toggleNewInCourse(document.courseresform);
7514: if (document.getElementById('newresource')) {
7515: document.getElementById('newresource').style.display = 'none';
7516: }
7517: } else {
7518: if (numcrsdirs) {
7519: document.courseresform.authorpath.selectedIndex = 0;
7520: }
7521: }
7522: if (document.courseresform.newresusetemp.length) {
7523: document.courseresform.newresusetemp[0].checked = true;
7524: toggleWithTemplate(document.courseresform);
7525: }
7526: document.courseresform.newresourcename.value = '';
7527: }
7528: }
7529: if (document.courseresform.newsubdir.length) {
7530: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7531: if (document.courseresform.newsubdir[j].value == 0) {
7532: document.courseresform.newsubdir[j].checked = true;
7533: }
7534: break;
7535: }
7536: if (document.getElementById('newsubdirname')) {
7537: document.getElementById('newsubdirname').type = "hidden";
7538: document.getElementById('newsubdirname').value = "";
7539: }
7540: if (document.getElementById('newsubdir')) {
7541: document.getElementById('newsubdir').innerHTML = "";
7542: }
7543: }
7544: document.getElementById('crsresform').style.display=disp;
7545: resize_scrollbox('contentscroll','1','0');
7546: }
7547: return;
7548: }
7549:
7550: function toggleNewsubdir(form) {
7551: if (form.newsubdir.length) {
7552: for (var j=0; j<form.newsubdir.length; j++) {
7553: if (form.newsubdir[j].checked) {
7554: if (document.getElementById('newsubdirname')) {
7555: if (form.newsubdir[j].value == '1') {
7556: document.getElementById('newsubdirname').type = "text";
7557: if (document.getElementById('newsubdir')) {
7558: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7559: }
7560: } else {
7561: document.getElementById('newsubdirname').type = "hidden";
7562: document.getElementById('newsubdirname').value = "";
7563: document.getElementById('newsubdir').innerHTML = "";
7564: }
7565: }
7566: break;
7567: }
7568: }
7569: }
7570: }
7571:
7572: function toggleCrsResTitle() {
7573: if (document.getElementById('newresource')) {
7574: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7575: document.getElementById('newresource').style.display = 'inline';
7576: document.courseresform.newresourceadd[0].checked = true;
7577: toggleNewInCourse(document.courseresform);
7578: } else {
7579: document.getElementById('newresource').style.display = 'none';
7580: }
7581: }
7582: }
7583:
7584: function toggleNewInCourse(form) {
7585: if (form.newresourceadd.length) {
7586: for (var i=0; i<form.newresourceadd.length; i++) {
7587: if (form.newresourceadd[i].checked) {
7588: if (document.getElementById('newresourcetitle')) {
7589: if (form.newresourceadd[i].value == '1') {
7590: document.getElementById('newresourcetitle').type = 'text';
7591: if (document.getElementById('newrestitle')) {
7592: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7593: }
7594: } else {
7595: document.getElementById('newresourcetitle').type = 'hidden';
7596: document.getElementById('newresourcetitle').value = '';
7597: if (document.getElementById('newrestitle')) {
7598: document.getElementById('newrestitle').innerHTML = '';
7599: }
7600: }
7601: }
7602: break;
7603: }
7604: }
7605: }
7606: }
7607:
7608: function toggleWithTemplate(form) {
7609: if (form.newresusetemp.length) {
7610: for (var i=0; i<form.newresusetemp.length; i++) {
7611: if (form.newresusetemp[i].checked) {
7612: if (document.getElementById('newrestemplate')) {
7613: if (form.newresusetemp[i].value == '1') {
7614: document.getElementById('newrestemplate').style.display = 'inline';
7615: toggleExampleText();
7616: } else {
7617: form.tempcategory.selectedIndex = 0;
7618: select1template_changed();
7619: document.getElementById('newrestemplate').style.display = 'none';
7620: }
7621: }
7622: }
7623: }
7624: }
7625: }
7626:
7627: function toggleExampleText() {
7628: if (document.getElementById('newresexample')) {
7629: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7630: if (url == '') {
7631: document.getElementById('newresexample').style.fontWeight = 'normal';
7632: } else {
7633: document.getElementById('newresexample').style.fontWeight = 'bold';
7634: }
7635: }
7636: }
7637:
7638: function getExample(width,height,scrolling,transparency) {
7639: var url;
7640: if (document.courseresform.newresusetemp.length) {
7641: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7642: if (document.courseresform.newresusetemp[i].checked) {
7643: if (document.courseresform.newresusetemp[i].value == '1') {
7644: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7645: if (url == '') {
7646: alert('Pick a category and template');
7647: } else {
7648: url = url.replace("$londocroot","");
7649: url += '?inhibitmenu=yes';
7650: }
7651: }
7652: break;
7653: }
7654: }
7655: }
7656: if (url != '') {
7657: openMyModal(url,width,height,scrolling,transparency,'');
7658: }
7659: }
7660:
7661: function toggleImportCrsres(caller,dircount) {
7662: var disp = 'none';
7663: if (document.getElementById('importcrsresform')) {
7664: if (caller == 'res') {
7665: var numdirs = parseInt(dircount);
7666: var curr = document.getElementById('importcrsresform').style.display;
7667: if (curr == 'none') {
7668: disp='block';
7669: if (numdirs > 1) {
7670: select1res_changed();
7671: }
7672: }
7673: }
7674: document.getElementById('importcrsresform').style.display=disp;
7675: resize_scrollbox('contentscroll','1','0');
7676: }
7677: return;
7678: }
7679:
7680: function makeims(imsform) {
7681: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7682: alert("$js_lt{'imsfile'}");
7683: return;
7684: }
7685: if (imsform.source.selectedIndex == 0) {
7686: alert("$js_lt{'imscms'}");
7687: return;
7688: }
7689: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7690: imsform.submit();
7691: }
7692:
7693: function updatePick(targetform,index,caller) {
7694: var pickitem;
7695: var picknumitem;
7696: var picknumtext;
7697: if (index == 'all') {
7698: pickitem = document.getElementById('randompickall');
7699: picknumitem = document.getElementById('rpicknumall');
7700: picknumtext = document.getElementById('rpicktextall');
7701: } else {
7702: pickitem = document.getElementById('randompick_'+index);
7703: picknumitem = document.getElementById('rpicknum_'+index);
7704: picknumtext = document.getElementById('randompicknum_'+index);
7705: }
7706: if (pickitem.checked) {
7707: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7708: if (picknum == '' || picknum == null) {
7709: if (caller == 'check') {
7710: pickitem.checked=false;
7711: if (index == 'all') {
7712: picknumtext.innerHTML = '';
7713: if (caller == 'link') {
7714: propagateState(targetform,'rpicknum');
7715: }
7716: } else {
7717: checkForSubmit(targetform,'randompick','settings');
7718: }
7719: }
7720: } else {
7721: picknum.toString();
7722: var regexdigit=/^\\d+\$/;
7723: if (regexdigit.test(picknum)) {
7724: picknumitem.value = picknum;
7725: if (index == 'all') {
7726: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7727: if (caller == 'link') {
7728: propagateState(targetform,'rpicknum');
7729: }
7730: } else {
7731: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7732: checkForSubmit(targetform,'randompick','settings');
7733: }
7734: } else {
7735: if (caller == 'check') {
7736: if (index == 'all') {
7737: picknumtext.innerHTML = '';
7738: if (caller == 'link') {
7739: propagateState(targetform,'rpicknum');
7740: }
7741: } else {
7742: pickitem.checked=false;
7743: checkForSubmit(targetform,'randompick','settings');
7744: }
7745: }
7746: return;
7747: }
7748: }
7749: } else {
7750: picknumitem.value = '';
7751: picknumtext.innerHTML = '';
7752: if (index == 'all') {
7753: if (caller == 'link') {
7754: propagateState(targetform,'rpicknum');
7755: }
7756: } else {
7757: checkForSubmit(targetform,'randompick','settings');
7758: }
7759: }
7760: }
7761:
7762: function propagateState(form,param) {
7763: if (document.getElementById(param+'all')) {
7764: var setcheck = 0;
7765: var rpick = 0;
7766: if (param == 'rpicknum') {
7767: if (document.getElementById('randompickall')) {
7768: if (document.getElementById('randompickall').checked) {
7769: if (document.getElementById('rpicknumall')) {
7770: rpick = document.getElementById('rpicknumall').value;
7771: }
7772: }
7773: }
7774: } else {
7775: if (document.getElementById(param+'all').checked) {
7776: setcheck = 1;
7777: }
7778: }
7779: var allidxlist;
7780: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7781: if (document.getElementById('all'+param+'idx')) {
7782: allidxlist = document.getElementById('all'+param+'idx').value;
7783: }
7784: var actions = new Array ('remove','cut','copy');
7785: for (var i=0; i<actions.length; i++) {
7786: if (actions[i] != param) {
7787: if (document.getElementById(actions[i]+'all')) {
7788: document.getElementById(actions[i]+'all').checked = false;
7789: }
7790: }
7791: }
7792: }
7793: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
7794: allidxlist = form.allidx.value;
7795: }
7796: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7797: allidxlist = form.allmapidx.value;
7798: }
7799: if ((allidxlist != '') && (allidxlist != null)) {
7800: var allidxs = allidxlist.split(',');
7801: if (allidxs.length > 1) {
7802: for (var i=0; i<allidxs.length; i++) {
7803: if (document.getElementById(param+'_'+allidxs[i])) {
7804: if (param == 'rpicknum') {
7805: if (document.getElementById('randompick_'+allidxs[i])) {
7806: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7807: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7808: if (rpick > 0) {
7809: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7810: } else {
7811: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7812: }
7813: }
7814: }
7815: } else {
7816: if (setcheck == 1) {
7817: document.getElementById(param+'_'+allidxs[i]).checked = true;
7818: } else {
7819: document.getElementById(param+'_'+allidxs[i]).checked = false;
7820: if (param == 'randompick') {
7821: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7822: }
7823: }
7824: }
7825: }
7826: }
7827: if (setcheck == 1) {
7828: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7829: var actions = new Array('copy','cut','remove');
7830: for (var i=0; i<actions.length; i++) {
7831: var otheractions;
7832: var otheridxs;
7833: if (actions[i] === param) {
7834: continue;
7835: } else {
7836: if (document.getElementById('all'+actions[i]+'idx')) {
7837: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7838: otheridxs = otheractions.split(',');
7839: if (otheridxs.length > 1) {
7840: for (var j=0; j<otheridxs.length; j++) {
7841: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7842: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7843: }
7844: }
7845: }
7846: }
7847: }
7848: }
7849: }
7850: }
7851: }
7852: }
7853: }
7854: return;
7855: }
7856:
7857: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
7858: var canedit = '$canedit';
7859: if (canedit == '') {
7860: alert("$js_lt{'edri'}");
7861: return;
7862: }
7863: var dosettings;
7864: var doaction;
7865: var control = document.togglemultsettings;
7866: if (context == 'actions') {
7867: control = document.togglemultactions;
7868: doaction = 1;
7869: } else {
7870: dosettings = 1;
7871: }
7872: if (control) {
7873: if (control.showmultpick.length) {
7874: for (var i=0; i<control.showmultpick.length; i++) {
7875: if (control.showmultpick[i].checked) {
7876: if (control.showmultpick[i].value == 1) {
7877: if (context == 'settings') {
7878: dosettings = 0;
7879: } else {
7880: doaction = 0;
7881: }
7882: }
7883: }
7884: }
7885: }
7886: }
7887: if (context == 'settings') {
7888: if (dosettings == 1) {
7889: targetform.changeparms.value=param;
7890: targetform.submit();
7891: }
7892: }
7893: if (context == 'actions') {
7894: if (doaction == 1) {
7895: targetform.cmd.value=param+'_'+index;
7896: targetform.folderpath.value=folderpath;
7897: targetform.markcopy.value=idx+':'+param;
7898: targetform.copyfolder.value=folder+'.'+container;
7899: if (param == 'remove') {
7900: var doremove = 0;
7901: if (skip_confirm) {
7902: if (confirm_removal) {
7903: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7904: doremove = 1;
7905: }
7906: } else {
7907: doremove = 1;
7908: }
7909: } else {
7910: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7911: doremove = 1;
7912: }
7913: }
7914: if (doremove) {
7915: targetform.markcopy.value='';
7916: targetform.copyfolder.value='';
7917: targetform.submit();
7918: }
7919: }
7920: if (param == 'cut') {
7921: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
7922: targetform.submit();
7923: return;
7924: }
7925: }
7926: if (param == 'copy') {
7927: targetform.submit();
7928: return;
7929: }
7930: targetform.markcopy.value='';
7931: targetform.copyfolder.value='';
7932: targetform.cmd.value='';
7933: targetform.folderpath.value='';
7934: return;
7935: } else {
7936: if (document.getElementById(param+'_'+idx)) {
7937: item = document.getElementById(param+'_'+idx);
7938: if (item.type == 'checkbox') {
7939: if (item.checked) {
7940: item.checked = false;
7941: } else {
7942: item.checked = true;
7943: singleCheck(item,idx,param);
7944: }
7945: }
7946: }
7947: }
7948: }
7949: return;
7950: }
7951:
7952: function singleCheck(caller,idx,action) {
7953: actions = new Array('cut','copy','remove');
7954: if (caller.checked) {
7955: for (var i=0; i<actions.length; i++) {
7956: if (actions[i] != action) {
7957: if (document.getElementById(actions[i]+'_'+idx)) {
7958: if (document.getElementById(actions[i]+'_'+idx).checked) {
7959: document.getElementById(actions[i]+'_'+idx).checked = false;
7960: }
7961: }
7962: }
7963: }
7964: }
7965: return;
7966: }
7967:
7968: function unselectInactive(nav) {
7969: currentNav = document.getElementById(nav);
7970: currentLis = currentNav.getElementsByTagName('LI');
7971: for (i = 0; i < currentLis.length; i++) {
7972: if (currentLis[i].className == 'goback') {
7973: currentLis[i].className = 'goback';
7974: } else {
7975: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
7976: currentLis[i].className = 'right';
7977: } else {
7978: currentLis[i].className = 'i';
7979: }
7980: }
7981: }
7982: }
7983:
7984: function hideAll(current, nav, data) {
7985: unselectInactive(nav);
7986: if (current) {
7987: if (current.className == 'right'){
7988: current.className = 'right active'
7989: } else {
7990: current.className = 'active';
7991: }
7992: }
7993: currentData = document.getElementById(data);
7994: currentDivs = currentData.getElementsByTagName('DIV');
7995: for (i = 0; i < currentDivs.length; i++) {
7996: if(currentDivs[i].className == 'LC_ContentBox'){
7997: currentDivs[i].style.display = 'none';
7998: }
7999: }
8000: }
8001:
8002: function openTabs(pageId) {
8003: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
8004: if(tabnav.length > 2 ){
8005: currentNav = document.getElementById(tabnav[1].id);
8006: currentLis = currentNav.getElementsByTagName('LI');
8007: for(i = 0; i< currentLis.length; i++){
8008: if(currentLis[i].className == 'active') {
8009: funcString = currentLis[i].onclick.toString();
8010: tab = funcString.split('"');
8011: if(tab.length < 2) {
8012: tab = funcString.split("'");
8013: }
8014: currentData = document.getElementById(tab[1]);
8015: currentData.style.display = 'block';
8016: }
8017: }
8018: }
8019: }
8020:
8021: function showPage(current, pageId, nav, data) {
8022: currstate = current.className;
8023: hideAll(current, nav, data);
8024: openTabs(pageId);
8025: unselectInactive(nav);
8026: if ((currstate == 'active') || (currstate == 'right active')) {
8027: if (currstate == 'active') {
8028: current.className = '';
8029: } else {
8030: current.className = 'right';
8031: }
8032: activeTab = '';
8033: toggleUpload();
8034: toggleMap();
8035: toggleCrsRes();
8036: toggleImportCrsres();
8037: resize_scrollbox('contentscroll','1','0');
8038: return;
8039: } else {
8040: current.className = 'active';
8041: }
8042: currentData = document.getElementById(pageId);
8043: currentData.style.display = 'block';
8044: activeTab = pageId;
8045: toggleUpload();
8046: toggleMap();
8047: toggleCrsRes();
8048: toggleImportCrsres();
8049: if (nav == 'mainnav') {
8050: var storedpath = "$docs_folderpath";
8051: var storedpage = "$main_container_page";
8052: var reg = new RegExp("^supplemental");
8053: if (pageId == 'mainCourseDocuments') {
8054: if (storedpage == 1) {
8055: document.simpleedit.folderpath.value = '';
8056: document.uploaddocument.folderpath.value = '';
8057: } else {
8058: if (reg.test(storedpath)) {
8059: document.simpleedit.folderpath.value = '$toplevelmain';
8060: document.uploaddocument.folderpath.value = '$toplevelmain';
8061: document.newext.folderpath.value = '$toplevelmain';
8062: } else {
8063: document.simpleedit.folderpath.value = storedpath;
8064: document.uploaddocument.folderpath.value = storedpath;
8065: document.newext.folderpath.value = storedpath;
8066: }
8067: }
8068: } else {
8069: if (reg.test(storedpath)) {
8070: document.simpleedit.folderpath.value = storedpath;
8071: document.supuploaddocument.folderpath.value = storedpath;
8072: document.supnewext.folderpath.value = storedpath;
8073: } else {
8074: document.simpleedit.folderpath.value = '$toplevelsupp';
8075: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8076: document.supnewext.folderpath.value = '$toplevelsupp';
8077: }
8078: }
8079: }
8080: resize_scrollbox('contentscroll','1','0');
8081: return false;
8082: }
8083:
8084: function toContents(jumpto) {
8085: var newurl = '$backtourl';
8086: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
8087: newurl = newurl+'?postdata='+jumpto;
8088: }
8089: location.href=newurl;
8090: }
8091:
8092: function togglePick(caller,value) {
8093: var disp = 'none';
8094: if (document.getElementById('multi'+caller)) {
8095: var curr = document.getElementById('multi'+caller).style.display;
8096: if (value == 1) {
8097: disp='block';
8098: }
8099: if (curr == disp) {
8100: return;
8101: }
8102: document.getElementById('multi'+caller).style.display=disp;
8103: if (value == 1) {
8104: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8105: } else {
8106: document.getElementById('more'+caller).innerHTML = '';
8107: }
8108: if (caller == 'actions') {
8109: setClass(value);
8110: setBoxes(value);
8111: }
8112: }
8113: var showButton = multiSettings();
8114: if (showButton != 1) {
8115: showButton = multiActions();
8116: }
8117: if (document.getElementById('multisave')) {
8118: if (showButton == 1) {
8119: document.getElementById('multisave').style.display='block';
8120: } else {
8121: document.getElementById('multisave').style.display='none';
8122: }
8123: }
8124: resize_scrollbox('contentscroll','1','1');
8125: return;
8126: }
8127:
8128: function toggleCheckUncheck(caller,more) {
8129: if (more == 1) {
8130: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
8131: document.getElementById('allfields'+caller).style.display='block';
8132: } else {
8133: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8134: document.getElementById('allfields'+caller).style.display='none';
8135: }
8136: resize_scrollbox('contentscroll','1','1');
8137: }
8138:
8139: function multiSettings() {
8140: var inuse = 0;
8141: var settingsform = document.togglemultsettings;
8142: if (settingsform.showmultpick.length > 1) {
8143: for (var i=0; i<settingsform.showmultpick.length; i++) {
8144: if (settingsform.showmultpick[i].checked) {
8145: if (settingsform.showmultpick[i].value == 1) {
8146: inuse = 1;
8147: }
8148: }
8149: }
8150: }
8151: return inuse;
8152: }
8153:
8154: function multiActions() {
8155: var inuse = 0;
8156: var actionsform = document.togglemultactions;
8157: if (actionsform.showmultpick.length > 1) {
8158: for (var i=0; i<actionsform.showmultpick.length; i++) {
8159: if (actionsform.showmultpick[i].checked) {
8160: if (actionsform.showmultpick[i].value == 1) {
8161: inuse = 1;
8162: }
8163: }
8164: }
8165: }
8166: return inuse;
8167: }
8168:
8169: function checkSubmits() {
8170: var numchanges = 0;
8171: var form = document.saveactions;
8172: var doactions = multiActions();
8173: var cutwarnings = 0;
8174: var remwarnings = 0;
8175: var removalinfo = 0;
8176: if (doactions == 1) {
8177: var remidxlist = document.cumulativeactions.allremoveidx.value;
8178: if ((remidxlist != '') && (remidxlist != null)) {
8179: var remidxs = remidxlist.split(',');
8180: for (var i=0; i<remidxs.length; i++) {
8181: if (document.getElementById('remove_'+remidxs[i])) {
8182: if (document.getElementById('remove_'+remidxs[i]).checked) {
8183: form.multiremove.value += remidxs[i]+',';
8184: numchanges ++;
8185: if (document.getElementById('skip_remove_'+remidxs[i])) {
8186: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8187: remwarnings ++;
8188: }
8189: }
8190: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8191: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8192: removalinfo ++;
8193: }
8194: }
8195: }
8196: }
8197: }
8198: }
8199: var cutidxlist = document.cumulativeactions.allcutidx.value;
8200: if ((cutidxlist != '') && (cutidxlist != null)) {
8201: var cutidxs = cutidxlist.split(',');
8202: for (var i=0; i<cutidxs.length; i++) {
8203: if (document.getElementById('cut_'+cutidxs[i])) {
8204: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8205: form.multicut.value += cutidxs[i]+',';
8206: numchanges ++;
8207: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8208: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8209: cutwarnings ++;
8210: }
8211: }
8212: }
8213: }
8214: }
8215: }
8216: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8217: if ((copyidxlist != '') && (copyidxlist != null)) {
8218: var copyidxs = copyidxlist.split(',');
8219: for (var i=0; i<copyidxs.length; i++) {
8220: if (document.getElementById('copy_'+copyidxs[i])) {
8221: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8222: form.multicopy.value += copyidxs[i]+',';
8223: numchanges ++;
8224: }
8225: }
8226: }
8227: }
8228: if (numchanges > 0) {
8229: form.multichange.value = numchanges;
8230: }
8231: }
8232: var dosettings = multiSettings();
8233: var haschanges = 0;
8234: if (dosettings == 1) {
8235: form.allencrypturl.value = '';
8236: form.allhiddenresource.value = '';
8237: form.changeparms.value = 'all';
8238: var patt=new RegExp(",\$");
8239: var allidxlist = document.cumulativesettings.allidx.value;
8240: if ((allidxlist != '') && (allidxlist != null)) {
8241: var allidxs = allidxlist.split(',');
8242: if (allidxs.length > 1) {
8243: for (var i=0; i<allidxs.length; i++) {
8244: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8245: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8246: form.allhiddenresource.value += allidxs[i]+',';
8247: }
8248: }
8249: if (document.getElementById('encrypturl_'+allidxs[i])) {
8250: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8251: form.allencrypturl.value += allidxs[i]+',';
8252: }
8253: }
8254: }
8255: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8256: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
8257: }
8258: }
8259: form.allrandompick.value = '';
8260: form.allrandomorder.value = '';
8261: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8262: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8263: var allmapidxs = allmapidxlist.split(',');
8264: for (var i=0; i<allmapidxs.length; i++) {
8265: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8266: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8267: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8268: if ((randompick.checked) && (rpicknum.value != '')) {
8269: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8270: }
8271: if (randorder.checked) {
8272: form.allrandomorder.value += allmapidxs[i]+',';
8273: }
8274: }
8275: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8276: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8277: }
8278: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8279: haschanges = 1;
8280: }
8281: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8282: haschanges = 1;
8283: }
8284: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8285: haschanges = 1;
8286: }
8287: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8288: haschanges = 1;
8289: }
8290: }
8291: if (doactions == 1) {
8292: if (numchanges > 0) {
8293: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
8294: if (remwarnings > 0) {
8295: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
8296: return false;
8297: }
8298: }
8299: if (removalinfo > 0) {
8300: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8301: return false;
8302: }
8303: }
8304: if (cutwarnings > 0) {
8305: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
8306: return false;
8307: }
8308: }
8309: }
8310: form.submit();
8311: return true;
8312: }
8313: }
8314: if (dosettings == 1) {
8315: if (haschanges == 1) {
8316: form.submit();
8317: return true;
8318: }
8319: }
8320: if ((dosettings == 1) && (doactions == 1)) {
8321: alert("$js_lt{'noor'}");
8322: } else {
8323: if (dosettings == 1) {
8324: alert("$js_lt{'noch'}");
8325: } else {
8326: alert("$js_lt{'noac'}");
8327: }
8328: }
8329: return false;
8330: }
8331:
8332: function setClass(value) {
8333: var cutclass = 'LC_docs_cut';
8334: var copyclass = 'LC_docs_copy';
8335: var removeclass = 'LC_docs_remove';
8336: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8337: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8338: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8339: var links = document.getElementsByTagName('a');
8340: for (var i=0; i<links.length; i++) {
8341: var classes = links[i].className;
8342: if (cutreg.test(classes)) {
8343: links[i].className = cutclass;
8344: if (value == 1) {
8345: links[i].className += " LC_menubuttons_link";
8346: }
8347: } else {
8348: if (copyreg.test(classes)) {
8349: links[i].className = copyclass;
8350: if (value == 1) {
8351: links[i].className += " LC_menubuttons_link";
8352: }
8353: } else {
8354: if (removereg.test(classes)) {
8355: links[i].className = removeclass;
8356: if (value == 1) {
8357: links[i].className += " LC_menubuttons_link";
8358: }
8359: }
8360: }
8361: }
8362: }
8363: return;
8364: }
8365:
8366: function setBoxes(value) {
8367: var remidxlist = document.cumulativeactions.allremoveidx.value;
8368: if ((remidxlist != '') && (remidxlist != null)) {
8369: var remidxs = remidxlist.split(',');
8370: for (var i=0; i<remidxs.length; i++) {
8371: if (document.getElementById('remove_'+remidxs[i])) {
8372: var item = document.getElementById('remove_'+remidxs[i]);
8373: if (value == 1) {
8374: item.className = 'LC_docs_remove';
8375: } else {
8376: item.className = 'LC_hidden';
8377: }
8378: }
8379: }
8380: }
8381: var cutidxlist = document.cumulativeactions.allcutidx.value;
8382: if ((cutidxlist != '') && (cutidxlist != null)) {
8383: var cutidxs = cutidxlist.split(',');
8384: for (var i=0; i<cutidxs.length; i++) {
8385: if (document.getElementById('cut_'+cutidxs[i])) {
8386: var item = document.getElementById('cut_'+cutidxs[i]);
8387: if (value == 1) {
8388: item.className = 'LC_docs_cut';
8389: } else {
8390: item.className = 'LC_hidden';
8391: }
8392: }
8393: }
8394: }
8395: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8396: if ((copyidxlist != '') && (copyidxlist != null)) {
8397: var copyidxs = copyidxlist.split(',');
8398: for (var i=0; i<copyidxs.length; i++) {
8399: if (document.getElementById('copy_'+copyidxs[i])) {
8400: var item = document.getElementById('copy_'+copyidxs[i]);
8401: if (value == 1) {
8402: item.className = 'LC_docs_copy';
8403: } else {
8404: item.className = 'LC_hidden';
8405: }
8406: }
8407: }
8408: }
8409: return;
8410: }
8411:
8412: function validImportCrsRes() {
8413: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8414: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8415: if ((fname == '') || (fname == null)) {
8416: alert("$js_lt{'nofi'}");
8417: return false;
8418: }
8419: var url = '/res/$coursedom/$coursenum/';
8420: if (path && path != '/') {
8421: url += path+'/';
8422: }
8423: if (fname != '') {
8424: url += fname;
8425: }
8426: var title = document.crsresimportform.crsrestitle.value;
8427: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8428: return true;
8429: }
8430:
8431: function validateNewRes(caller) {
8432: if (caller == 'single') {
8433: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8434: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8435: var resname = document.courseresform.newresourcename.value;
8436: }
8437: }
8438:
8439: ENDSCRIPT
8440: }
8441:
8442: sub history_tab_js {
8443: return <<"ENDHIST";
8444: function toggleHistoryDisp(choice) {
8445: document.docslogform.docslog.value = choice;
8446: document.docslogform.submit();
8447: return;
8448: }
8449:
8450: ENDHIST
8451: }
8452:
8453: sub inject_data_js {
8454: return <<ENDINJECT;
8455:
8456: function injectData(current, hiddenField, name, value) {
8457: currentElement = document.getElementById(hiddenField);
8458: currentElement.name = name;
8459: currentElement.value = value;
8460: current.submit();
8461: }
8462:
8463: ENDINJECT
8464: }
8465:
8466: sub dump_switchserver_js {
8467: my @hosts = @_;
8468: my %js_lt = &Apache::lonlocal::texthash(
8469: dump => 'Copying content to Authoring Space requires switching server.',
8470: swit => 'Switch server?',
8471: );
8472: my %html_js_lt = &Apache::lonlocal::texthash(
8473: swit => 'Switch server?',
8474: duco => 'Copying Content to Authoring Space',
8475: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8476: chos => 'Choose server',
8477: );
8478: &js_escape(\%js_lt);
8479: &html_escape(\%html_js_lt);
8480: &js_escape(\%html_js_lt);
8481: my $role = $env{'request.role'};
8482: my $js = <<"ENDSWJS";
8483: <script type="text/javascript">
8484: function write_switchserver() {
8485: var server;
8486: if (document.setserver.posshosts.length > 0) {
8487: for (var i=0; i<document.setserver.posshosts.length; i++) {
8488: if (document.setserver.posshosts[i].checked) {
8489: server = document.setserver.posshosts[i].value;
8490: }
8491: }
8492: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8493: }
8494: window.close();
8495: }
8496: </script>
8497:
8498: ENDSWJS
8499:
8500: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8501: {'only_body' => 1,
8502: 'js_ready' => 1,});
8503: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8504:
8505: my $hostpicker;
8506: my $count = 0;
8507: foreach my $host (sort(@hosts)) {
8508: my $checked;
8509: if ($count == 0) {
8510: $checked = ' checked="checked"';
8511: }
8512: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8513: $host.'"'.$checked.' />'.$host.'</label> ';
8514: $count++;
8515: }
8516:
8517: return <<"ENDSWITCHJS";
8518:
8519: function dump_needs_switchserver(url) {
8520: if (url!='' && url!= null) {
8521: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8522: go(url);
8523: }
8524: }
8525: return;
8526: }
8527:
8528: function choose_switchserver_window() {
8529: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8530: newWindow.document.open();
8531: newWindow.document.writeln('$startpage');
8532: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8533: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8534: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8535: '<form name="setserver" method="post" action="" \\/>\\n'+
8536: '$hostpicker\\n'+
8537: '<br \\/><br \\/>\\n'+
8538: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8539: 'onclick="write_switchserver();" \\/>\\n'+
8540: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8541: newWindow.document.writeln('$endpage');
8542: newWindow.document.close();
8543: newWindow.focus();
8544: }
8545:
8546: ENDSWITCHJS
8547: }
8548:
8549: sub makedocslogform {
8550: my ($formelems,$docslog) = @_;
8551: return <<"LOGSFORM";
8552: <form action="/adm/coursedocs" method="post" name="docslogform">
8553: <input type="hidden" name="docslog" value="$docslog" />
8554: $formelems
8555: </form>
8556: LOGSFORM
8557: }
8558:
8559: sub makesimpleeditform {
8560: my ($formelems) = @_;
8561: return <<"SIMPFORM";
8562: <form name="simpleedit" method="post" action="/adm/coursedocs">
8563: <input type="hidden" name="importdetail" value="" />
8564: $formelems
8565: </form>
8566: SIMPFORM
8567: }
8568:
8569: sub makenewproblem {
8570: my ($r,$coursedom,$coursenum) = @_;
8571: # Creating a new problem
8572: my ($redirect,$error);
8573: if ($env{'form.authorrole'}) {
8574: my ($newsubdir,$filename);
8575: if ($env{'form.newsubdir'}) {
8576: if ($env{'form.newsubdirname'} ne '') {
8577: $newsubdir = $env{'form.newsubdirname'};
8578: }
8579: }
8580: if ($env{'form.newresourcename'}) {
8581: $filename = $env{'form.newresourcename'};
8582: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8583: $filename =~ s/`//g;
8584: $filename =~ s{/\.\./}{_}g;
8585: $filename =~ s/\.+/./g;
8586: $filename =~ s{/+}{_}g;
8587: if ($filename ne '') {
8588: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8589: if (($ext) && ($ext ne '.problem')) {
8590: $filename = $name.'.problem';
8591: } elsif ($ext eq '') {
8592: $filename .= '.problem';
8593: }
8594: my $docroot = $r->dir_config('lonDocRoot');
8595: my @ids=&Apache::lonnet::current_machine_ids();
8596: if ($env{'form.authorrole'} eq 'author') {
8597: if ($env{'user.author'}) {
8598: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8599: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8600: my $path = $docroot.$url;
8601: my $subdir = $env{'form.authorpath'};
8602: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8603: }
8604: }
8605: } elsif ($env{'form.authorrole'} eq 'course') {
8606: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8607: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8608: my $url = "/priv/$coursedom/$coursenum";
8609: my $path=$docroot.$url;
8610: my $subdir = $env{'form.authorpath'};
8611: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8612: if ($redirect) {
8613: my $rightsfile = 'default.rights';
8614: my $sourcerights = "$path/$rightsfile";
8615: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8616: my $now = time;
8617: if (!-e $sourcerights) {
8618: my $cid = $coursedom.'_'.$coursenum;
8619: if (open(my $fh,">$sourcerights")) {
8620: print $fh <<END;
8621: <accessrule effect="deny" realm="" type="course" role="" />
8622: <accessrule effect="allow" realm="$cid" type="course" role="" />
8623: END
8624: close($fh);
8625: }
8626: }
8627: if (!-e "$sourcerights.meta") {
8628: if (open(my $fh,">$sourcerights.meta")) {
8629: my $author=$env{'environment.firstname'}.' '.
8630: $env{'environment.middlename'}.' '.
8631: $env{'environment.lastname'}.' '.
8632: $env{'environment.generation'};
8633: $author =~ s/\s+$//;
8634: print $fh <<"END";
8635:
8636: <abstract></abstract>
8637: <author>$author</author>
8638: <authorspace>$coursenum:$coursedom</authorspace>
8639: <copyright>private</copyright>
8640: <creationdate>$now</creationdate>
8641: <customdistributionfile></customdistributionfile>
8642: <dependencies></dependencies>
8643: <domain>$coursedom</domain>
8644: <highestgradelevel>0</highestgradelevel>
8645: <keywords></keywords>
8646: <language>notset </language>
8647: <lastrevisiondate>$now</lastrevisiondate>
8648: <lowestgradelevel>0</lowestgradelevel>
8649: <mime>rights</mime>
8650: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8651: <notes></notes>
8652: <obsolete></obsolete>
8653: <obsoletereplacement></obsoletereplacement>
8654: <owner>$coursenum:$coursedom</owner>
8655: <rule>deny:::course,allow:$cid::course</rule>
8656: <sourceavail></sourceavail>
8657: <standards></standards>
8658: <subject></subject>
8659: <title></title>
8660: END
8661: close($fh);
8662: }
8663: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8664: if (!-e "$docroot/res/$coursedom") {
8665: mkdir("$docroot/res/$coursedom",0755);
8666: }
8667: if (!-e "$docroot/res/$coursedom/$coursenum") {
8668: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8669: }
8670: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8671: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8672: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8673: }
8674: }
8675: }
8676: if ($env{'form.newresourceadd'}) {
8677: my $template = $env{'form.template'};
8678: my $source = $docroot.$redirect;
8679: my $target = $redirect;
8680: $target =~ s{^/priv/}{/res/};
8681: $target = $docroot.$target;
8682: if (!-e $source) {
8683: my $copyfrom;
8684: if ($template) {
8685: my %templates;
8686: my @files = &Apache::lonhomework::get_template_list('problem');
8687: foreach my $poss (@files) {
8688: if (ref($poss) eq 'ARRAY') {
8689: if ($template eq $poss->[0]) {
8690: $templates{$template} = 1;
8691: last;
8692: }
8693: }
8694: }
8695: if ($templates{$template}) {
8696: $copyfrom = $template;
8697: }
8698: }
8699: unless ($copyfrom) {
8700: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8701: }
8702: &File::Copy::copy($copyfrom,$source);
8703: }
8704: if (!-e "$source.meta") {
8705: my $cid = $coursedom.'_'.$coursenum;
8706: my $now = time;
8707: if (open(my $fh,">$source.meta")) {
8708: my $author=$env{'environment.firstname'}.' '.
8709: $env{'environment.middlename'}.' '.
8710: $env{'environment.lastname'}.' '.
8711: $env{'environment.generation'};
8712: $author =~ s/\s+$//;
8713: my $title = $env{'form.newresourcetitle'};
8714: $title =~ s/^\s+|\s+$//g;
8715: print $fh <<END;
8716:
8717: <abstract></abstract>
8718: <author>$author</author>
8719: <authorspace>$coursenum:$coursedom</authorspace>
8720: <copyright>custom</copyright>
8721: <creationdate>$now</creationdate>
8722: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8723: <dependencies></dependencies>
8724: <domain>$coursedom</domain>
8725: <highestgradelevel>0</highestgradelevel>
8726: <keywords></keywords>
8727: <language>notset </language>
8728: <lastrevisiondate>$now</lastrevisiondate>
8729: <lowestgradelevel>0</lowestgradelevel>
8730: <mime>problem</mime>
8731: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8732: <notes></notes>
8733: <obsolete></obsolete>
8734: <obsoletereplacement></obsoletereplacement>
8735: <owner>$coursenum:$coursedom</owner>
8736: <sourceavail></sourceavail>
8737: <standards></standards>
8738: <subject></subject>
8739: <title>$title</title>
8740: END
8741: close($fh);
8742: }
8743: }
8744: }
8745: }
8746: }
8747: } else {
8748: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8749: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8750: if (grep(/^\Q$rolehome\E$/,@ids)) {
8751: my $now = time;
8752: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8753: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8754: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8755: my $url = "/priv/$audom/$auname";
8756: my $path = $r->dir_config('lonDocRoot').$url;
8757: my $subdir = $env{'form.authorpath'};
8758: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8759: }
8760: }
8761: }
8762: }
8763: }
8764: }
8765: }
8766: return ($redirect,$error);
8767: }
8768:
8769: sub finishnewprob {
8770: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
8771: unless (-d $path) {
8772: unless (mkdir($path,02770)) {
8773: return;
8774: }
8775: }
8776: my $redirect;
8777: if ($subdir ne '/') {
8778: $subdir = &cleandir($subdir);
8779: if (($subdir ne '') && (-d "$path/$subdir")) {
8780: $path .= "/$subdir";
8781: $url .= "/$subdir";
8782: }
8783: }
8784: my $dest;
8785: if ($newsubdir ne '') {
8786: $newsubdir = &cleandir($newsubdir);
8787: }
8788: if ($newsubdir ne '') {
8789: if (-d "$path/$newsubdir") {
8790: $dest = "$path/$newsubdir/$filename";
8791: } else {
8792: my $dirok;
8793: unless (-e "$path/$newsubdir") {
8794: if (mkdir("$path/$newsubdir",02770)) {
8795: if (chmod(02770,"$path/$newsubdir")) {
8796: $dirok = 1;
8797: }
8798: }
8799: }
8800: if ($dirok) {
8801: $dest = "$path/$newsubdir/$filename";
8802: }
8803: }
8804: if (($dest ne '') && (!-e $dest)) {
8805: $redirect = "$url/$newsubdir/$filename";
8806: }
8807: } else {
8808: $dest = "$path/$filename";
8809: if (($dest ne '') && (!-e $dest)) {
8810: $redirect = "$url/$filename";
8811: }
8812: }
8813: return $redirect;
8814: }
8815:
8816: sub cleandir {
8817: my ($dir) = @_;
8818: $dir =~ s/^\s+//;
8819: $dir =~ s/\s+$//;
8820: $dir =~ s/\.+//g;
8821: $dir =~ s/[\#\?&%\":]//g;
8822: return $dir;
8823: }
8824:
8825: 1;
8826: __END__
8827:
8828:
8829: =head1 NAME
8830:
8831: Apache::londocs.pm
8832:
8833: =head1 SYNOPSIS
8834:
8835: This is part of the LearningOnline Network with CAPA project
8836: described at http://www.lon-capa.org.
8837:
8838: =head1 SUBROUTINES
8839:
8840: =over
8841:
8842: =item %help=()
8843:
8844: Available help topics
8845:
8846: =item mapread()
8847:
8848: Mapread read maps into LONCAPA::map:: global arrays
8849: @order and @resources, determines status
8850: sets @order - pointer to resources in right order
8851: sets @resources - array with the resources with correct idx
8852:
8853: =item authorhosts()
8854:
8855: Return hash with valid author names
8856:
8857: =item clean()
8858:
8859: =item dumpcourse()
8860:
8861: Actually dump course
8862:
8863: =item group_import()
8864:
8865: Imports the given (name, url) resources into the course
8866: coursenum, coursedom, and folder must precede the list
8867:
8868: =item breadcrumbs()
8869:
8870: =item log_docs()
8871:
8872: =item docs_change_log()
8873:
8874: =item update_paste_buffer()
8875:
8876: =item print_paste_buffer()
8877:
8878: =item do_paste_from_buffer()
8879:
8880: =item do_buffer_empty()
8881:
8882: =item clear_from_buffer()
8883:
8884: =item get_newmap_url()
8885:
8886: =item dbcopy()
8887:
8888: =item uniqueness_check()
8889:
8890: =item contained_map_check()
8891:
8892: =item url_paste_fixups()
8893:
8894: =item apply_fixups()
8895:
8896: =item copy_dependencies()
8897:
8898: =item update_parameter()
8899:
8900: =item handle_edit_cmd()
8901:
8902: =item editor()
8903:
8904: =item process_file_upload()
8905:
8906: =item process_secondary_uploads()
8907:
8908: =item is_supplemental_title()
8909:
8910: =item entryline()
8911:
8912: =item tiehash()
8913:
8914: =item untiehash()
8915:
8916: =item checkonthis()
8917:
8918: check on this
8919:
8920: =item verifycontent()
8921:
8922: Verify Content
8923:
8924: =item devalidateversioncache()
8925:
8926: =item checkversions()
8927:
8928: Check Versions
8929:
8930: =item mark_hash_old()
8931:
8932: =item is_hash_old()
8933:
8934: =item changewarning()
8935:
8936: =item init_breadcrumbs()
8937:
8938: Breadcrumbs for special functions
8939:
8940: =item create_list_elements()
8941:
8942: =item create_form_ul()
8943:
8944: =item startContentScreen()
8945:
8946: =item endContentScreen()
8947:
8948: =item supplemental_base()
8949:
8950: =item embedded_form_elems()
8951:
8952: =item embedded_destination()
8953:
8954: =item return_to_editor()
8955:
8956: =item decompression_info()
8957:
8958: =item decompression_phase_one()
8959:
8960: =item decompression_phase_two()
8961:
8962: =item remove_archive()
8963:
8964: =item generate_admin_menu()
8965:
8966: =item generate_edit_table()
8967:
8968: =item editing_js()
8969:
8970: =item history_tab_js()
8971:
8972: =item inject_data_js()
8973:
8974: =item dump_switchserver_js()
8975:
8976: =item resize_scrollbox_js()
8977:
8978: =item makedocslogform()
8979:
8980: =item makesimpleeditform()
8981:
8982: =back
8983:
8984: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>