File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.611:
download - view:
text,
annotated -
select for diffs
Tue Nov 22 00:43:12 2016 UTC (7 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- 'cev' priv assignable to custom roles in course/community allows
view-only access to Course Editor.
- Intended for assignment to custom ad hoc course/community roles assignable
to domain helpdesk personnel.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.611 2016/11/22 00:43:12 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonhtmlcommon;
37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
42: use Apache::lonnavdisplay();
43: use Apache::lonextresedit();
44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
46: use Apache::lonhomework();
47: use Apache::lonpublisher();
48: use HTML::Entities;
49: use HTML::TokeParser;
50: use GDBM_File;
51: use File::MMagic;
52: use File::Copy;
53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
65: my $suppchanges;
66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
86: $map,1,$report);
87: if ($errtext) { return ($errtext,2); }
88:
89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
126: if ($allowed) {
127: $home++;
128: $outhash{'home_'.$ca.':'.$cd}=1;
129: } else {
130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
142: return $title;
143: }
144:
145:
146:
147: sub dumpcourse {
148: my ($r) = @_;
149: my $crstype = &Apache::loncommon::course_type();
150: my ($starthash,$js);
151: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
152: $js = <<"ENDJS";
153: <script type="text/javascript">
154: // <![CDATA[
155:
156: function hide_searching() {
157: if (document.getElementById('searching')) {
158: document.getElementById('searching').style.display = 'none';
159: }
160: return;
161: }
162:
163: // ]]>
164: </script>
165: ENDJS
166: $starthash = {
167: add_entries => {'onload' => "hide_searching();"},
168: };
169: }
170: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
171: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
172: $r->print(&startContentScreen('tools'));
173: my ($home,$other,%outhash)=&authorhosts();
174: unless ($home) {
175: $r->print(&endContentScreen());
176: return '';
177: }
178: my $origcrsid=$env{'request.course.id'};
179: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
180: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
181: # Do the dumping
182: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
183: $r->print(&endContentScreen());
184: return '';
185: }
186: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
187: $r->print('<h3>'.&mt('Copying Files').'</h3>');
188: my $title=$env{'form.authorfolder'};
189: $title=&clean($title);
190: my ($navmap,$errormsg) =
191: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
192: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
193: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
194: my (%maps,%resources,%titles);
195: if (!ref($navmap)) {
196: $r->print($errormsg.
197: &endContentScreen());
198: return '';
199: } else {
200: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
201: 'dumpdocs',$cdom,$cnum);
202: }
203: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
204: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
205: %newcontent,%has_simpleprobs);
206: foreach my $item (sort {$a <=> $b} (@todump)) {
207: my $name = $env{'form.namefor_'.$item};
208: if ($resources{$item}) {
209: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
210: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
211: $tocopy{$1} = $name;
212: $display{$item} = $1;
213: $lookup{$1} = $item;
214: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
215: $simpleproblems{$item} = {
216: symb => $resources{$item},
217: name => $name,
218: };
219: $display{$item} = 'simpleproblem_'.$name;
220: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
221: $has_simpleprobs{$1}{$id} = $item;
222: }
223: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
224: my $marker = $1;
225: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
226: $simplepages{$item} = {
227: res => $res,
228: title => $titles{$item},
229: db => $db_name,
230: marker => $marker,
231: symb => $resources{$item},
232: name => $name,
233: };
234: $display{$item} = '/'.$res;
235: }
236: } elsif ($maps{$item}) {
237: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
238: $tocopy{$1} = $name;
239: $display{$item} = $1;
240: $lookup{$1} = $item;
241: }
242: } else {
243: next;
244: }
245: }
246: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
247: $crs=~s/\_/\//g;
248: my $mm = new File::MMagic;
249: my $prefix = "/uploaded/$cdom/$cnum/";
250: %replacehash = %tocopy;
251: foreach my $item (sort(keys(%simpleproblems))) {
252: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
253: $newcontent{$display{$item}} = $content;
254: }
255: my $gateway = Apache::lonhtmlgateway->new('web');
256: foreach my $item (sort(keys(%simplepages))) {
257: if (ref($simplepages{$item}) eq 'HASH') {
258: my $pagetitle = $simplepages{$item}{'title'};
259: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
260: my %contents;
261: foreach my $field (keys(%fields)) {
262: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
263: my $name = $1;
264: my $msg = $fields{$field};
265: if ($name eq 'webreferences') {
266: if ($msg =~ m{^https?://}) {
267: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
268: }
269: } else {
270: $msg = &Encode::decode('utf8',$msg);
271: $msg = $gateway->process_outgoing_html($msg,1);
272: $contents{$name} = $msg;
273: }
274: } elsif ($field eq 'uploaded.photourl') {
275: my $marker = $simplepages{$item}{marker};
276: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
277: my $filepath = $1;
278: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
279: if ($fname ne '') {
280: $fname=~s/\.(\w+)$//;
281: my $ext=$1;
282: $fname = &clean($fname);
283: $fname.='.'.$ext;
284: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
285: $replacehash{$filepath} = $relpath.$fname;
286: $deps{$item}{$filepath} = 1;
287: }
288: }
289: }
290: }
291: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
292: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
293: my $content = '
294: <html>
295: <head>
296: <title>'.$pagetitle.'</title>
297: </head>
298: <body bgcolor="#ffffff">';
299: if ($contents{title}) {
300: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
301: }
302: if ($contents{image}) {
303: $content .= "\n".$contents{image};
304: }
305: if ($contents{content}) {
306: $content .= '
307: <div class="LC_Box">
308: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
309: $contents{content}.'
310: </div>';
311: }
312: if ($contents{webreferences}) {
313: $content .= '
314: <div class="LC_Box">
315: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
316: $contents{webreferences}.'
317: </div>';
318: }
319: $content .= '
320: </body>
321: </html>
322: ';
323: $newcontent{'/'.$simplepages{$item}{res}} = $content;
324: }
325: }
326: foreach my $item (keys(%tocopy)) {
327: unless ($item=~/\.(sequence|page)$/) {
328: my $currurlpath = $prefix.$item;
329: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
330: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
331: }
332: }
333: foreach my $num (sort {$a <=> $b} (@todump)) {
334: my $src = $display{$num};
335: next if ($src eq '');
336: my @needcopy = ();
337: if ($replacehash{$src}) {
338: push(@needcopy,$src);
339: if (ref($deps{$num}) eq 'HASH') {
340: foreach my $dep (sort(keys(%{$deps{$num}}))) {
341: if ($replacehash{$dep}) {
342: push(@needcopy,$dep);
343: }
344: }
345: }
346: } elsif ($src =~ /^simpleproblem_/) {
347: push(@needcopy,$src);
348: }
349: next if (@needcopy == 0);
350: my ($result,$depresult);
351: for (my $i=0; $i<@needcopy; $i++) {
352: my $item = $needcopy[$i];
353: my $newfilename;
354: if ($simpleproblems{$num}) {
355: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
356: } else {
357: $newfilename=$title.'/'.$replacehash{$item};
358: }
359: $newfilename=~s/\.(\w+)$//;
360: my $ext=$1;
361: $newfilename=&clean($newfilename);
362: $newfilename.='.'.$ext;
363: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
364: if ($newrelpath ne $replacehash{$item}) {
365: $replacehash{$item} = $newrelpath;
366: }
367: my @dirs=split(/\//,$newfilename);
368: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
369: my $makepath=$path;
370: my $fail;
371: my $origin;
372: for (my $i=0;$i<$#dirs;$i++) {
373: $makepath.='/'.$dirs[$i];
374: unless (-e $makepath) {
375: unless(mkdir($makepath,0755)) {
376: $fail = &mt('Directory creation failed.');
377: }
378: }
379: }
380: if ($i == 0) {
381: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
382: } else {
383: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
384: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
385: &mt('(dependency)').'</span>: ';
386: }
387: if (-e $path.'/'.$newfilename) {
388: $fail = &mt('Destination already exists -- not overwriting.');
389: } else {
390: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
391: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
392: ($item =~ /^simpleproblem_/)) {
393: print $fh $newcontent{$item};
394: } else {
395: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
396: if (-e $fileloc) {
397: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
398: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
399: (ref($has_simpleprobs{$item}) eq 'HASH')) {
400: my %changes = %{$has_simpleprobs{$item}};
401: my $content = &Apache::lonclonecourse::rewritefile(
402: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
403: (%replacehash,$crs => '')
404: );
405: my $updatedcontent = '';
406: my $parser = HTML::TokeParser->new(\$content);
407: $parser->attr_encoded(1);
408: while (my $token = $parser->get_token) {
409: if ($token->[0] eq 'S') {
410: if (($token->[1] eq 'resource') &&
411: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
412: ($changes{$token->[2]->{'id'}})) {
413: my $id = $token->[2]->{'id'};
414: $updatedcontent .= '<'.$token->[1];
415: foreach my $attrib (@{$token->[3]}) {
416: next unless ($attrib =~ /^(src|type|title|id)$/);
417: if ($attrib eq 'src') {
418: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
419: if ($file) {
420: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
421: } else {
422: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
423: }
424: } else {
425: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
426: }
427: }
428: $updatedcontent .= ' />'."\n";
429: } else {
430: $updatedcontent .= $token->[4]."\n";
431: }
432: } else {
433: $updatedcontent .= $token->[2];
434: }
435: }
436: print $fh $updatedcontent;
437: } else {
438: print $fh &Apache::lonclonecourse::rewritefile(
439: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
440: (%replacehash,$crs => '')
441: );
442: }
443: } else {
444: print $fh
445: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
446: }
447: } else {
448: $fail = &mt('Source does not exist.');
449: }
450: }
451: $fh->close();
452: } else {
453: $fail = &mt('Could not write to destination.');
454: }
455: }
456: my $text;
457: if ($fail) {
458: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
459: } else {
460: $text = '<span class="LC_success">'.&mt('ok').'</span>';
461: }
462: if ($i == 0) {
463: $result .= $text;
464: } else {
465: $depresult .= $text.'</li>';
466: }
467: }
468: $r->print($result);
469: if ($depresult) {
470: $r->print('<ul>'.$depresult.'</ul>');
471: }
472: }
473: } else {
474: my ($navmap,$errormsg) =
475: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
476: if (!ref($navmap)) {
477: $r->print($errormsg);
478: } else {
479: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
480: $r->rflush();
481: my ($preamble,$formname);
482: $formname = 'dumpdoc';
483: unless ($home==1) {
484: $preamble = '<div class="LC_left_float">'.
485: '<fieldset><legend>'.
486: &mt('Select the Authoring Space').
487: '</legend><select name="authorspace">';
488: }
489: my @orderspaces = ();
490: foreach my $key (sort(keys(%outhash))) {
491: if ($key=~/^home_(.+)$/) {
492: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
493: unshift(@orderspaces,$1);
494: } else {
495: push(@orderspaces,$1);
496: }
497: }
498: }
499: if ($home>1) {
500: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
501: }
502: foreach my $user (@orderspaces) {
503: if ($home==1) {
504: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
505: } else {
506: $preamble .= '<option value="'.$user.'">'.$user.' - '.
507: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
508: }
509: }
510: unless ($home==1) {
511: $preamble .= '</select></fieldset></div>'."\n";
512: }
513: my $title=$origcrsdata{'description'};
514: $title=~s/[\/\s]+/\_/gs;
515: $title=&clean($title);
516: $preamble .= '<div class="LC_left_float">'.
517: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
518: '<input type="text" size="50" name="authorfolder" value="'.
519: $title.'" />'.
520: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
521: my %uploadedfiles;
522: &tiehash();
523: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
524: my ($ext)=($file=~/\.(\w+)$/);
525: # FIXME Check supplemental here
526: my $title=$hash{'title_'.$hash{
527: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
528: if (!$title) {
529: $title=$file;
530: } else {
531: $title=~s|/|_|g;
532: }
533: $title=~s/\.(\w+)$//;
534: $title=&clean($title);
535: $title.='.'.$ext;
536: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
537: $uploadedfiles{$file} = $title;
538: }
539: &untiehash();
540: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
541: undef,undef,$preamble,$home,\%uploadedfiles));
542: }
543: }
544: $r->print(&endContentScreen());
545: }
546:
547: sub recurse_html {
548: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
549: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
550: my (%allfiles,%codebase);
551: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
552: if (keys(%allfiles)) {
553: foreach my $dependency (keys(%allfiles)) {
554: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
555: my ($depurl,$relfile,$newcontainer);
556: if ($dependency =~ m{^/}) {
557: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
558: $relfile = $1;
559: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
560: $newcontainer = $1;
561: next if ($replacehash->{$newcontainer});
562: }
563: $depurl = $dependency;
564: } else {
565: next;
566: }
567: } else {
568: $relfile = $dependency;
569: $depurl = $currurlpath;
570: $depurl =~ s{[^/]+$}{};
571: $depurl .= $dependency;
572: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
573: }
574: next if ($relfile eq '');
575: my $newname = $replacehash->{$container};
576: $newname =~ s{[^/]+$}{};
577: $replacehash->{$newcontainer} = $newname.$relfile;
578: $deps->{$item}{$newcontainer} = 1;
579: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
580: my $depfile = &Apache::lonnet::filelocation('',$depurl);
581: my $type = $mm->checktype_filename($depfile);
582: if ($type eq 'text/html') {
583: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
584: }
585: }
586: }
587: }
588: return;
589: }
590:
591: sub group_import {
592: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
593: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
594: %removeparam,$importuploaded,$fixuperrors);
595: $allmaps = {};
596: while (@files) {
597: my ($name, $url, $residx) = @{ shift(@files) };
598: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
599: && ($caller eq 'londocs')
600: && (!&Apache::lonnet::stat_file($url))) {
601:
602: my $errtext = '';
603: my $fatal = 0;
604: my $newmapstr = '<map>'."\n".
605: '<resource id="1" src="" type="start"></resource>'."\n".
606: '<link from="1" to="2" index="1"></link>'."\n".
607: '<resource id="2" src="" type="finish"></resource>'."\n".
608: '</map>';
609: $env{'form.output'}=$newmapstr;
610: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
611: 'output',$1.$2);
612: if ($result !~ m{^/uploaded/}) {
613: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
614: $fatal = 2;
615: }
616: if ($fatal) {
617: return ($errtext,$fatal);
618: }
619: }
620: if ($url) {
621: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
622: $url = $1;
623: my $marker = $2;
624: my $info = $3;
625: my ($toolid,%toolhash,%toolsettings);
626: my @toolinfo = split(/:/,$info);
627: if ($residx) {
628: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
629: $toolid = $toolsettings{'id'};
630: } else {
631: $toolid = shift(@toolinfo);
632: }
633: $toolid =~ s/\D//g;
634: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
635: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
636: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
637: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
638: if (ref($ltitoolsref) eq 'HASH') {
639: my @deleted;
640: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
641: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
642: $url =~ s/exttool$/exttools/;
643: }
644: $toolhash{'id'} = $toolid;
645: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
646: if ($toolhash{'target'} eq 'window') {
647: foreach my $item ('width','height') {
648: $toolhash{$item} =~ s/^\s+//;
649: $toolhash{$item} =~ s/\s+$//;
650: }
651: }
652: } elsif ($residx) {
653: $toolhash{'target'} = $toolsettings{'target'};
654: if ($toolhash{'target'} eq 'window') {
655: $toolhash{'width'} = $toolsettings{'width'};
656: $toolhash{'height'} = $toolsettings{'height'};
657: }
658: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
659: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
660: if ($toolhash{'target'} eq 'window') {
661: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
662: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
663: }
664: }
665: if ($toolhash{'target'} eq 'iframe') {
666: delete($toolhash{'width'});
667: delete($toolhash{'height'});
668: if ($residx) {
669: if ($toolsettings{'width'}) {
670: push(@deleted,'width');
671: }
672: if ($toolsettings{'height'}) {
673: push(@deleted,'height');
674: }
675: }
676: }
677: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
678: foreach my $item ('label','title') {
679: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
680: $toolhash{'crs'.$item} =~ s/^\s+//;
681: $toolhash{'crs'.$item} =~ s/\s+$//;
682: if ($toolhash{'crs'.$item} eq '') {
683: delete($toolhash{'crs'.$item});
684: }
685: } else {
686: delete($toolhash{'crs'.$item});
687: }
688: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
689: unless (exists($toolhash{'crs'.$item})) {
690: push(@deleted,'crs'.$item);
691: }
692: }
693: }
694: }
695: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
696: if ($putres eq 'ok') {
697: if (@deleted) {
698: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
699: }
700: }
701: }
702: }
703: }
704: if (($caller eq 'londocs') &&
705: ($folder =~ /^default/)) {
706: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
707: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
708: my $cid = $coursedom.'_'.$coursenum;
709: $allmaps =
710: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
711: $chome,$cid);
712: $donechk = 1;
713: }
714: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
715: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
716: \%addedmaps,\%hierarchy,\%titles,$allmaps);
717: $importuploaded = 1;
718: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
719: next if ($allmaps->{$url});
720: }
721: }
722: if (!$residx
723: || defined($LONCAPA::map::zombies[$residx])) {
724: $residx = &LONCAPA::map::getresidx($url,$residx);
725: push(@LONCAPA::map::order, $residx);
726: }
727: my $ext = 'false';
728: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
729: $name = &LONCAPA::map::qtunescape($name);
730: if ($name eq '') {
731: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
732: }
733: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
734: my $filepath = $1;
735: my $fname = $name;
736: if ($fname =~ /^\W+$/) {
737: $fname = 'web';
738: } else {
739: $fname =~ s/\W/_/g;
740: }
741: if (length($fname) > 15) {
742: $fname = substr($fname,0,14);
743: }
744: my $initialtext = &mt('Replace with your own content.');
745: my $newhtml = <<END;
746: <html>
747: <head>
748: <title>$name</title>
749: </head>
750: <body bgcolor="#ffffff">
751: $initialtext
752: </body>
753: </html>
754: END
755: $env{'form.output'}=$newhtml;
756: my $result =
757: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
758: 'output',
759: "$filepath/$residx/$fname.html");
760: if ($result =~ m{^/uploaded/}) {
761: $url = $result;
762: if ($filepath =~ /^supplemental/) {
763: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
764: $env{'user.domain'}.'___&&&___'.$name;
765: }
766: } else {
767: return (&mt('Failed to save new web page.'),1);
768: }
769: }
770: $url = &LONCAPA::map::qtunescape($url);
771: $LONCAPA::map::resources[$residx] =
772: join(':', ($name, $url, $ext, 'normal', 'res'));
773: }
774: }
775: if ($importuploaded) {
776: my %import_errors;
777: my %updated = (
778: removefrommap => \%removefrommap,
779: removeparam => \%removeparam,
780: );
781: my ($result,$msgsarray,$lockerror) =
782: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
783: if (keys(%import_errors) > 0) {
784: $fixuperrors =
785: '<p span class="LC_warning">'."\n".
786: &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".
787: '<ul>'."\n";
788: foreach my $key (sort(keys(%import_errors))) {
789: $fixuperrors .= '<li>'.$key.'</li>'."\n";
790: }
791: $fixuperrors .= '</ul></p>'."\n";
792: }
793: if (ref($msgsarray) eq 'ARRAY') {
794: if (@{$msgsarray} > 0) {
795: $fixuperrors .= '<p class="LC_info">'.
796: join('<br />',@{$msgsarray}).
797: '</p>';
798: }
799: }
800: if ($lockerror) {
801: $fixuperrors .= '<p class="LC_error">'.
802: $lockerror.
803: '</p>';
804: }
805: }
806: my ($errtext,$fatal) =
807: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
808: unless ($fatal) {
809: if ($folder =~ /^supplemental/) {
810: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
811: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
812: $folder.'.'.$container);
813: }
814: }
815: return ($errtext,$fatal,$fixuperrors);
816: }
817:
818: sub log_docs {
819: return &Apache::lonnet::write_log('course','docslog',@_);
820: }
821:
822: {
823: my @oldresources=();
824: my @oldorder=();
825: my $parmidx;
826: my %parmaction=();
827: my %parmvalue=();
828: my $changedflag;
829:
830: sub snapshotbefore {
831: @oldresources=@LONCAPA::map::resources;
832: @oldorder=@LONCAPA::map::order;
833: $parmidx=undef;
834: %parmaction=();
835: %parmvalue=();
836: $changedflag=0;
837: }
838:
839: sub remember_parms {
840: my ($idx,$parameter,$action,$value)=@_;
841: $parmidx=$idx;
842: $parmaction{$parameter}=$action;
843: $parmvalue{$parameter}=$value;
844: $changedflag=1;
845: }
846:
847: sub log_differences {
848: my ($plain)=@_;
849: my %storehash=('folder' => $plain,
850: 'currentfolder' => $env{'form.folder'});
851: if ($parmidx) {
852: $storehash{'parameter_res'}=$oldresources[$parmidx];
853: foreach my $parm (keys(%parmaction)) {
854: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
855: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
856: }
857: }
858: my $maxidx=$#oldresources;
859: if ($#LONCAPA::map::resources>$#oldresources) {
860: $maxidx=$#LONCAPA::map::resources;
861: }
862: for (my $idx=0; $idx<=$maxidx; $idx++) {
863: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
864: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
865: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
866: $changedflag=1;
867: }
868: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
869: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
870: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
871: $changedflag=1;
872: }
873: }
874: $storehash{'maxidx'}=$maxidx;
875: if ($changedflag) { &log_docs(\%storehash); }
876: }
877: }
878:
879: sub docs_change_log {
880: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
881: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
882: my $js = '<script type="text/javascript">'."\n".
883: '// <![CDATA['."\n".
884: &Apache::loncommon::display_filter_js('docslog')."\n".
885: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
886: $coursedom,$coursenum,'','',$canedit)."\n".
887: &history_tab_js()."\n".
888: &Apache::lonratedt::editscript('simple')."\n".
889: '// ]]>'."\n".
890: '</script>'."\n";
891: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
892: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
893: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
894: my %orderhash;
895: my $container='sequence';
896: my $pathitem;
897: if ($env{'form.folderpath'} =~ /\:1$/) {
898: $container='page';
899: }
900: my $folderpath=$env{'form.folderpath'};
901: if ($folderpath eq '') {
902: $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
903: }
904: $pathitem = '<input type="hidden" name="folderpath" value="'.
905: &HTML::Entities::encode($folderpath,'<>&"').'" />';
906: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
907: my $jumpto = $readfile;
908: $jumpto =~ s{^/}{};
909: my $tid = 1;
910: if ($supplementalflag) {
911: $tid = 2;
912: }
913: my ($breadcrumbtrail) =
914: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
915: $r->print($breadcrumbtrail.
916: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
917: $readfile));
918: my %docslog=&Apache::lonnet::dump('nohist_docslog',
919: $env{'course.'.$env{'request.course.id'}.'.domain'},
920: $env{'course.'.$env{'request.course.id'}.'.num'});
921:
922: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
923:
924: my %saveable_parameters = ('show' => 'scalar',);
925: &Apache::loncommon::store_course_settings('docs_log',
926: \%saveable_parameters);
927: &Apache::loncommon::restore_course_settings('docs_log',
928: \%saveable_parameters);
929: if (!$env{'form.show'}) { $env{'form.show'}=10; }
930: # FIXME: internationalization seems wrong here
931: my %lt=('hiddenresource' => 'Resources hidden',
932: 'encrypturl' => 'URL hidden',
933: 'randompick' => 'Randomly pick',
934: 'randomorder' => 'Randomly ordered',
935: 'set' => 'set to',
936: 'del' => 'deleted');
937: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
938: $pathitem."\n".
939: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
940: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
941: $r->print('<div class="LC_left_float">'.
942: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
943: &makedocslogform($filter,1).
944: '</fieldset></div><br clear="all" />');
945: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
946: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
947: &mt('After').'</th>'.
948: &Apache::loncommon::end_data_table_header_row());
949: my $shown=0;
950: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
951: if ($env{'form.displayfilter'} eq 'currentfolder') {
952: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
953: }
954: my @changes=keys(%{$docslog{$id}{'logentry'}});
955: if ($env{'form.displayfilter'} eq 'containing') {
956: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
957: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
958: foreach my $key (@changes) {
959: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
960: }
961: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
962: }
963: my $count = 0;
964: my $time =
965: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
966: my $plainname =
967: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
968: $docslog{$id}{'exe_udom'});
969: my $about_me_link =
970: &Apache::loncommon::aboutmewrapper($plainname,
971: $docslog{$id}{'exe_uname'},
972: $docslog{$id}{'exe_udom'});
973: my $send_msg_link='';
974: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
975: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
976: $send_msg_link ='<br />'.
977: &Apache::loncommon::messagewrapper(&mt('Send message'),
978: $docslog{$id}{'exe_uname'},
979: $docslog{$id}{'exe_udom'});
980: }
981: $r->print(&Apache::loncommon::start_data_table_row());
982: $r->print('<td>'.$time.'</td>
983: <td>'.$about_me_link.
984: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
985: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
986: $send_msg_link.'</td><td>'.
987: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
988: my $is_supp = 0;
989: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
990: $is_supp = 1;
991: }
992: # Before
993: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
994: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
995: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
996: if ($oldname ne $newname) {
997: my $shown = &LONCAPA::map::qtescape($oldname);
998: if ($is_supp) {
999: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1000: }
1001: $r->print($shown);
1002: }
1003: }
1004: $r->print('<ul>');
1005: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1006: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1007: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1008: if ($is_supp) {
1009: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1010: }
1011: $r->print('<li>'.$shown.'</li>');
1012: }
1013: }
1014: $r->print('</ul>');
1015: # After
1016: $r->print('</td><td>');
1017:
1018: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1019: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1020: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1021: if ($oldname ne '' && $oldname ne $newname) {
1022: my $shown = &LONCAPA::map::qtescape($newname);
1023: if ($is_supp) {
1024: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1025: }
1026: $r->print($shown);
1027: }
1028: }
1029: $r->print('<ul>');
1030: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1031: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1032: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1033: if ($is_supp) {
1034: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1035: }
1036: $r->print('<li>'.$shown.'</li>');
1037: }
1038: }
1039: $r->print('</ul>');
1040: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1041: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1042: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1043: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1044: # FIXME: internationalization seems wrong here
1045: $r->print('<li>'.
1046: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1047: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1048: .'</li>');
1049: }
1050: }
1051: $r->print('</ul>');
1052: }
1053: # End
1054: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1055: $shown++;
1056: if (!($env{'form.show'} eq &mt('all')
1057: || $shown<=$env{'form.show'})) { last; }
1058: }
1059: $r->print(&Apache::loncommon::end_data_table()."\n".
1060: &makesimpleeditform($pathitem)."\n".
1061: '</div></div>');
1062: $r->print(&endContentScreen());
1063: }
1064:
1065: sub update_paste_buffer {
1066: my ($coursenum,$coursedom,$folder) = @_;
1067: my (@possibles,%removals,%cuts,$output);
1068: if ($env{'form.multiremove'}) {
1069: $env{'form.multiremove'} =~ s/,$//;
1070: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1071: }
1072: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1073: if ($env{'form.multicut'}) {
1074: $env{'form.multicut'} =~ s/,$//;
1075: foreach my $item (split(/,/,$env{'form.multicut'})) {
1076: unless ($removals{$item}) {
1077: $cuts{$item} = 1;
1078: push(@possibles,$item.':cut');
1079: }
1080: }
1081: }
1082: if ($env{'form.multicopy'}) {
1083: $env{'form.multicopy'} =~ s/,$//;
1084: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1085: unless ($removals{$item} || $cuts{$item}) {
1086: push(@possibles,$item.':copy');
1087: }
1088: }
1089: }
1090: } elsif ($env{'form.markcopy'}) {
1091: @possibles = split(/,/,$env{'form.markcopy'});
1092: }
1093:
1094: return if (@possibles == 0);
1095: return if (!defined($env{'form.copyfolder'}));
1096:
1097: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1098: $env{'form.copyfolder'});
1099: return if ($fatal);
1100:
1101: my %curr_groups = &Apache::longroup::coursegroups();
1102:
1103: # Retrieve current paste buffer suffixes.
1104: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1105: my (%pasteurls,@newpaste);
1106:
1107: # Construct identifiers for current contents of user's paste buffer
1108: if (@currpaste) {
1109: foreach my $suffix (@currpaste) {
1110: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1111: my $url = $env{'docs.markedcopy_url_'.$suffix};
1112: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1113: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1114: ($url ne '')) {
1115: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1116: }
1117: }
1118: }
1119:
1120: # Mark items for copying (skip any items already in user's paste buffer)
1121: my %addtoenv;
1122:
1123: my @pathitems = split(/\&/,$env{'form.folderpath'});
1124: my @folderconf = split(/\:/,$pathitems[-1]);
1125: my $ispage = $folderconf[4];
1126:
1127: foreach my $item (@possibles) {
1128: my ($orderidx,$cmd) = split(/:/,$item);
1129: next if ($orderidx =~ /\D/);
1130: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1131: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1132: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1133: my %denied = &action_restrictions($coursenum,$coursedom,
1134: &LONCAPA::map::qtescape($url),
1135: $env{'form.folderpath'},\%curr_groups);
1136: next if ($denied{'copy'});
1137: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1138: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1139: my ($suffix,$errortxt,$locknotfreed) =
1140: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1141: if ($suffix ne '') {
1142: push(@newpaste,$suffix);
1143: } else {
1144: if ($locknotfreed) {
1145: return $locknotfreed;
1146: }
1147: }
1148: if (&is_supplemental_title($title)) {
1149: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1150: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1151: }
1152:
1153: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1154: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1155: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1156: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1157: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1158: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1159: my $prefix = $1;
1160: my $subdir =$2;
1161: if ($subdir eq '') {
1162: $subdir = $prefix;
1163: }
1164: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1165: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1166: \%hierarchy,\%titles,\%allmaps);
1167: if (ref($hierarchy{$url}) eq 'HASH') {
1168: my ($nested,$nestednames);
1169: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1170: $nested =~ s/\&$//;
1171: $nestednames =~ s/\Q___&&&___\E$//;
1172: if ($nested ne '') {
1173: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1174: }
1175: if ($nestednames ne '') {
1176: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1177: }
1178: }
1179: }
1180: if ($locknotfreed) {
1181: $output = $locknotfreed;
1182: last;
1183: }
1184: }
1185: if (@newpaste) {
1186: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1187: }
1188: &Apache::lonnet::appenv(\%addtoenv);
1189: delete($env{'form.markcopy'});
1190: return $output;
1191: }
1192:
1193: sub recurse_uploaded_maps {
1194: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1195: if (ref($hierarchy->{$url}) eq 'HASH') {
1196: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1197: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1198: my (@uploaded,@names,%shorter);
1199: for (my $i=0; $i<@maps; $i++) {
1200: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1201: if ($inner ne '') {
1202: push(@uploaded,$inner);
1203: push(@names,&escape($titles[$i]));
1204: $shorter{$maps[$i]} = $inner;
1205: }
1206: }
1207: $$nestref .= "$dir:".join(',',@uploaded).'&';
1208: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1209: foreach my $map (@maps) {
1210: if ($shorter{$map} ne '') {
1211: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1212: }
1213: }
1214: }
1215: return;
1216: }
1217:
1218: sub print_paste_buffer {
1219: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1220: return if (!defined($env{'docs.markedcopies'}));
1221:
1222: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1223: return if ($env{'docs.markedcopies'} eq '');
1224: }
1225:
1226: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1227: my ($pasteitems,@pasteable);
1228: my $clipboardcount = 0;
1229:
1230: # Construct identifiers for current contents of user's paste buffer
1231: foreach my $suffix (@currpaste) {
1232: next if ($suffix =~ /\D/);
1233: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1234: my $url = $env{'docs.markedcopy_url_'.$suffix};
1235: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1236: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1237: ($url ne '')) {
1238: $clipboardcount ++;
1239: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1240: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1241: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1242: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1243: $is_external = 1;
1244: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1245: $is_exttool = 1;
1246: }
1247: if ($folder =~ /^supplemental/) {
1248: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1249: unless ($canpaste) {
1250: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1251: }
1252: } else {
1253: $canpaste = 1;
1254: }
1255: if ($canpaste) {
1256: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1257: my $srcdom = $1;
1258: my $srcnum = $2;
1259: my $rem = $3;
1260: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1261: $othercourse = 1;
1262: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1263: $othercrs = '<br />'.&mt('(from another course)');
1264: } else {
1265: $canpaste = 0;
1266: $nopaste = &mt('Paste from another course unavailable.');
1267: }
1268: }
1269: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1270: my $prefix = $1;
1271: $parent = $2;
1272: if ($folder !~ /^\Q$prefix\E/) {
1273: $areachange = 1;
1274: }
1275: $is_uploaded_map = 1;
1276: }
1277: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1278: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1279: if ($cid ne $env{'request.course.id'}) {
1280: my ($srcdom,$srcnum) = split(/_/,$cid);
1281: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1282: $othercrs = '<br />'.&mt('(from another course)');
1283: } else {
1284: $canpaste = 0;
1285: $nopaste = &mt('Paste from another course unavailable.');
1286: }
1287: }
1288: }
1289: if ($canpaste) {
1290: push(@pasteable,$suffix);
1291: }
1292: }
1293: my $buffer;
1294: if (($is_external) || ($is_exttool)) {
1295: $buffer = &mt('External Resource').': '.
1296: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1297: &LONCAPA::map::qtescape($url).')';
1298: } else {
1299: my $icon = &Apache::loncommon::icon($extension);
1300: if ($extension eq 'sequence' &&
1301: $url =~ m{/default_\d+\.sequence$}x) {
1302: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1303: $icon .= '/navmap.folder.closed.gif';
1304: }
1305: my $title = $env{'docs.markedcopy_title_'.$suffix};
1306: if ($title eq '') {
1307: ($title) = ($url =~ m{/([^/]+)$});
1308: }
1309: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1310: ': '.
1311: &Apache::loncommon::parse_supplemental_title(
1312: &LONCAPA::map::qtescape($title));
1313: }
1314: $pasteitems .= '<div class="LC_left_float">';
1315: my ($options,$onclick);
1316: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1317: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1318: if (($is_uploaded_map) ||
1319: ($url =~ /(bulletinboard|smppg)$/) ||
1320: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1321: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1322: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1323: }
1324: }
1325: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1326: if ($nopaste) {
1327: $pasteitems .= $nopaste;
1328: } else {
1329: if ($othercrs) {
1330: $pasteitems .= $othercrs;
1331: }
1332: if ($options) {
1333: $pasteitems .= $options;
1334: }
1335: }
1336: $pasteitems .= '</div>';
1337: }
1338: }
1339: if ($pasteitems eq '') {
1340: &Apache::lonnet::delenv('docs.markedcopies');
1341: }
1342: my ($pasteform,$form_start,$buttons,$form_end);
1343: if ($pasteitems) {
1344: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1345: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1346: if (@pasteable) {
1347: my $value = &mt('Paste to current folder');
1348: if ($container eq 'page') {
1349: $value = &mt('Paste to current page');
1350: }
1351: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1352: }
1353: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1354: if ($clipboardcount > 1) {
1355: $buttons .=
1356: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1357: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1358: (' 'x2).
1359: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1360: (' 'x2);
1361: }
1362: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1363: '</form>';
1364: } else {
1365: $pasteitems = &mt('Clipboard is empty');
1366: }
1367: $r->print($form_start
1368: .'<fieldset>'
1369: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1370: .$pasteitems
1371: .'</fieldset>'
1372: .$form_end);
1373: }
1374:
1375: sub paste_options {
1376: my ($suffix,$is_uploaded_map,$parent) = @_;
1377: my ($copytext,$movetext);
1378: if ($is_uploaded_map) {
1379: $copytext = &mt('Copy to new folder');
1380: $movetext = &mt('Move old');
1381: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1382: $copytext = &mt('Copy to new board');
1383: $movetext = &mt('Move (not posts)');
1384: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1385: $copytext = &mt('Copy to new page');
1386: $movetext = &mt('Move');
1387: } else {
1388: $copytext = &mt('Copy to new file');
1389: $movetext = &mt('Move');
1390: }
1391: my $output = '<br />'.
1392: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1393: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1394: '<label>'.
1395: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1396: $copytext.'</label></span>'.(' 'x2).' '.
1397: '<span class="LC_nobreak"><label>'.
1398: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1399: $movetext.'</label></span>';
1400: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1401: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1402: '</legend><table border="0">';
1403: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1404: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1405: my $lastdir = $parent;
1406: my %depths = (
1407: $lastdir => 0,
1408: );
1409: my (%display,%deps);
1410: for (my $i=0; $i<@pastemaps; $i++) {
1411: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1412: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1413: my @subfolders = split(/,/,$subfolderstr);
1414: $deps{$lastdir} = \@subfolders;
1415: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1416: my $depth = $depths{$lastdir} + 1;
1417: my $offset = int($depth * 4);
1418: my $indent = (' ' x $offset);
1419: for (my $j=0; $j<@subfolders; $j++) {
1420: $depths{$subfolders[$j]} = $depth;
1421: $display{$subfolders[$j]} =
1422: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1423: '<td><label>'.
1424: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1425: '<label>'.
1426: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1427: &mt('Move old').'</label>'.
1428: '</td></tr>';
1429: }
1430: }
1431: &recurse_print(\$output,$parent,\%deps,\%display);
1432: $output .= '</table></fieldset>';
1433: }
1434: $output .= '</div>';
1435: return $output;
1436: }
1437:
1438: sub recurse_print {
1439: my ($outputref,$dir,$deps,$display) = @_;
1440: $$outputref .= $display->{$dir}."\n";
1441: if (ref($deps->{$dir}) eq 'ARRAY') {
1442: foreach my $subdir (@{$deps->{$dir}}) {
1443: &recurse_print($outputref,$subdir,$deps,$display);
1444: }
1445: }
1446: }
1447:
1448: sub supp_pasteable {
1449: my ($url) = @_;
1450: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1451: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1452: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1453: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1454: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1455: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1456: return 1;
1457: }
1458: return;
1459: }
1460:
1461: sub paste_popup_js {
1462: my %html_js_lt = &Apache::lonlocal::texthash(
1463: show => 'Show Options',
1464: hide => 'Hide Options',
1465: );
1466: my %js_lt = &Apache::lonlocal::texthash(
1467: none => 'No items selected from clipboard.',
1468: );
1469: &html_escape(\%html_js_lt);
1470: &js_escape(\%html_js_lt);
1471: &js_escape(\%js_lt);
1472: return <<"END";
1473:
1474: function showPasteOptions(suffix) {
1475: document.getElementById('pasteoptions_'+suffix).style.display='block';
1476: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1477: return;
1478: }
1479:
1480: function hidePasteOptions(suffix) {
1481: document.getElementById('pasteoptions_'+suffix).style.display='none';
1482: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1483: return;
1484: }
1485:
1486: function showOptions(caller,suffix) {
1487: if (document.getElementById('pasteoptionstext_'+suffix)) {
1488: if (caller.checked) {
1489: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1490: } else {
1491: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1492: }
1493: if (document.getElementById('pasteoptions_'+suffix)) {
1494: document.getElementById('pasteoptions_'+suffix).style.display='none';
1495: }
1496: }
1497: return;
1498: }
1499:
1500: function validateClipboard() {
1501: var numchk = 0;
1502: if (document.pasteform.pasting.length > 1) {
1503: for (var i=0; i<document.pasteform.pasting.length; i++) {
1504: if (document.pasteform.pasting[i].checked) {
1505: numchk ++;
1506: }
1507: }
1508: } else {
1509: if (document.pasteform.pasting.type == 'checkbox') {
1510: if (document.pasteform.pasting.checked) {
1511: numchk ++;
1512: }
1513: }
1514: }
1515: if (numchk > 0) {
1516: return true;
1517: } else {
1518: alert("$js_lt{'none'}");
1519: return false;
1520: }
1521: }
1522:
1523: function checkClipboard() {
1524: if (document.pasteform.pasting.length > 1) {
1525: for (var i=0; i<document.pasteform.pasting.length; i++) {
1526: document.pasteform.pasting[i].checked = true;
1527: }
1528: }
1529: return;
1530: }
1531:
1532: function uncheckClipboard() {
1533: if (document.pasteform.pasting.length >1) {
1534: for (var i=0; i<document.pasteform.pasting.length; i++) {
1535: document.pasteform.pasting[i].checked = false;
1536: }
1537: }
1538: return;
1539: }
1540:
1541: END
1542:
1543: }
1544:
1545: sub do_paste_from_buffer {
1546: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1547:
1548: # Array of items in paste buffer
1549: my (@currpaste,%pastebuffer,%allerrors);
1550: @currpaste = split(/,/,$env{'docs.markedcopies'});
1551:
1552: # Early out if paste buffer is empty
1553: if (@currpaste == 0) {
1554: return ();
1555: }
1556: map { $pastebuffer{$_} = 1; } @currpaste;
1557:
1558: # Array of items selected items to paste
1559: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1560:
1561: # Early out if nothing selected to paste
1562: if (@reqpaste == 0) {
1563: return();
1564: }
1565: my @topaste;
1566: foreach my $suffix (@reqpaste) {
1567: next if ($suffix =~ /\D/);
1568: next unless (exists($pastebuffer{$suffix}));
1569: push(@topaste,$suffix);
1570: }
1571:
1572: # Early out if nothing available to paste
1573: if (@topaste == 0) {
1574: return();
1575: }
1576:
1577: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1578: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1579:
1580: foreach my $suffix (@topaste) {
1581: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1582: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1583: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1584: # Supplemental content may only include certain types of content
1585: # Early out if pasted content is not supported in Supplemental area
1586: if ($folder =~ /^supplemental/) {
1587: unless (&supp_pasteable($url)) {
1588: $notinsupp{$suffix} = 1;
1589: next;
1590: }
1591: }
1592: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1593: my $srcd = $1;
1594: my $srcn = $2;
1595: # When paste buffer was populated using an active role in a different course
1596: # check for mdc privilege in the course from which the resource was pasted
1597: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1598: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1599: $notincrs{$suffix} = 1;
1600: next;
1601: }
1602: }
1603: $srcdom{$suffix} = $srcd;
1604: $srcnum{$suffix} = $srcn;
1605: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1606: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1607: my ($srcd,$srcn) = split(/_/,$cid);
1608: # When paste buffer was populated using an active role in a different course
1609: # check for mdc privilege in the course from which the resource was pasted
1610: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1611: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1612: $notincrs{$suffix} = 1;
1613: next;
1614: }
1615: }
1616: $srcdom{$suffix} = $srcd;
1617: $srcnum{$suffix} = $srcn;
1618: }
1619: $srcmapidx{$suffix} = $mapidx;
1620: push(@dopaste,$suffix);
1621: if ($url=~/\.(page|sequence)$/) {
1622: $is_map{$suffix} = 1;
1623: }
1624:
1625: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1626: my $oldprefix = $1;
1627: # When pasting content from Main Content to Supplemental Content and vice versa
1628: # URLs will contain different paths (which depend on whether pasted item is
1629: # a folder/page or a document).
1630: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1631: $prefixchg{$suffix} = 'docstosupp';
1632: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1633: $prefixchg{$suffix} = 'supptodocs';
1634: }
1635:
1636: # If pasting an uploaded map, get list of contained uploaded maps.
1637: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1638: my @nested;
1639: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1640: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1641: my @deps = map { /\d+:([\d,]+$)/ } @items;
1642: foreach my $dep (@deps) {
1643: if ($dep =~ /,/) {
1644: push(@nested,split(/,/,$dep));
1645: } else {
1646: push(@nested,$dep);
1647: }
1648: }
1649: foreach my $item (@nested) {
1650: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1651: push(@{$marktomove{$suffix}},$type.'_'.$item);
1652: }
1653: }
1654: }
1655: }
1656: }
1657:
1658: # Early out if nothing available to paste
1659: if (@dopaste == 0) {
1660: return ();
1661: }
1662:
1663: # Populate message hash and hashes used for main content <=> supplemental content
1664: # changes
1665:
1666: %msgs = &Apache::lonlocal::texthash (
1667: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1668: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1669: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1670: );
1671:
1672: %before = (
1673: docstosupp => {
1674: map => 'default',
1675: doc => 'docs',
1676: },
1677: supptodocs => {
1678: map => 'supplemental',
1679: doc => 'supplemental',
1680: },
1681: );
1682:
1683: %after = (
1684: docstosupp => {
1685: map => 'supplemental',
1686: doc => 'supplemental'
1687: },
1688: supptodocs => {
1689: map => 'default',
1690: doc => 'docs',
1691: },
1692: );
1693:
1694: # Retrieve information about all course maps in main content area
1695:
1696: my $allmaps = {};
1697: if ($folder =~ /^default/) {
1698: $allmaps =
1699: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1700: $env{"course.$env{'request.course.id'}.home"},
1701: $env{'request.course.id'});
1702: }
1703:
1704: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1705:
1706: # Loop over the items to paste
1707: foreach my $suffix (@dopaste) {
1708: # Maps need to be copied first
1709: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1710: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1711: %newurls,%tomove,%resdatacopy);
1712: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1713: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1714: }
1715: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1716: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1717: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1718: my $oldurl = $url;
1719: if ($is_map{$suffix}) {
1720: # If pasting a map, check if map contains other maps
1721: my (%hierarchy,%titles);
1722: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1723: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1724: if ($url=~ m{^/uploaded/}) {
1725: my $newurl;
1726: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1727: ($newurl,my $error) =
1728: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1729: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1730: \$title,$allmaps,\%newurls);
1731: if ($error) {
1732: $allerrors{$suffix} = $error;
1733: next;
1734: }
1735: if ($newurl ne '') {
1736: if ($newurl ne $url) {
1737: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1738: $newsubdir{$url} = $1;
1739: }
1740: $mapchanges{$url} = 1;
1741: }
1742: }
1743: }
1744: if (($srcdom{$suffix} ne $coursedom) ||
1745: ($srcnum{$suffix} ne $coursenum) ||
1746: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1747: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1748: $coursedom,$coursenum,$srcdom{$suffix},
1749: $srcnum{$suffix},$allmaps,\%rewrites,
1750: \%retitles,\%copies,\%dbcopies,
1751: \%zombies,\%params,\%mapmoves,
1752: \%mapchanges,\%tomove,\%newsubdir,
1753: \%newurls,\%resdatacopy)) {
1754: $mapmoves{$url} = 1;
1755: }
1756: $url = $newurl;
1757: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1758: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1759: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1760: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1761: \%zombies,\%params,\%mapmoves,\%mapchanges,
1762: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1763: }
1764: } elsif ($url=~m {^/res/}) {
1765: # published map can only exist once, so remove from paste buffer when done
1766: push(@toclear,$suffix);
1767: # if pasting published map (main content area only) check map not already in course
1768: if ($folder =~ /^default/) {
1769: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1770: $duplicate{$suffix} = 1;
1771: next;
1772: }
1773: }
1774: }
1775: }
1776: if ($url=~ m{/(bulletinboard|smppg)$}) {
1777: my $prefix = $1;
1778: my $fromothercrs;
1779: #need to copy the db contents to a new one, unless this is a move.
1780: my %info = (
1781: src => $url,
1782: cdom => $coursedom,
1783: cnum => $coursenum,
1784: );
1785: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1786: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1787: $fromothercrs = 1;
1788: $info{'cdom'} = $srcdom{$suffix};
1789: $info{'cnum'} = $srcnum{$suffix};
1790: }
1791: }
1792: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1793: my (%lockerr,$msg);
1794: my ($newurl,$result,$errtext) =
1795: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1796: if ($result eq 'ok') {
1797: $url = $newurl;
1798: $title=&mt('Copy of').' '.$title;
1799: } else {
1800: if ($prefix eq 'smppg') {
1801: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1802: } elsif ($prefix eq 'bulletinboard') {
1803: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1804: }
1805: $results{$suffix} = $result;
1806: $msgerrs{$suffix} = $msg;
1807: $lockerrs{$suffix} = $lockerr{$prefix};
1808: next;
1809: }
1810: if ($lockerr{$prefix}) {
1811: $lockerrs{$suffix} = $lockerr{$prefix};
1812: }
1813: }
1814: }
1815: $title = &LONCAPA::map::qtunescape($title);
1816: my $ext='false';
1817: if ($url=~m{^http(|s)://}) { $ext='true'; }
1818: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1819: if ($folder !~ /^supplemental/) {
1820: (undef,undef,$title) =
1821: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1822: }
1823: } else {
1824: if ($folder=~/^supplemental/) {
1825: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1826: $env{'user.domain'}.'___&&&___'.$title;
1827: }
1828: }
1829:
1830: # For uploaded files (excluding pages/sequences) path in copied file is changed
1831: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1832: # courses.
1833:
1834: unless ($is_map{$suffix}) {
1835: my $newidx;
1836: # Now insert the URL at the bottom
1837: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1838: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1839: my $relpath = $1;
1840: if ($relpath ne '') {
1841: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1842: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1843: my $newprefix = $newloc;
1844: if ($newloc eq 'default') {
1845: $newprefix = 'docs';
1846: }
1847: if ($newdocsdir eq '') {
1848: $newdocsdir = 'default';
1849: }
1850: if (($prefixchg{$suffix}) ||
1851: ($srcdom{$suffix} ne $coursedom) ||
1852: ($srcnum{$suffix} ne $coursenum) ||
1853: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1854: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1855: $url =
1856: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1857: &Apache::lonnet::getfile($oldurl));
1858: if ($url eq '/adm/notfound.html') {
1859: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1860: next;
1861: } else {
1862: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1863: $newsubpath =~ s{/+$}{/};
1864: $docmoves{$oldurl} = $newsubpath;
1865: }
1866: }
1867: }
1868: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1869: my $template = $1;
1870: if ($newidx) {
1871: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1872: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1873: }
1874: }
1875: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1876: ':'.$ext.':normal:res';
1877: push(@LONCAPA::map::order,$newidx);
1878: # Store the result
1879: my ($errtext,$fatal) =
1880: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1881: if ($fatal) {
1882: $save_err .= $errtext;
1883: $allresult = 'fail';
1884: }
1885: }
1886:
1887: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1888: # resourcedata for simpleproblems copied from another course
1889: unless ($allresult eq 'fail') {
1890: my %updated = (
1891: rewrites => \%rewrites,
1892: zombies => \%zombies,
1893: removefrommap => \%removefrommap,
1894: removeparam => \%removeparam,
1895: dbcopies => \%dbcopies,
1896: resdatacopy => \%resdatacopy,
1897: retitles => \%retitles,
1898: );
1899: my %info = (
1900: newsubdir => \%newsubdir,
1901: params => \%params,
1902: );
1903: if ($prefixchg{$suffix}) {
1904: $info{'before'} = $before{$prefixchg{$suffix}};
1905: $info{'after'} = $after{$prefixchg{$suffix}};
1906: }
1907: my %moves = (
1908: copies => \%copies,
1909: docmoves => \%docmoves,
1910: mapmoves => \%mapmoves,
1911: );
1912: (my $result,$msgs{$suffix},my $lockerror) =
1913: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1914: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1915: $url,'paste');
1916: $lockerrors .= $lockerror;
1917: if ($result eq 'ok') {
1918: if ($is_map{$suffix}) {
1919: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1920: $folder.'.'.$container);
1921: if ($fatal) {
1922: $allresult = 'failread';
1923: } else {
1924: if ($#LONCAPA::map::order<1) {
1925: my $idx=&LONCAPA::map::getresidx();
1926: if ($idx<=0) { $idx=1; }
1927: $LONCAPA::map::order[0]=$idx;
1928: $LONCAPA::map::resources[$idx]='';
1929: }
1930: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1931: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1932: ':'.$ext.':normal:res';
1933: push(@LONCAPA::map::order,$newidx);
1934:
1935: # Store the result
1936: my ($errtext,$fatal) =
1937: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1938: if ($fatal) {
1939: $save_err .= $errtext;
1940: $allresult = 'failstore';
1941: }
1942: }
1943: }
1944: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1945: push(@toclear,$suffix);
1946: }
1947: }
1948: }
1949: }
1950: &clear_from_buffer(\@toclear,\@currpaste);
1951: my $msgsarray;
1952: foreach my $suffix (keys(%msgs)) {
1953: if (ref($msgs{$suffix}) eq 'ARRAY') {
1954: $msgsarray .= join(',',@{$msgs{$suffix}});
1955: }
1956: }
1957: return ($allresult,$save_err,$msgsarray,$lockerrors);
1958: }
1959:
1960: sub do_buffer_empty {
1961: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1962: if (@currpaste == 0) {
1963: return &mt('Clipboard is already empty');
1964: }
1965: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1966: if (@toclear == 0) {
1967: return &mt('Nothing selected to clear from clipboard');
1968: }
1969: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1970: if ($numdel) {
1971: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1972: } else {
1973: return &mt('Clipboard unchanged');
1974: }
1975: return;
1976: }
1977:
1978: sub clear_from_buffer {
1979: my ($toclear,$currpaste) = @_;
1980: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1981: my %pastebuffer;
1982: map { $pastebuffer{$_} = 1; } @{$currpaste};
1983: my $numdel = 0;
1984: foreach my $suffix (@{$toclear}) {
1985: next if ($suffix =~ /\D/);
1986: next unless (exists($pastebuffer{$suffix}));
1987: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1988: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1989: delete($pastebuffer{$suffix});
1990: $numdel ++;
1991: }
1992: }
1993: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1994: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1995: return $numdel;
1996: }
1997:
1998: sub get_newmap_url {
1999: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2000: $titleref,$allmaps,$newurls) = @_;
2001: my $newurl;
2002: if ($url=~ m{^/uploaded/}) {
2003: $$titleref=&mt('Copy of').' '.$$titleref;
2004: }
2005: my $now = time;
2006: my $suffix=$$.int(rand(100)).$now;
2007: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2008: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2009: my $path = $1;
2010: my $prefix = $2;
2011: my $ancestor = $3;
2012: if (length($ancestor) > 10) {
2013: $ancestor = substr($ancestor,-10,10);
2014: }
2015: my $newid;
2016: if ($prefixchg) {
2017: if ($folder =~ /^supplemental/) {
2018: $prefix =~ s/^default/supplemental/;
2019: } else {
2020: $prefix =~ s/^supplemental/default/;
2021: }
2022: }
2023: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2024: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2025: } else {
2026: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2027: }
2028: my $counter = 0;
2029: my $is_unique = &uniqueness_check($newurl);
2030: if ($folder =~ /^default/) {
2031: if ($allmaps->{$newurl}) {
2032: $is_unique = 0;
2033: }
2034: }
2035: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2036: $counter ++;
2037: $suffix ++;
2038: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2039: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2040: } else {
2041: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2042: }
2043: $is_unique = &uniqueness_check($newurl);
2044: }
2045: if ($is_unique) {
2046: $newurls->{$newurl} = 1;
2047: } else {
2048: if ($url=~/\.page$/) {
2049: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2050: } else {
2051: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2052: }
2053: }
2054: }
2055: return ($newurl);
2056: }
2057:
2058: sub dbcopy {
2059: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2060: my ($url,$result,$errtext);
2061: if (ref($dbref) eq 'HASH') {
2062: $url = $dbref->{'src'};
2063: if ($url =~ m{/(smppg|bulletinboard)$}) {
2064: my $prefix = $1;
2065: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2066: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2067: my $db_name;
2068: my $marker = (split(m{/},$url))[4];
2069: $marker=~s/\D//g;
2070: if ($dbref->{'src'} =~ m{/smppg$}) {
2071: $db_name =
2072: &Apache::lonsimplepage::get_db_name($url,$marker,
2073: $dbref->{'cdom'},
2074: $dbref->{'cnum'});
2075: } else {
2076: $db_name = 'bulletinpage_'.$marker;
2077: }
2078: my ($suffix,$freedlock,$error) =
2079: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2080: $coursedom,$coursenum,
2081: 'concat');
2082: if (!$suffix) {
2083: if ($prefix eq 'smppg') {
2084: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2085: } else {
2086: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2087: }
2088: if ($error) {
2089: $errtext .= '<br />'.$error;
2090: }
2091: } else {
2092: #need to copy the db contents to a new one.
2093: my %contents=&Apache::lonnet::dump($db_name,
2094: $dbref->{'cdom'},
2095: $dbref->{'cnum'});
2096: if (exists($contents{'uploaded.photourl'})) {
2097: my $photo = $contents{'uploaded.photourl'};
2098: my ($subdir,$fname) =
2099: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2100: my $newphoto;
2101: if ($fname ne '') {
2102: my $content = &Apache::lonnet::getfile($photo);
2103: unless ($content eq '-1') {
2104: $env{'form.'.$suffix.'.photourl'} = $content;
2105: $newphoto =
2106: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2107: delete($env{'form.'.$suffix.'.photourl'});
2108: }
2109: }
2110: if ($newphoto =~ m{^/uploaded/}) {
2111: $contents{'uploaded.photourl'} = $newphoto;
2112: }
2113: }
2114: $db_name =~ s{_\d*$ }{_$suffix}x;
2115: $result=&Apache::lonnet::put($db_name,\%contents,
2116: $coursedom,$coursenum);
2117: if ($result eq 'ok') {
2118: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2119: }
2120: }
2121: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2122: $lockerrorsref->{$prefix} =
2123: '<div class="LC_error">'.
2124: &mt('There was a problem removing a lockfile.');
2125: if ($prefix eq 'smppg') {
2126: $lockerrorsref->{$prefix} .=
2127: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2128: } else {
2129: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2130: }
2131: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2132: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2133: '</div>';
2134: }
2135: }
2136: } elsif ($url =~ m{/syllabus$}) {
2137: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2138: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2139: if (($dbref->{'cdom'} ne $coursedom) ||
2140: ($dbref->{'cnum'} ne $coursenum)) {
2141: my %contents=&Apache::lonnet::dump('syllabus',
2142: $dbref->{'cdom'},
2143: $dbref->{'cnum'});
2144: $result=&Apache::lonnet::put('syllabus',\%contents,
2145: $coursedom,$coursenum);
2146: }
2147: }
2148: }
2149: }
2150: return ($url,$result,$errtext);
2151: }
2152:
2153: sub copy_templated_files {
2154: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2155: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2156: my $srccontainer = 'sequence';
2157: if ($srcwaspage) {
2158: $srccontainer = 'page';
2159: }
2160: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2161: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2162: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2163: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2164: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2165: $template.'.problem';
2166: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2167: if ($template eq 'simpleproblem') {
2168: $srcprefix .= '.0.';
2169: my $weightprefix = $newprefix;
2170: $newprefix .= '.0.';
2171: my @simpleprobqtypes = qw(radio option string essay numerical);
2172: my $qtype=$srcparms{$srcprefix.'questiontype'};
2173: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2174: my %newdata;
2175: foreach my $type (@simpleprobqtypes) {
2176: if ($type eq $qtype) {
2177: $newdata{"$weightprefix.$type.weight"}=1;
2178: } else {
2179: $newdata{"$weightprefix.$type.weight"}=0;
2180: }
2181: }
2182: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2183: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2184: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2185: if ($qtype eq 'numerical') {
2186: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2187: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2188: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2189: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2190: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2191: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2192: unless (defined($maxfoils)) { $maxfoils=10; }
2193: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2194: if ($maxfoils<=0) { $maxfoils=10; }
2195: my $randomize=$srcparms{$srcprefix.'randomize'};
2196: unless (defined($randomize)) { $randomize='yes'; }
2197: unless ($randomize eq 'no') { $randomize='yes'; }
2198: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2199: $newdata{$newprefix.'randomize'} = $randomize;
2200: if ($qtype eq 'option') {
2201: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2202: }
2203: for (my $i=1; $i<=10; $i++) {
2204: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2205: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2206: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2207: }
2208:
2209: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2210: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2211: unless (defined($maxfoils)) { $maxfoils=10; }
2212: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2213: if ($maxfoils<=0) { $maxfoils=10; }
2214: my $randomize=$srcparms{$srcprefix.'randomize'};
2215: unless (defined($randomize)) { $randomize='yes'; }
2216: unless ($randomize eq 'no') { $randomize='yes'; }
2217: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2218: $newdata{$newprefix.'randomize'} = $randomize;
2219: if ($qtype eq 'option') {
2220: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2221: }
2222: for (my $i=1; $i<=10; $i++) {
2223: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2224: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2225: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2226: }
2227: } elsif ($qtype eq 'string') {
2228: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2229: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2230: }
2231: if (keys(%newdata)) {
2232: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2233: $coursenum);
2234: if ($putres eq 'ok') {
2235: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2236: }
2237: }
2238: }
2239: }
2240: }
2241:
2242: sub uniqueness_check {
2243: my ($newurl) = @_;
2244: my $unique = 1;
2245: foreach my $res (@LONCAPA::map::order) {
2246: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2247: $url=&LONCAPA::map::qtescape($url);
2248: if ($newurl eq $url) {
2249: $unique = 0;
2250: last;
2251: }
2252: }
2253: return $unique;
2254: }
2255:
2256: sub contained_map_check {
2257: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2258: $allmaps) = @_;
2259: my $content = &Apache::lonnet::getfile($url);
2260: unless ($content eq '-1') {
2261: my $parser = HTML::TokeParser->new(\$content);
2262: $parser->attr_encoded(1);
2263: while (my $token = $parser->get_token) {
2264: next if ($token->[0] ne 'S');
2265: if ($token->[1] eq 'resource') {
2266: next if ($token->[2]->{'type'} eq 'zombie');
2267: my $ressrc = $token->[2]->{'src'};
2268: if ($folder =~ /^supplemental/) {
2269: unless (&supp_pasteable($ressrc)) {
2270: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2271: next;
2272: }
2273: }
2274: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2275: if ($1 eq 'uploaded') {
2276: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2277: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2278: } else {
2279: if ($allmaps->{$ressrc}) {
2280: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2281: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2282: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2283: } else {
2284: $addedmaps->{$ressrc} = [$url];
2285: }
2286: }
2287: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2288: $addedmaps,$hierarchy,$titles,$allmaps);
2289: }
2290: } elsif ($token->[1] eq 'param') {
2291: if ($folder =~ /^supplemental/) {
2292: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2293: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2294: } else {
2295: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2296: }
2297: }
2298: }
2299: }
2300: }
2301: return;
2302: }
2303:
2304: sub url_paste_fixups {
2305: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2306: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2307: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2308: my $checktitle;
2309: if (($prefixchg) &&
2310: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2311: $checktitle = 1;
2312: }
2313: my $skip;
2314: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2315: my $mapid = $1.$2;
2316: if ($tomove->{$mapid}) {
2317: $skip = 1;
2318: }
2319: }
2320: my $file = &Apache::lonnet::getfile($oldurl);
2321: return if ($file eq '-1');
2322: my $parser = HTML::TokeParser->new(\$file);
2323: $parser->attr_encoded(1);
2324: my $changed = 0;
2325: while (my $token = $parser->get_token) {
2326: next if ($token->[0] ne 'S');
2327: if ($token->[1] eq 'resource') {
2328: my $ressrc = $token->[2]->{'src'};
2329: next if ($ressrc eq '');
2330: my $id = $token->[2]->{'id'};
2331: my $title = $token->[2]->{'title'};
2332: if ($checktitle) {
2333: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2334: $retitles->{$oldurl}{$id} = $ressrc;
2335: }
2336: }
2337: next if ($token->[2]->{'type'} eq 'external');
2338: if ($token->[2]->{'type'} eq 'zombie') {
2339: next if ($skip);
2340: $zombies->{$oldurl}{$id} = $ressrc;
2341: $changed = 1;
2342: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2343: my $srcdom = $1;
2344: my $srcnum = $2;
2345: my $rem = $3;
2346: my $newurl;
2347: my $mapname;
2348: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2349: my $prefix = $1;
2350: $mapname = $prefix.$2;
2351: if ($tomove->{$mapname}) {
2352: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2353: $srcdom,$srcnum,$allmaps,$rewrites,
2354: $retitles,$copies,$dbcopies,$zombies,
2355: $params,$mapmoves,$mapchanges,$tomove,
2356: $newsubdir,$newurls,$resdatacopy);
2357: next;
2358: } else {
2359: ($newurl,my $error) =
2360: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2361: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2362: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2363: $newsubdir->{$ressrc} = $1;
2364: }
2365: if ($error) {
2366: next;
2367: }
2368: }
2369: }
2370: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2371: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2372:
2373: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2374: $rewrites->{$oldurl}{$id} = $ressrc;
2375: $mapchanges->{$ressrc} = 1;
2376: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2377: $cnum,$srcdom,$srcnum,$allmaps,
2378: $rewrites,$retitles,$copies,$dbcopies,
2379: $zombies,$params,$mapmoves,$mapchanges,
2380: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2381: $mapmoves->{$ressrc} = 1;
2382: }
2383: $changed = 1;
2384: } else {
2385: $rewrites->{$oldurl}{$id} = $ressrc;
2386: $copies->{$oldurl}{$ressrc} = $id;
2387: $changed = 1;
2388: }
2389: }
2390: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2391: next if ($skip);
2392: my $srcdom = $1;
2393: my $srcnum = $2;
2394: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2395: $rewrites->{$oldurl}{$id} = $ressrc;
2396: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2397: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2398: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2399: $changed = 1;
2400: }
2401: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2402: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2403: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2404: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2405: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2406: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2407: $changed = 1;
2408: }
2409: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2410: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2411: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2412: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2413: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2414: }
2415: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2416: next if ($skip);
2417: my $srcdom = $1;
2418: my $srcnum = $2;
2419: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2420: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2421: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2422: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2423: $changed = 1;
2424: }
2425: }
2426: } elsif ($token->[1] eq 'param') {
2427: next if ($skip);
2428: my $to = $token->[2]->{'to'};
2429: if ($to ne '') {
2430: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2431: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2432: } else {
2433: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2434: }
2435: }
2436: }
2437: }
2438: return $changed;
2439: }
2440:
2441: sub apply_fixups {
2442: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2443: $oldurl,$url,$caller) = @_;
2444: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2445: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2446: %resdatacopy,%lockerrors,$lockmsg);
2447: if (ref($updated) eq 'HASH') {
2448: if (ref($updated->{'rewrites'}) eq 'HASH') {
2449: %rewrites = %{$updated->{'rewrites'}};
2450: }
2451: if (ref($updated->{'zombies'}) eq 'HASH') {
2452: %zombies = %{$updated->{'zombies'}};
2453: }
2454: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2455: %removefrommap = %{$updated->{'removefrommap'}};
2456: }
2457: if (ref($updated->{'removeparam'}) eq 'HASH') {
2458: %removeparam = %{$updated->{'removeparam'}};
2459: }
2460: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2461: %dbcopies = %{$updated->{'dbcopies'}};
2462: }
2463: if (ref($updated->{'retitles'}) eq 'HASH') {
2464: %retitles = %{$updated->{'retitles'}};
2465: }
2466: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2467: %resdatacopy = %{$updated->{'resdatacopy'}};
2468: }
2469: }
2470: if (ref($info) eq 'HASH') {
2471: if (ref($info->{'newsubdir'}) eq 'HASH') {
2472: %newsubdir = %{$info->{'newsubdir'}};
2473: }
2474: if (ref($info->{'params'}) eq 'HASH') {
2475: %params = %{$info->{'params'}};
2476: }
2477: if (ref($info->{'before'}) eq 'HASH') {
2478: %before = %{$info->{'before'}};
2479: }
2480: if (ref($info->{'after'}) eq 'HASH') {
2481: %after = %{$info->{'after'}};
2482: }
2483: }
2484: if (ref($moves) eq 'HASH') {
2485: if (ref($moves->{'copies'}) eq 'HASH') {
2486: %copies = %{$moves->{'copies'}};
2487: }
2488: if (ref($moves->{'docmoves'}) eq 'HASH') {
2489: %docmoves = %{$moves->{'docmoves'}};
2490: }
2491: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2492: %mapmoves = %{$moves->{'mapmoves'}};
2493: }
2494: }
2495: foreach my $key (keys(%copies),keys(%docmoves)) {
2496: my @allcopies;
2497: if (exists($copies{$key})) {
2498: if (ref($copies{$key}) eq 'HASH') {
2499: my %added;
2500: foreach my $innerkey (keys(%{$copies{$key}})) {
2501: if (($innerkey ne '') && (!$added{$innerkey})) {
2502: push(@allcopies,$innerkey);
2503: $added{$innerkey} = 1;
2504: }
2505: }
2506: undef(%added);
2507: }
2508: }
2509: if ($key eq $oldurl) {
2510: if ((exists($docmoves{$key}))) {
2511: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2512: push(@allcopies,$oldurl);
2513: }
2514: }
2515: }
2516: if (@allcopies > 0) {
2517: foreach my $item (@allcopies) {
2518: my ($relpath,$oldsubdir,$fname) =
2519: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2520: if ($fname ne '') {
2521: my $content = &Apache::lonnet::getfile($item);
2522: unless ($content eq '-1') {
2523: my $storefn;
2524: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2525: $storefn = $docmoves{$key};
2526: } else {
2527: $storefn = $relpath;
2528: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2529: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2530: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2531: }
2532: if ($newsubdir{$key}) {
2533: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2534: }
2535: }
2536: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2537: my $copyurl =
2538: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2539: $storefn.$fname,$content);
2540: if ($copyurl eq '/adm/notfound.html') {
2541: if (exists($docmoves{$oldurl})) {
2542: return &mt('Paste failed: an error occurred copying the file.');
2543: } elsif (ref($errors) eq 'HASH') {
2544: $errors->{$item} = 1;
2545: }
2546: }
2547: }
2548: }
2549: }
2550: }
2551: }
2552: foreach my $key (keys(%mapmoves)) {
2553: my $storefn=$key;
2554: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2555: if ($prefixchg && $before{'map'} && $after{'map'}) {
2556: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2557: }
2558: if ($newsubdir{$key}) {
2559: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2560: }
2561: my $mapcontent = &Apache::lonnet::getfile($key);
2562: if ($mapcontent eq '-1') {
2563: if (ref($errors) eq 'HASH') {
2564: $errors->{$key} = 1;
2565: }
2566: } else {
2567: my $newmap =
2568: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2569: $mapcontent);
2570: if ($newmap eq '/adm/notfound.html') {
2571: if (ref($errors) eq 'HASH') {
2572: $errors->{$key} = 1;
2573: }
2574: }
2575: }
2576: }
2577: my %updates;
2578: if ($is_map) {
2579: if (ref($updated) eq 'HASH') {
2580: foreach my $type (keys(%{$updated})) {
2581: if (ref($updated->{$type}) eq 'HASH') {
2582: foreach my $key (keys(%{$updated->{$type}})) {
2583: $updates{$key} = 1;
2584: }
2585: }
2586: }
2587: }
2588: foreach my $key (keys(%updates)) {
2589: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2590: if (ref($rewrites{$key}) eq 'HASH') {
2591: %torewrite = %{$rewrites{$key}};
2592: }
2593: if (ref($retitles{$key}) eq 'HASH') {
2594: %toretitle = %{$retitles{$key}};
2595: }
2596: if (ref($removefrommap{$key}) eq 'HASH') {
2597: %toremove = %{$removefrommap{$key}};
2598: }
2599: if (ref($removeparam{$key}) eq 'HASH') {
2600: %remparam = %{$removeparam{$key}};
2601: }
2602: if (ref($zombies{$key}) eq 'HASH') {
2603: %zombie = %{$zombies{$key}};
2604: }
2605: if (ref($dbcopies{$key}) eq 'HASH') {
2606: foreach my $idx (keys(%{$dbcopies{$key}})) {
2607: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2608: my ($newurl,$result,$errtext) =
2609: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2610: if ($result eq 'ok') {
2611: $newdb{$idx} = $newurl;
2612: } elsif (ref($errors) eq 'HASH') {
2613: $errors->{$key} = 1;
2614: }
2615: push(@msgs,$errtext);
2616: }
2617: }
2618: }
2619: if (ref($resdatacopy{$key}) eq 'HASH') {
2620: if ($newsubdir{$key}) {
2621:
2622: }
2623: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2624: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2625: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2626: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2627: my $template = $1;
2628: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2629: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2630: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2631: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2632: my ($newmapname) = ($key =~ m{/([^/]+)$});
2633: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2634: my $srcmapinfo = $srcfolder.':'.$idx;
2635: if ($srccontainer eq 'page') {
2636: $srcmapinfo .= ':1';
2637: }
2638: if ($newsubdir{$key}) {
2639: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2640: }
2641: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2642: $cnum,$template,$idx,$newmapname);
2643: }
2644: }
2645: }
2646: }
2647: }
2648: if (ref($params{$key}) eq 'HASH') {
2649: %currparam = %{$params{$key}};
2650: }
2651: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2652: if ($fatal) {
2653: return ($errtext);
2654: }
2655: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2656: if (defined($LONCAPA::map::zombies[$i])) {
2657: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2658: if ($zombie{$i} eq $src) {
2659: undef($LONCAPA::map::zombies[$i]);
2660: }
2661: }
2662: }
2663: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2664: my $idx = $LONCAPA::map::order[$i];
2665: if (defined($LONCAPA::map::resources[$idx])) {
2666: my $changed;
2667: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2668: if ((exists($toremove{$idx})) &&
2669: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2670: splice(@LONCAPA::map::order,$i,1);
2671: if (ref($currparam{$idx}) eq 'ARRAY') {
2672: foreach my $name (@{$currparam{$idx}}) {
2673: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2674: }
2675: }
2676: next;
2677: }
2678: my $origsrc = $src;
2679: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2680: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2681: $changed = 1;
2682: }
2683: }
2684: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2685: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2686: if ($origsrc =~ m{^/uploaded/}) {
2687: if ($prefixchg && $before{'map'} && $after{'map'}) {
2688: if ($src =~ /\.(page|sequence)$/) {
2689: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2690: } else {
2691: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2692: }
2693: }
2694: if ($origsrc =~ /\.(page|sequence)$/) {
2695: if ($newsubdir{$origsrc}) {
2696: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2697: }
2698: } elsif ($newsubdir{$key}) {
2699: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2700: }
2701: }
2702: $changed = 1;
2703: } elsif ($newdb{$idx} ne '') {
2704: $src = $newdb{$idx};
2705: $changed = 1;
2706: }
2707: if ($changed) {
2708: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2709: }
2710: }
2711: }
2712: foreach my $idx (keys(%remparam)) {
2713: if (ref($remparam{$idx}) eq 'ARRAY') {
2714: foreach my $name (@{$remparam{$idx}}) {
2715: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2716: }
2717: }
2718: }
2719: if (values(%lockerrors) > 0) {
2720: $lockmsg = join('<br />',values(%lockerrors));
2721: }
2722: my $storefn;
2723: if ($key eq $oldurl) {
2724: $storefn = $url;
2725: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2726: } else {
2727: $storefn = $key;
2728: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2729: if ($prefixchg && $before{'map'} && $after{'map'}) {
2730: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2731: }
2732: if ($newsubdir{$key}) {
2733: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2734: }
2735: }
2736: my $report;
2737: if ($folder !~ /^supplemental/) {
2738: $report = 1;
2739: }
2740: (my $outtext,$errtext) =
2741: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2742: if ($errtext) {
2743: if ($caller eq 'paste') {
2744: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2745: }
2746: }
2747: }
2748: }
2749: return ('ok',\@msgs,$lockmsg);
2750: }
2751:
2752: sub copy_dependencies {
2753: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2754: my $content;
2755: if (ref($contentref)) {
2756: $content = $$contentref;
2757: } else {
2758: $content = &Apache::lonnet::getfile($item);
2759: }
2760: unless ($content eq '-1') {
2761: my $mm = new File::MMagic;
2762: my $mimetype = $mm->checktype_contents($content);
2763: if ($mimetype eq 'text/html') {
2764: my (%allfiles,%codebase,$state);
2765: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2766: if ($res eq 'ok') {
2767: my ($numexisting,$numpathchanges,$existing);
2768: (undef,$numexisting,$numpathchanges,$existing) =
2769: &Apache::loncommon::ask_for_embedded_content(
2770: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2771: {'error_on_invalid_names' => 1,
2772: 'ignore_remote_references' => 1,
2773: 'docs_url' => $item,
2774: 'context' => 'paste'});
2775: if ($numexisting > 0) {
2776: if (ref($existing) eq 'HASH') {
2777: foreach my $dep (keys(%{$existing})) {
2778: my $depfile = $dep;
2779: unless ($depfile =~ m{^\Q$relpath\E}) {
2780: $depfile = $relpath.$dep;
2781: }
2782: my $depcontent = &Apache::lonnet::getfile($depfile);
2783: unless ($depcontent eq '-1') {
2784: my $storedep = $dep;
2785: $storedep =~ s{^\Q$relpath\E}{};
2786: my $dep_url =
2787: &Apache::lonclonecourse::writefile(
2788: $env{'request.course.id'},
2789: $storefn.$storedep,$depcontent);
2790: if ($dep_url eq '/adm/notfound.html') {
2791: if (ref($errors) eq 'HASH') {
2792: $errors->{$depfile} = 1;
2793: }
2794: } else {
2795: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2796: }
2797: }
2798: }
2799: }
2800: }
2801: }
2802: }
2803: }
2804: return;
2805: }
2806:
2807: my %parameter_type = ( 'randompick' => 'int_pos',
2808: 'hiddenresource' => 'string_yesno',
2809: 'encrypturl' => 'string_yesno',
2810: 'randomorder' => 'string_yesno',);
2811: my $valid_parameters_re = join('|',keys(%parameter_type));
2812: # set parameters
2813: sub update_parameter {
2814: if ($env{'form.changeparms'} eq 'all') {
2815: my (@allidx,@allmapidx,%allchecked,%currchecked);
2816: %allchecked = (
2817: 'hiddenresource' => {},
2818: 'encrypturl' => {},
2819: 'randompick' => {},
2820: 'randomorder' => {},
2821: );
2822: foreach my $which (keys(%allchecked)) {
2823: $env{'form.all'.$which} =~ s/,$//;
2824: if ($which eq 'randompick') {
2825: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2826: my ($res,$value) = split(/:/,$item);
2827: if ($value =~ /^\d+$/) {
2828: $allchecked{$which}{$res} = $value;
2829: }
2830: }
2831: } else {
2832: if ($env{'form.all'.$which}) {
2833: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2834: }
2835: }
2836: }
2837: my $haschanges = 0;
2838: foreach my $res (@LONCAPA::map::order) {
2839: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2840: $name=&LONCAPA::map::qtescape($name);
2841: $url=&LONCAPA::map::qtescape($url);
2842: next unless ($name && $url);
2843: my $is_map;
2844: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2845: $is_map = 1;
2846: }
2847: foreach my $which (keys(%allchecked)) {
2848: if (($which eq 'randompick' || $which eq 'randomorder')) {
2849: next if (!$is_map);
2850: }
2851: my $oldvalue = 0;
2852: my $newvalue = 0;
2853: if ($allchecked{$which}{$res}) {
2854: $newvalue = $allchecked{$which}{$res};
2855: }
2856: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2857: if ($which eq 'randompick') {
2858: if ($current =~ /^(\d+)$/) {
2859: $oldvalue = $1;
2860: }
2861: } else {
2862: if ($current =~ /^yes$/i) {
2863: $oldvalue = 1;
2864: }
2865: }
2866: if ($oldvalue ne $newvalue) {
2867: $haschanges = 1;
2868: if ($newvalue) {
2869: my $storeval = 'yes';
2870: if ($which eq 'randompick') {
2871: $storeval = $newvalue;
2872: }
2873: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2874: $storeval,
2875: $parameter_type{$which});
2876: &remember_parms($res,$which,'set',$storeval);
2877: } elsif ($oldvalue) {
2878: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2879: &remember_parms($res,$which,'del');
2880: }
2881: }
2882: }
2883: }
2884: return $haschanges;
2885: } else {
2886: my $haschanges = 0;
2887: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
2888:
2889: my $which = $env{'form.changeparms'};
2890: my $idx = $env{'form.setparms'};
2891: my $oldvalue = 0;
2892: my $newvalue = 0;
2893: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2894: if ($which eq 'randompick') {
2895: if ($current =~ /^(\d+)$/) {
2896: $oldvalue = $1;
2897: }
2898: } elsif ($current =~ /^yes$/i) {
2899: $oldvalue = 1;
2900: }
2901: if ($env{'form.'.$which.'_'.$idx}) {
2902: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2903: : 1;
2904: }
2905: if ($oldvalue ne $newvalue) {
2906: $haschanges = 1;
2907: if ($newvalue) {
2908: my $storeval = 'yes';
2909: if ($which eq 'randompick') {
2910: $storeval = $newvalue;
2911: }
2912: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($idx,$which,'set',$storeval);
2915: } else {
2916: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2917: &remember_parms($idx,$which,'del');
2918: }
2919: }
2920: return $haschanges;
2921: }
2922: }
2923:
2924: sub handle_edit_cmd {
2925: my ($coursenum,$coursedom) =@_;
2926: if ($env{'form.cmd'} eq '') {
2927: return 0;
2928: }
2929: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2930:
2931: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2932: my ($title, $url, @rrest) = split(':', $ratstr);
2933:
2934: if ($cmd eq 'remove') {
2935: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2936: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2937: &Apache::lonnet::removeuploadedurl($url);
2938: } else {
2939: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2940: }
2941: splice(@LONCAPA::map::order, $idx, 1);
2942:
2943: } elsif ($cmd eq 'cut') {
2944: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2945: splice(@LONCAPA::map::order, $idx, 1);
2946:
2947: } elsif ($cmd eq 'up'
2948: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2949: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2950:
2951: } elsif ($cmd eq 'down'
2952: && defined($LONCAPA::map::order[$idx+1])) {
2953: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2954:
2955: } elsif ($cmd eq 'rename') {
2956: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2957: if ($comment=~/\S/) {
2958: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2959: $comment.':'.join(':', $url, @rrest);
2960: }
2961: # Devalidate title cache
2962: my $renamed_url=&LONCAPA::map::qtescape($url);
2963: &Apache::lonnet::devalidate_title_cache($renamed_url);
2964:
2965: } else {
2966: return 0;
2967: }
2968: return 1;
2969: }
2970:
2971: sub editor {
2972: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
2973: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,$canedit)=@_;
2974: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2975: if ($allowed) {
2976: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2977: $is_random_order,$container) =
2978: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2979: $r->print($breadcrumbtrail);
2980: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2981: $container = 'page';
2982: } else {
2983: $container = 'sequence';
2984: }
2985:
2986: my $jumpto;
2987:
2988: unless ($supplementalflag) {
2989: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
2990: }
2991:
2992: unless ($allowed) {
2993: $randompick = -1;
2994: }
2995:
2996: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2997: $folder.'.'.$container);
2998: return $errtext if ($fatal);
2999:
3000: if ($#LONCAPA::map::order<1) {
3001: my $idx=&LONCAPA::map::getresidx();
3002: if ($idx<=0) { $idx=1; }
3003: $LONCAPA::map::order[0]=$idx;
3004: $LONCAPA::map::resources[$idx]='';
3005: }
3006:
3007: # ------------------------------------------------------------ Process commands
3008:
3009: # ---------------- if they are for this folder and user allowed to make changes
3010: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3011: # set parameters and change order
3012: &snapshotbefore();
3013:
3014: if (&update_parameter()) {
3015: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3016: return $errtext if ($fatal);
3017: }
3018:
3019: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3020: # change order
3021: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3022: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3023:
3024: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3025: return $errtext if ($fatal);
3026: }
3027:
3028: if ($env{'form.pastemarked'}) {
3029: my %paste_errors;
3030: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3031: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3032: \%paste_errors);
3033: if (ref($pastemsgarray) eq 'ARRAY') {
3034: if (@{$pastemsgarray} > 0) {
3035: $r->print('<p class="LC_info">'.
3036: join('<br />',@{$pastemsgarray}).
3037: '</p>');
3038: }
3039: }
3040: if ($lockerror) {
3041: $r->print('<p class="LC_error">'.
3042: $lockerror.
3043: '</p>');
3044: }
3045: if ($save_error ne '') {
3046: return $save_error;
3047: }
3048: if ($paste_res) {
3049: my %errortext = &Apache::lonlocal::texthash (
3050: fail => 'Storage of folder contents failed',
3051: failread => 'Reading folder contents failed',
3052: failstore => 'Storage of folder contents failed',
3053: );
3054: if ($errortext{$paste_res}) {
3055: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3056: }
3057: }
3058: if (keys(%paste_errors) > 0) {
3059: $r->print('<p class="LC_warning">'."\n".
3060: &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".
3061: '<ul>'."\n");
3062: foreach my $key (sort(keys(%paste_errors))) {
3063: $r->print('<li>'.$key.'</li>'."\n");
3064: }
3065: $r->print('</ul></p>'."\n");
3066: }
3067: } elsif ($env{'form.clearmarked'}) {
3068: my $output = &do_buffer_empty();
3069: if ($output) {
3070: $r->print('<p class="LC_info">'.$output.'</p>');
3071: }
3072: }
3073:
3074: $r->print($upload_output);
3075:
3076: # Rename, cut, copy or remove a single resource
3077: if (&handle_edit_cmd($coursenum,$coursedom)) {
3078: my $contentchg;
3079: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
3080: $contentchg = 1;
3081: }
3082: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3083: return $errtext if ($fatal);
3084: }
3085:
3086: # Cut, copy and/or remove multiple resources
3087: if ($env{'form.multichange'}) {
3088: my %allchecked = (
3089: cut => {},
3090: remove => {},
3091: );
3092: my $needsupdate;
3093: foreach my $which (keys(%allchecked)) {
3094: $env{'form.multi'.$which} =~ s/,$//;
3095: if ($env{'form.multi'.$which}) {
3096: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3097: if (ref($allchecked{$which}) eq 'HASH') {
3098: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3099: }
3100: }
3101: }
3102: if ($needsupdate) {
3103: my $haschanges = 0;
3104: my %curr_groups = &Apache::longroup::coursegroups();
3105: my $total = scalar(@LONCAPA::map::order) - 1;
3106: for (my $i=$total; $i>=0; $i--) {
3107: my $res = $LONCAPA::map::order[$i];
3108: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3109: $name=&LONCAPA::map::qtescape($name);
3110: $url=&LONCAPA::map::qtescape($url);
3111: next unless $url;
3112: my %denied =
3113: &action_restrictions($coursenum,$coursedom,$url,
3114: $env{'form.folderpath'},\%curr_groups);
3115: foreach my $which (keys(%allchecked)) {
3116: next if ($denied{$which});
3117: next unless ($allchecked{$which}{$res});
3118: if ($which eq 'remove') {
3119: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3120: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3121: &Apache::lonnet::removeuploadedurl($url);
3122: } else {
3123: &LONCAPA::map::makezombie($res);
3124: }
3125: splice(@LONCAPA::map::order,$i,1);
3126: $haschanges ++;
3127: } elsif ($which eq 'cut') {
3128: &LONCAPA::map::makezombie($res);
3129: splice(@LONCAPA::map::order,$i,1);
3130: $haschanges ++;
3131: }
3132: }
3133: }
3134: if ($haschanges) {
3135: ($errtext,$fatal) =
3136: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3137: return $errtext if ($fatal);
3138: }
3139: }
3140: }
3141:
3142: # Group import/search
3143: if ($env{'form.importdetail'}) {
3144: my @imports;
3145: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3146: if (defined($item)) {
3147: my ($name,$url,$residx)=
3148: map { &unescape($_); } split(/\=/,$item);
3149: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3150: my ($suffix,$errortxt,$locknotfreed) =
3151: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3152: if ($locknotfreed) {
3153: $r->print($locknotfreed);
3154: }
3155: if ($suffix) {
3156: $url =~ s/_new\./_$suffix./;
3157: } else {
3158: return $errortxt;
3159: }
3160: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3161: my $type = $1;
3162: my ($suffix,$errortxt,$locknotfreed) =
3163: &new_timebased_suffix($coursedom,$coursenum,$type);
3164: if ($locknotfreed) {
3165: $r->print($locknotfreed);
3166: }
3167: if ($suffix) {
3168: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3169: } else {
3170: return $errortxt;
3171: }
3172: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3173: my ($suffix,$errortxt,$locknotfreed) =
3174: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3175: if ($locknotfreed) {
3176: $r->print($locknotfreed);
3177: }
3178: if ($suffix) {
3179: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3180: } else {
3181: return $errortxt;
3182: }
3183: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3184: if ($supplementalflag) {
3185: next unless ($1 eq 'supplemental');
3186: if ($folder eq 'supplemental') {
3187: next unless ($2 eq 'default');
3188: } else {
3189: next unless ($folder eq 'supplemental_'.$2);
3190: }
3191: } else {
3192: next unless ($1 eq 'docs');
3193: if ($folder eq 'default') {
3194: next unless ($2 eq 'default');
3195: } else {
3196: next unless ($folder eq 'default_'.$2);
3197: }
3198: }
3199: }
3200: push(@imports, [$name, $url, $residx]);
3201: }
3202: }
3203: ($errtext,$fatal,my $fixuperrors) =
3204: &group_import($coursenum, $coursedom, $folder,$container,
3205: 'londocs',$ltitoolsref,@imports);
3206: return $errtext if ($fatal);
3207: if ($fixuperrors) {
3208: $r->print($fixuperrors);
3209: }
3210: }
3211: # Loading a complete map
3212: if ($env{'form.loadmap'}) {
3213: if ($env{'form.importmap'}=~/\w/) {
3214: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3215: my ($title,$url,$ext,$type)=split(/\:/,$res);
3216: my $idx=&LONCAPA::map::getresidx($url);
3217: $LONCAPA::map::resources[$idx]=$res;
3218: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3219: }
3220: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3221: $folder.'.'.$container,1);
3222: return $errtext if ($fatal);
3223: } else {
3224: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3225:
3226: }
3227: }
3228: &log_differences($plain);
3229: }
3230: # ---------------------------------------------------------------- End commands
3231: # ---------------------------------------------------------------- Print screen
3232: my $idx=0;
3233: my $shown=0;
3234: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3235: $r->print('<div class="LC_Box">'.
3236: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3237: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3238: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3239: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3240: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3241: '</ol>');
3242: if ($randompick>=0) {
3243: $r->print('<p class="LC_warning">'
3244: .&mt('Caution: this folder is set to randomly pick a subset'
3245: .' of resources. Adding or removing resources from this'
3246: .' folder will change the set of resources that the'
3247: .' students see, resulting in spurious or missing credit'
3248: .' for completed problems, not limited to ones you'
3249: .' modify. Do not modify the contents of this folder if'
3250: .' it is in active student use.')
3251: .'</p>'
3252: );
3253: }
3254: if ($is_random_order) {
3255: $r->print('<p class="LC_warning">'
3256: .&mt('Caution: this folder is set to randomly order its'
3257: .' contents. Adding or removing resources from this folder'
3258: .' will change the order of resources shown.')
3259: .'</p>'
3260: );
3261: }
3262: $r->print('</div>');
3263: }
3264:
3265: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3266: %filters = (
3267: canremove => [],
3268: cancut => [],
3269: cancopy => [],
3270: hiddenresource => [],
3271: encrypturl => [],
3272: randomorder => [],
3273: randompick => [],
3274: );
3275: %curr_groups = &Apache::longroup::coursegroups();
3276: &Apache::loncommon::start_data_table_count(); #setup a row counter
3277: foreach my $res (@LONCAPA::map::order) {
3278: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3279: $name=&LONCAPA::map::qtescape($name);
3280: $url=&LONCAPA::map::qtescape($url);
3281: unless ($name) { $name=(split(/\//,$url))[-1]; }
3282: unless ($name) { $idx++; next; }
3283: push(@allidx,$res);
3284: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3285: push(@allmapidx,$res);
3286: }
3287: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3288: $coursenum,$coursedom,$crstype,
3289: $pathitem,$supplementalflag,$container,
3290: \%filters,\%curr_groups,$ltitoolsref,$canedit);
3291: $idx++;
3292: $shown++;
3293: }
3294: &Apache::loncommon::end_data_table_count();
3295:
3296: my $need_save;
3297: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3298: my $toolslink;
3299: if ($allowed) {
3300: $toolslink = '<table><tr><td>'
3301: .&Apache::loncommon::help_open_menu('Navigation Screen',
3302: 'Navigation_Screen',undef,'RAT')
3303: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3304: .'<td align="left"><ul id="LC_toolbar">'
3305: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3306: .'id="LC_content_toolbar_edittoplevel" '
3307: .'class="LC_toolbarItem" '
3308: .'title="'.&mt('Supplemental Content Editor').'">'
3309: .'</a></li></ul></td></tr></table><br />';
3310: }
3311: if ($shown) {
3312: if ($allowed) {
3313: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3314: .&Apache::loncommon::start_data_table(undef,'contentlist')
3315: .&Apache::loncommon::start_data_table_header_row()
3316: .'<th colspan="2">'.&mt('Move').'</th>'
3317: .'<th colspan="2">'.&mt('Actions').'</th>'
3318: .'<th>'.&mt('Document').'</th>';
3319: if ($folder !~ /^supplemental/) {
3320: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3321: }
3322: $to_show .= &Apache::loncommon::end_data_table_header_row();
3323: if ($folder !~ /^supplemental/) {
3324: $lists{'canhide'} = join(',',@allidx);
3325: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3326: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3327: 'randomorder','randompick');
3328: foreach my $item (@possfilters) {
3329: if (ref($filters{$item}) eq 'ARRAY') {
3330: if (@{$filters{$item}} > 0) {
3331: $lists{$item} = join(',',@{$filters{$item}});
3332: }
3333: }
3334: }
3335: if (@allidx > 0) {
3336: my $path;
3337: if ($env{'form.folderpath'}) {
3338: $path =
3339: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3340: }
3341: if (@allidx > 1) {
3342: $to_show .=
3343: &Apache::loncommon::continue_data_table_row().
3344: '<td colspan="2"> </td>'.
3345: '<td>'.
3346: &multiple_check_form('actions',\%lists,$canedit).
3347: '</td>'.
3348: '<td> </td>'.
3349: '<td> </td>'.
3350: '<td colspan="4">'.
3351: &multiple_check_form('settings',\%lists,$canedit).
3352: '</td>'.
3353: &Apache::loncommon::end_data_table_row();
3354: $need_save = 1;
3355: }
3356: }
3357: }
3358: $to_show .= $output.' '
3359: .&Apache::loncommon::end_data_table()
3360: .'<br style="line-height:2px;" />'
3361: .&Apache::loncommon::end_scrollbox();
3362: } else {
3363: $to_show .= $toolslink
3364: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3365: .$output.' '
3366: .&Apache::loncommon::end_data_table();
3367: }
3368: } else {
3369: if (!$allowed) {
3370: $to_show .= $toolslink;
3371: }
3372: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3373: .'<div class="LC_info" id="contentlist">'
3374: .&mt('Currently empty')
3375: .'</div>'
3376: .&Apache::loncommon::end_scrollbox();
3377: }
3378: } else {
3379: if ($shown) {
3380: $to_show = '<div>'
3381: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3382: .$output
3383: .&Apache::loncommon::end_data_table()
3384: .'</div>';
3385: } else {
3386: $to_show = '<div class="LC_info" id="contentlist">'
3387: .&mt('Currently empty')
3388: .'</div>'
3389: }
3390: }
3391: my $tid = 1;
3392: if ($supplementalflag) {
3393: $tid = 2;
3394: }
3395: if ($allowed) {
3396: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3397: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3398: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3399: if ($canedit) {
3400: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3401: }
3402: } else {
3403: $r->print($to_show);
3404: }
3405: return;
3406: }
3407:
3408: sub multiple_check_form {
3409: my ($caller,$listsref,$canedit) = @_;
3410: return unless (ref($listsref) eq 'HASH');
3411: my $disabled;
3412: unless ($canedit) {
3413: $disabled = 'disabled="disabled"';
3414: }
3415: my $output =
3416: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3417: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3418: '<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>'.
3419: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3420: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3421: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3422: if ($caller eq 'settings') {
3423: $output .=
3424: '<table><tr>'.
3425: '<td class="LC_docs_entry_parameter">'.
3426: '<span class="LC_nobreak"><label>'.
3427: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3428: '</label></span></td>'.
3429: '<td class="LC_docs_entry_parameter">'.
3430: '<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="" />'.
3431: '</span></td>'.
3432: '</tr>'."\n".
3433: '<tr>'.
3434: '<td class="LC_docs_entry_parameter">'.
3435: '<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').
3436: '</label></span>'.
3437: '</td></tr></table>'."\n";
3438: } else {
3439: $output .=
3440: '<table><tr>'.
3441: '<td class="LC_docs_entry_parameter">'.
3442: '<span class="LC_nobreak LC_docs_remove">'.
3443: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3444: '</label></span></td>'.
3445: '<td class="LC_docs_entry_parameter">'.
3446: '<span class="LC_nobreak LC_docs_cut">'.
3447: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3448: '</label></span></td>'."\n".
3449: '<td class="LC_docs_entry_parameter">'.
3450: '<span class="LC_nobreak LC_docs_copy">'.
3451: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3452: '</label></span></td>'.
3453: '</tr></table>'."\n";
3454: }
3455: $output .=
3456: '</fieldset>'.
3457: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3458: if ($caller eq 'settings') {
3459: $output .=
3460: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3461: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3462: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3463: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3464: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3465: } elsif ($caller eq 'actions') {
3466: $output .=
3467: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3468: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3469: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3470: }
3471: $output .=
3472: '</form>'.
3473: '</div>';
3474: return $output;
3475: }
3476:
3477: sub process_file_upload {
3478: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3479: # upload a file, if present
3480: my $filesize = length($env{'form.uploaddoc'});
3481: if (!$filesize) {
3482: $$upload_output = '<div class="LC_error">'.
3483: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3484: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3485: $filesize).'<br />'.
3486: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3487: '</div>';
3488: return;
3489: }
3490: my $quotatype = 'unofficial';
3491: if ($crstype eq 'Community') {
3492: $quotatype = 'community';
3493: } elsif ($crstype eq 'Placement') {
3494: $quotatype = 'placement';
3495: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3496: $quotatype = 'official';
3497: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3498: $quotatype = 'textbook';
3499: }
3500: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3501: $filesize = int($filesize/1000); #expressed in kb
3502: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3503: $env{'form.uploaddoc.filename'},$filesize,
3504: 'upload',$quotatype);
3505: return if ($$upload_output);
3506: }
3507: my ($parseaction,$showupload,$nextphase,$mimetype);
3508: if ($env{'form.parserflag'}) {
3509: $parseaction = 'parse';
3510: }
3511: my $folder=$env{'form.folder'};
3512: if ($folder eq '') {
3513: $folder='default';
3514: }
3515: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3516: my $errtext='';
3517: my $fatal=0;
3518: my $container='sequence';
3519: if ($env{'form.folderpath'} =~ /:1$/) {
3520: $container='page';
3521: }
3522: ($errtext,$fatal)=
3523: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3524: if ($#LONCAPA::map::order<1) {
3525: $LONCAPA::map::order[0]=1;
3526: $LONCAPA::map::resources[1]='';
3527: }
3528: my $destination = 'docs/';
3529: if ($folder =~ /^supplemental/) {
3530: $destination = 'supplemental/';
3531: }
3532: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3533: $destination .= 'default/';
3534: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3535: $destination .= $2.'/';
3536: }
3537: if ($fatal) {
3538: $$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>';
3539: return;
3540: }
3541: # this is for a course, not a user, so set context to coursedoc.
3542: my $newidx=&LONCAPA::map::getresidx();
3543: $destination .= $newidx;
3544: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3545: $parseaction,$allfiles,
3546: $codebase,undef,undef,undef,undef,
3547: undef,undef,\$mimetype);
3548: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3549: my $stored = $1;
3550: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3551: $stored.'</span>').'</p>';
3552: } else {
3553: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3554:
3555: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3556: return;
3557: }
3558: my $ext='false';
3559: if ($url=~m{^http://}) { $ext='true'; }
3560: $url = &LONCAPA::map::qtunescape($url);
3561: my $comment=$env{'form.comment'};
3562: $comment = &LONCAPA::map::qtunescape($comment);
3563: if ($folder=~/^supplemental/) {
3564: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3565: $env{'user.domain'}.'___&&&___'.$comment;
3566: }
3567:
3568: $LONCAPA::map::resources[$newidx]=
3569: $comment.':'.$url.':'.$ext.':normal:res';
3570: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3571: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3572: $folder.'.'.$container,1);
3573: if ($fatal) {
3574: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3575: return;
3576: } else {
3577: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3578: $$upload_output = $showupload;
3579: my $total_embedded = scalar(keys(%{$allfiles}));
3580: if ($total_embedded > 0) {
3581: my $uploadphase = 'upload_embedded';
3582: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3583: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3584: my ($embedded,$num) =
3585: &Apache::loncommon::ask_for_embedded_content(
3586: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3587: if ($embedded) {
3588: if ($num) {
3589: $$upload_output .=
3590: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3591: $nextphase = $uploadphase;
3592: } else {
3593: $$upload_output .= $embedded;
3594: }
3595: } else {
3596: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3597: }
3598: } else {
3599: $$upload_output .= &mt('No embedded items identified').'<br />';
3600: }
3601: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3602: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3603: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3604: $nextphase = 'decompress_uploaded';
3605: my $position = scalar(@LONCAPA::map::order)-1;
3606: my $noextract = &return_to_editor();
3607: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3608: my %archiveitems = (
3609: folderpath => $env{'form.folderpath'},
3610: cmd => $nextphase,
3611: newidx => $newidx,
3612: position => $position,
3613: phase => $nextphase,
3614: comment => $comment,
3615: );
3616: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3617: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3618: $$upload_output = $showupload.
3619: &Apache::loncommon::decompress_form($mimetype,
3620: $archiveurl,'/adm/coursedocs',$noextract,
3621: \%archiveitems,\@current);
3622: }
3623: }
3624: }
3625: return $nextphase;
3626: }
3627:
3628: sub get_dir_list {
3629: my ($url,$coursenum,$coursedom,$newidx) = @_;
3630: my ($destination,$dir_root) = &embedded_destination();
3631: my ($dirlistref,$listerror) =
3632: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3633: my @dir_lines;
3634: my $dirptr=16384;
3635: if (ref($dirlistref) eq 'ARRAY') {
3636: foreach my $dir_line (sort
3637: {
3638: my ($afile)=split('&',$a,2);
3639: my ($bfile)=split('&',$b,2);
3640: return (lc($afile) cmp lc($bfile));
3641: } (@{$dirlistref})) {
3642: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3643: $filename =~ s/\s+$//;
3644: next if ($filename =~ /^\.\.?$/);
3645: my $isdir = 0;
3646: if ($dirptr&$testdir) {
3647: $isdir = 1;
3648: }
3649: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3650: }
3651: }
3652: return @dir_lines;
3653: }
3654:
3655: sub is_supplemental_title {
3656: my ($title) = @_;
3657: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3658: }
3659:
3660: # --------------------------------------------------------------- An entry line
3661:
3662: sub entryline {
3663: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3664: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3665: $ltitoolsref,$canedit)=@_;
3666: my ($foldertitle,$renametitle,$oldtitle);
3667: if (&is_supplemental_title($title)) {
3668: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3669: } else {
3670: $title=&HTML::Entities::encode($title,'"<>&\'');
3671: $renametitle=$title;
3672: $foldertitle=$title;
3673: }
3674:
3675: my ($disabled,$readonly,$js_lt);
3676: unless ($canedit) {
3677: $disabled = 'disabled="disabled"';
3678: $readonly = 1;
3679: }
3680:
3681: my $orderidx=$LONCAPA::map::order[$index];
3682:
3683: $renametitle=~s/\\/\\\\/g;
3684: $renametitle=~s/\"\;/\\\"/g;
3685: $renametitle=~s/"/%22/g;
3686: $renametitle=~s/ /%20/g;
3687: $oldtitle = $renametitle;
3688: $renametitle=~s/\'/\\\'/g;
3689: my $line=&Apache::loncommon::start_data_table_row();
3690: my ($form_start,$form_end,$form_common,$form_param);
3691: # Edit commands
3692: my ($esc_path, $path, $symb);
3693: if ($env{'form.folderpath'}) {
3694: $esc_path=&escape($env{'form.folderpath'});
3695: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3696: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3697: }
3698: my $isexternal;
3699: if ($residx) {
3700: my $currurl = $url;
3701: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3702: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3703: $isexternal = 1;
3704: }
3705: if (!$supplementalflag) {
3706: my $path = 'uploaded/'.
3707: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3708: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3709: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3710: $residx,
3711: &Apache::lonnet::declutter($currurl));
3712: }
3713: }
3714: my ($renamelink,%lt,$ishash);
3715: if (ref($filtersref) eq 'HASH') {
3716: $ishash = 1;
3717: }
3718:
3719: if ($allowed) {
3720: $form_start = '
3721: <form action="/adm/coursedocs" method="post">
3722: ';
3723: $form_common=(<<END);
3724: <input type="hidden" name="folderpath" value="$path" />
3725: <input type="hidden" name="symb" value="$symb" />
3726: END
3727: $form_param=(<<END);
3728: <input type="hidden" name="setparms" value="$orderidx" />
3729: <input type="hidden" name="changeparms" value="0" />
3730: END
3731: $form_end = '</form>';
3732:
3733: my $incindex=$index+1;
3734: my $selectbox='';
3735: if (($#LONCAPA::map::order>0) &&
3736: ((split(/\:/,
3737: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3738: ne '') &&
3739: ((split(/\:/,
3740: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
3741: ne '')) {
3742: $selectbox=
3743: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
3744: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
3745: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3746: if ($i==$incindex) {
3747: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
3748: } else {
3749: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3750: }
3751: }
3752: $selectbox.='</select>';
3753: }
3754: %lt=&Apache::lonlocal::texthash(
3755: 'up' => 'Move Up',
3756: 'dw' => 'Move Down',
3757: 'rm' => 'Remove',
3758: 'ct' => 'Cut',
3759: 'rn' => 'Rename',
3760: 'cp' => 'Copy',
3761: 'ex' => 'External Resource',
3762: 'et' => 'External Tool',
3763: 'ed' => 'Edit',
3764: 'pr' => 'Preview',
3765: 'sv' => 'Save',
3766: 'ul' => 'URL',
3767: 'ti' => 'Title',
3768: 'er' => 'Editing rights unavailable for your current role',
3769: );
3770: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3771: $env{'form.folderpath'},
3772: $currgroups);
3773: my ($copylink,$cutlink,$removelink);
3774: my $skip_confirm = 0;
3775: my $confirm_removal = 0;
3776: if ( $folder =~ /^supplemental/
3777: || ($url =~ m{( /smppg$
3778: |/syllabus$
3779: |/aboutme$
3780: |/navmaps$
3781: |/bulletinboard$
3782: |/exttools?$
3783: |\.html$)}x)
3784: || $isexternal) {
3785: $skip_confirm = 1;
3786: }
3787: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3788: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3789: $confirm_removal = 1;
3790: }
3791:
3792: if ($denied{'copy'}) {
3793: $copylink=(<<ENDCOPY)
3794: <span style="visibility: hidden;">$lt{'cp'}</span>
3795: ENDCOPY
3796: } else {
3797: my $formname = 'edit_copy_'.$orderidx;
3798: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3799: $copylink=(<<ENDCOPY);
3800: <form name="$formname" method="post" action="/adm/coursedocs">
3801: $form_common
3802: <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>
3803: $form_end
3804: ENDCOPY
3805: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3806: push(@{$filtersref->{'cancopy'}},$orderidx);
3807: }
3808: }
3809: if ($denied{'cut'}) {
3810: $cutlink=(<<ENDCUT);
3811: <span style="visibility: hidden;">$lt{'ct'}</span>
3812: ENDCUT
3813: } else {
3814: my $formname = 'edit_cut_'.$orderidx;
3815: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3816: $cutlink=(<<ENDCUT);
3817: <form name="$formname" method="post" action="/adm/coursedocs">
3818: $form_common
3819: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
3820: <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>
3821: $form_end
3822: ENDCUT
3823: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3824: push(@{$filtersref->{'cancut'}},$orderidx);
3825: }
3826: }
3827: if ($denied{'remove'}) {
3828: $removelink=(<<ENDREM);
3829: <span style="visibility: hidden;">$lt{'rm'}</a>
3830: ENDREM
3831: } else {
3832: my $formname = 'edit_remove_'.$orderidx;
3833: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
3834: $removelink=(<<ENDREM);
3835: <form name="$formname" method="post" action="/adm/coursedocs">
3836: $form_common
3837: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
3838: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
3839: <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>
3840: $form_end
3841: ENDREM
3842: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3843: push(@{$filtersref->{'canremove'}},$orderidx);
3844: }
3845: }
3846: $renamelink=(<<ENDREN);
3847: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
3848: ENDREN
3849: my ($uplink,$downlink);
3850: if ($canedit) {
3851: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3852: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3853: } else {
3854: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3855: $downlink = $uplink;
3856: }
3857: $line.=(<<END);
3858: <td>
3859: <div class="LC_docs_entry_move">
3860: <a href="$uplink">
3861: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
3862: </a>
3863: </div>
3864: <div class="LC_docs_entry_move">
3865: <a href="$downlink">
3866: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
3867: </a>
3868: </div>
3869: </td>
3870: <td>
3871: $form_start
3872: $form_param
3873: $form_common
3874: $selectbox
3875: $form_end
3876: </td>
3877: <td class="LC_docs_entry_commands LC_nobreak">
3878: $removelink
3879: $cutlink
3880: $copylink
3881: </td>
3882: END
3883: }
3884: # Figure out what kind of a resource this is
3885: my ($extension)=($url=~/\.(\w+)$/);
3886: my $uploaded=($url=~/^\/*uploaded\//);
3887: my $icon=&Apache::loncommon::icon($url);
3888: my $isfolder;
3889: my $ispage;
3890: my $containerarg;
3891: if ($uploaded) {
3892: if (($extension eq 'sequence') || ($extension eq 'page')) {
3893: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
3894: $containerarg = $1;
3895: if ($extension eq 'sequence') {
3896: $icon=$iconpath.'navmap.folder.closed.gif';
3897: $isfolder=1;
3898: } else {
3899: $icon=$iconpath.'page.gif';
3900: $ispage=1;
3901: }
3902: if ($allowed) {
3903: $url='/adm/coursedocs?';
3904: } else {
3905: $url='/adm/supplemental?';
3906: }
3907: } else {
3908: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3909: }
3910: }
3911:
3912: my ($editlink,$extresform,$anchor);
3913: my $orig_url = $url;
3914: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
3915: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3916: if (!$supplementalflag && $residx && $symb) {
3917: if ((!$isfolder) && (!$ispage)) {
3918: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3919: $url=&Apache::lonnet::clutter($url);
3920: if ($url=~/^\/*uploaded\//) {
3921: $url=~/\.(\w+)$/;
3922: my $embstyle=&Apache::loncommon::fileembstyle($1);
3923: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3924: $url='/adm/wrapper'.$url;
3925: } elsif ($embstyle eq 'ssi') {
3926: #do nothing with these
3927: } elsif ($url!~/\.(sequence|page)$/) {
3928: $url='/adm/coursedocs/showdoc'.$url;
3929: }
3930: } elsif ($url=~m|^/ext/|) {
3931: $url='/adm/wrapper'.$url;
3932: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3933: $url='/adm/wrapper'.$url;
3934: }
3935: if (&Apache::lonnet::symbverify($symb,$url)) {
3936: my $shownsymb = $symb;
3937: if ($isexternal) {
3938: if ($url =~ /^([^#]+)#([^#]+)$/) {
3939: $url = $1;
3940: $anchor = $2;
3941: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3942: $shownsymb = $1.&escape('#').$anchor;
3943: }
3944: }
3945: }
3946: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3947: } else {
3948: $url='';
3949: }
3950: }
3951: } elsif ($supplementalflag) {
3952: if ($isexternal) {
3953: if ($url =~ /^([^#]+)#([^#]+)$/) {
3954: $url = $1;
3955: $anchor = $2;
3956: }
3957: }
3958: }
3959: my ($rand_pick_text,$rand_order_text);
3960: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
3961: my $foldername=&escape($foldertitle);
3962: my $folderpath=$env{'form.folderpath'};
3963: if ($folderpath) { $folderpath.='&' };
3964: if (!$allowed && $supplementalflag) {
3965: $folderpath.=$containerarg.'&'.$foldername;
3966: $url.='folderpath='.&escape($folderpath);
3967: } else {
3968: # Append randompick number, hidden, and encrypted with ":" to foldername,
3969: # so it gets transferred between levels
3970: $folderpath.=$containerarg.'&'.$foldername.
3971: ':'.(&LONCAPA::map::getparameter($orderidx,
3972: 'parameter_randompick'))[0]
3973: .':'.((&LONCAPA::map::getparameter($orderidx,
3974: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3975: .':'.((&LONCAPA::map::getparameter($orderidx,
3976: 'parameter_encrypturl'))[0]=~/^yes$/i)
3977: .':'.((&LONCAPA::map::getparameter($orderidx,
3978: 'parameter_randomorder'))[0]=~/^yes$/i)
3979: .':'.$ispage;
3980: $url.='folderpath='.&escape($folderpath);
3981: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3982: 'parameter_randompick'))[0];
3983: my $rpckchk;
3984: if ($rpicknum) {
3985: $rpckchk = ' checked="checked"';
3986: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3987: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3988: }
3989: }
3990: my $formname = 'edit_randompick_'.$orderidx;
3991: $rand_pick_text =
3992: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
3993: $form_param."\n".
3994: $form_common."\n".
3995: '<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.'">';
3996: if ($rpicknum ne '') {
3997: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3998: }
3999: $rand_pick_text .= '</span></span>'.
4000: $form_end;
4001: my $ro_set;
4002: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
4003: $ro_set = 'checked="checked"';
4004: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4005: push(@{$filtersref->{'randomorder'}},$orderidx);
4006: }
4007: }
4008: $formname = 'edit_rorder_'.$orderidx;
4009: $rand_order_text =
4010: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4011: $form_param."\n".
4012: $form_common."\n".
4013: '<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>'.
4014: $form_end;
4015: }
4016: } elsif ($supplementalflag && !$allowed) {
4017: my $isexttool;
4018: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4019: $url='/adm/wrapper'.$url;
4020: $isexttool = 1;
4021: }
4022: $url .= ($url =~ /\?/) ? '&':'?';
4023: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4024: if ($title) {
4025: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4026: }
4027: if ((($isexternal) || ($isexttool)) && $orderidx) {
4028: $url .= '&idx='.$orderidx;
4029: }
4030: if ($anchor ne '') {
4031: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4032: }
4033: }
4034: my ($tdalign,$tdwidth);
4035: if ($allowed) {
4036: my $fileloc =
4037: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4038: if ($isexternal) {
4039: ($editlink,$extresform) =
4040: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4041: undef,undef,undef,undef,undef,undef,
4042: undef,$disabled);
4043: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4044: ($editlink,$extresform) =
4045: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4046: undef,undef,undef,'tool',$coursedom,
4047: $coursenum,$ltitoolsref,$disabled);
4048: } elsif (!$isfolder && !$ispage) {
4049: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4050: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4051: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4052: my $suppanchor;
4053: if ($supplementalflag) {
4054: $suppanchor = $anchor;
4055: }
4056: my $jscall =
4057: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4058: $switchserver,
4059: $forceedit,
4060: undef,$symb,
4061: &escape($env{'form.folderpath'}),
4062: $renametitle,'','',1,$suppanchor);
4063: if ($jscall) {
4064: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4065: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4066: }
4067: }
4068: }
4069: $tdalign = ' align="right" valign="top"';
4070: $tdwidth = ' width="80%"';
4071: }
4072: my $reinit;
4073: if ($crstype eq 'Community') {
4074: $reinit = &mt('(re-initialize community to access)');
4075: } else {
4076: $reinit = &mt('(re-initialize course to access)');
4077: }
4078: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4079: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4080: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4081: } elsif ($url) {
4082: if ($anchor ne '') {
4083: if ($supplementalflag) {
4084: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4085: } else {
4086: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4087: }
4088: }
4089: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4090: (($anchor ne '')?$anchor:''),
4091: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4092: } else {
4093: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4094: }
4095: $line.='</span></td><td'.$tdwidth.'>';
4096: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4097: $line.='<a href="'.$url.'">'.$title.'</a>';
4098: } elsif ($url) {
4099: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4100: (($anchor ne '')?$anchor:''),
4101: $title,600,500);
4102: } else {
4103: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4104: }
4105: $line.="$extresform</td>";
4106: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4107: $rand_order_text = ' ' if ($rand_order_text eq '');
4108: if (($allowed) && ($folder!~/^supplemental/)) {
4109: my %lt=&Apache::lonlocal::texthash(
4110: 'hd' => 'Hidden',
4111: 'ec' => 'URL hidden');
4112: my ($enctext,$hidtext);
4113: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4114: $enctext = ' checked="checked"';
4115: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4116: push(@{$filtersref->{'encrypturl'}},$orderidx);
4117: }
4118: }
4119: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4120: $hidtext = ' checked="checked"';
4121: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4122: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4123: }
4124: }
4125: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4126: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
4127: $line.=(<<ENDPARMS);
4128: <td class="LC_docs_entry_parameter">
4129: <form action="/adm/coursedocs" method="post" name="$formhidden">
4130: $form_param
4131: $form_common
4132: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4133: $form_end
4134: <br />
4135: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4136: $form_param
4137: $form_common
4138: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4139: $form_end
4140: </td>
4141: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4142: $rand_order_text</td>
4143: ENDPARMS
4144: }
4145: $line.=&Apache::loncommon::end_data_table_row();
4146: return $line;
4147: }
4148:
4149: sub action_restrictions {
4150: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4151: my %denied = (
4152: cut => 0,
4153: copy => 0,
4154: remove => 0,
4155: );
4156: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4157: # no copy for published maps
4158: $denied{'copy'} = 1;
4159: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4160: unless ($1 eq 'simpleproblem') {
4161: $denied{'copy'} = 1;
4162: }
4163: $denied{'cut'} = 1;
4164: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4165: if ($folderpath =~ /^default&[^\&]+$/) {
4166: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4167: $denied{'remove'} = 1;
4168: }
4169: $denied{'cut'} = 1;
4170: $denied{'copy'} = 1;
4171: }
4172: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4173: my $group = $1;
4174: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4175: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4176: $denied{'remove'} = 1;
4177: }
4178: }
4179: $denied{'cut'} = 1;
4180: $denied{'copy'} = 1;
4181: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4182: my $group = $1;
4183: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4184: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4185: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4186: if (keys(%groupsettings) > 0) {
4187: $denied{'remove'} = 1;
4188: }
4189: $denied{'cut'} = 1;
4190: $denied{'copy'} = 1;
4191: }
4192: }
4193: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4194: my $group = $1;
4195: if ($url =~ /group_boards_\Q$group\E/) {
4196: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4197: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4198: if (keys(%groupsettings) > 0) {
4199: if (ref($groupsettings{'functions'}) eq 'HASH') {
4200: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4201: $denied{'remove'} = 1;
4202: }
4203: }
4204: }
4205: $denied{'cut'} = 1;
4206: $denied{'copy'} = 1;
4207: }
4208: }
4209: }
4210: return %denied;
4211: }
4212:
4213: sub new_timebased_suffix {
4214: my ($dom,$num,$type,$area,$container) = @_;
4215: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4216: if ($type eq 'paste') {
4217: $prefix = $type;
4218: $namespace = 'courseeditor';
4219: $idtype = 'addcode';
4220: } elsif ($type eq 'map') {
4221: $prefix = 'docs';
4222: if ($area eq 'supplemental') {
4223: $prefix = 'supp';
4224: }
4225: $prefix .= $container;
4226: $namespace = 'uploadedmaps';
4227: } else {
4228: $prefix = $type;
4229: $namespace = 'templated';
4230: }
4231: my ($suffix,$freedlock,$error) =
4232: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4233: if (!$suffix) {
4234: if ($type eq 'paste') {
4235: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4236: } elsif ($type eq 'map') {
4237: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4238: } elsif ($type eq 'smppg') {
4239: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4240: } else {
4241: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4242: }
4243: if ($error) {
4244: $errtext .= '<br />'.$error;
4245: }
4246: }
4247: if ($freedlock ne 'ok') {
4248: $locknotfreed =
4249: '<div class="LC_error">'.
4250: &mt('There was a problem removing a lockfile.').' ';
4251: if ($type eq 'paste') {
4252: if ($freedlock eq 'nolock') {
4253: $locknotfreed =
4254: '<div class="LC_error">'.
4255: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4256:
4257: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4258: } else {
4259: $locknotfreed .=
4260: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4261: }
4262: } elsif ($type eq 'map') {
4263: $locknotfreed .=
4264: &mt('This will prevent creation of additional folders or composite pages in this course.');
4265: } elsif ($type eq 'smppg') {
4266: $locknotfreed .=
4267: &mt('This will prevent creation of additional simple pages in this course.');
4268: } else {
4269: $locknotfreed .=
4270: &mt('This will prevent creation of additional discussion boards in this course.');
4271: }
4272: unless ($type eq 'paste') {
4273: $locknotfreed .=
4274: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4275: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4276: }
4277: $locknotfreed .= '</div>';
4278: }
4279: return ($suffix,$errtext,$locknotfreed);
4280: }
4281:
4282: =pod
4283:
4284: =item tiehash()
4285:
4286: tie the hash
4287:
4288: =cut
4289:
4290: sub tiehash {
4291: my ($mode)=@_;
4292: $hashtied=0;
4293: if ($env{'request.course.fn'}) {
4294: if ($mode eq 'write') {
4295: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4296: &GDBM_WRCREAT(),0640)) {
4297: $hashtied=2;
4298: }
4299: } else {
4300: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4301: &GDBM_READER(),0640)) {
4302: $hashtied=1;
4303: }
4304: }
4305: }
4306: }
4307:
4308: sub untiehash {
4309: if ($hashtied) { untie %hash; }
4310: $hashtied=0;
4311: return OK;
4312: }
4313:
4314:
4315:
4316:
4317: sub checkonthis {
4318: my ($r,$url,$level,$title)=@_;
4319: $url=&unescape($url);
4320: $alreadyseen{$url}=1;
4321: $r->rflush();
4322: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4323: $r->print("\n<br />");
4324: if ($level==0) {
4325: $r->print("<br />");
4326: }
4327: for (my $i=0;$i<=$level*5;$i++) {
4328: $r->print(' ');
4329: }
4330: $r->print('<a href="'.$url.'" target="cat">'.
4331: ($title?$title:$url).'</a> ');
4332: if ($url=~/^\/res\//) {
4333: my $result=&Apache::lonnet::repcopy(
4334: &Apache::lonnet::filelocation('',$url));
4335: if ($result eq 'ok') {
4336: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4337: $r->rflush();
4338: &Apache::lonnet::countacc($url);
4339: $url=~/\.(\w+)$/;
4340: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4341: $r->print('<br />');
4342: $r->rflush();
4343: for (my $i=0;$i<=$level*5;$i++) {
4344: $r->print(' ');
4345: }
4346: $r->print('- '.&mt('Rendering:').' ');
4347: my ($errorcount,$warningcount)=split(/:/,
4348: &Apache::lonnet::ssi_body($url,
4349: ('grade_target'=>'web',
4350: 'return_only_error_and_warning_counts' => 1)));
4351: if (($errorcount) ||
4352: ($warningcount)) {
4353: if ($errorcount) {
4354: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4355: &mt('[quant,_1,error]',$errorcount).'</span>');
4356: }
4357: if ($warningcount) {
4358: $r->print('<span class="LC_warning">'.
4359: &mt('[quant,_1,warning]',$warningcount).'</span>');
4360: }
4361: } else {
4362: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4363: }
4364: $r->rflush();
4365: }
4366: my $dependencies=
4367: &Apache::lonnet::metadata($url,'dependencies');
4368: foreach my $dep (split(/\,/,$dependencies)) {
4369: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4370: &checkonthis($r,$dep,$level+1);
4371: }
4372: }
4373: } elsif ($result eq 'unavailable') {
4374: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4375: } elsif ($result eq 'not_found') {
4376: unless ($url=~/\$/) {
4377: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4378: } else {
4379: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4380: }
4381: } else {
4382: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4383: }
4384: }
4385: }
4386: }
4387:
4388:
4389:
4390: =pod
4391:
4392: =item list_symbs()
4393:
4394: List Content Identifiers
4395:
4396: =cut
4397:
4398: sub list_symbs {
4399: my ($r) = @_;
4400:
4401: my $crstype = &Apache::loncommon::course_type();
4402: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4403: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4404: $r->print(&startContentScreen('tools'));
4405: my $navmap = Apache::lonnavmaps::navmap->new();
4406: if (!defined($navmap)) {
4407: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4408: '<div class="LC_error">'.
4409: &mt('Unable to retrieve information about course contents').
4410: '</div>');
4411: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4412: } else {
4413: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4414: &Apache::loncommon::start_data_table().
4415: &Apache::loncommon::start_data_table_header_row().
4416: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4417: &Apache::loncommon::end_data_table_header_row()."\n");
4418: my $count;
4419: foreach my $res ($navmap->retrieveResources()) {
4420: $r->print(&Apache::loncommon::start_data_table_row().
4421: '<td>'.$res->compTitle().'</td>'.
4422: '<td>'.$res->symb().'</td>'.
4423: &Apache::loncommon::end_data_table_row());
4424: $count ++;
4425: }
4426: if (!$count) {
4427: $r->print(&Apache::loncommon::start_data_table_row().
4428: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4429: &Apache::loncommon::end_data_table_row());
4430: }
4431: $r->print(&Apache::loncommon::end_data_table());
4432: }
4433: $r->print(&endContentScreen());
4434: }
4435:
4436:
4437: sub verifycontent {
4438: my ($r) = @_;
4439: my $crstype = &Apache::loncommon::course_type();
4440: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4441: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4442: $r->print(&startContentScreen('tools'));
4443: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4444: $hashtied=0;
4445: undef %alreadyseen;
4446: %alreadyseen=();
4447: &tiehash();
4448:
4449: foreach my $key (keys(%hash)) {
4450: if ($hash{$key}=~/\.(page|sequence)$/) {
4451: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4452: $r->print('<hr /><span class="LC_error">'.
4453: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
4454: &unescape($hash{$key}).'</span><br />'.
4455: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
4456: }
4457: }
4458: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4459: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4460: }
4461: }
4462: &untiehash();
4463: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
4464: $r->print(&endContentScreen());
4465: }
4466:
4467:
4468: sub devalidateversioncache {
4469: my $src=shift;
4470: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4471: &Apache::lonnet::clutter($src));
4472: }
4473:
4474: sub checkversions {
4475: my ($r,$canedit) = @_;
4476: my $crstype = &Apache::loncommon::course_type();
4477: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4478: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
4479: $r->print(&startContentScreen('tools'));
4480:
4481: my $header='';
4482: my $startsel='';
4483: my $monthsel='';
4484: my $weeksel='';
4485: my $daysel='';
4486: my $allsel='';
4487: my %changes=();
4488: my $starttime=0;
4489: my $haschanged=0;
4490: my %setversions=&Apache::lonnet::dump('resourceversions',
4491: $env{'course.'.$env{'request.course.id'}.'.domain'},
4492: $env{'course.'.$env{'request.course.id'}.'.num'});
4493:
4494: $hashtied=0;
4495: &tiehash();
4496: if ($canedit) {
4497: my %newsetversions=();
4498: if ($env{'form.setmostrecent'}) {
4499: $haschanged=1;
4500: foreach my $key (keys(%hash)) {
4501: if ($key=~/^ids\_(\/res\/.+)$/) {
4502: $newsetversions{$1}='mostrecent';
4503: &devalidateversioncache($1);
4504: }
4505: }
4506: } elsif ($env{'form.setcurrent'}) {
4507: $haschanged=1;
4508: foreach my $key (keys(%hash)) {
4509: if ($key=~/^ids\_(\/res\/.+)$/) {
4510: my $getvers=&Apache::lonnet::getversion($1);
4511: if ($getvers>0) {
4512: $newsetversions{$1}=$getvers;
4513: &devalidateversioncache($1);
4514: }
4515: }
4516: }
4517: } elsif ($env{'form.setversions'}) {
4518: $haschanged=1;
4519: foreach my $key (keys(%env)) {
4520: if ($key=~/^form\.set_version_(.+)$/) {
4521: my $src=$1;
4522: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4523: $newsetversions{$src}=$env{$key};
4524: &devalidateversioncache($src);
4525: }
4526: }
4527: }
4528: }
4529: if ($haschanged) {
4530: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4531: $env{'course.'.$env{'request.course.id'}.'.domain'},
4532: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4533: $r->print(&Apache::loncommon::confirmwrapper(
4534: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4535: } else {
4536: $r->print(&Apache::loncommon::confirmwrapper(
4537: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4538: }
4539: &mark_hash_old();
4540: }
4541: &changewarning($r,'');
4542: }
4543: if ($env{'form.timerange'} eq 'all') {
4544: # show all documents
4545: $header=&mt('All content in '.$crstype);
4546: $allsel=' selected="selected"';
4547: foreach my $key (keys(%hash)) {
4548: if ($key=~/^ids\_(\/res\/.+)$/) {
4549: my $src=$1;
4550: $changes{$src}=1;
4551: }
4552: }
4553: } else {
4554: # show documents which changed
4555: %changes=&Apache::lonnet::dump
4556: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4557: $env{'course.'.$env{'request.course.id'}.'.num'});
4558: my $firstkey=(keys(%changes))[0];
4559: unless ($firstkey=~/^error\:/) {
4560: unless ($env{'form.timerange'}) {
4561: $env{'form.timerange'}=604800;
4562: }
4563: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4564: .&mt('seconds');
4565: if ($env{'form.timerange'}==-1) {
4566: $seltext='since start of course';
4567: $startsel=' selected="selected"';
4568: $env{'form.timerange'}=time;
4569: }
4570: $starttime=time-$env{'form.timerange'};
4571: if ($env{'form.timerange'}==2592000) {
4572: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4573: $monthsel=' selected="selected"';
4574: } elsif ($env{'form.timerange'}==604800) {
4575: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4576: $weeksel=' selected="selected"';
4577: } elsif ($env{'form.timerange'}==86400) {
4578: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
4579: $daysel=' selected="selected"';
4580: }
4581: $header=&mt('Content changed').' '.$seltext;
4582: } else {
4583: $header=&mt('No content modifications yet.');
4584: }
4585: }
4586: %setversions=&Apache::lonnet::dump('resourceversions',
4587: $env{'course.'.$env{'request.course.id'}.'.domain'},
4588: $env{'course.'.$env{'request.course.id'}.'.num'});
4589: my %lt=&Apache::lonlocal::texthash
4590: ('st' => 'Version changes since start of '.$crstype,
4591: 'lm' => 'Version changes since last Month',
4592: 'lw' => 'Version changes since last Week',
4593: 'sy' => 'Version changes since Yesterday',
4594: 'al' => 'All Resources (possibly large output)',
4595: 'cd' => 'Change display',
4596: 'sd' => 'Display',
4597: 'fi' => 'File',
4598: 'md' => 'Modification Date',
4599: 'mr' => 'Most recently published Version',
4600: 've' => 'Version used in '.$crstype,
4601: 'vu' => 'Set Version to be used in '.$crstype,
4602: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
4603: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4604: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
4605: 'di' => 'Differences',
4606: 'save' => 'Save changes',
4607: 'vers' => 'Version choice(s) for specific resources',
4608: 'act' => 'Actions');
4609: my ($disabled,$readonly);
4610: unless ($canedit) {
4611: $disabled = 'disabled="disabled"';
4612: $readonly = 1;
4613: }
4614: $r->print(<<ENDHEADERS);
4615: <h4 class="LC_info">$header</h4>
4616: <form action="/adm/coursedocs" method="post">
4617: <input type="hidden" name="versions" value="1" />
4618: <div class="LC_left_float">
4619: <fieldset>
4620: <legend>$lt{'cd'}</legend>
4621: <select name="timerange">
4622: <option value='all'$allsel>$lt{'al'}</option>
4623: <option value="-1"$startsel>$lt{'st'}</option>
4624: <option value="2592000"$monthsel>$lt{'lm'}</option>
4625: <option value="604800"$weeksel>$lt{'lw'}</option>
4626: <option value="86400"$daysel>$lt{'sy'}</option>
4627: </select>
4628: <input type="submit" name="display" value="$lt{'sd'}" />
4629: </fieldset>
4630: </div>
4631: <div class="LC_left_float">
4632: <fieldset>
4633: <legend>$lt{'act'}</legend>
4634: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4635: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
4636: </fieldset>
4637: </div>
4638: <br clear="all" />
4639: <hr />
4640: <h4>$lt{'vers'}</h4>
4641: ENDHEADERS
4642: #number of columns for version history
4643: my %changedbytime;
4644: foreach my $key (keys(%changes)) {
4645: #excludes not versionable problems from resource version history:
4646: next if ($key =~ /^\/res\/lib\/templates/);
4647: my $chg;
4648: if ($env{'form.timerange'} eq 'all') {
4649: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4650: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4651: } else {
4652: $chg = $changes{$key};
4653: next if ($chg < $starttime);
4654: }
4655: push(@{$changedbytime{$chg}},$key);
4656: }
4657: if (keys(%changedbytime) == 0) {
4658: &untiehash();
4659: $r->print(&mt('No content changes in imported content in specified time frame').
4660: &endContentScreen());
4661: return;
4662: }
4663: $r->print(
4664: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
4665: &Apache::loncommon::start_data_table().
4666: &Apache::loncommon::start_data_table_header_row().
4667: '<th>'.&mt('Resources').'</th>'.
4668: "<th>$lt{'mr'}</th>".
4669: "<th>$lt{'ve'}</th>".
4670: "<th>$lt{'vu'}</th>".
4671: '<th>'.&mt('History').'</th>'.
4672: &Apache::loncommon::end_data_table_header_row()
4673: );
4674: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4675: foreach my $key (sort(@{$changedbytime{$chg}})) {
4676: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4677: my $currentversion=&Apache::lonnet::getversion($key);
4678: if ($currentversion<0) {
4679: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4680: }
4681: my $linkurl=&Apache::lonnet::clutter($key);
4682: $r->print(
4683: &Apache::loncommon::start_data_table_row().
4684: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4685: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4686: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4687: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4688: '<td align="right">'
4689: );
4690: # Used in course
4691: my $usedversion=$hash{'version_'.$linkurl};
4692: if (($usedversion) && ($usedversion ne 'mostrecent')) {
4693: if ($usedversion != $currentversion) {
4694: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
4695: } else {
4696: $r->print($usedversion);
4697: }
4698: } else {
4699: $r->print($currentversion);
4700: }
4701: $r->print('</td><td title="'.$lt{'vu'}.'">');
4702: # Set version
4703: $r->print(&Apache::loncommon::select_form(
4704: $setversions{$linkurl},
4705: 'set_version_'.$linkurl,
4706: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4707: '' => '',
4708: 'mostrecent' => &mt('most recent'),
4709: map {$_,$_} (1..$currentversion)},'',$readonly));
4710: my $lastold=1;
4711: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4712: my $url=$root.'.'.$prevvers.'.'.$extension;
4713: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4714: $lastold=$prevvers;
4715: }
4716: }
4717: $r->print('</td>');
4718: # List all available versions
4719: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4720: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4721: my $url=$root.'.'.$prevvers.'.'.$extension;
4722: $r->print(
4723: '<span class="LC_nobreak">'
4724: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4725: .&mt('Version [_1]',$prevvers).'</a>'
4726: .' ('.&Apache::lonlocal::locallocaltime(
4727: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4728: .')');
4729: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4730: $r->print(
4731: ' <a href="/adm/diff?filename='.
4732: &Apache::lonnet::clutter($root.'.'.$extension).
4733: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4734: '" target="diffs">'.&mt('Diffs').'</a>');
4735: }
4736: $r->print('</span><br />');
4737: }
4738: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
4739: }
4740: }
4741: $r->print(
4742: &Apache::loncommon::end_data_table().
4743: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
4744: '</form>'
4745: );
4746:
4747: &untiehash();
4748: $r->print(&endContentScreen());
4749: return;
4750: }
4751:
4752: sub mark_hash_old {
4753: my $retie_hash=0;
4754: if ($hashtied) {
4755: $retie_hash=1;
4756: &untiehash();
4757: }
4758: &tiehash('write');
4759: $hash{'old'}=1;
4760: &untiehash();
4761: if ($retie_hash) { &tiehash(); }
4762: }
4763:
4764: sub is_hash_old {
4765: my $untie_hash=0;
4766: if (!$hashtied) {
4767: $untie_hash=1;
4768: &tiehash();
4769: }
4770: my $return=$hash{'old'};
4771: if ($untie_hash) { &untiehash(); }
4772: return $return;
4773: }
4774:
4775: sub changewarning {
4776: my ($r,$postexec,$message,$url)=@_;
4777: if (!&is_hash_old()) { return; }
4778: my $pathvar='folderpath';
4779: my $path=&escape($env{'form.folderpath'});
4780: if (!defined($url)) {
4781: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4782: }
4783: my $course_type = &Apache::loncommon::course_type();
4784: if (!defined($message)) {
4785: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4786: }
4787: $r->print("\n\n".
4788: '<script type="text/javascript">'."\n".
4789: '// <![CDATA['."\n".
4790: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4791: '// ]]>'."\n".
4792: '</script>'."\n".
4793: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
4794: '<input type="hidden" name="orgurl" value="'.$url.
4795: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
4796: &mt($message,' <input type="hidden" name="'.
4797: $env{'request.role'}.'" value="1" /><input type="button" value="'.
4798: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
4799: $help{'Caching'}.'</p></form>'."\n\n");
4800: }
4801:
4802:
4803: sub init_breadcrumbs {
4804: my ($form,$text,$help)=@_;
4805: &Apache::lonhtmlcommon::clear_breadcrumbs();
4806: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
4807: text=>&Apache::loncommon::course_type().' Editor',
4808: faq=>273,
4809: bug=>'Instructor Interface',
4810: help => $help});
4811: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4812: text=>$text,
4813: faq=>273,
4814: bug=>'Instructor Interface'});
4815: }
4816:
4817: # subroutine to list form elements
4818: sub create_list_elements {
4819: my @formarr = @_;
4820: my $list = '';
4821: foreach my $button (@formarr){
4822: foreach my $picture (keys(%{$button})) {
4823: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
4824: }
4825: }
4826: return $list;
4827: }
4828:
4829: # subroutine to create ul from list elements
4830: sub create_form_ul {
4831: my $list = shift;
4832: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4833: return $ul;
4834: }
4835:
4836: #
4837: # Start tabs
4838: #
4839:
4840: sub startContentScreen {
4841: my ($mode) = @_;
4842: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
4843: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
4844: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4845: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4846: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4847: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4848: } else {
4849: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
4850: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4851: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4852: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4853: }
4854: $output .= "\n".'</ul>'."\n";
4855: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4856: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4857: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4858: return $output;
4859: }
4860:
4861: #
4862: # End tabs
4863: #
4864:
4865: sub endContentScreen {
4866: return '</div></div></div>';
4867: }
4868:
4869: sub supplemental_base {
4870: return 'supplemental&'.&escape(&mt('Supplemental Content'));
4871: }
4872:
4873: sub handler {
4874: my $r = shift;
4875: &Apache::loncommon::content_type($r,'text/html');
4876: $r->send_http_header;
4877: return OK if $r->header_only;
4878:
4879: # get course data
4880: my $crstype = &Apache::loncommon::course_type();
4881: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4882: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4883:
4884: # get docroot
4885: my $londocroot = $r->dir_config('lonDocRoot');
4886:
4887: # graphics settings
4888: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
4889:
4890: #
4891: # --------------------------------------------- Initialize help topics for this
4892: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4893: 'Adding_External_Resource','Navigate_Content',
4894: 'Adding_Folders','Docs_Overview', 'Load_Map',
4895: 'Supplemental','Score_Upload_Form','Adding_Pages',
4896: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
4897: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4898: 'Dropbox','Simple_Problem') {
4899: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4900: }
4901: # Composite help files
4902: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4903: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4904: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4905: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4906: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4907: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
4908: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
4909: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
4910: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
4911: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
4912:
4913: my ($allowed,$canedit,$canview,$noendpage,$disabled);
4914: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4915: unless ($r->uri eq '/adm/supplemental') {
4916: # does this user have privileges to modify content.
4917: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4918: $allowed = 1;
4919: $canedit = 1;
4920: $canview = 1;
4921: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4922: $allowed = 1;
4923: $canview = 1;
4924: }
4925: }
4926: unless ($canedit) {
4927: $disabled = ' disabled="disabled"';
4928: }
4929: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4930: if ($allowed && $env{'form.verify'}) {
4931: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
4932: &verifycontent($r);
4933: } elsif ($allowed && $env{'form.listsymbs'}) {
4934: &init_breadcrumbs('listsymbs','List Content IDs');
4935: &list_symbs($r);
4936: } elsif ($allowed && $env{'form.docslog'}) {
4937: &init_breadcrumbs('docslog','Show Log');
4938: my $folder = $env{'form.folder'};
4939: if ($folder eq '') {
4940: $folder='default';
4941: }
4942: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
4943: } elsif ($allowed && $env{'form.versions'}) {
4944: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
4945: &checkversions($r,$canedit);
4946: } elsif ($canedit && $env{'form.dumpcourse'}) {
4947: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
4948: &dumpcourse($r);
4949: } elsif ($canedit && $env{'form.exportcourse'}) {
4950: &init_breadcrumbs('exportcourse','IMS Export');
4951: &Apache::imsexport::exportcourse($r);
4952: } else {
4953: if ($canedit && $env{'form.authorrole'}) {
4954: $noendpage = 1;
4955: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
4956: if ($redirect) {
4957: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
4958: my $container = 'sequence';
4959: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4960: $is_random_order,$container) =
4961: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4962: my (@folders)=split('&',$env{'form.folderpath'});
4963: $env{'form.foldername'}=&unescape(pop(@folders));
4964: my $folder=pop(@folders);
4965: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4966: $folder.'.'.$container);
4967: my $warning;
4968: if ($fatal) {
4969: if ($container eq 'page') {
4970: $warning = &mt('An error occurred retrieving the contents of the current page.');
4971: } else {
4972: $warning = &mt('An error occurred retrieving the contents of the current folder.');
4973: }
4974: } else {
4975: my $url = $redirect;
4976: my $srcfile = $londocroot.$url;
4977: $url =~ s{^/priv/}{/res/};
4978: my $targetfile = $londocroot.$url;
4979: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
4980: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
4981: $env{'form.folder'} = $folder;
4982: &snapshotbefore();
4983: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
4984: my $ext = 'false';
4985: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
4986: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
4987: ':'.$ext.':normal:res';
4988: push(@LONCAPA::map::order,$newidx);
4989: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
4990: 'string_yesno');
4991: &remember_parms($newidx,'hiddenresource','set','yes');
4992: ($errtext,$fatal) =
4993: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
4994: &log_differences($plain);
4995: &mark_hash_old();
4996: $r->internal_redirect($redirect);
4997: return OK;
4998: }
4999: }
5000: }
5001: }
5002: #
5003: # Done catching special calls
5004: # The whole rest is for course and supplemental documents and utilities menu
5005: # Get the parameters that may be needed
5006: #
5007: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5008: ['folderpath',
5009: 'forcesupplement','forcestandard',
5010: 'tools','symb','command','supppath']);
5011:
5012: # standard=1: this is a "new-style" course with an uploaded map as top level
5013: # standard=2: this is a "old-style" course, and there is nothing we can do
5014:
5015: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5016:
5017: # Decide whether this should display supplemental or main content or utilities
5018: # supplementalflag=1: show supplemental documents
5019: # supplementalflag=0: show standard documents
5020: # toolsflag=1: show utilities
5021:
5022: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5023: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5024: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5025: $supplementalflag=0;
5026: }
5027: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5028: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5029: unless ($allowed) { $supplementalflag=1; }
5030: unless ($standard) { $supplementalflag=1; }
5031: my $toolsflag=0;
5032: if ($env{'form.tools'}) { $toolsflag=1; }
5033:
5034: my $script='';
5035: my $showdoc=0;
5036: my $addentries = {};
5037: my $container;
5038: my $containertag;
5039: my $pathitem;
5040: my %ltitools;
5041:
5042: # Do we directly jump somewhere?
5043:
5044: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5045: if ($env{'form.symb'} ne '') {
5046: $env{'form.folderpath'}=
5047: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
5048: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5049: $env{'form.command'}.'_'.$env{'form.symb'}});
5050: } elsif ($env{'form.supppath'} ne '') {
5051: $env{'form.folderpath'}=$env{'form.supppath'};
5052: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5053: $env{'form.command'}.'_'.$env{'form.supppath'}});
5054: }
5055: } elsif ($env{'form.command'} eq 'editdocs') {
5056: $env{'form.folderpath'} = 'default&'.
5057: &escape(&mt('Main Content').':::::');
5058: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5059: } elsif ($env{'form.command'} eq 'editsupp') {
5060: $env{'form.folderpath'} = 'supplemental&'.
5061: &escape('Supplemental Content');
5062: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5063: } elsif ($env{'form.command'} eq 'contents') {
5064: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5065: } elsif ($env{'form.command'} eq 'home') {
5066: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5067: }
5068:
5069:
5070: # Where do we store these for when we come back?
5071: my $stored_folderpath='docs_folderpath';
5072: if ($supplementalflag) {
5073: $stored_folderpath='docs_sup_folderpath';
5074: }
5075:
5076: # No folderpath, and in edit mode, see if we have something stored
5077: if ((!$env{'form.folderpath'}) && $allowed) {
5078: &Apache::loncommon::restore_course_settings($stored_folderpath,
5079: {'folderpath' => 'scalar'});
5080: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5081: undef($env{'form.folderpath'});
5082: }
5083: }
5084:
5085: # If we are not allowed to make changes, all we can see are supplemental docs
5086: if (!$allowed) {
5087: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5088: $env{'form.folderpath'} = &supplemental_base();
5089: }
5090: }
5091: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5092: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5093: $env{'form.folderpath'} = &supplemental_base()
5094: .'&'.
5095: $env{'form.folderpath'};
5096: }
5097: # If after all of this, we still don't have any paths, make them
5098: unless ($env{'form.folderpath'}) {
5099: if ($supplementalflag) {
5100: $env{'form.folderpath'}=&supplemental_base();
5101: } else {
5102: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
5103: ':::::');
5104: }
5105: }
5106:
5107: # Store this
5108: unless ($toolsflag) {
5109: if ($allowed) {
5110: &Apache::loncommon::store_course_settings($stored_folderpath,
5111: {'folderpath' => 'scalar'});
5112: }
5113: my $folderpath;
5114: if ($env{'form.folderpath'}) {
5115: $folderpath = $env{'form.folderpath'};
5116: my (@folders)=split('&',$env{'form.folderpath'});
5117: $env{'form.foldername'}=&unescape(pop(@folders));
5118: if ($env{'form.foldername'} =~ /\:1$/) {
5119: $container = 'page';
5120: } else {
5121: $container = 'sequence';
5122: }
5123: $env{'form.folder'}=pop(@folders);
5124: } else {
5125: if ($env{'form.folder'} eq '' ||
5126: $env{'form.folder'} eq 'supplemental') {
5127: $folderpath='default&'.
5128: &escape(&mt('Main Content').':::::');
5129: }
5130: }
5131: $containertag = '<input type="hidden" name="folderpath" value="" />';
5132: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5133: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5134: $showdoc='/'.$1;
5135: }
5136: if ($showdoc) { # got called in sequence from course
5137: $allowed=0;
5138: } else {
5139: if ($canedit) {
5140: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5141: $script=&Apache::lonratedt::editscript('simple');
5142: }
5143: }
5144: }
5145:
5146: # get personal data
5147: my $uname=$env{'user.name'};
5148: my $udom=$env{'user.domain'};
5149: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5150:
5151: if ($allowed) {
5152: if ($toolsflag) {
5153: $script .= &inject_data_js();
5154: my ($home,$other,%outhash)=&authorhosts();
5155: if (!$home && $other) {
5156: my @hosts;
5157: foreach my $aurole (keys(%outhash)) {
5158: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5159: push(@hosts,$outhash{$aurole});
5160: }
5161: }
5162: $script .= &dump_switchserver_js(@hosts);
5163: }
5164: } else {
5165: my $tid = 1;
5166: my @tabids;
5167: if ($supplementalflag) {
5168: @tabids = ('002','ee2','ff2');
5169: $tid = 2;
5170: } else {
5171: @tabids = ('aa1','bb1','cc1','ff1');
5172: unless ($env{'form.folderpath'} =~ /\:1$/) {
5173: unshift(@tabids,'001');
5174: push(@tabids,('dd1','ee1'));
5175: }
5176: }
5177: my $tabidstr = join("','",@tabids);
5178: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
5179: my $posslti = keys(%ltitools);
5180: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5181: $londocroot,$canedit).
5182: &history_tab_js().
5183: &inject_data_js().
5184: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5185: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5186: $addentries = {
5187: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5188: };
5189: }
5190: $script .= &paste_popup_js();
5191: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5192: &mt('Switch server?');
5193:
5194:
5195: }
5196: # -------------------------------------------------------------------- Body tag
5197: $script = '<script type="text/javascript">'."\n"
5198: .'// <![CDATA['."\n"
5199: .$script."\n"
5200: .'// ]]>'."\n"
5201: .'</script>'."\n"
5202: .'<script type="text/javascript"
5203: src="/res/adm/includes/file_upload.js"></script>'."\n";
5204:
5205: # Breadcrumbs
5206: &Apache::lonhtmlcommon::clear_breadcrumbs();
5207:
5208: if ($showdoc) {
5209: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5210: {'force_register' => $showdoc,}));
5211: } elsif ($toolsflag) {
5212: my ($breadtext,$breadtitle);
5213: $breadtext = "$crstype Contents";
5214: if ($canedit) {
5215: $breadtitle = 'Editing '.$crstype.' Contents';
5216: } else {
5217: $breadtext .= ' (View-only mode)';
5218: $breadtitle = 'Viewing '.$crstype.' Contents';
5219: }
5220: &Apache::lonhtmlcommon::add_breadcrumb({
5221: href=>"/adm/coursedocs",text=>$breadtext});
5222: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5223: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5224: .&Apache::lonhtmlcommon::breadcrumbs(
5225: $breadtitle)
5226: );
5227: } elsif ($r->uri eq '/adm/supplemental') {
5228: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5229: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5230: {'bread_crumbs' => $brcrum,}));
5231: } else {
5232: my ($breadtext,$breadtitle,$helpitem);
5233: $breadtext = "$crstype Contents";
5234: if ($canedit) {
5235: $breadtitle = 'Editing '.$crstype.' Contents';
5236: $helpitem = 'Docs_Adding_Course_Doc';
5237: } else {
5238: $breadtext .= ' (View-only mode)';
5239: $breadtitle = 'Viewing '.$crstype.' Contents';
5240: $helpitem = 'Docs_Viewing_Course_Doc';
5241: }
5242: &Apache::lonhtmlcommon::add_breadcrumb({
5243: href=>"/adm/coursedocs",text=>$breadtext});
5244: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5245: {'add_entries' => $addentries}
5246: )
5247: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5248: .&Apache::lonhtmlcommon::breadcrumbs(
5249: $breadtitle,
5250: $helpitem)
5251: );
5252: }
5253:
5254: my %allfiles = ();
5255: my %codebase = ();
5256: my ($upload_result,$upload_output,$uploadphase);
5257: if ($canedit) {
5258: if (($env{'form.uploaddoc.filename'}) &&
5259: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5260: my $context = $1;
5261: # Process file upload - phase one - upload and parse primary file.
5262: undef($hadchanges);
5263: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5264: \%allfiles,\%codebase,$context,$crstype);
5265: if ($hadchanges) {
5266: &mark_hash_old();
5267: }
5268: $r->print($upload_output);
5269: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5270: # Process file upload - phase two - upload embedded objects
5271: $uploadphase = 'check_embedded';
5272: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5273: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5274: $env{'form.newidx'});
5275: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5276: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5277: my ($destination,$dir_root) = &embedded_destination();
5278: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5279: my $actionurl = '/adm/coursedocs';
5280: my ($result,$flag) =
5281: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5282: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5283: $actionurl);
5284: $r->print($result.&return_to_editor());
5285: } elsif ($env{'form.phase'} eq 'check_embedded') {
5286: # Process file upload - phase three - modify references in HTML file
5287: $uploadphase = 'modified_orightml';
5288: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5289: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5290: my ($destination,$dir_root) = &embedded_destination();
5291: my $result =
5292: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5293: $docuname,$docudom,undef,
5294: $dir_root);
5295: $r->print($result.&return_to_editor());
5296: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5297: $uploadphase = 'decompress_phase_one';
5298: $r->print(&decompression_phase_one().
5299: &return_to_editor());
5300: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5301: $uploadphase = 'decompress_phase_two';
5302: $r->print(&decompression_phase_two().
5303: &return_to_editor());
5304: }
5305: }
5306:
5307: if ($allowed && $toolsflag) {
5308: $r->print(&startContentScreen('tools'));
5309: $r->print(&generate_admin_menu($crstype,$canedit));
5310: $r->print(&endContentScreen());
5311: } elsif ((!$showdoc) && (!$uploadphase)) {
5312: # -----------------------------------------------------------------------------
5313: my %lt=&Apache::lonlocal::texthash(
5314: 'copm' => 'All documents out of a published map into this folder',
5315: 'upfi' => 'Upload File',
5316: 'upld' => 'Upload Content',
5317: 'srch' => 'Search',
5318: 'impo' => 'Import',
5319: 'lnks' => 'Import from Stored Links',
5320: 'impm' => 'Import from Assembled Map',
5321: 'imcr' => 'Import from Course Resources',
5322: 'extr' => 'External Resource',
5323: 'extt' => 'External Tool',
5324: 'selm' => 'Select Map',
5325: 'load' => 'Load Map',
5326: 'newf' => 'New Folder',
5327: 'newp' => 'New Composite Page',
5328: 'syll' => 'Syllabus',
5329: 'navc' => 'Table of Contents',
5330: 'sipa' => 'Simple Course Page',
5331: 'sipr' => 'Simple Problem',
5332: 'webp' => 'Blank Web Page (editable)',
5333: 'stpr' => 'Standard Problem',
5334: 'news' => 'New sub-directory',
5335: 'crpr' => 'Create Problem',
5336: 'drbx' => 'Drop Box',
5337: 'scuf' => 'External Scores (handgrade, upload, clicker)',
5338: 'bull' => 'Discussion Board',
5339: 'mypi' => 'My Personal Information Page',
5340: 'grpo' => 'Group Portfolio',
5341: 'rost' => 'Course Roster',
5342: 'abou' => 'Personal Information Page for a User',
5343: 'imsf' => 'IMS Upload',
5344: 'imsl' => 'Upload IMS package',
5345: 'cms' => 'Origin of IMS package',
5346: 'se' => 'Select',
5347: 'file' => 'File',
5348: 'title' => 'Title',
5349: 'addp' => 'Add Placeholder to course?',
5350: 'uste' => 'Use Template?',
5351: 'fnam' => 'File Name:',
5352: 'loca' => 'Location:',
5353: 'dire' => 'Directory:',
5354: 'cate' => 'Category:',
5355: 'tmpl' => 'Template:',
5356: 'comment' => 'Comment',
5357: 'parse' => 'Upload embedded images/multimedia files if HTML file',
5358: 'bb5' => 'Blackboard 5',
5359: 'bb6' => 'Blackboard 6',
5360: 'angel5' => 'ANGEL 5.5',
5361: 'webctce4' => 'WebCT 4 Campus Edition',
5362: 'yes' => 'Yes',
5363: 'no' => 'No',
5364: 'er' => 'Editing rights unavailable for your current role',
5365: );
5366: # -----------------------------------------------------------------------------
5367:
5368: # Calculate free quota space for a user or course. A javascript function checks
5369: # file size to determine if upload should be allowed.
5370: my $quotatype = 'unofficial';
5371: if ($crstype eq 'Community') {
5372: $quotatype = 'community';
5373: } elsif ($crstype eq 'Placement') {
5374: $quotatype = 'placement';
5375: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5376: $quotatype = 'official';
5377: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5378: $quotatype = 'textbook';
5379: }
5380: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5381: 'course',$quotatype); # expressed in MB
5382: my $current_disk_usage = 0;
5383: foreach my $subdir ('docs','supplemental') {
5384: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5385: "userfiles/$subdir",1); # expressed in kB
5386: }
5387: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5388: my $usage = $current_disk_usage/1024; # in MB
5389: my $quota = $disk_quota;
5390: my $percent;
5391: if ($disk_quota == 0) {
5392: $percent = 100.0;
5393: } else {
5394: $percent = 100*($current_disk_usage/$disk_quota);
5395: }
5396: $usage = sprintf("%.2f",$usage);
5397: $quota = sprintf("%.2f",$quota);
5398: $percent = sprintf("%.0f",$percent);
5399: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5400: $percent.'%',$quota.' MB').'</p>';
5401:
5402: my $fileupload=(<<FIUP);
5403: $quotainfo
5404: $lt{'file'}:<br />
5405: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
5406: <input type="hidden" id="free_space" value="$free_space" />
5407: FIUP
5408:
5409: my $checkbox=(<<CHBO);
5410: <!-- <label>$lt{'parse'}?
5411: <input type="checkbox" name="parserflag" />
5412: </label> -->
5413: <label>
5414: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
5415: </label>
5416: CHBO
5417: my $imsfolder = $env{'form.folder'};
5418: if ($imsfolder eq '') {
5419: $imsfolder = 'default';
5420: }
5421: my $imspform=(<<IMSFORM);
5422: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5423: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5424: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
5425: <fieldset id="uploadimsform" style="display: none;">
5426: <legend>$lt{'imsf'}</legend>
5427: $fileupload
5428: <br />
5429: <p>
5430: $lt{'cms'}:
5431: <select name="source" $disabled>
5432: <option value="-1" selected="selected">$lt{'se'}</option>
5433: <option value="bb5">$lt{'bb5'}</option>
5434: <option value="bb6">$lt{'bb6'}</option>
5435: <option value="angel5">$lt{'angel5'}</option>
5436: <option value="webctce4">$lt{'webctce4'}</option>
5437: </select>
5438: <input type="hidden" name="folder" value="$imsfolder" />
5439: </p>
5440: <input type="hidden" name="phase" value="one" />
5441: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
5442: </fieldset>
5443: </form>
5444: IMSFORM
5445:
5446: my $fileuploadform=(<<FUFORM);
5447: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5448: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5449: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
5450: <fieldset id="uploaddocform" style="display: none;">
5451: <legend>$lt{'upfi'}</legend>
5452: <input type="hidden" name="active" value="aa" />
5453: $fileupload
5454: <br />
5455: $lt{'title'}:<br />
5456: <input type="text" size="60" name="comment" $disabled />
5457: $pathitem
5458: <input type="hidden" name="cmd" value="upload_default" />
5459: <br />
5460: <span class="LC_nobreak" style="float:left">
5461: $checkbox
5462: </span>
5463: <br clear="all" />
5464: <input type="submit" value="$lt{'upld'}" $disabled />
5465: </fieldset>
5466: </form>
5467: FUFORM
5468:
5469: my $mapimportjs;
5470: if ($canedit) {
5471: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5472: } else {
5473: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5474: }
5475: my $importpubform=(<<SEDFFORM);
5476: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
5477: $lt{'impm'}</a>$help{'Load_Map'}
5478: <form action="/adm/coursedocs" method="post" name="mapimportform">
5479: <fieldset id="importmapform" style="display: none;">
5480: <legend>$lt{'impm'}</legend>
5481: <input type="hidden" name="active" value="bb" />
5482: $lt{'copm'}<br />
5483: <span class="LC_nobreak">
5484: <input type="text" name="importmap" size="40" value=""
5485: onfocus="this.blur();$mapimportjs" $disabled />
5486: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5487: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
5488: </fieldset>
5489: </form>
5490:
5491: SEDFFORM
5492: my $importcrsresform;
5493: my ($numdirs,$pickfile) =
5494: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5495: "resize_scrollbox('contentscroll','1','0');",
5496: undef,'res');
5497: if ($pickfile) {
5498: $importcrsresform=(<<CRSFORM);
5499: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5500: $lt{'imcr'}</a>$help{'Course_Resources'}
5501: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5502: <fieldset id="importcrsresform" style="display: none;">
5503: <legend>$lt{'imcr'}</legend>
5504: <input type="hidden" name="active" value="bb" />
5505: $pickfile
5506: <p>
5507: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
5508: </p>
5509: <input type="hidden" name="importdetail" value="" />
5510: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
5511: </fieldset>
5512: </form>
5513: CRSFORM
5514: }
5515:
5516: my $fromstoredjs;
5517: if ($canedit) {
5518: $fromstoredjs = 'open_StoredLinks_Import()';
5519: } else {
5520: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5521: }
5522:
5523: my @importpubforma = (
5524: { '<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>" },
5525: { '<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'}" },
5526: { '<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>' },
5527: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5528: );
5529: if ($pickfile) {
5530: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5531: }
5532: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5533: my $extresourcesform =
5534: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5535: $help{'Adding_External_Resource'},
5536: undef,undef,undef,undef,undef,undef,$disabled);
5537: my $exttoolform =
5538: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5539: $help{'Adding_External_Tool'},undef,
5540: undef,'tool',$coursedom,$coursenum,
5541: \%ltitools,$disabled);
5542: if ($allowed) {
5543: my $folder = $env{'form.folder'};
5544: if ($folder eq '') {
5545: $folder='default';
5546: }
5547: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5548: if ($output) {
5549: $r->print($output);
5550: }
5551: $r->print(<<HIDDENFORM);
5552: <form name="renameform" method="post" action="/adm/coursedocs">
5553: <input type="hidden" name="title" />
5554: <input type="hidden" name="cmd" />
5555: <input type="hidden" name="markcopy" />
5556: <input type="hidden" name="copyfolder" />
5557: $containertag
5558: </form>
5559:
5560: HIDDENFORM
5561: $r->print(&makesimpleeditform($pathitem)."\n".
5562: &makedocslogform($pathitem."\n".
5563: '<input type="hidden" name="folder" value="'.
5564: $env{'form.folder'}.'" />'."\n"));
5565: }
5566:
5567: # Generate the tabs
5568: my ($mode,$needs_end);
5569: if (($supplementalflag) && (!$allowed)) {
5570: my @folders = split('&',$env{'form.folderpath'});
5571: unless (@folders > 2) {
5572: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5573: $needs_end = 1;
5574: }
5575: } else {
5576: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
5577: $needs_end = 1;
5578: }
5579:
5580: #
5581:
5582: my $savefolderpath;
5583:
5584: if ($allowed) {
5585: my $folder=$env{'form.folder'};
5586: if ($folder eq '' || $supplementalflag) {
5587: $folder='default';
5588: $savefolderpath = $env{'form.folderpath'};
5589: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
5590: $pathitem = '<input type="hidden" name="folderpath" value="'.
5591: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5592: }
5593: my $postexec='';
5594: if ($folder eq 'default') {
5595: $r->print('<script type="text/javascript">'."\n"
5596: .'// <![CDATA['."\n"
5597: .'this.window.name="loncapaclient";'."\n"
5598: .'// ]]>'."\n"
5599: .'</script>'."\n"
5600: );
5601: } else {
5602: #$postexec='self.close();';
5603: }
5604: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5605: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
5606: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5607:
5608: my $newnavform=(<<NNFORM);
5609: <form action="/adm/coursedocs" method="post" name="newnav">
5610: <input type="hidden" name="active" value="ee" />
5611: $pathitem
5612: <input type="hidden" name="importdetail"
5613: value="$lt{'navc'}=/adm/navmaps" />
5614: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
5615: $help{'Navigate_Content'}
5616: </form>
5617: NNFORM
5618: my $newsmppageform=(<<NSPFORM);
5619: <form action="/adm/coursedocs" method="post" name="newsmppg">
5620: <input type="hidden" name="active" value="ee" />
5621: $pathitem
5622: <input type="hidden" name="importdetail" value="" />
5623: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
5624: $help{'Simple Page'}
5625: </form>
5626: NSPFORM
5627:
5628: my $newsmpproblemform=(<<NSPROBFORM);
5629: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
5630: <input type="hidden" name="active" value="cc" />
5631: $pathitem
5632: <input type="hidden" name="importdetail" value="" />
5633: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
5634: $help{'Simple_Problem'}
5635: </form>
5636:
5637: NSPROBFORM
5638:
5639: my $newdropboxform=(<<NDBFORM);
5640: <form action="/adm/coursedocs" method="post" name="newdropbox">
5641: <input type="hidden" name="active" value="cc" />
5642: $pathitem
5643: <input type="hidden" name="importdetail" value="" />
5644: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
5645: $help{'Dropbox'}
5646: </form>
5647: NDBFORM
5648:
5649: my $newexuploadform=(<<NEXUFORM);
5650: <form action="/adm/coursedocs" method="post" name="newexamupload">
5651: <input type="hidden" name="active" value="cc" />
5652: $pathitem
5653: <input type="hidden" name="importdetail" value="" />
5654: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
5655: $help{'Score_Upload_Form'}
5656: </form>
5657: NEXUFORM
5658:
5659: my $newbulform=(<<NBFORM);
5660: <form action="/adm/coursedocs" method="post" name="newbul">
5661: <input type="hidden" name="active" value="dd" />
5662: $pathitem
5663: <input type="hidden" name="importdetail" value="" />
5664: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
5665: $help{'Bulletin Board'}
5666: </form>
5667: NBFORM
5668:
5669: my $newaboutmeform=(<<NAMFORM);
5670: <form action="/adm/coursedocs" method="post" name="newaboutme">
5671: <input type="hidden" name="active" value="dd" />
5672: $pathitem
5673: <input type="hidden" name="importdetail"
5674: value="$plainname=/adm/$udom/$uname/aboutme" />
5675: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
5676: $help{'My Personal Information Page'}
5677: </form>
5678: NAMFORM
5679:
5680: my $newaboutsomeoneform=(<<NASOFORM);
5681: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
5682: <input type="hidden" name="active" value="dd" />
5683: $pathitem
5684: <input type="hidden" name="importdetail" value="" />
5685: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
5686: </form>
5687: NASOFORM
5688:
5689: my $newrosterform=(<<NROSTFORM);
5690: <form action="/adm/coursedocs" method="post" name="newroster">
5691: <input type="hidden" name="active" value="dd" />
5692: $pathitem
5693: <input type="hidden" name="importdetail"
5694: value="$lt{'rost'}=/adm/viewclasslist" />
5695: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
5696: $help{'Course_Roster'}
5697: </form>
5698: NROSTFORM
5699:
5700: my $newwebpage;
5701: if ($folder =~ /^default_?(\d*)$/) {
5702: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5703: if ($1) {
5704: $newwebpage .= $1;
5705: } else {
5706: $newwebpage .= 'default';
5707: }
5708: $newwebpage .= '/new.html';
5709: }
5710: my $newwebpageform =(<<NWEBFORM);
5711: <form action="/adm/coursedocs" method="post" name="newwebpage">
5712: <input type="hidden" name="active" value="ee" />
5713: $pathitem
5714: <input type="hidden" name="importdetail" value="$newwebpage" />
5715: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
5716: $help{'Web_Page'}
5717: </form>
5718: NWEBFORM
5719:
5720: my @ids=&Apache::lonnet::current_machine_ids();
5721: my %select_menus;
5722: my $numauthor = 0;
5723: my $numcrsdirs = 0;
5724: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5725: if ($env{'user.author'}) {
5726: $numauthor ++;
5727: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5728: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5729: my $is_home = 1;
5730: my %subdirs;
5731: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5732: $select_menus{'author'}->{'default'} = '/';
5733: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5734: my @ordered = ('/');
5735: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5736: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5737: push(@ordered,$relpath);
5738: }
5739: $select_menus{'author'}->{'order'} = \@ordered;
5740: } else {
5741: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5742: $select_menus{'author'}->{'default'} = 'switch';
5743: $select_menus{'author'}->{'order'} = ['switch'];
5744: }
5745: }
5746: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5747: ['active'],['ca','aa']);
5748: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5749: my %by_roletype;
5750: if (keys(%roleshash)) {
5751: foreach my $entry (keys(%roleshash)) {
5752: my ($auname,$audom,$roletype) = split(/:/,$entry);
5753: my $key = $entry;
5754: $key =~ s/:/___/g;
5755: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5756: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5757: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5758: if (grep(/^\Q$rolehome\E$/,@ids)) {
5759: my $is_home = 1;
5760: my (%subdirs,@ordered);
5761: my $toppath="/priv/$audom/$auname";
5762: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5763: $select_menus{$key}->{'default'} = '/';
5764: $select_menus{$key}->{'select2'}->{'/'} = '/';
5765: my @ordered = ('/');
5766: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5767: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5768: push(@ordered,$relpath);
5769: }
5770: $select_menus{$key}->{'order'} = \@ordered;
5771: } else {
5772: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5773: $select_menus{$key}->{'default'} = 'switch';
5774: $select_menus{$key}->{'order'} = ['switch'];
5775: }
5776: $numauthor ++;
5777: }
5778: }
5779: my ($pickdir,$showtitle);;
5780: if ($numauthor) {
5781: my @order;
5782: my $defrole;
5783: if ($env{'user.author'}) {
5784: push(@order,'author');
5785: $defrole = 'author';
5786: }
5787: if (keys(%by_roletype)) {
5788: foreach my $possrole ('ca','aa') {
5789: if (ref($by_roletype{$possrole}) eq 'HASH') {
5790: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5791: unless ($defrole) {
5792: $defrole = $author;
5793: }
5794: push(@order,$author.'___'.$possrole);
5795: }
5796: }
5797: }
5798: }
5799: $select_menus{'course'}->{'text'} = &mt('Course Resource');
5800: if (grep(/^\Q$crshome\E$/,@ids)) {
5801: my $is_home = 1;
5802: my %subdirs;
5803: my $toppath="/priv/$coursedom/$coursenum";
5804: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5805: $numcrsdirs = keys(%subdirs);
5806: $select_menus{'course'}->{'default'} = '/';
5807: $select_menus{'course'}->{'select2'}->{'/'} = '/';
5808: my @ordered = ('/');
5809: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5810: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
5811: push(@ordered,$relpath);
5812: }
5813: $select_menus{'course'}->{'order'} = \@ordered;
5814: } else {
5815: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
5816: $select_menus{'course'}->{'default'} = 'switch';
5817: $select_menus{'course'}->{'order'} = ['switch'];
5818: }
5819: push(@order,'course');
5820: $pickdir = $lt{'loca'}.
5821: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
5822: $defrole,'authorrole','authorpath',
5823: \%select_menus,\@order,'toggleCrsResTitle();',
5824: '','priv').'<br />';
5825: $showtitle = 'none';
5826: } else {
5827: my $is_home;
5828: $showtitle = 'inline';
5829: if (grep(/^\Q$crshome\E$/,@ids)) {
5830: $is_home = 1;
5831: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
5832: my $toppath="/priv/$coursedom/$coursenum'}";
5833: my %subdirs;
5834: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
5835: $numcrsdirs = keys(%subdirs);
5836: if ($numcrsdirs) {
5837: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
5838: '<option value="/">/</option>'."\n";
5839: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5840: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
5841: }
5842: $pickdir .= '</select>';
5843: } else {
5844: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
5845: }
5846: }
5847: }
5848:
5849: my %seltemplate_menus;
5850: my @files = &Apache::lonhomework::get_template_list('problem');
5851: my @noexamplelink = ('blank.problem','blank.library','script.library');
5852: my $currentcategory = '';
5853: my @ordered = ('');
5854: my %templatehelp;
5855: my $defcategory = '';
5856: my @catorder = ($defcategory);
5857: $seltemplate_menus{$defcategory}->{'order'} = [''];
5858: $seltemplate_menus{$defcategory}->{'text'} = '';
5859: foreach my $file (@files) {
5860: if (ref($file) eq 'ARRAY') {
5861: my ($path,$title,$category,$help) = @{$file};
5862: next if ($title !~ /\S/);
5863: if (&js_escape($category) ne $currentcategory) {
5864: $currentcategory = &js_escape($category);
5865: push(@catorder,&js_escape($currentcategory));
5866: $seltemplate_menus{$currentcategory}->{'text'} = $category;
5867: $seltemplate_menus{$currentcategory}->{'default'} = '';
5868: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
5869: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
5870: }
5871: if ($path) {
5872: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
5873: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
5874: if ($help) {
5875: $templatehelp{$path} = $help;
5876: }
5877: }
5878: }
5879: }
5880:
5881: my $templates = $lt{'cate'}.' '.
5882: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
5883: $defcategory,'tempcategory','template',
5884: \%seltemplate_menus,\@catorder,
5885: "resize_scrollbox('contentscroll','1','0');",
5886: "toggleExampleText();",'template').'<br />';
5887: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
5888: '<span id="newresexample">'.&mt('Example').'<span></a>';
5889: my $crsresform=(<<RESFORM);
5890: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
5891: $lt{'stpr'}</a>$help{'Course_Resource'}
5892: <form action="/adm/coursedocs" method="post" name="courseresform">
5893: <fieldset id="crsresform" style="display:none;">
5894: <legend>$lt{'stpr'}</legend>
5895: <input type="hidden" name="active" value="ee" />
5896: <p>
5897: $pickdir
5898: <span class="LC_nobreak">$lt{'news'}?
5899: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
5900:
5901: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
5902: </span><span id="newsubdir"></span>
5903: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
5904: </p>
5905: $lt{'fnam'}
5906: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
5907: <p>
5908: <div id="newresource" style="display:$showtitle">
5909: $lt{'addp'}
5910: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
5911: $lt{'no'}</label>
5912: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
5913: $lt{'yes'}</label>
5914: <span id="newrestitle"></span>
5915: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
5916: </div>
5917: </p>
5918: <p>
5919: $lt{'uste'}
5920: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
5921: $lt{'no'}</label>
5922: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
5923: $lt{'yes'}</label>
5924: <div id="newrestemplate" style="display:none">
5925: $templates
5926: $templatepreview
5927: </div>
5928: </p>
5929: <span class="LC_nobreak">
5930: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
5931: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
5932: </span>
5933: </fieldset>
5934: </form>
5935:
5936: RESFORM
5937:
5938: my $specialdocumentsform;
5939: my @specialdocumentsforma;
5940: my $gradingform;
5941: my @gradingforma;
5942: my $communityform;
5943: my @communityforma;
5944: my $newfolderform;
5945: my $newfolderb;
5946:
5947: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5948:
5949: my $newpageform=(<<NPFORM);
5950: <form action="/adm/coursedocs" method="post" name="newpage">
5951: <input type="hidden" name="folderpath" value="$path" />
5952: <input type="hidden" name="importdetail" value="" />
5953: <input type="hidden" name="active" value="ee" />
5954: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
5955: $help{'Adding_Pages'}
5956: </form>
5957: NPFORM
5958:
5959:
5960: $newfolderform=(<<NFFORM);
5961: <form action="/adm/coursedocs" method="post" name="newfolder">
5962: $pathitem
5963: <input type="hidden" name="importdetail" value="" />
5964: <input type="hidden" name="active" value="" />
5965: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
5966: </form>
5967: NFFORM
5968:
5969: my $newsylform=(<<NSYLFORM);
5970: <form action="/adm/coursedocs" method="post" name="newsyl">
5971: <input type="hidden" name="active" value="ee" />
5972: $pathitem
5973: <input type="hidden" name="importdetail"
5974: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
5975: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
5976: $help{'Syllabus'}
5977:
5978: </form>
5979: NSYLFORM
5980:
5981: my $newgroupfileform=(<<NGFFORM);
5982: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
5983: <input type="hidden" name="active" value="dd" />
5984: $pathitem
5985: <input type="hidden" name="importdetail"
5986: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
5987: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
5988: $help{'Group Portfolio'}
5989: </form>
5990: NGFFORM
5991: @specialdocumentsforma=(
5992: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
5993: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="makenew(document.newsyl);" />'=>$newsylform},
5994: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
5995: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
5996: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
5997: );
5998: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5999:
6000:
6001: my @importdoc = (
6002: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6003: );
6004: if (keys(%ltitools)) {
6005: push(@importdoc,
6006: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6007: );
6008: }
6009: unless ($container eq 'page') {
6010: push(@importdoc,
6011: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6012: );
6013: }
6014: push(@importdoc,
6015: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6016: );
6017: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6018:
6019: @gradingforma=(
6020: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6021: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6022: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6023: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6024: );
6025: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6026:
6027: @communityforma=(
6028: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6029: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6030: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6031: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6032: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6033: );
6034: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6035:
6036: my %orderhash = (
6037: 'aa' => ['Upload',$fileuploadform],
6038: 'bb' => ['Import',$importpubform],
6039: 'cc' => ['Grading',$gradingform],
6040: );
6041: unless ($container eq 'page') {
6042: $orderhash{'00'} = ['Newfolder',$newfolderform];
6043: $orderhash{'dd'} = ['Collaboration',$communityform];
6044: $orderhash{'ee'} = ['Other',$specialdocumentsform];
6045: }
6046:
6047: $hadchanges=0;
6048: unless (($supplementalflag || $toolsflag)) {
6049: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6050: $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools,$canedit);
6051: if ($error) {
6052: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6053: }
6054: if ($hadchanges) {
6055: &mark_hash_old();
6056: }
6057:
6058: &changewarning($r,'');
6059: }
6060: }
6061:
6062: # Supplemental documents start here
6063:
6064: my $folder=$env{'form.folder'};
6065: unless ($supplementalflag) {
6066: $folder='supplemental';
6067: }
6068: if ($folder =~ /^supplemental$/ &&
6069: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6070: $env{'form.folderpath'} = &supplemental_base();
6071: } elsif ($allowed) {
6072: $env{'form.folderpath'} = $savefolderpath;
6073: }
6074: $pathitem = '<input type="hidden" name="folderpath" value="'.
6075: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6076: if ($allowed) {
6077: my $folderseq=
6078: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6079:
6080: my $supupdocform=(<<SUPDOCFORM);
6081: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6082: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6083: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6084: <fieldset id="uploadsuppdocform" style="display: none;">
6085: <legend>$lt{'upfi'}</legend>
6086: <input type="hidden" name="active" value="ee" />
6087: $fileupload
6088: <br />
6089: <br />
6090: <span class="LC_nobreak">
6091: $checkbox
6092: </span>
6093: <br /><br />
6094: $lt{'comment'}:<br />
6095: <textarea cols="50" rows="4" name="comment"></textarea>
6096: <br />
6097: $pathitem
6098: <input type="hidden" name="cmd" value="upload_supplemental" />
6099: <input type='submit' value="$lt{'upld'}" />
6100: </form>
6101: SUPDOCFORM
6102:
6103: my $supnewfolderform=(<<SNFFORM);
6104: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6105: <input type="hidden" name="active" value="" />
6106: $pathitem
6107: <input type="hidden" name="importdetail" value="" />
6108: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6109: $help{'Adding_Folders'}
6110: </form>
6111: SNFFORM
6112:
6113: my $supextform =
6114: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6115: $help{'Adding_External_Resource'},
6116: undef,undef,undef,undef,undef,undef,
6117: $disabled);
6118:
6119: my $supexttoolform =
6120: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6121: $help{'Adding_External_Tool'},
6122: undef,undef,'tool',$coursedom,
6123: $coursenum,\%ltitools,$disabled);
6124:
6125: my $supnewsylform=(<<SNSFORM);
6126: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6127: <input type="hidden" name="active" value="ff" />
6128: $pathitem
6129: <input type="hidden" name="importdetail"
6130: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6131: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6132: $help{'Syllabus'}
6133: </form>
6134: SNSFORM
6135:
6136: my $supnewaboutmeform=(<<SNAMFORM);
6137: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6138: <input type="hidden" name="active" value="ff" />
6139: $pathitem
6140: <input type="hidden" name="importdetail"
6141: value="$plainname=/adm/$udom/$uname/aboutme" />
6142: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6143: $help{'My Personal Information Page'}
6144: </form>
6145: SNAMFORM
6146:
6147: my $supwebpage;
6148: if ($folder =~ /^supplemental_?(\d*)$/) {
6149: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6150: if ($1) {
6151: $supwebpage .= $1;
6152: } else {
6153: $supwebpage .= 'default';
6154: }
6155: $supwebpage .= '/new.html';
6156: }
6157: my $supwebpageform =(<<SWEBFORM);
6158: <form action="/adm/coursedocs" method="post" name="supwebpage">
6159: <input type="hidden" name="active" value="cc" />
6160: $pathitem
6161: <input type="hidden" name="importdetail" value="$supwebpage" />
6162: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6163: $help{'Web_Page'}
6164: </form>
6165: SWEBFORM
6166:
6167:
6168: my @specialdocs = (
6169: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="makenew(document.supnewsyl);" />'
6170: =>$supnewsylform},
6171: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6172: =>$supnewaboutmeform},
6173: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6174:
6175: );
6176: my @supimportdoc = (
6177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
6178: =>$supextform});
6179: if (keys(%ltitools)) {
6180: push(@supimportdoc,
6181: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6182: =>$supexttoolform});
6183: }
6184: push(@supimportdoc,
6185: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6186: =>$supupdocform},
6187: );
6188:
6189: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6190: my %suporderhash = (
6191: '00' => ['Supnewfolder', $supnewfolderform],
6192: 'ee' => ['Upload',$supupdocform],
6193: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6194: );
6195: if ($supplementalflag) {
6196: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6197: $supplementalflag,\%suporderhash,$iconpath,$pathitem,\%ltitools,$canedit);
6198: if ($error) {
6199: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6200: } else {
6201: if ($suppchanges) {
6202: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6203: my @ids=&Apache::lonnet::current_machine_ids();
6204: foreach my $server (keys(%servers)) {
6205: next if (grep(/^\Q$server\E$/,@ids));
6206: my $hashid=$coursenum.':'.$coursedom;
6207: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6208: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
6209: }
6210: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6211: undef($suppchanges);
6212: }
6213: }
6214: }
6215: } elsif ($supplementalflag) {
6216: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6217: $supplementalflag,'',$iconpath,$pathitem,$canedit);
6218: if ($error) {
6219: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6220: }
6221: }
6222:
6223: if ($needs_end) {
6224: $r->print(&endContentScreen());
6225: }
6226:
6227: if ($allowed) {
6228: $r->print('
6229: <form method="post" name="extimport" action="/adm/coursedocs">
6230: <input type="hidden" name="title" />
6231: <input type="hidden" name="url" />
6232: <input type="hidden" name="useform" />
6233: <input type="hidden" name="residx" />
6234: </form>');
6235: }
6236: } elsif ($showdoc) {
6237: # -------------------------------------------------------- This is showdoc mode
6238: $r->print("<h1>".&mt('Uploaded Document').' - '.
6239: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6240: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6241: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6242: }
6243: }
6244: unless ($noendpage) {
6245: $r->print(&Apache::loncommon::end_page());
6246: }
6247: return OK;
6248: }
6249:
6250: sub embedded_form_elems {
6251: my ($phase,$primaryurl,$newidx) = @_;
6252: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6253: return <<STATE;
6254: <input type="hidden" name="folderpath" value="$folderpath" />
6255: <input type="hidden" name="cmd" value="upload_embedded" />
6256: <input type="hidden" name="newidx" value="$newidx" />
6257: <input type="hidden" name="phase" value="$phase" />
6258: <input type="hidden" name="primaryurl" value="$primaryurl" />
6259: STATE
6260: }
6261:
6262: sub embedded_destination {
6263: my $folder=$env{'form.folder'};
6264: my $destination = 'docs/';
6265: if ($folder =~ /^supplemental/) {
6266: $destination = 'supplemental/';
6267: }
6268: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6269: $destination .= 'default/';
6270: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6271: $destination .= $2.'/';
6272: }
6273: $destination .= $env{'form.newidx'};
6274: my $dir_root = '/userfiles';
6275: return ($destination,$dir_root);
6276: }
6277:
6278: sub return_to_editor {
6279: my $actionurl = '/adm/coursedocs';
6280: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6281: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6282: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6283: '</a></p>';
6284: }
6285:
6286: sub decompression_info {
6287: my ($destination,$dir_root) = &embedded_destination();
6288: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6289: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6290: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6291: my $container='sequence';
6292: my ($pathitem,$hiddenelem);
6293: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
6294: if ($env{'form.folderpath'} =~ /\:1$/) {
6295: $container='page';
6296: }
6297: unshift(@hiddens,$pathitem);
6298: foreach my $item (@hiddens) {
6299: if ($env{'form.'.$item}) {
6300: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
6301: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
6302: }
6303: }
6304: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6305: $hiddenelem);
6306: }
6307:
6308: sub decompression_phase_one {
6309: my ($dir,$file,$warning,$error,$output);
6310: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6311: &decompression_info();
6312: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
6313: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6314: } else {
6315: my $file = $1;
6316: $output =
6317: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6318: $destination,$dir_root,
6319: $hiddenelem);
6320: if ($env{'form.autoextract_camtasia'}) {
6321: $output .= &remove_archive($docudom,$docuname,$container);
6322: }
6323: }
6324: if ($error) {
6325: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6326: $error.'</p>'."\n";
6327: }
6328: if ($warning) {
6329: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6330: }
6331: return $output;
6332: }
6333:
6334: sub decompression_phase_two {
6335: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6336: &decompression_info();
6337: my $output;
6338: if ($env{'form.archivedelete'}) {
6339: $output = &remove_archive($docudom,$docuname,$container);
6340: }
6341: $output .=
6342: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
6343: $destination,$dir_root,$hiddenelem);
6344: return $output;
6345: }
6346:
6347: sub remove_archive {
6348: my ($docudom,$docuname,$container) = @_;
6349: my $map = $env{'form.folder'}.'.'.$container;
6350: my ($output,$delwarning,$delresult,$url);
6351: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6352: if ($fatal) {
6353: if ($container eq 'page') {
6354: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6355: } else {
6356: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6357: }
6358: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
6359: } else {
6360: my $currcmd = $env{'form.cmd'};
6361: my $position = $env{'form.position'};
6362: my $archiveidx = $position;
6363: if ($position > 0) {
6364: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6365: $archiveidx = $position-1;
6366: }
6367: $env{'form.cmd'} = 'remove_'.$archiveidx;
6368: my ($title,$url,@rrest) =
6369: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6370: if ($url eq $env{'form.archiveurl'}) {
6371: if (&handle_edit_cmd($docuname,$docudom)) {
6372: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6373: if ($fatal) {
6374: if ($container eq 'page') {
6375: $delwarning = &mt('An error occurred updating the contents of the current page.');
6376: } else {
6377: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6378: }
6379: } else {
6380: $delresult = &mt('Archive file removed.');
6381: }
6382: }
6383: } else {
6384: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6385: ' '.&mt('As a result the archive file has not been removed.');
6386: }
6387: }
6388: $env{'form.cmd'} = $currcmd;
6389: }
6390: if ($delwarning) {
6391: $output = '<p class="LC_warning">'.
6392: $delwarning.
6393: '</p>';
6394: }
6395: if ($delresult) {
6396: $output .= '<p class="LC_info">'.
6397: $delresult.
6398: '</p>';
6399: }
6400: return $output;
6401: }
6402:
6403: sub generate_admin_menu {
6404: my ($crstype,$canedit) = @_;
6405: my $lc_crstype = lc($crstype);
6406: my ($home,$other,%outhash)=&authorhosts();
6407: my %lt= ( # do not translate here
6408: 'vc' => 'Verify Content',
6409: 'cv' => 'Check/Set Resource Versions',
6410: 'ls' => 'List Resource Identifiers',
6411: 'imse' => 'Export contents to IMS Archive',
6412: 'dcd' => "Copy $crstype Content to Authoring Space",
6413: );
6414: my ($candump,$dumpurl);
6415: if ($home + $other > 0) {
6416: $candump = 'F';
6417: if ($home) {
6418: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6419: } else {
6420: my @hosts;
6421: foreach my $aurole (keys(%outhash)) {
6422: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6423: push(@hosts,$outhash{$aurole});
6424: }
6425: }
6426: if (@hosts == 1) {
6427: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6428: '&role='.
6429: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6430: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6431: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6432: } else {
6433: $dumpurl = "javascript:choose_switchserver_window()";
6434: }
6435: }
6436: }
6437: my @menu=
6438: ({ categorytitle=>'Administration',
6439: items =>[
6440: { linktext => $lt{'vc'},
6441: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6442: permission => 'F',
6443: help => 'Docs_Verify_Content',
6444: icon => 'verify.png',
6445: linktitle => 'Verify contents can be retrieved/rendered',
6446: },
6447: { linktext => $lt{'cv'},
6448: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6449: permission => 'F',
6450: help => 'Docs_Check_Resource_Versions',
6451: icon => 'resversion.png',
6452: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6453: },
6454: { linktext => $lt{'ls'},
6455: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6456: permission => 'F',
6457: #help => '',
6458: icon => 'symbs.png',
6459: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6460: },
6461: ]
6462: });
6463: if ($canedit) {
6464: push(@menu,
6465: { categorytitle=>'Export',
6466: items =>[
6467: { linktext => $lt{'imse'},
6468: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6469: permission => 'F',
6470: help => 'Docs_Export_Course_Docs',
6471: icon => 'imsexport.png',
6472: linktitle => $lt{'imse'},
6473: },
6474: { linktext => $lt{'dcd'},
6475: url => $dumpurl,
6476: permission => $candump,
6477: help => 'Docs_Dump_Course_Docs',
6478: icon => 'dump.png',
6479: linktitle => $lt{'dcd'},
6480: },
6481: ]
6482: });
6483: }
6484: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6485: '<input type="hidden" id="dummy" />'."\n".
6486: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6487: '</form>';
6488: }
6489:
6490: sub generate_edit_table {
6491: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
6492: $need_save,$copyfolder,$canedit) = @_;
6493: return unless(ref($orderhash_ref) eq 'HASH');
6494: my %orderhash = %{$orderhash_ref};
6495: my ($form, $activetab, $active, $disabled);
6496: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
6497: $activetab = $env{'form.active'};
6498: }
6499: unless ($canedit) {
6500: $disabled = ' disabled="disabled"';
6501: }
6502: my $backicon = $iconpath.'clickhere.gif';
6503: my $backtext = &mt('Exit Editor');
6504: $form = '<div class="LC_Box" style="margin:0;">'.
6505: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6506: '<li class="goback">'.
6507: '<a href="javascript:toContents('."'$jumpto'".');">'.
6508: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6509: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6510: '<li>'.
6511: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6512: &mt('Undo Delete').'</a></li>'."\n";
6513: if ($env{'form.docslog'}) {
6514: $form .= '<li class="active">';
6515: } else {
6516: $form .= '<li>';
6517: }
6518: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6519: &mt('History').'</a></li>'."\n";
6520: if ($env{'form.docslog'}) {
6521: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6522: &mt('Edit').'</a></li>'."\n";
6523: }
6524: foreach my $name (reverse(sort(keys(%orderhash)))) {
6525: if($name ne '00'){
6526: if($activetab eq '' || $activetab ne $name){
6527: $active = '';
6528: }elsif($activetab eq $name){
6529: $active = 'class="active"';
6530: }
6531: $form .= '<li style="float:right" '.$active
6532: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
6533: } else {
6534: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
6535:
6536: }
6537: }
6538: $form .= '</ul>'."\n";
6539: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
6540:
6541: if ($to_show ne '') {
6542: my $saveform;
6543: if ($need_save) {
6544: my $button = &mt('Make changes');
6545: my $path;
6546: if ($env{'form.folderpath'}) {
6547: $path =
6548: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6549: }
6550: $saveform = <<"END";
6551: <div id="multisave" style="display:none; clear:both;" >
6552: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6553: <input type="hidden" name="folderpath" value="$path" />
6554: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6555: <input type="hidden" name="allhiddenresource" value="" />
6556: <input type="hidden" name="allencrypturl" value="" />
6557: <input type="hidden" name="allrandompick" value="" />
6558: <input type="hidden" name="allrandomorder" value="" />
6559: <input type="hidden" name="changeparms" value="" />
6560: <input type="hidden" name="multiremove" value="" />
6561: <input type="hidden" name="multicut" value="" />
6562: <input type="hidden" name="multicopy" value="" />
6563: <input type="hidden" name="multichange" value="" />
6564: <input type="hidden" name="copyfolder" value="$copyfolder" />
6565: <input type="submit" name="savemultiples" value="$button" $disabled />
6566: </form>
6567: </div>
6568: END
6569: }
6570: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
6571: }
6572: foreach my $field (keys(%orderhash)){
6573: if($field ne '00'){
6574: if($activetab eq '' || $activetab ne $field){
6575: $active = 'style="display: none;float:left"';
6576: }elsif($activetab eq $field){
6577: $active = 'style="display:block;float:left"';
6578: }
6579: $form .= '<div id="'.$field.$tid.'"'
6580: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
6581: .'</div>'."\n";
6582: }
6583: }
6584: unless ($env{'form.docslog'}) {
6585: $form .= '</div></div>'."\n";
6586: }
6587: return $form;
6588: }
6589:
6590: sub editing_js {
6591: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit) = @_;
6592: my %js_lt = &Apache::lonlocal::texthash(
6593: p_mnf => 'Name of New Folder',
6594: t_mnf => 'New Folder',
6595: p_mnp => 'Name of New Page',
6596: t_mnp => 'New Page',
6597: p_mxu => 'Title for the External Score',
6598: p_msp => 'Name of Simple Course Page',
6599: p_msb => 'Title for the Problem',
6600: p_mdb => 'Title for the Drop Box',
6601: p_mbb => 'Title for the Discussion Board',
6602: p_mwp => 'Title for Web Page',
6603: p_mnr => 'Title for the Resource',
6604: p_mab => "Enter user:domain for User's Personal Information Page",
6605: p_mab2 => 'Personal Information Page of ',
6606: p_mab_alrt1 => 'Not a valid user:domain',
6607: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6608: p_chn => 'New Title',
6609: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
6610: p_rmr2a => 'Remove',
6611: p_rmr2b => '?',
6612: p_rmr3a => 'Remove those',
6613: p_rmr3b => 'items?',
6614: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6615: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
6616: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6617: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
6618: p_ctr2a => 'Cut',
6619: p_ctr2b => '?',
6620: p_ctr3a => 'Cut those',
6621: p_ctr3b => 'items?',
6622: rpck => 'Enter number to pick (e.g., 3)',
6623: imsfile => 'You must choose an IMS package for import',
6624: imscms => 'You must select which Course Management System was the source of the IMS package',
6625: invurl => 'Invalid URL',
6626: titbl => 'Title is blank',
6627: more => '(More ...)',
6628: less => '(Less ...)',
6629: noor => 'No actions selected or changes to settings specified.',
6630: noch => 'No changes to settings specified.',
6631: noac => 'No actions selected.',
6632: nofi => 'No file selected',
6633: tinc => 'Title in course',
6634: sunm => 'Sub-directory name',
6635: edri => 'Editing rights unavailable for your current role',
6636: );
6637: &js_escape(\%js_lt);
6638: my $crstype = &Apache::loncommon::course_type();
6639: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6640: my $main_container_page;
6641: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6642: $main_container_page = 1;
6643: }
6644: my $toplevelmain =
6645: &escape(&mt('Main Content').':::::');
6646: my $toplevelsupp = &supplemental_base();
6647:
6648: my $backtourl;
6649: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6650: my $caller = $1;
6651: if ($caller =~ /^supplemental/) {
6652: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6653: } else {
6654: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6655: $res = &Apache::lonnet::clutter($res);
6656: if (&Apache::lonnet::is_on_map($res)) {
6657: my ($url,$anchor);
6658: if ($res =~ /^([^#]+)#([^#]+)$/) {
6659: $url = $1;
6660: $anchor = $2;
6661: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6662: $caller = $1.&escape('#').$anchor;
6663: }
6664: }
6665: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
6666: &HTML::Entities::encode($caller,'<>&"');
6667: if ($anchor ne '') {
6668: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6669: }
6670: $backtourl = &Apache::loncommon::escape_single($backtourl);
6671: } else {
6672: $backtourl = '/adm/navmaps';
6673: }
6674: }
6675: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6676: $backtourl = '/adm/menu';
6677: } elsif ($supplementalflag) {
6678: $backtourl = '/adm/supplemental';
6679: } else {
6680: $backtourl = '/adm/navmaps';
6681: }
6682:
6683: my $fieldsets = "'ext','doc'";
6684: if ($posslti) {
6685: $fieldsets .= ",'tool'";
6686: }
6687: unless ($main_container_page) {
6688: $fieldsets .=",'ims'";
6689: }
6690: if ($supplementalflag) {
6691: $fieldsets = "'suppext','suppdoc'";
6692: if ($posslti) {
6693: $fieldsets .= ",'supptool'";
6694: }
6695: }
6696:
6697: my $jsmakefunctions;
6698: if ($canedit) {
6699: $jsmakefunctions = <<ENDNEWSCRIPT;
6700: function makenewfolder(targetform,folderseq) {
6701: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
6702: if (foldername) {
6703: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6704: targetform.submit();
6705: }
6706: }
6707:
6708: function makenewpage(targetform,folderseq) {
6709: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
6710: if (pagename) {
6711: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6712: targetform.submit();
6713: }
6714: }
6715:
6716: function makeexamupload() {
6717: var title=prompt('$js_lt{"p_mxu"}');
6718: if (title) {
6719: this.document.forms.newexamupload.importdetail.value=
6720: escape(title)+'=/res/lib/templates/examupload.problem';
6721: this.document.forms.newexamupload.submit();
6722: }
6723: }
6724:
6725: function makesmppage() {
6726: var title=prompt('$js_lt{"p_msp"}');
6727: if (title) {
6728: this.document.forms.newsmppg.importdetail.value=
6729: escape(title)+'=/adm/$udom/$uname/new/smppg';
6730: this.document.forms.newsmppg.submit();
6731: }
6732: }
6733:
6734: function makewebpage(type) {
6735: var title=prompt('$js_lt{"p_mwp"}');
6736: var formname;
6737: if (type == 'supp') {
6738: formname = this.document.forms.supwebpage;
6739: } else {
6740: formname = this.document.forms.newwebpage;
6741: }
6742: if (title) {
6743: var webpage = formname.importdetail.value;
6744: formname.importdetail.value = escape(title)+'='+webpage;
6745: formname.submit();
6746: }
6747: }
6748:
6749: function makesmpproblem() {
6750: var title=prompt('$js_lt{"p_msb"}');
6751: if (title) {
6752: this.document.forms.newsmpproblem.importdetail.value=
6753: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6754: this.document.forms.newsmpproblem.submit();
6755: }
6756: }
6757:
6758: function makedropbox() {
6759: var title=prompt('$js_lt{"p_mdb"}');
6760: if (title) {
6761: this.document.forms.newdropbox.importdetail.value=
6762: escape(title)+'=/res/lib/templates/DropBox.problem';
6763: this.document.forms.newdropbox.submit();
6764: }
6765: }
6766:
6767: function makebulboard() {
6768: var title=prompt('$js_lt{"p_mbb"}');
6769: if (title) {
6770: this.document.forms.newbul.importdetail.value=
6771: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
6772: this.document.forms.newbul.submit();
6773: }
6774: }
6775:
6776: function makeabout() {
6777: var user=prompt("$js_lt{'p_mab'}");
6778: if (user) {
6779: var comp=new Array();
6780: comp=user.split(':');
6781: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6782: if ((comp[0]) && (comp[1])) {
6783: this.document.forms.newaboutsomeone.importdetail.value=
6784: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
6785: this.document.forms.newaboutsomeone.submit();
6786: } else {
6787: alert("$js_lt{'p_mab_alrt1'}");
6788: }
6789: } else {
6790: alert("$js_lt{'p_mab_alrt2'}");
6791: }
6792: }
6793: }
6794:
6795: function makenew(targetform) {
6796: targetform.submit();
6797: }
6798:
6799: function changename(folderpath,index,oldtitle) {
6800: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6801: if (title) {
6802: this.document.forms.renameform.markcopy.value='';
6803: this.document.forms.renameform.title.value=title;
6804: this.document.forms.renameform.cmd.value='rename_'+index;
6805: this.document.forms.renameform.folderpath.value=folderpath;
6806: this.document.forms.renameform.submit();
6807: }
6808: }
6809:
6810: ENDNEWSCRIPT
6811: } else {
6812: $jsmakefunctions = <<ENDNEWSCRIPT;
6813:
6814: function makenewfolder() {
6815: alert("$js_lt{'edri'}");
6816: }
6817:
6818: function makenewpage() {
6819: alert("$js_lt{'edri'}");
6820: }
6821:
6822: function makeexamupload() {
6823: alert("$js_lt{'edri'}");
6824: }
6825:
6826: function makesmppage() {
6827: alert("$js_lt{'edri'}");
6828: }
6829:
6830: function makewebpage(type) {
6831: alert("$js_lt{'edri'}");
6832: }
6833:
6834: function makesmpproblem() {
6835: alert("$js_lt{'edri'}");
6836: }
6837:
6838: function makedropbox() {
6839: alert("$js_lt{'edri'}");
6840: }
6841:
6842: function makebulboard() {
6843: alert("$js_lt{'edri'}");
6844: }
6845:
6846: function makeabout() {
6847: alert("$js_lt{'edri'}");
6848: }
6849:
6850: function changename() {
6851: alert("$js_lt{'edri'}");
6852: }
6853:
6854: function makenew() {
6855: alert("$js_lt{'edri'}");
6856: }
6857:
6858: function groupimport() {
6859: alert("$js_lt{'edri'}");
6860: }
6861:
6862: function groupsearch() {
6863: alert("$js_lt{'edri'}");
6864: }
6865:
6866: function groupopen(url,recover) {
6867: var options="scrollbars=1,resizable=1,menubar=0";
6868: idxflag=1;
6869: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6870: idx.focus();
6871: }
6872:
6873: ENDNEWSCRIPT
6874:
6875: }
6876: return <<ENDSCRIPT;
6877:
6878: $jsmakefunctions
6879:
6880: function toggleUpload(caller) {
6881: var blocks = Array($fieldsets);
6882: for (var i=0; i<blocks.length; i++) {
6883: var disp = 'none';
6884: if (caller == blocks[i]) {
6885: var curr = document.getElementById('upload'+caller+'form').style.display;
6886: if (curr == 'none') {
6887: disp='block';
6888: }
6889: }
6890: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6891: if ((caller == 'tool') || (caller == 'supptool')) {
6892: if (disp == 'block') {
6893: if (document.getElementById('LC_exttoolid')) {
6894: var toolselector = document.getElementById('LC_exttoolid');
6895: var suppflag = 0;
6896: if (caller == 'supptool') {
6897: suppflag = 1;
6898: }
6899: currForm = document.getElementById('new'+caller);
6900: updateExttool(toolselector,currForm,suppflag);
6901: }
6902: }
6903: }
6904: }
6905: resize_scrollbox('contentscroll','1','1');
6906: return;
6907: }
6908:
6909: function toggleMap(caller) {
6910: var disp = 'none';
6911: if (document.getElementById('importmapform')) {
6912: if (caller == 'map') {
6913: var curr = document.getElementById('importmapform').style.display;
6914: if (curr == 'none') {
6915: disp='block';
6916: }
6917: }
6918: document.getElementById('importmapform').style.display=disp;
6919: resize_scrollbox('contentscroll','1','1');
6920: }
6921: return;
6922: }
6923:
6924: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
6925: var disp = 'none';
6926: if (document.getElementById('crsresform')) {
6927: if (caller == 'res') {
6928: var curr = document.getElementById('crsresform').style.display;
6929: if (curr == 'none') {
6930: disp='block';
6931: numauthor = parseInt(numauthorrole);
6932: if (numauthor > 0) {
6933: document.courseresform.authorrole.selectedIndex = 0;
6934: select1priv_changed();
6935: document.courseresform.authorpath.selectedIndex = 0;
6936: document.courseresform.newresourceadd.selectedIndex = 0;
6937: toggleNewInCourse(document.courseresform);
6938: if (document.getElementById('newresource')) {
6939: document.getElementById('newresource').style.display = 'none';
6940: }
6941: } else {
6942: if (numcrsdirs) {
6943: document.courseresform.authorpath.selectedIndex = 0;
6944: }
6945: }
6946: if (document.courseresform.newresusetemp.length) {
6947: document.courseresform.newresusetemp[0].checked = true;
6948: toggleWithTemplate(document.courseresform);
6949: }
6950: document.courseresform.newresourcename.value = '';
6951: }
6952: }
6953: if (document.courseresform.newsubdir.length) {
6954: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
6955: if (document.courseresform.newsubdir[j].value == 0) {
6956: document.courseresform.newsubdir[j].checked = true;
6957: }
6958: break;
6959: }
6960: if (document.getElementById('newsubdirname')) {
6961: document.getElementById('newsubdirname').type = "hidden";
6962: document.getElementById('newsubdirname').value = "";
6963: }
6964: if (document.getElementById('newsubdir')) {
6965: document.getElementById('newsubdir').innerHTML = "";
6966: }
6967: }
6968: document.getElementById('crsresform').style.display=disp;
6969: resize_scrollbox('contentscroll','1','0');
6970: }
6971: return;
6972: }
6973:
6974: function toggleNewsubdir(form) {
6975: if (form.newsubdir.length) {
6976: for (var j=0; j<form.newsubdir.length; j++) {
6977: if (form.newsubdir[j].checked) {
6978: if (document.getElementById('newsubdirname')) {
6979: if (form.newsubdir[j].value == '1') {
6980: document.getElementById('newsubdirname').type = "text";
6981: if (document.getElementById('newsubdir')) {
6982: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
6983: }
6984: } else {
6985: document.getElementById('newsubdirname').type = "hidden";
6986: document.getElementById('newsubdirname').value = "";
6987: document.getElementById('newsubdir').innerHTML = "";
6988: }
6989: }
6990: break;
6991: }
6992: }
6993: }
6994: }
6995:
6996: function toggleCrsResTitle() {
6997: if (document.getElementById('newresource')) {
6998: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
6999: document.getElementById('newresource').style.display = 'inline';
7000: document.courseresform.newresourceadd[0].checked = true;
7001: toggleNewInCourse(document.courseresform);
7002: } else {
7003: document.getElementById('newresource').style.display = 'none';
7004: }
7005: }
7006: }
7007:
7008: function toggleNewInCourse(form) {
7009: if (form.newresourceadd.length) {
7010: for (var i=0; i<form.newresourceadd.length; i++) {
7011: if (form.newresourceadd[i].checked) {
7012: if (document.getElementById('newresourcetitle')) {
7013: if (form.newresourceadd[i].value == '1') {
7014: document.getElementById('newresourcetitle').type = 'text';
7015: if (document.getElementById('newrestitle')) {
7016: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7017: }
7018: } else {
7019: document.getElementById('newresourcetitle').type = 'hidden';
7020: document.getElementById('newresourcetitle').value = '';
7021: if (document.getElementById('newrestitle')) {
7022: document.getElementById('newrestitle').innerHTML = '';
7023: }
7024: }
7025: }
7026: break;
7027: }
7028: }
7029: }
7030: }
7031:
7032: function toggleWithTemplate(form) {
7033: if (form.newresusetemp.length) {
7034: for (var i=0; i<form.newresusetemp.length; i++) {
7035: if (form.newresusetemp[i].checked) {
7036: if (document.getElementById('newrestemplate')) {
7037: if (form.newresusetemp[i].value == '1') {
7038: document.getElementById('newrestemplate').style.display = 'inline';
7039: toggleExampleText();
7040: } else {
7041: form.tempcategory.selectedIndex = 0;
7042: select1template_changed();
7043: document.getElementById('newrestemplate').style.display = 'none';
7044: }
7045: }
7046: }
7047: }
7048: }
7049: }
7050:
7051: function toggleExampleText() {
7052: if (document.getElementById('newresexample')) {
7053: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7054: if (url == '') {
7055: document.getElementById('newresexample').style.fontWeight = 'normal';
7056: } else {
7057: document.getElementById('newresexample').style.fontWeight = 'bold';
7058: }
7059: }
7060: }
7061:
7062: function getExample(width,height,scrolling,transparency) {
7063: var url;
7064: if (document.courseresform.newresusetemp.length) {
7065: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7066: if (document.courseresform.newresusetemp[i].checked) {
7067: if (document.courseresform.newresusetemp[i].value == '1') {
7068: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7069: if (url == '') {
7070: alert('Pick a category and template');
7071: } else {
7072: url = url.replace("$londocroot","");
7073: url += '?inhibitmenu=yes';
7074: }
7075: }
7076: break;
7077: }
7078: }
7079: }
7080: if (url != '') {
7081: openMyModal(url,width,height,scrolling,transparency,'');
7082: }
7083: }
7084:
7085: function toggleImportCrsres(caller,dircount) {
7086: var disp = 'none';
7087: if (document.getElementById('importcrsresform')) {
7088: if (caller == 'res') {
7089: var numdirs = parseInt(dircount);
7090: var curr = document.getElementById('importcrsresform').style.display;
7091: if (curr == 'none') {
7092: disp='block';
7093: if (numdirs > 1) {
7094: select1res_changed();
7095: }
7096: }
7097: }
7098: document.getElementById('importcrsresform').style.display=disp;
7099: resize_scrollbox('contentscroll','1','0');
7100: }
7101: return;
7102: }
7103:
7104: function makeims(imsform) {
7105: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7106: alert("$js_lt{'imsfile'}");
7107: return;
7108: }
7109: if (imsform.source.selectedIndex == 0) {
7110: alert("$js_lt{'imscms'}");
7111: return;
7112: }
7113: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7114: imsform.submit();
7115: }
7116:
7117: function updatePick(targetform,index,caller) {
7118: var pickitem;
7119: var picknumitem;
7120: var picknumtext;
7121: if (index == 'all') {
7122: pickitem = document.getElementById('randompickall');
7123: picknumitem = document.getElementById('rpicknumall');
7124: picknumtext = document.getElementById('rpicktextall');
7125: } else {
7126: pickitem = document.getElementById('randompick_'+index);
7127: picknumitem = document.getElementById('rpicknum_'+index);
7128: picknumtext = document.getElementById('randompicknum_'+index);
7129: }
7130: if (pickitem.checked) {
7131: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7132: if (picknum == '' || picknum == null) {
7133: if (caller == 'check') {
7134: pickitem.checked=false;
7135: if (index == 'all') {
7136: picknumtext.innerHTML = '';
7137: if (caller == 'link') {
7138: propagateState(targetform,'rpicknum');
7139: }
7140: } else {
7141: checkForSubmit(targetform,'randompick','settings');
7142: }
7143: }
7144: } else {
7145: picknum.toString();
7146: var regexdigit=/^\\d+\$/;
7147: if (regexdigit.test(picknum)) {
7148: picknumitem.value = picknum;
7149: if (index == 'all') {
7150: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7151: if (caller == 'link') {
7152: propagateState(targetform,'rpicknum');
7153: }
7154: } else {
7155: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7156: checkForSubmit(targetform,'randompick','settings');
7157: }
7158: } else {
7159: if (caller == 'check') {
7160: if (index == 'all') {
7161: picknumtext.innerHTML = '';
7162: if (caller == 'link') {
7163: propagateState(targetform,'rpicknum');
7164: }
7165: } else {
7166: pickitem.checked=false;
7167: checkForSubmit(targetform,'randompick','settings');
7168: }
7169: }
7170: return;
7171: }
7172: }
7173: } else {
7174: picknumitem.value = '';
7175: picknumtext.innerHTML = '';
7176: if (index == 'all') {
7177: if (caller == 'link') {
7178: propagateState(targetform,'rpicknum');
7179: }
7180: } else {
7181: checkForSubmit(targetform,'randompick','settings');
7182: }
7183: }
7184: }
7185:
7186: function propagateState(form,param) {
7187: if (document.getElementById(param+'all')) {
7188: var setcheck = 0;
7189: var rpick = 0;
7190: if (param == 'rpicknum') {
7191: if (document.getElementById('randompickall')) {
7192: if (document.getElementById('randompickall').checked) {
7193: if (document.getElementById('rpicknumall')) {
7194: rpick = document.getElementById('rpicknumall').value;
7195: }
7196: }
7197: }
7198: } else {
7199: if (document.getElementById(param+'all').checked) {
7200: setcheck = 1;
7201: }
7202: }
7203: var allidxlist;
7204: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7205: if (document.getElementById('all'+param+'idx')) {
7206: allidxlist = document.getElementById('all'+param+'idx').value;
7207: }
7208: var actions = new Array ('remove','cut','copy');
7209: for (var i=0; i<actions.length; i++) {
7210: if (actions[i] != param) {
7211: if (document.getElementById(actions[i]+'all')) {
7212: document.getElementById(actions[i]+'all').checked = false;
7213: }
7214: }
7215: }
7216: }
7217: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
7218: allidxlist = form.allidx.value;
7219: }
7220: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7221: allidxlist = form.allmapidx.value;
7222: }
7223: if ((allidxlist != '') && (allidxlist != null)) {
7224: var allidxs = allidxlist.split(',');
7225: if (allidxs.length > 1) {
7226: for (var i=0; i<allidxs.length; i++) {
7227: if (document.getElementById(param+'_'+allidxs[i])) {
7228: if (param == 'rpicknum') {
7229: if (document.getElementById('randompick_'+allidxs[i])) {
7230: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7231: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7232: if (rpick > 0) {
7233: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7234: } else {
7235: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7236: }
7237: }
7238: }
7239: } else {
7240: if (setcheck == 1) {
7241: document.getElementById(param+'_'+allidxs[i]).checked = true;
7242: } else {
7243: document.getElementById(param+'_'+allidxs[i]).checked = false;
7244: if (param == 'randompick') {
7245: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7246: }
7247: }
7248: }
7249: }
7250: }
7251: if (setcheck == 1) {
7252: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7253: var actions = new Array('copy','cut','remove');
7254: for (var i=0; i<actions.length; i++) {
7255: var otheractions;
7256: var otheridxs;
7257: if (actions[i] === param) {
7258: continue;
7259: } else {
7260: if (document.getElementById('all'+actions[i]+'idx')) {
7261: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7262: otheridxs = otheractions.split(',');
7263: if (otheridxs.length > 1) {
7264: for (var j=0; j<otheridxs.length; j++) {
7265: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7266: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7267: }
7268: }
7269: }
7270: }
7271: }
7272: }
7273: }
7274: }
7275: }
7276: }
7277: }
7278: return;
7279: }
7280:
7281: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
7282: var canedit = '$canedit';
7283: if (canedit == '') {
7284: alert("$js_lt{'edri'}");
7285: return;
7286: }
7287: var dosettings;
7288: var doaction;
7289: var control = document.togglemultsettings;
7290: if (context == 'actions') {
7291: control = document.togglemultactions;
7292: doaction = 1;
7293: } else {
7294: dosettings = 1;
7295: }
7296: if (control) {
7297: if (control.showmultpick.length) {
7298: for (var i=0; i<control.showmultpick.length; i++) {
7299: if (control.showmultpick[i].checked) {
7300: if (control.showmultpick[i].value == 1) {
7301: if (context == 'settings') {
7302: dosettings = 0;
7303: } else {
7304: doaction = 0;
7305: }
7306: }
7307: }
7308: }
7309: }
7310: }
7311: if (context == 'settings') {
7312: if (dosettings == 1) {
7313: targetform.changeparms.value=param;
7314: targetform.submit();
7315: }
7316: }
7317: if (context == 'actions') {
7318: if (doaction == 1) {
7319: targetform.cmd.value=param+'_'+index;
7320: targetform.folderpath.value=folderpath;
7321: targetform.markcopy.value=idx+':'+param;
7322: targetform.copyfolder.value=folder+'.'+container;
7323: if (param == 'remove') {
7324: var doremove = 0;
7325: if (skip_confirm) {
7326: if (confirm_removal) {
7327: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7328: doremove = 1;
7329: }
7330: } else {
7331: doremove = 1;
7332: }
7333: } else {
7334: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7335: doremove = 1;
7336: }
7337: }
7338: if (doremove) {
7339: targetform.markcopy.value='';
7340: targetform.copyfolder.value='';
7341: targetform.submit();
7342: }
7343: }
7344: if (param == 'cut') {
7345: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
7346: targetform.submit();
7347: return;
7348: }
7349: }
7350: if (param == 'copy') {
7351: targetform.submit();
7352: return;
7353: }
7354: targetform.markcopy.value='';
7355: targetform.copyfolder.value='';
7356: targetform.cmd.value='';
7357: targetform.folderpath.value='';
7358: return;
7359: } else {
7360: if (document.getElementById(param+'_'+idx)) {
7361: item = document.getElementById(param+'_'+idx);
7362: if (item.type == 'checkbox') {
7363: if (item.checked) {
7364: item.checked = false;
7365: } else {
7366: item.checked = true;
7367: singleCheck(item,idx,param);
7368: }
7369: }
7370: }
7371: }
7372: }
7373: return;
7374: }
7375:
7376: function singleCheck(caller,idx,action) {
7377: actions = new Array('cut','copy','remove');
7378: if (caller.checked) {
7379: for (var i=0; i<actions.length; i++) {
7380: if (actions[i] != action) {
7381: if (document.getElementById(actions[i]+'_'+idx)) {
7382: if (document.getElementById(actions[i]+'_'+idx).checked) {
7383: document.getElementById(actions[i]+'_'+idx).checked = false;
7384: }
7385: }
7386: }
7387: }
7388: }
7389: return;
7390: }
7391:
7392: function unselectInactive(nav) {
7393: currentNav = document.getElementById(nav);
7394: currentLis = currentNav.getElementsByTagName('LI');
7395: for (i = 0; i < currentLis.length; i++) {
7396: if (currentLis[i].className == 'goback') {
7397: currentLis[i].className = 'goback';
7398: } else {
7399: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
7400: currentLis[i].className = 'right';
7401: } else {
7402: currentLis[i].className = 'i';
7403: }
7404: }
7405: }
7406: }
7407:
7408: function hideAll(current, nav, data) {
7409: unselectInactive(nav);
7410: if (current) {
7411: if (current.className == 'right'){
7412: current.className = 'right active'
7413: } else {
7414: current.className = 'active';
7415: }
7416: }
7417: currentData = document.getElementById(data);
7418: currentDivs = currentData.getElementsByTagName('DIV');
7419: for (i = 0; i < currentDivs.length; i++) {
7420: if(currentDivs[i].className == 'LC_ContentBox'){
7421: currentDivs[i].style.display = 'none';
7422: }
7423: }
7424: }
7425:
7426: function openTabs(pageId) {
7427: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
7428: if(tabnav.length > 2 ){
7429: currentNav = document.getElementById(tabnav[1].id);
7430: currentLis = currentNav.getElementsByTagName('LI');
7431: for(i = 0; i< currentLis.length; i++){
7432: if(currentLis[i].className == 'active') {
7433: funcString = currentLis[i].onclick.toString();
7434: tab = funcString.split('"');
7435: if(tab.length < 2) {
7436: tab = funcString.split("'");
7437: }
7438: currentData = document.getElementById(tab[1]);
7439: currentData.style.display = 'block';
7440: }
7441: }
7442: }
7443: }
7444:
7445: function showPage(current, pageId, nav, data) {
7446: currstate = current.className;
7447: hideAll(current, nav, data);
7448: openTabs(pageId);
7449: unselectInactive(nav);
7450: if ((currstate == 'active') || (currstate == 'right active')) {
7451: if (currstate == 'active') {
7452: current.className = '';
7453: } else {
7454: current.className = 'right';
7455: }
7456: activeTab = '';
7457: toggleUpload();
7458: toggleMap();
7459: toggleCrsRes();
7460: toggleImportCrsres();
7461: resize_scrollbox('contentscroll','1','0');
7462: return;
7463: } else {
7464: current.className = 'active';
7465: }
7466: currentData = document.getElementById(pageId);
7467: currentData.style.display = 'block';
7468: activeTab = pageId;
7469: toggleUpload();
7470: toggleMap();
7471: toggleCrsRes();
7472: toggleImportCrsres();
7473: if (nav == 'mainnav') {
7474: var storedpath = "$docs_folderpath";
7475: var storedpage = "$main_container_page";
7476: var reg = new RegExp("^supplemental");
7477: if (pageId == 'mainCourseDocuments') {
7478: if (storedpage == 1) {
7479: document.simpleedit.folderpath.value = '';
7480: document.uploaddocument.folderpath.value = '';
7481: } else {
7482: if (reg.test(storedpath)) {
7483: document.simpleedit.folderpath.value = '$toplevelmain';
7484: document.uploaddocument.folderpath.value = '$toplevelmain';
7485: document.newext.folderpath.value = '$toplevelmain';
7486: } else {
7487: document.simpleedit.folderpath.value = storedpath;
7488: document.uploaddocument.folderpath.value = storedpath;
7489: document.newext.folderpath.value = storedpath;
7490: }
7491: }
7492: } else {
7493: if (reg.test(storedpath)) {
7494: document.simpleedit.folderpath.value = storedpath;
7495: document.supuploaddocument.folderpath.value = storedpath;
7496: document.supnewext.folderpath.value = storedpath;
7497: } else {
7498: document.simpleedit.folderpath.value = '$toplevelsupp';
7499: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7500: document.supnewext.folderpath.value = '$toplevelsupp';
7501: }
7502: }
7503: }
7504: resize_scrollbox('contentscroll','1','0');
7505: return false;
7506: }
7507:
7508: function toContents(jumpto) {
7509: var newurl = '$backtourl';
7510: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
7511: newurl = newurl+'?postdata='+jumpto;
7512: }
7513: location.href=newurl;
7514: }
7515:
7516: function togglePick(caller,value) {
7517: var disp = 'none';
7518: if (document.getElementById('multi'+caller)) {
7519: var curr = document.getElementById('multi'+caller).style.display;
7520: if (value == 1) {
7521: disp='block';
7522: }
7523: if (curr == disp) {
7524: return;
7525: }
7526: document.getElementById('multi'+caller).style.display=disp;
7527: if (value == 1) {
7528: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
7529: } else {
7530: document.getElementById('more'+caller).innerHTML = '';
7531: }
7532: if (caller == 'actions') {
7533: setClass(value);
7534: setBoxes(value);
7535: }
7536: }
7537: var showButton = multiSettings();
7538: if (showButton != 1) {
7539: showButton = multiActions();
7540: }
7541: if (document.getElementById('multisave')) {
7542: if (showButton == 1) {
7543: document.getElementById('multisave').style.display='block';
7544: } else {
7545: document.getElementById('multisave').style.display='none';
7546: }
7547: }
7548: resize_scrollbox('contentscroll','1','1');
7549: return;
7550: }
7551:
7552: function toggleCheckUncheck(caller,more) {
7553: if (more == 1) {
7554: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
7555: document.getElementById('allfields'+caller).style.display='block';
7556: } else {
7557: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
7558: document.getElementById('allfields'+caller).style.display='none';
7559: }
7560: resize_scrollbox('contentscroll','1','1');
7561: }
7562:
7563: function multiSettings() {
7564: var inuse = 0;
7565: var settingsform = document.togglemultsettings;
7566: if (settingsform.showmultpick.length > 1) {
7567: for (var i=0; i<settingsform.showmultpick.length; i++) {
7568: if (settingsform.showmultpick[i].checked) {
7569: if (settingsform.showmultpick[i].value == 1) {
7570: inuse = 1;
7571: }
7572: }
7573: }
7574: }
7575: return inuse;
7576: }
7577:
7578: function multiActions() {
7579: var inuse = 0;
7580: var actionsform = document.togglemultactions;
7581: if (actionsform.showmultpick.length > 1) {
7582: for (var i=0; i<actionsform.showmultpick.length; i++) {
7583: if (actionsform.showmultpick[i].checked) {
7584: if (actionsform.showmultpick[i].value == 1) {
7585: inuse = 1;
7586: }
7587: }
7588: }
7589: }
7590: return inuse;
7591: }
7592:
7593: function checkSubmits() {
7594: var numchanges = 0;
7595: var form = document.saveactions;
7596: var doactions = multiActions();
7597: var cutwarnings = 0;
7598: var remwarnings = 0;
7599: var removalinfo = 0;
7600: if (doactions == 1) {
7601: var remidxlist = document.cumulativeactions.allremoveidx.value;
7602: if ((remidxlist != '') && (remidxlist != null)) {
7603: var remidxs = remidxlist.split(',');
7604: for (var i=0; i<remidxs.length; i++) {
7605: if (document.getElementById('remove_'+remidxs[i])) {
7606: if (document.getElementById('remove_'+remidxs[i]).checked) {
7607: form.multiremove.value += remidxs[i]+',';
7608: numchanges ++;
7609: if (document.getElementById('skip_remove_'+remidxs[i])) {
7610: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7611: remwarnings ++;
7612: }
7613: }
7614: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7615: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7616: removalinfo ++;
7617: }
7618: }
7619: }
7620: }
7621: }
7622: }
7623: var cutidxlist = document.cumulativeactions.allcutidx.value;
7624: if ((cutidxlist != '') && (cutidxlist != null)) {
7625: var cutidxs = cutidxlist.split(',');
7626: for (var i=0; i<cutidxs.length; i++) {
7627: if (document.getElementById('cut_'+cutidxs[i])) {
7628: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7629: form.multicut.value += cutidxs[i]+',';
7630: numchanges ++;
7631: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7632: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7633: cutwarnings ++;
7634: }
7635: }
7636: }
7637: }
7638: }
7639: }
7640: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7641: if ((copyidxlist != '') && (copyidxlist != null)) {
7642: var copyidxs = copyidxlist.split(',');
7643: for (var i=0; i<copyidxs.length; i++) {
7644: if (document.getElementById('copy_'+copyidxs[i])) {
7645: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7646: form.multicopy.value += copyidxs[i]+',';
7647: numchanges ++;
7648: }
7649: }
7650: }
7651: }
7652: if (numchanges > 0) {
7653: form.multichange.value = numchanges;
7654: }
7655: }
7656: var dosettings = multiSettings();
7657: var haschanges = 0;
7658: if (dosettings == 1) {
7659: form.allencrypturl.value = '';
7660: form.allhiddenresource.value = '';
7661: form.changeparms.value = 'all';
7662: var patt=new RegExp(",\$");
7663: var allidxlist = document.cumulativesettings.allidx.value;
7664: if ((allidxlist != '') && (allidxlist != null)) {
7665: var allidxs = allidxlist.split(',');
7666: if (allidxs.length > 1) {
7667: for (var i=0; i<allidxs.length; i++) {
7668: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7669: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7670: form.allhiddenresource.value += allidxs[i]+',';
7671: }
7672: }
7673: if (document.getElementById('encrypturl_'+allidxs[i])) {
7674: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7675: form.allencrypturl.value += allidxs[i]+',';
7676: }
7677: }
7678: }
7679: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7680: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7681: }
7682: }
7683: form.allrandompick.value = '';
7684: form.allrandomorder.value = '';
7685: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7686: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7687: var allmapidxs = allmapidxlist.split(',');
7688: for (var i=0; i<allmapidxs.length; i++) {
7689: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7690: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7691: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7692: if ((randompick.checked) && (rpicknum.value != '')) {
7693: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7694: }
7695: if (randorder.checked) {
7696: form.allrandomorder.value += allmapidxs[i]+',';
7697: }
7698: }
7699: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7700: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7701: }
7702: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7703: haschanges = 1;
7704: }
7705: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7706: haschanges = 1;
7707: }
7708: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7709: haschanges = 1;
7710: }
7711: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7712: haschanges = 1;
7713: }
7714: }
7715: if (doactions == 1) {
7716: if (numchanges > 0) {
7717: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
7718: if (remwarnings > 0) {
7719: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
7720: return false;
7721: }
7722: }
7723: if (removalinfo > 0) {
7724: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7725: return false;
7726: }
7727: }
7728: if (cutwarnings > 0) {
7729: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
7730: return false;
7731: }
7732: }
7733: }
7734: form.submit();
7735: return true;
7736: }
7737: }
7738: if (dosettings == 1) {
7739: if (haschanges == 1) {
7740: form.submit();
7741: return true;
7742: }
7743: }
7744: if ((dosettings == 1) && (doactions == 1)) {
7745: alert("$js_lt{'noor'}");
7746: } else {
7747: if (dosettings == 1) {
7748: alert("$js_lt{'noch'}");
7749: } else {
7750: alert("$js_lt{'noac'}");
7751: }
7752: }
7753: return false;
7754: }
7755:
7756: function setClass(value) {
7757: var cutclass = 'LC_docs_cut';
7758: var copyclass = 'LC_docs_copy';
7759: var removeclass = 'LC_docs_remove';
7760: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7761: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7762: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7763: var links = document.getElementsByTagName('a');
7764: for (var i=0; i<links.length; i++) {
7765: var classes = links[i].className;
7766: if (cutreg.test(classes)) {
7767: links[i].className = cutclass;
7768: if (value == 1) {
7769: links[i].className += " LC_menubuttons_link";
7770: }
7771: } else {
7772: if (copyreg.test(classes)) {
7773: links[i].className = copyclass;
7774: if (value == 1) {
7775: links[i].className += " LC_menubuttons_link";
7776: }
7777: } else {
7778: if (removereg.test(classes)) {
7779: links[i].className = removeclass;
7780: if (value == 1) {
7781: links[i].className += " LC_menubuttons_link";
7782: }
7783: }
7784: }
7785: }
7786: }
7787: return;
7788: }
7789:
7790: function setBoxes(value) {
7791: var remidxlist = document.cumulativeactions.allremoveidx.value;
7792: if ((remidxlist != '') && (remidxlist != null)) {
7793: var remidxs = remidxlist.split(',');
7794: for (var i=0; i<remidxs.length; i++) {
7795: if (document.getElementById('remove_'+remidxs[i])) {
7796: var item = document.getElementById('remove_'+remidxs[i]);
7797: if (value == 1) {
7798: item.className = 'LC_docs_remove';
7799: } else {
7800: item.className = 'LC_hidden';
7801: }
7802: }
7803: }
7804: }
7805: var cutidxlist = document.cumulativeactions.allcutidx.value;
7806: if ((cutidxlist != '') && (cutidxlist != null)) {
7807: var cutidxs = cutidxlist.split(',');
7808: for (var i=0; i<cutidxs.length; i++) {
7809: if (document.getElementById('cut_'+cutidxs[i])) {
7810: var item = document.getElementById('cut_'+cutidxs[i]);
7811: if (value == 1) {
7812: item.className = 'LC_docs_cut';
7813: } else {
7814: item.className = 'LC_hidden';
7815: }
7816: }
7817: }
7818: }
7819: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7820: if ((copyidxlist != '') && (copyidxlist != null)) {
7821: var copyidxs = copyidxlist.split(',');
7822: for (var i=0; i<copyidxs.length; i++) {
7823: if (document.getElementById('copy_'+copyidxs[i])) {
7824: var item = document.getElementById('copy_'+copyidxs[i]);
7825: if (value == 1) {
7826: item.className = 'LC_docs_copy';
7827: } else {
7828: item.className = 'LC_hidden';
7829: }
7830: }
7831: }
7832: }
7833: return;
7834: }
7835:
7836: function validImportCrsRes() {
7837: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
7838: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
7839: if ((fname == '') || (fname == null)) {
7840: alert("$js_lt{'nofi'}");
7841: return false;
7842: }
7843: var url = '/res/$coursedom/$coursenum/';
7844: if (path && path != '/') {
7845: url += path+'/';
7846: }
7847: if (fname != '') {
7848: url += fname;
7849: }
7850: var title = document.crsresimportform.crsrestitle.value;
7851: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
7852: return true;
7853: }
7854:
7855: function validateNewRes(caller) {
7856: if (caller == 'single') {
7857: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7858: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
7859: var resname = document.courseresform.newresourcename.value;
7860: }
7861: }
7862:
7863: ENDSCRIPT
7864: }
7865:
7866: sub history_tab_js {
7867: return <<"ENDHIST";
7868: function toggleHistoryDisp(choice) {
7869: document.docslogform.docslog.value = choice;
7870: document.docslogform.submit();
7871: return;
7872: }
7873:
7874: ENDHIST
7875: }
7876:
7877: sub inject_data_js {
7878: return <<ENDINJECT;
7879:
7880: function injectData(current, hiddenField, name, value) {
7881: currentElement = document.getElementById(hiddenField);
7882: currentElement.name = name;
7883: currentElement.value = value;
7884: current.submit();
7885: }
7886:
7887: ENDINJECT
7888: }
7889:
7890: sub dump_switchserver_js {
7891: my @hosts = @_;
7892: my %js_lt = &Apache::lonlocal::texthash(
7893: dump => 'Copying content to Authoring Space requires switching server.',
7894: swit => 'Switch server?',
7895: );
7896: my %html_js_lt = &Apache::lonlocal::texthash(
7897: swit => 'Switch server?',
7898: duco => 'Copying Content to Authoring Space',
7899: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7900: chos => 'Choose server',
7901: );
7902: &js_escape(\%js_lt);
7903: &html_escape(\%html_js_lt);
7904: &js_escape(\%html_js_lt);
7905: my $role = $env{'request.role'};
7906: my $js = <<"ENDSWJS";
7907: <script type="text/javascript">
7908: function write_switchserver() {
7909: var server;
7910: if (document.setserver.posshosts.length > 0) {
7911: for (var i=0; i<document.setserver.posshosts.length; i++) {
7912: if (document.setserver.posshosts[i].checked) {
7913: server = document.setserver.posshosts[i].value;
7914: }
7915: }
7916: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7917: }
7918: window.close();
7919: }
7920: </script>
7921:
7922: ENDSWJS
7923:
7924: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7925: {'only_body' => 1,
7926: 'js_ready' => 1,});
7927: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7928:
7929: my $hostpicker;
7930: my $count = 0;
7931: foreach my $host (sort(@hosts)) {
7932: my $checked;
7933: if ($count == 0) {
7934: $checked = ' checked="checked"';
7935: }
7936: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7937: $host.'"'.$checked.' />'.$host.'</label> ';
7938: $count++;
7939: }
7940:
7941: return <<"ENDSWITCHJS";
7942:
7943: function dump_needs_switchserver(url) {
7944: if (url!='' && url!= null) {
7945: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
7946: go(url);
7947: }
7948: }
7949: return;
7950: }
7951:
7952: function choose_switchserver_window() {
7953: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7954: newWindow.document.open();
7955: newWindow.document.writeln('$startpage');
7956: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7957: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7958: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
7959: '<form name="setserver" method="post" action="" \\/>\\n'+
7960: '$hostpicker\\n'+
7961: '<br \\/><br \\/>\\n'+
7962: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
7963: 'onclick="write_switchserver();" \\/>\\n'+
7964: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7965: newWindow.document.writeln('$endpage');
7966: newWindow.document.close();
7967: newWindow.focus();
7968: }
7969:
7970: ENDSWITCHJS
7971: }
7972:
7973: sub makedocslogform {
7974: my ($formelems,$docslog) = @_;
7975: return <<"LOGSFORM";
7976: <form action="/adm/coursedocs" method="post" name="docslogform">
7977: <input type="hidden" name="docslog" value="$docslog" />
7978: $formelems
7979: </form>
7980: LOGSFORM
7981: }
7982:
7983: sub makesimpleeditform {
7984: my ($formelems) = @_;
7985: return <<"SIMPFORM";
7986: <form name="simpleedit" method="post" action="/adm/coursedocs">
7987: <input type="hidden" name="importdetail" value="" />
7988: $formelems
7989: </form>
7990: SIMPFORM
7991: }
7992:
7993: sub makenewproblem {
7994: my ($r,$coursedom,$coursenum) = @_;
7995: # Creating a new problem
7996: my ($redirect,$error);
7997: if ($env{'form.authorrole'}) {
7998: my ($newsubdir,$filename);
7999: if ($env{'form.newsubdir'}) {
8000: if ($env{'form.newsubdirname'} ne '') {
8001: $newsubdir = $env{'form.newsubdirname'};
8002: }
8003: }
8004: if ($env{'form.newresourcename'}) {
8005: $filename = $env{'form.newresourcename'};
8006: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8007: $filename =~ s/`//g;
8008: $filename =~ s{/\.\./}{_}g;
8009: $filename =~ s/\.+/./g;
8010: $filename =~ s{/+}{_}g;
8011: if ($filename ne '') {
8012: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8013: if (($ext) && ($ext ne '.problem')) {
8014: $filename = $name.'.problem';
8015: } elsif ($ext eq '') {
8016: $filename .= '.problem';
8017: }
8018: my $docroot = $r->dir_config('lonDocRoot');
8019: my @ids=&Apache::lonnet::current_machine_ids();
8020: if ($env{'form.authorrole'} eq 'author') {
8021: if ($env{'user.author'}) {
8022: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8023: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8024: my $path = $docroot.$url;
8025: my $subdir = $env{'form.authorpath'};
8026: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8027: }
8028: }
8029: } elsif ($env{'form.authorrole'} eq 'course') {
8030: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8031: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8032: my $url = "/priv/$coursedom/$coursenum";
8033: my $path=$docroot.$url;
8034: my $subdir = $env{'form.authorpath'};
8035: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8036: if ($redirect) {
8037: my $rightsfile = 'default.rights';
8038: my $sourcerights = "$path/$rightsfile";
8039: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8040: my $now = time;
8041: if (!-e $sourcerights) {
8042: my $cid = $coursedom.'_'.$coursenum;
8043: if (open(my $fh,">$sourcerights")) {
8044: print $fh <<END;
8045: <accessrule effect="deny" realm="" type="course" role="" />
8046: <accessrule effect="allow" realm="$cid" type="course" role="" />
8047: END
8048: close($fh);
8049: }
8050: }
8051: if (!-e "$sourcerights.meta") {
8052: if (open(my $fh,">$sourcerights.meta")) {
8053: my $author=$env{'environment.firstname'}.' '.
8054: $env{'environment.middlename'}.' '.
8055: $env{'environment.lastname'}.' '.
8056: $env{'environment.generation'};
8057: $author =~ s/\s+$//;
8058: print $fh <<"END";
8059:
8060: <abstract></abstract>
8061: <author>$author</author>
8062: <authorspace>$coursenum:$coursedom</authorspace>
8063: <copyright>private</copyright>
8064: <creationdate>$now</creationdate>
8065: <customdistributionfile></customdistributionfile>
8066: <dependencies></dependencies>
8067: <domain>$coursedom</domain>
8068: <highestgradelevel>0</highestgradelevel>
8069: <keywords></keywords>
8070: <language>notset </language>
8071: <lastrevisiondate>$now</lastrevisiondate>
8072: <lowestgradelevel>0</lowestgradelevel>
8073: <mime>rights</mime>
8074: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8075: <notes></notes>
8076: <obsolete></obsolete>
8077: <obsoletereplacement></obsoletereplacement>
8078: <owner>$coursenum:$coursedom</owner>
8079: <rule>deny:::course,allow:$cid::course</rule>
8080: <sourceavail></sourceavail>
8081: <standards></standards>
8082: <subject></subject>
8083: <title></title>
8084: END
8085: close($fh);
8086: }
8087: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8088: if (!-e "$docroot/res/$coursedom") {
8089: mkdir("$docroot/res/$coursedom",0755);
8090: }
8091: if (!-e "$docroot/res/$coursedom/$coursenum") {
8092: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8093: }
8094: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8095: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8096: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8097: }
8098: }
8099: }
8100: if ($env{'form.newresourceadd'}) {
8101: my $template = $env{'form.template'};
8102: my $source = $docroot.$redirect;
8103: my $target = $redirect;
8104: $target =~ s{^/priv/}{/res/};
8105: $target = $docroot.$target;
8106: if (!-e $source) {
8107: my $copyfrom;
8108: if ($template) {
8109: my %templates;
8110: my @files = &Apache::lonhomework::get_template_list('problem');
8111: foreach my $poss (@files) {
8112: if (ref($poss) eq 'ARRAY') {
8113: if ($template eq $poss->[0]) {
8114: $templates{$template} = 1;
8115: last;
8116: }
8117: }
8118: }
8119: if ($templates{$template}) {
8120: $copyfrom = $template;
8121: }
8122: }
8123: unless ($copyfrom) {
8124: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8125: }
8126: &File::Copy::copy($copyfrom,$source);
8127: }
8128: if (!-e "$source.meta") {
8129: my $cid = $coursedom.'_'.$coursenum;
8130: my $now = time;
8131: if (open(my $fh,">$source.meta")) {
8132: my $author=$env{'environment.firstname'}.' '.
8133: $env{'environment.middlename'}.' '.
8134: $env{'environment.lastname'}.' '.
8135: $env{'environment.generation'};
8136: $author =~ s/\s+$//;
8137: my $title = $env{'form.newresourcetitle'};
8138: $title =~ s/^\s+|\s+$//g;
8139: print $fh <<END;
8140:
8141: <abstract></abstract>
8142: <author>$author</author>
8143: <authorspace>$coursenum:$coursedom</authorspace>
8144: <copyright>custom</copyright>
8145: <creationdate>$now</creationdate>
8146: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8147: <dependencies></dependencies>
8148: <domain>$coursedom</domain>
8149: <highestgradelevel>0</highestgradelevel>
8150: <keywords></keywords>
8151: <language>notset </language>
8152: <lastrevisiondate>$now</lastrevisiondate>
8153: <lowestgradelevel>0</lowestgradelevel>
8154: <mime>problem</mime>
8155: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8156: <notes></notes>
8157: <obsolete></obsolete>
8158: <obsoletereplacement></obsoletereplacement>
8159: <owner>$coursenum:$coursedom</owner>
8160: <sourceavail></sourceavail>
8161: <standards></standards>
8162: <subject></subject>
8163: <title>$title</title>
8164: END
8165: close($fh);
8166: }
8167: }
8168: }
8169: }
8170: }
8171: } else {
8172: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8173: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8174: if (grep(/^\Q$rolehome\E$/,@ids)) {
8175: my $now = time;
8176: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8177: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8178: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8179: my $url = "/priv/$audom/$auname";
8180: my $path = $r->dir_config('lonDocRoot').$url;
8181: my $subdir = $env{'form.authorpath'};
8182: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8183: }
8184: }
8185: }
8186: }
8187: }
8188: }
8189: }
8190: return ($redirect,$error);
8191: }
8192:
8193: sub finishnewprob {
8194: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
8195: unless (-d $path) {
8196: unless (mkdir($path,02770)) {
8197: return;
8198: }
8199: }
8200: my $redirect;
8201: if ($subdir ne '/') {
8202: $subdir = &cleandir($subdir);
8203: if (($subdir ne '') && (-d "$path/$subdir")) {
8204: $path .= "/$subdir";
8205: $url .= "/$subdir";
8206: }
8207: }
8208: my $dest;
8209: if ($newsubdir ne '') {
8210: $newsubdir = &cleandir($newsubdir);
8211: }
8212: if ($newsubdir ne '') {
8213: if (-d "$path/$newsubdir") {
8214: $dest = "$path/$newsubdir/$filename";
8215: } else {
8216: my $dirok;
8217: unless (-e "$path/$newsubdir") {
8218: if (mkdir("$path/$newsubdir",02770)) {
8219: if (chmod(02770,"$path/$newsubdir")) {
8220: $dirok = 1;
8221: }
8222: }
8223: }
8224: if ($dirok) {
8225: $dest = "$path/$newsubdir/$filename";
8226: }
8227: }
8228: if (($dest ne '') && (!-e $dest)) {
8229: $redirect = "$url/$newsubdir/$filename";
8230: }
8231: } else {
8232: $dest = "$path/$filename";
8233: if (($dest ne '') && (!-e $dest)) {
8234: $redirect = "$url/$filename";
8235: }
8236: }
8237: return $redirect;
8238: }
8239:
8240: sub cleandir {
8241: my ($dir) = @_;
8242: $dir =~ s/^\s+//;
8243: $dir =~ s/\s+$//;
8244: $dir =~ s/\.+//g;
8245: $dir =~ s/[\#\?&%\":]//g;
8246: return $dir;
8247: }
8248:
8249: 1;
8250: __END__
8251:
8252:
8253: =head1 NAME
8254:
8255: Apache::londocs.pm
8256:
8257: =head1 SYNOPSIS
8258:
8259: This is part of the LearningOnline Network with CAPA project
8260: described at http://www.lon-capa.org.
8261:
8262: =head1 SUBROUTINES
8263:
8264: =over
8265:
8266: =item %help=()
8267:
8268: Available help topics
8269:
8270: =item mapread()
8271:
8272: Mapread read maps into LONCAPA::map:: global arrays
8273: @order and @resources, determines status
8274: sets @order - pointer to resources in right order
8275: sets @resources - array with the resources with correct idx
8276:
8277: =item authorhosts()
8278:
8279: Return hash with valid author names
8280:
8281: =item clean()
8282:
8283: =item dumpcourse()
8284:
8285: Actually dump course
8286:
8287: =item group_import()
8288:
8289: Imports the given (name, url) resources into the course
8290: coursenum, coursedom, and folder must precede the list
8291:
8292: =item breadcrumbs()
8293:
8294: =item log_docs()
8295:
8296: =item docs_change_log()
8297:
8298: =item update_paste_buffer()
8299:
8300: =item print_paste_buffer()
8301:
8302: =item do_paste_from_buffer()
8303:
8304: =item do_buffer_empty()
8305:
8306: =item clear_from_buffer()
8307:
8308: =item get_newmap_url()
8309:
8310: =item dbcopy()
8311:
8312: =item uniqueness_check()
8313:
8314: =item contained_map_check()
8315:
8316: =item url_paste_fixups()
8317:
8318: =item apply_fixups()
8319:
8320: =item copy_dependencies()
8321:
8322: =item update_parameter()
8323:
8324: =item handle_edit_cmd()
8325:
8326: =item editor()
8327:
8328: =item process_file_upload()
8329:
8330: =item process_secondary_uploads()
8331:
8332: =item is_supplemental_title()
8333:
8334: =item entryline()
8335:
8336: =item tiehash()
8337:
8338: =item untiehash()
8339:
8340: =item checkonthis()
8341:
8342: check on this
8343:
8344: =item verifycontent()
8345:
8346: Verify Content
8347:
8348: =item devalidateversioncache() & checkversions()
8349:
8350: Check Versions
8351:
8352: =item mark_hash_old()
8353:
8354: =item is_hash_old()
8355:
8356: =item changewarning()
8357:
8358: =item init_breadcrumbs()
8359:
8360: Breadcrumbs for special functions
8361:
8362: =item create_list_elements()
8363:
8364: =item create_form_ul()
8365:
8366: =item startContentScreen()
8367:
8368: =item endContentScreen()
8369:
8370: =item supplemental_base()
8371:
8372: =item embedded_form_elems()
8373:
8374: =item embedded_destination()
8375:
8376: =item return_to_editor()
8377:
8378: =item decompression_info()
8379:
8380: =item decompression_phase_one()
8381:
8382: =item decompression_phase_two()
8383:
8384: =item remove_archive()
8385:
8386: =item generate_admin_menu()
8387:
8388: =item generate_edit_table()
8389:
8390: =item editing_js()
8391:
8392: =item history_tab_js()
8393:
8394: =item inject_data_js()
8395:
8396: =item dump_switchserver_js()
8397:
8398: =item resize_scrollbox_js()
8399:
8400: =item makedocslogform()
8401:
8402: =item makesimpleeditform()
8403:
8404: =back
8405:
8406: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>