Annotation of loncom/interface/londocs.pm, revision 1.597
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.597 ! raeburn 4: # $Id: londocs.pm,v 1.596 2015/08/20 00:28:52 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.488 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.578 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.557 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.492 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.557 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
142:
143:
144: sub dumpcourse {
145: my ($r) = @_;
1.408 raeburn 146: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 147: my ($starthash,$js);
148: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
149: $js = <<"ENDJS";
150: <script type="text/javascript">
151: // <![CDATA[
152:
153: function hide_searching() {
154: if (document.getElementById('searching')) {
155: document.getElementById('searching').style.display = 'none';
156: }
157: return;
158: }
159:
160: // ]]>
161: </script>
162: ENDJS
163: $starthash = {
164: add_entries => {'onload' => "hide_searching();"},
165: };
166: }
1.568 raeburn 167: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
168: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 169: $r->print(&startContentScreen('tools'));
1.329 droeschl 170: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 171: unless ($home) {
172: $r->print(&endContentScreen());
173: return '';
174: }
1.329 droeschl 175: my $origcrsid=$env{'request.course.id'};
176: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
177: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
178: # Do the dumping
1.484 raeburn 179: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
180: $r->print(&endContentScreen());
181: return '';
182: }
1.531 raeburn 183: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 184: $r->print('<h3>'.&mt('Copying Files').'</h3>');
185: my $title=$env{'form.authorfolder'};
186: $title=&clean($title);
1.567 raeburn 187: my ($navmap,$errormsg) =
188: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
189: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
190: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
191: my (%maps,%resources,%titles);
192: if (!ref($navmap)) {
193: $r->print($errormsg.
194: &endContentScreen());
195: return '';
196: } else {
197: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
198: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 199: }
1.567 raeburn 200: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
201: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
202: %newcontent,%has_simpleprobs);
203: foreach my $item (sort {$a <=> $b} (@todump)) {
204: my $name = $env{'form.namefor_'.$item};
205: if ($resources{$item}) {
206: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
207: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
208: $tocopy{$1} = $name;
209: $display{$item} = $1;
210: $lookup{$1} = $item;
211: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
212: $simpleproblems{$item} = {
213: symb => $resources{$item},
214: name => $name,
215: };
216: $display{$item} = 'simpleproblem_'.$name;
217: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
218: $has_simpleprobs{$1}{$id} = $item;
219: }
220: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
221: my $marker = $1;
222: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
223: $simplepages{$item} = {
224: res => $res,
225: title => $titles{$item},
226: db => $db_name,
227: marker => $marker,
228: symb => $resources{$item},
229: name => $name,
230: };
231: $display{$item} = '/'.$res;
232: }
233: } elsif ($maps{$item}) {
234: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
235: $tocopy{$1} = $name;
236: $display{$item} = $1;
237: $lookup{$1} = $item;
238: }
239: } else {
240: next;
241: }
242: }
1.329 droeschl 243: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
244: $crs=~s/\_/\//g;
1.567 raeburn 245: my $mm = new File::MMagic;
246: my $prefix = "/uploaded/$cdom/$cnum/";
247: %replacehash = %tocopy;
248: foreach my $item (sort(keys(%simpleproblems))) {
249: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
250: $newcontent{$display{$item}} = $content;
251: }
252: my $gateway = Apache::lonhtmlgateway->new('web');
253: foreach my $item (sort(keys(%simplepages))) {
254: if (ref($simplepages{$item}) eq 'HASH') {
255: my $pagetitle = $simplepages{$item}{'title'};
256: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
257: my %contents;
258: foreach my $field (keys(%fields)) {
259: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
260: my $name = $1;
261: my $msg = $fields{$field};
262: if ($name eq 'webreferences') {
263: if ($msg =~ m{^https?://}) {
264: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
265: }
266: } else {
267: $msg = &Encode::decode('utf8',$msg);
268: $msg = $gateway->process_outgoing_html($msg,1);
269: $contents{$name} = $msg;
270: }
271: } elsif ($field eq 'uploaded.photourl') {
272: my $marker = $simplepages{$item}{marker};
273: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
274: my $filepath = $1;
275: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
276: if ($fname ne '') {
277: $fname=~s/\.(\w+)$//;
278: my $ext=$1;
279: $fname = &clean($fname);
280: $fname.='.'.$ext;
281: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
282: $replacehash{$filepath} = $relpath.$fname;
283: $deps{$item}{$filepath} = 1;
284: }
285: }
286: }
287: }
288: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
289: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
290: my $content = '
291: <html>
292: <head>
293: <title>'.$pagetitle.'</title>
294: </head>
295: <body bgcolor="#ffffff">';
296: if ($contents{title}) {
297: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
298: }
299: if ($contents{image}) {
300: $content .= "\n".$contents{image};
301: }
302: if ($contents{content}) {
303: $content .= '
304: <div class="LC_Box">
1.577 bisitz 305: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 306: $contents{content}.'
307: </div>';
308: }
309: if ($contents{webreferences}) {
310: $content .= '
311: <div class="LC_Box">
1.577 bisitz 312: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 313: $contents{webreferences}.'
314: </div>';
315: }
316: $content .= '
317: </body>
318: </html>
319: ';
320: $newcontent{'/'.$simplepages{$item}{res}} = $content;
321: }
322: }
323: foreach my $item (keys(%tocopy)) {
324: unless ($item=~/\.(sequence|page)$/) {
325: my $currurlpath = $prefix.$item;
326: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
327: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
328: }
329: }
330: foreach my $num (sort {$a <=> $b} (@todump)) {
331: my $src = $display{$num};
332: next if ($src eq '');
333: my @needcopy = ();
334: if ($replacehash{$src}) {
335: push(@needcopy,$src);
336: if (ref($deps{$num}) eq 'HASH') {
337: foreach my $dep (sort(keys(%{$deps{$num}}))) {
338: if ($replacehash{$dep}) {
339: push(@needcopy,$dep);
340: }
341: }
342: }
343: } elsif ($src =~ /^simpleproblem_/) {
344: push(@needcopy,$src);
345: }
346: next if (@needcopy == 0);
347: my ($result,$depresult);
348: for (my $i=0; $i<@needcopy; $i++) {
349: my $item = $needcopy[$i];
350: my $newfilename;
351: if ($simpleproblems{$num}) {
352: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
353: } else {
354: $newfilename=$title.'/'.$replacehash{$item};
355: }
356: $newfilename=~s/\.(\w+)$//;
357: my $ext=$1;
358: $newfilename=&clean($newfilename);
359: $newfilename.='.'.$ext;
360: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
361: if ($newrelpath ne $replacehash{$item}) {
362: $replacehash{$item} = $newrelpath;
363: }
364: my @dirs=split(/\//,$newfilename);
365: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
366: my $makepath=$path;
367: my $fail;
368: my $origin;
369: for (my $i=0;$i<$#dirs;$i++) {
370: $makepath.='/'.$dirs[$i];
371: unless (-e $makepath) {
372: unless(mkdir($makepath,0755)) {
373: $fail = &mt('Directory creation failed.');
374: }
375: }
376: }
377: if ($i == 0) {
378: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
379: } else {
380: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
381: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
382: &mt('(dependency)').'</span>: ';
383: }
384: if (-e $path.'/'.$newfilename) {
385: $fail = &mt('Destination already exists -- not overwriting.');
386: } else {
387: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
388: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
389: ($item =~ /^simpleproblem_/)) {
390: print $fh $newcontent{$item};
391: } else {
392: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
393: if (-e $fileloc) {
394: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
395: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
396: (ref($has_simpleprobs{$item}) eq 'HASH')) {
397: my %changes = %{$has_simpleprobs{$item}};
398: my $content = &Apache::lonclonecourse::rewritefile(
399: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
400: (%replacehash,$crs => '')
401: );
402: my $updatedcontent = '';
403: my $parser = HTML::TokeParser->new(\$content);
404: $parser->attr_encoded(1);
405: while (my $token = $parser->get_token) {
406: if ($token->[0] eq 'S') {
407: if (($token->[1] eq 'resource') &&
408: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
409: ($changes{$token->[2]->{'id'}})) {
410: my $id = $token->[2]->{'id'};
411: $updatedcontent .= '<'.$token->[1];
412: foreach my $attrib (@{$token->[3]}) {
413: next unless ($attrib =~ /^(src|type|title|id)$/);
414: if ($attrib eq 'src') {
415: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
416: if ($file) {
417: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
418: } else {
419: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
420: }
421: } else {
422: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
423: }
424: }
425: $updatedcontent .= ' />'."\n";
426: } else {
427: $updatedcontent .= $token->[4]."\n";
428: }
429: } else {
430: $updatedcontent .= $token->[2];
431: }
432: }
433: print $fh $updatedcontent;
434: } else {
435: print $fh &Apache::lonclonecourse::rewritefile(
436: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
437: (%replacehash,$crs => '')
438: );
439: }
440: } else {
441: print $fh
442: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
443: }
444: } else {
445: $fail = &mt('Source does not exist.');
446: }
447: }
448: $fh->close();
449: } else {
450: $fail = &mt('Could not write to destination.');
451: }
452: }
453: my $text;
454: if ($fail) {
455: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
456: } else {
457: $text = '<span class="LC_success">'.&mt('ok').'</span>';
458: }
459: if ($i == 0) {
460: $result .= $text;
461: } else {
462: $depresult .= $text.'</li>';
463: }
464: }
465: $r->print($result);
466: if ($depresult) {
467: $r->print('<ul>'.$depresult.'</ul>');
468: }
469: }
470: } else {
471: my ($navmap,$errormsg) =
472: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
473: if (!ref($navmap)) {
474: $r->print($errormsg);
475: } else {
476: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
477: $r->rflush();
478: my ($preamble,$formname);
479: $formname = 'dumpdoc';
480: unless ($home==1) {
481: $preamble = '<div class="LC_left_float">'.
482: '<fieldset><legend>'.
483: &mt('Select the Authoring Space').
484: '</legend><select name="authorspace">';
1.329 droeschl 485: }
1.567 raeburn 486: my @orderspaces = ();
487: foreach my $key (sort(keys(%outhash))) {
488: if ($key=~/^home_(.+)$/) {
489: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
490: unshift(@orderspaces,$1);
491: } else {
492: push(@orderspaces,$1);
493: }
494: }
495: }
1.569 raeburn 496: if ($home>1) {
497: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
498: }
1.567 raeburn 499: foreach my $user (@orderspaces) {
1.329 droeschl 500: if ($home==1) {
1.567 raeburn 501: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 502: } else {
1.567 raeburn 503: $preamble .= '<option value="'.$user.'">'.$user.' - '.
504: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
505: }
1.329 droeschl 506: }
1.567 raeburn 507: unless ($home==1) {
508: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 509: }
1.567 raeburn 510: my $title=$origcrsdata{'description'};
511: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 512: $title=&clean($title);
1.567 raeburn 513: $preamble .= '<div class="LC_left_float">'.
514: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
515: '<input type="text" size="50" name="authorfolder" value="'.
516: $title.'" />'.
517: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
518: my %uploadedfiles;
519: &tiehash();
520: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
521: my ($ext)=($file=~/\.(\w+)$/);
522: # FIXME Check supplemental here
523: my $title=$hash{'title_'.$hash{
524: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
525: if (!$title) {
526: $title=$file;
527: } else {
528: $title=~s|/|_|g;
529: }
530: $title=~s/\.(\w+)$//;
531: $title=&clean($title);
532: $title.='.'.$ext;
533: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
534: $uploadedfiles{$file} = $title;
535: }
536: &untiehash();
537: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
538: undef,undef,$preamble,$home,\%uploadedfiles));
539: }
1.329 droeschl 540: }
1.484 raeburn 541: $r->print(&endContentScreen());
1.329 droeschl 542: }
543:
1.567 raeburn 544: sub recurse_html {
545: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
546: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
547: my (%allfiles,%codebase);
548: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
549: if (keys(%allfiles)) {
550: foreach my $dependency (keys(%allfiles)) {
551: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
552: my ($depurl,$relfile,$newcontainer);
553: if ($dependency =~ m{^/}) {
554: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
555: $relfile = $1;
556: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
557: $newcontainer = $1;
558: next if ($replacehash->{$newcontainer});
559: }
560: $depurl = $dependency;
561: } else {
562: next;
563: }
564: } else {
565: $relfile = $dependency;
566: $depurl = $currurlpath;
567: $depurl =~ s{[^/]+$}{};
568: $depurl .= $dependency;
569: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
570: }
571: next if ($relfile eq '');
572: my $newname = $replacehash->{$container};
573: $newname =~ s{[^/]+$}{};
574: $replacehash->{$newcontainer} = $newname.$relfile;
575: $deps->{$item}{$newcontainer} = 1;
576: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
577: my $depfile = &Apache::lonnet::filelocation('',$depurl);
578: my $type = $mm->checktype_filename($depfile);
579: if ($type eq 'text/html') {
580: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
581: }
582: }
583: }
584: }
585: return;
586: }
587:
1.329 droeschl 588: sub group_import {
589: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.529 raeburn 590: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
591: %removeparam,$importuploaded,$fixuperrors);
592: $allmaps = {};
1.329 droeschl 593: while (@files) {
594: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 595: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 596: && ($caller eq 'londocs')
597: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 598:
1.329 droeschl 599: my $errtext = '';
600: my $fatal = 0;
601: my $newmapstr = '<map>'."\n".
602: '<resource id="1" src="" type="start"></resource>'."\n".
603: '<link from="1" to="2" index="1"></link>'."\n".
604: '<resource id="2" src="" type="finish"></resource>'."\n".
605: '</map>';
606: $env{'form.output'}=$newmapstr;
607: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
608: 'output',$1.$2);
1.534 raeburn 609: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 610: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
611: $fatal = 2;
612: }
613: if ($fatal) {
614: return ($errtext,$fatal);
615: }
616: }
617: if ($url) {
1.529 raeburn 618: if (($caller eq 'londocs') &&
619: ($folder =~ /^default/)) {
1.534 raeburn 620: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 621: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
622: my $cid = $coursedom.'_'.$coursenum;
623: $allmaps =
624: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
625: $chome,$cid);
626: $donechk = 1;
627: }
628: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
629: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
630: \%addedmaps,\%hierarchy,\%titles,$allmaps);
631: $importuploaded = 1;
632: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
633: next if ($allmaps->{$url});
634: }
635: }
1.344 bisitz 636: if (!$residx
1.329 droeschl 637: || defined($LONCAPA::map::zombies[$residx])) {
638: $residx = &LONCAPA::map::getresidx($url,$residx);
639: push(@LONCAPA::map::order, $residx);
640: }
641: my $ext = 'false';
642: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
643: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 644: if ($name eq '') {
1.538 raeburn 645: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 646: }
647: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
648: my $filepath = $1;
649: my $fname = $name;
650: if ($fname =~ /^\W+$/) {
651: $fname = 'web';
652: } else {
653: $fname =~ s/\W/_/g;
654: }
655: if (length($fname > 15)) {
656: $fname = substr($fname,0,14);
657: }
658: my $initialtext = &mt('Replace with your own content.');
659: my $newhtml = <<END;
1.545 raeburn 660: <html>
1.534 raeburn 661: <head>
662: <title>$name</title>
663: </head>
664: <body bgcolor="#ffffff">
665: $initialtext
666: </body>
667: </html>
668: END
669: $env{'form.output'}=$newhtml;
670: my $result =
671: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
672: 'output',
673: "$filepath/$residx/$fname.html");
674: if ($result =~ m{^/uploaded/}) {
675: $url = $result;
676: if ($filepath =~ /^supplemental/) {
677: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
678: $env{'user.domain'}.'___&&&___'.$name;
679: }
680: } else {
681: return (&mt('Failed to save new web page.'),1);
682: }
683: }
1.538 raeburn 684: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 685: $LONCAPA::map::resources[$residx] =
1.329 droeschl 686: join(':', ($name, $url, $ext, 'normal', 'res'));
687: }
688: }
1.529 raeburn 689: if ($importuploaded) {
690: my %import_errors;
691: my %updated = (
692: removefrommap => \%removefrommap,
693: removeparam => \%removeparam,
694: );
1.533 raeburn 695: my ($result,$msgsarray,$lockerror) =
696: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 697: if (keys(%import_errors) > 0) {
1.530 raeburn 698: $fixuperrors =
1.529 raeburn 699: '<p span class="LC_warning">'."\n".
700: &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".
701: '<ul>'."\n";
702: foreach my $key (sort(keys(%import_errors))) {
703: $fixuperrors .= '<li>'.$key.'</li>'."\n";
704: }
705: $fixuperrors .= '</ul></p>'."\n";
706: }
1.533 raeburn 707: if (ref($msgsarray) eq 'ARRAY') {
708: if (@{$msgsarray} > 0) {
709: $fixuperrors .= '<p class="LC_info">'.
710: join('<br />',@{$msgsarray}).
711: '</p>';
712: }
713: }
714: if ($lockerror) {
715: $fixuperrors .= '<p class="LC_error">'.
716: $lockerror.
717: '</p>';
718: }
1.529 raeburn 719: }
720: my ($errtext,$fatal) =
721: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 722: unless ($fatal) {
723: if ($folder =~ /^supplemental/) {
724: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 725: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
726: $folder.'.'.$container);
1.557 raeburn 727: }
728: }
1.529 raeburn 729: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 730: }
731:
732: sub log_docs {
1.494 raeburn 733: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 734: }
735:
736: {
737: my @oldresources=();
738: my @oldorder=();
739: my $parmidx;
740: my %parmaction=();
741: my %parmvalue=();
742: my $changedflag;
743:
744: sub snapshotbefore {
745: @oldresources=@LONCAPA::map::resources;
746: @oldorder=@LONCAPA::map::order;
747: $parmidx=undef;
748: %parmaction=();
749: %parmvalue=();
750: $changedflag=0;
751: }
752:
753: sub remember_parms {
754: my ($idx,$parameter,$action,$value)=@_;
755: $parmidx=$idx;
756: $parmaction{$parameter}=$action;
757: $parmvalue{$parameter}=$value;
758: $changedflag=1;
759: }
760:
761: sub log_differences {
762: my ($plain)=@_;
763: my %storehash=('folder' => $plain,
764: 'currentfolder' => $env{'form.folder'});
765: if ($parmidx) {
766: $storehash{'parameter_res'}=$oldresources[$parmidx];
767: foreach my $parm (keys(%parmaction)) {
768: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
769: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
770: }
771: }
772: my $maxidx=$#oldresources;
773: if ($#LONCAPA::map::resources>$#oldresources) {
774: $maxidx=$#LONCAPA::map::resources;
775: }
776: for (my $idx=0; $idx<=$maxidx; $idx++) {
777: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
778: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
779: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
780: $changedflag=1;
781: }
782: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
783: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
784: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
785: $changedflag=1;
786: }
787: }
788: $storehash{'maxidx'}=$maxidx;
789: if ($changedflag) { &log_docs(\%storehash); }
790: }
791: }
792:
793: sub docs_change_log {
1.484 raeburn 794: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486 raeburn 795: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 796: my $js = '<script type="text/javascript">'."\n".
797: '// <![CDATA['."\n".
798: &Apache::loncommon::display_filter_js('docslog')."\n".
1.486 raeburn 799: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
1.483 raeburn 800: &history_tab_js()."\n".
1.484 raeburn 801: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 802: '// ]]>'."\n".
803: '</script>'."\n";
1.484 raeburn 804: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
805: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 806: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 807: my %orderhash;
808: my $container='sequence';
809: my $pathitem;
1.519 raeburn 810: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 811: $container='page';
812: }
1.519 raeburn 813: my $folderpath=$env{'form.folderpath'};
814: if ($folderpath eq '') {
1.548 raeburn 815: $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
1.519 raeburn 816: }
817: $pathitem = '<input type="hidden" name="folderpath" value="'.
818: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 819: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
820: my $jumpto = $readfile;
821: $jumpto =~ s{^/}{};
822: my $tid = 1;
1.489 raeburn 823: if ($supplementalflag) {
824: $tid = 2;
825: }
1.509 raeburn 826: my ($breadcrumbtrail) =
827: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 828: $r->print($breadcrumbtrail.
829: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
830: $readfile));
1.329 droeschl 831: my %docslog=&Apache::lonnet::dump('nohist_docslog',
832: $env{'course.'.$env{'request.course.id'}.'.domain'},
833: $env{'course.'.$env{'request.course.id'}.'.num'});
834:
835: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
836:
837: my %saveable_parameters = ('show' => 'scalar',);
838: &Apache::loncommon::store_course_settings('docs_log',
839: \%saveable_parameters);
840: &Apache::loncommon::restore_course_settings('docs_log',
841: \%saveable_parameters);
842: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 843: # FIXME: internationalization seems wrong here
1.329 droeschl 844: my %lt=('hiddenresource' => 'Resources hidden',
845: 'encrypturl' => 'URL hidden',
846: 'randompick' => 'Randomly pick',
847: 'randomorder' => 'Randomly ordered',
848: 'set' => 'set to',
849: 'del' => 'deleted');
1.484 raeburn 850: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
851: $pathitem."\n".
852: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
853: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
854: $r->print('<div class="LC_left_float">'.
855: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
856: &makedocslogform($filter,1).
857: '</fieldset></div><br clear="all" />');
1.329 droeschl 858: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
859: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
860: &mt('After').'</th>'.
861: &Apache::loncommon::end_data_table_header_row());
862: my $shown=0;
863: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
864: if ($env{'form.displayfilter'} eq 'currentfolder') {
865: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
866: }
867: my @changes=keys(%{$docslog{$id}{'logentry'}});
868: if ($env{'form.displayfilter'} eq 'containing') {
869: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
870: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
871: foreach my $key (@changes) {
872: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
873: }
1.344 bisitz 874: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 875: }
876: my $count = 0;
877: my $time =
878: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
879: my $plainname =
880: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
881: $docslog{$id}{'exe_udom'});
882: my $about_me_link =
883: &Apache::loncommon::aboutmewrapper($plainname,
884: $docslog{$id}{'exe_uname'},
885: $docslog{$id}{'exe_udom'});
886: my $send_msg_link='';
887: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
888: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
889: $send_msg_link ='<br />'.
890: &Apache::loncommon::messagewrapper(&mt('Send message'),
891: $docslog{$id}{'exe_uname'},
892: $docslog{$id}{'exe_udom'});
893: }
894: $r->print(&Apache::loncommon::start_data_table_row());
895: $r->print('<td>'.$time.'</td>
896: <td>'.$about_me_link.
897: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
898: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
899: $send_msg_link.'</td><td>'.
900: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 901: my $is_supp = 0;
902: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
903: $is_supp = 1;
904: }
1.329 droeschl 905: # Before
906: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
907: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
908: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
909: if ($oldname ne $newname) {
1.488 raeburn 910: my $shown = &LONCAPA::map::qtescape($oldname);
911: if ($is_supp) {
912: $shown = &Apache::loncommon::parse_supplemental_title($shown);
913: }
914: $r->print($shown);
1.329 droeschl 915: }
916: }
917: $r->print('<ul>');
918: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
919: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 920: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
921: if ($is_supp) {
922: $shown = &Apache::loncommon::parse_supplemental_title($shown);
923: }
924: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 925: }
926: }
927: $r->print('</ul>');
928: # After
929: $r->print('</td><td>');
930:
931: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
932: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
933: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
934: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 935: my $shown = &LONCAPA::map::qtescape($newname);
936: if ($is_supp) {
937: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
938: }
939: $r->print($shown);
1.329 droeschl 940: }
1.364 bisitz 941: }
1.329 droeschl 942: $r->print('<ul>');
943: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
944: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 945: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
946: if ($is_supp) {
947: $shown = &Apache::loncommon::parse_supplemental_title($shown);
948: }
949: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 950: }
951: }
952: $r->print('</ul>');
953: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
954: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
955: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
956: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 957: # FIXME: internationalization seems wrong here
1.329 droeschl 958: $r->print('<li>'.
959: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
960: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
961: .'</li>');
962: }
963: }
964: $r->print('</ul>');
965: }
966: # End
967: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
968: $shown++;
969: if (!($env{'form.show'} eq &mt('all')
970: || $shown<=$env{'form.show'})) { last; }
971: }
1.484 raeburn 972: $r->print(&Apache::loncommon::end_data_table()."\n".
973: &makesimpleeditform($pathitem)."\n".
974: '</div></div>');
975: $r->print(&endContentScreen());
1.329 droeschl 976: }
977:
978: sub update_paste_buffer {
1.492 raeburn 979: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 980: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 981: if ($env{'form.multiremove'}) {
982: $env{'form.multiremove'} =~ s/,$//;
983: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
984: }
985: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
986: if ($env{'form.multicut'}) {
987: $env{'form.multicut'} =~ s/,$//;
988: foreach my $item (split(/,/,$env{'form.multicut'})) {
989: unless ($removals{$item}) {
990: $cuts{$item} = 1;
991: push(@possibles,$item.':cut');
992: }
993: }
994: }
995: if ($env{'form.multicopy'}) {
996: $env{'form.multicopy'} =~ s/,$//;
997: foreach my $item (split(/,/,$env{'form.multicopy'})) {
998: unless ($removals{$item} || $cuts{$item}) {
999: push(@possibles,$item.':copy');
1000: }
1001: }
1002: }
1003: } elsif ($env{'form.markcopy'}) {
1004: @possibles = split(/,/,$env{'form.markcopy'});
1005: }
1.329 droeschl 1006:
1.538 raeburn 1007: return if (@possibles == 0);
1.329 droeschl 1008: return if (!defined($env{'form.copyfolder'}));
1009:
1010: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1011: $env{'form.copyfolder'});
1.538 raeburn 1012: return if ($fatal);
1013:
1014: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1015:
1.538 raeburn 1016: # Retrieve current paste buffer suffixes.
1017: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1018: my (%pasteurls,@newpaste);
1019:
1020: # Construct identifiers for current contents of user's paste buffer
1021: if (@currpaste) {
1022: foreach my $suffix (@currpaste) {
1023: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1024: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 ! raeburn 1025: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1026: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1027: ($url ne '')) {
1.597 ! raeburn 1028: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1029: }
1030: }
1031: }
1032:
1033: # Mark items for copying (skip any items already in user's paste buffer)
1034: my %addtoenv;
1.597 ! raeburn 1035:
! 1036: my @pathitems = split(/\&/,$env{'form.folderpath'});
! 1037: my @folderconf = split(/\:/,$pathitems[-1]);
! 1038: my $ispage = $folderconf[4];
! 1039:
1.538 raeburn 1040: foreach my $item (@possibles) {
1041: my ($orderidx,$cmd) = split(/:/,$item);
1042: next if ($orderidx =~ /\D/);
1043: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 ! raeburn 1044: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1045: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1046: my %denied = &action_restrictions($coursenum,$coursedom,
1047: &LONCAPA::map::qtescape($url),
1048: $env{'form.folderpath'},\%curr_groups);
1049: next if ($denied{'copy'});
1050: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 ! raeburn 1051: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1052: my ($suffix,$errortxt,$locknotfreed) =
1053: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1054: if ($suffix ne '') {
1055: push(@newpaste,$suffix);
1056: } else {
1057: if ($locknotfreed) {
1058: return $locknotfreed;
1059: }
1.538 raeburn 1060: }
1061: if (&is_supplemental_title($title)) {
1062: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1063: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1064: }
1.329 droeschl 1065:
1.538 raeburn 1066: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1067: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1068: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1069: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 ! raeburn 1070: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1071: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1072: my $prefix = $1;
1073: my $subdir =$2;
1074: if ($subdir eq '') {
1075: $subdir = $prefix;
1.492 raeburn 1076: }
1.538 raeburn 1077: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1078: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1079: \%hierarchy,\%titles,\%allmaps);
1080: if (ref($hierarchy{$url}) eq 'HASH') {
1081: my ($nested,$nestednames);
1082: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1083: $nested =~ s/\&$//;
1084: $nestednames =~ s/\Q___&&&___\E$//;
1085: if ($nested ne '') {
1086: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1087: }
1088: if ($nestednames ne '') {
1089: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1090: }
1.492 raeburn 1091: }
1092: }
1.591 raeburn 1093: if ($locknotfreed) {
1094: $output = $locknotfreed;
1095: last;
1096: }
1.492 raeburn 1097: }
1.538 raeburn 1098: if (@newpaste) {
1099: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1100: }
1.492 raeburn 1101: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1102: delete($env{'form.markcopy'});
1.591 raeburn 1103: return $output;
1.329 droeschl 1104: }
1105:
1.492 raeburn 1106: sub recurse_uploaded_maps {
1107: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1108: if (ref($hierarchy->{$url}) eq 'HASH') {
1109: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1110: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1111: my (@uploaded,@names,%shorter);
1112: for (my $i=0; $i<@maps; $i++) {
1113: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1114: if ($inner ne '') {
1115: push(@uploaded,$inner);
1116: push(@names,&escape($titles[$i]));
1117: $shorter{$maps[$i]} = $inner;
1118: }
1119: }
1120: $$nestref .= "$dir:".join(',',@uploaded).'&';
1121: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1122: foreach my $map (@maps) {
1123: if ($shorter{$map} ne '') {
1124: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1125: }
1126: }
1127: }
1128: return;
1129: }
1130:
1.329 droeschl 1131: sub print_paste_buffer {
1.492 raeburn 1132: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1133: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1134:
1.538 raeburn 1135: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1136: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1137: }
1138:
1.538 raeburn 1139: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1140: my ($pasteitems,@pasteable);
1.575 raeburn 1141: my $clipboardcount = 0;
1.488 raeburn 1142:
1.538 raeburn 1143: # Construct identifiers for current contents of user's paste buffer
1144: foreach my $suffix (@currpaste) {
1145: next if ($suffix =~ /\D/);
1146: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1147: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 ! raeburn 1148: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1149: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1150: ($url ne '')) {
1.575 raeburn 1151: $clipboardcount ++;
1.538 raeburn 1152: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1153: $canpaste,$nopaste,$othercrs,$areachange);
1154: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1155: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1156: $is_external = 1;
1157: }
1158: if ($folder =~ /^supplemental/) {
1159: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1160: unless ($canpaste) {
1161: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1162: }
1163: } else {
1164: $canpaste = 1;
1165: }
1166: if ($canpaste) {
1167: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1168: my $srcdom = $1;
1169: my $srcnum = $2;
1170: my $rem = $3;
1171: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1172: $othercourse = 1;
1173: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1174: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1175: } else {
1176: $canpaste = 0;
1177: $nopaste = &mt('Paste from another course unavailable.');
1178: }
1179: }
1180: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1181: my $prefix = $1;
1182: $parent = $2;
1183: if ($folder !~ /^\Q$prefix\E/) {
1184: $areachange = 1;
1185: }
1186: $is_uploaded_map = 1;
1.492 raeburn 1187: }
1.597 ! raeburn 1188: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
! 1189: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1190: if ($cid ne $env{'request.course.id'}) {
1191: my ($srcdom,$srcnum) = split(/_/,$cid);
1192: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1193: $othercrs = '<br />'.&mt('(from another course)');
1194: } else {
1195: $canpaste = 0;
1196: $nopaste = &mt('Paste from another course unavailable.');
1197: }
1198: }
1.492 raeburn 1199: }
1.596 raeburn 1200: if ($canpaste) {
1201: push(@pasteable,$suffix);
1202: }
1.538 raeburn 1203: }
1204: my $buffer;
1205: if ($is_external) {
1206: $buffer = &mt('External Resource').': '.
1207: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1208: &LONCAPA::map::qtescape($url).')';
1209: } else {
1210: my $icon = &Apache::loncommon::icon($extension);
1211: if ($extension eq 'sequence' &&
1212: $url =~ m{/default_\d+\.sequence$}x) {
1213: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1214: $icon .= '/navmap.folder.closed.gif';
1215: }
1.589 raeburn 1216: my $title = $env{'docs.markedcopy_title_'.$suffix};
1217: if ($title eq '') {
1218: ($title) = ($url =~ m{/([^/]+)$});
1219: }
1.538 raeburn 1220: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1221: ': '.
1222: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1223: &LONCAPA::map::qtescape($title));
1.538 raeburn 1224: }
1225: $pasteitems .= '<div class="LC_left_float">';
1226: my ($options,$onclick);
1227: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1228: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1229: if (($is_uploaded_map) ||
1230: ($url =~ /(bulletinboard|smppg)$/) ||
1231: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1232: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1233: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1234: }
1235: }
1236: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1237: if ($nopaste) {
1238: $pasteitems .= $nopaste;
1239: } else {
1240: if ($othercrs) {
1241: $pasteitems .= $othercrs;
1242: }
1243: if ($options) {
1244: $pasteitems .= $options;
1.492 raeburn 1245: }
1246: }
1.538 raeburn 1247: $pasteitems .= '</div>';
1248: }
1249: }
1250: if ($pasteitems eq '') {
1251: &Apache::lonnet::delenv('docs.markedcopies');
1252: }
1253: my ($pasteform,$form_start,$buttons,$form_end);
1254: if ($pasteitems) {
1255: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1256: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1257: if (@pasteable) {
1.575 raeburn 1258: my $value = &mt('Paste to current folder');
1259: if ($container eq 'page') {
1260: $value = &mt('Paste to current page');
1261: }
1262: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1263: }
1264: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1265: if ($clipboardcount > 1) {
1266: $buttons .=
1267: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1268: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1269: (' 'x2).
1270: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1271: (' 'x2);
1.492 raeburn 1272: }
1.575 raeburn 1273: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1274: '</form>';
1.538 raeburn 1275: } else {
1276: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1277: }
1.538 raeburn 1278: $r->print($form_start
1279: .'<fieldset>'
1280: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1281: .$pasteitems
1282: .'</fieldset>'
1283: .$form_end);
1284: }
1285:
1286: sub paste_options {
1287: my ($suffix,$is_uploaded_map,$parent) = @_;
1288: my ($copytext,$movetext);
1289: if ($is_uploaded_map) {
1290: $copytext = &mt('Copy to new folder');
1291: $movetext = &mt('Move old');
1292: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1293: $copytext = &mt('Copy to new board');
1294: $movetext = &mt('Move (not posts)');
1295: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1296: $copytext = &mt('Copy to new page');
1297: $movetext = &mt('Move');
1.533 raeburn 1298: } else {
1.538 raeburn 1299: $copytext = &mt('Copy to new file');
1300: $movetext = &mt('Move');
1301: }
1302: my $output = '<br />'.
1303: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1304: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1305: '<label>'.
1306: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1307: $copytext.'</label></span>'.(' 'x2).' '.
1308: '<span class="LC_nobreak"><label>'.
1309: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1310: $movetext.'</label></span>';
1311: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1312: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1313: '</legend><table border="0">';
1314: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1315: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1316: my $lastdir = $parent;
1317: my %depths = (
1318: $lastdir => 0,
1319: );
1320: my (%display,%deps);
1321: for (my $i=0; $i<@pastemaps; $i++) {
1322: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1323: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1324: my @subfolders = split(/,/,$subfolderstr);
1325: $deps{$lastdir} = \@subfolders;
1326: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1327: my $depth = $depths{$lastdir} + 1;
1328: my $offset = int($depth * 4);
1329: my $indent = (' ' x $offset);
1330: for (my $j=0; $j<@subfolders; $j++) {
1331: $depths{$subfolders[$j]} = $depth;
1332: $display{$subfolders[$j]} =
1333: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1334: '<td><label>'.
1335: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1336: '<label>'.
1337: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1338: &mt('Move old').'</label>'.
1339: '</td></tr>';
1340: }
1.492 raeburn 1341: }
1.538 raeburn 1342: &recurse_print(\$output,$parent,\%deps,\%display);
1343: $output .= '</table></fieldset>';
1.329 droeschl 1344: }
1.538 raeburn 1345: $output .= '</div>';
1346: return $output;
1.488 raeburn 1347: }
1348:
1.492 raeburn 1349: sub recurse_print {
1.538 raeburn 1350: my ($outputref,$dir,$deps,$display) = @_;
1351: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1352: if (ref($deps->{$dir}) eq 'ARRAY') {
1353: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1354: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1355: }
1356: }
1357: }
1358:
1.488 raeburn 1359: sub supp_pasteable {
1360: my ($url) = @_;
1361: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1362: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1363: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1364: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1365: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1366: return 1;
1367: }
1368: return;
1.329 droeschl 1369: }
1370:
1.492 raeburn 1371: sub paste_popup_js {
1.594 damieng 1372: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1373: show => 'Show Options',
1374: hide => 'Hide Options',
1.594 damieng 1375: );
1376: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1377: none => 'No items selected from clipboard.',
1.492 raeburn 1378: );
1.594 damieng 1379: &html_escape(\%html_js_lt);
1380: &js_escape(\%html_js_lt);
1381: &js_escape(\%js_lt);
1.492 raeburn 1382: return <<"END";
1383:
1.538 raeburn 1384: function showPasteOptions(suffix) {
1385: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1386: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1387: return;
1388: }
1389:
1.538 raeburn 1390: function hidePasteOptions(suffix) {
1391: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1392: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1393: return;
1394: }
1395:
1396: function showOptions(caller,suffix) {
1397: if (document.getElementById('pasteoptionstext_'+suffix)) {
1398: if (caller.checked) {
1.594 damieng 1399: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1400: } else {
1401: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1402: }
1403: if (document.getElementById('pasteoptions_'+suffix)) {
1404: document.getElementById('pasteoptions_'+suffix).style.display='none';
1405: }
1406: }
1.492 raeburn 1407: return;
1408: }
1409:
1.541 raeburn 1410: function validateClipboard() {
1411: var numchk = 0;
1412: if (document.pasteform.pasting.length > 1) {
1413: for (var i=0; i<document.pasteform.pasting.length; i++) {
1414: if (document.pasteform.pasting[i].checked) {
1415: numchk ++;
1416: }
1417: }
1418: } else {
1419: if (document.pasteform.pasting.type == 'checkbox') {
1420: if (document.pasteform.pasting.checked) {
1421: numchk ++;
1422: }
1423: }
1424: }
1425: if (numchk > 0) {
1426: return true;
1427: } else {
1.594 damieng 1428: alert("$js_lt{'none'}");
1.541 raeburn 1429: return false;
1430: }
1431: }
1432:
1.575 raeburn 1433: function checkClipboard() {
1434: if (document.pasteform.pasting.length > 1) {
1435: for (var i=0; i<document.pasteform.pasting.length; i++) {
1436: document.pasteform.pasting[i].checked = true;
1437: }
1438: }
1439: return;
1440: }
1441:
1442: function uncheckClipboard() {
1443: if (document.pasteform.pasting.length >1) {
1444: for (var i=0; i<document.pasteform.pasting.length; i++) {
1445: document.pasteform.pasting[i].checked = false;
1446: }
1447: }
1448: return;
1449: }
1450:
1.492 raeburn 1451: END
1452:
1453: }
1454:
1.329 droeschl 1455: sub do_paste_from_buffer {
1.492 raeburn 1456: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1457:
1.538 raeburn 1458: # Array of items in paste buffer
1459: my (@currpaste,%pastebuffer,%allerrors);
1460: @currpaste = split(/,/,$env{'docs.markedcopies'});
1461:
1.492 raeburn 1462: # Early out if paste buffer is empty
1.538 raeburn 1463: if (@currpaste == 0) {
1.492 raeburn 1464: return ();
1.538 raeburn 1465: }
1466: map { $pastebuffer{$_} = 1; } @currpaste;
1467:
1468: # Array of items selected items to paste
1469: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1470:
1471: # Early out if nothing selected to paste
1472: if (@reqpaste == 0) {
1473: return();
1474: }
1475: my @topaste;
1476: foreach my $suffix (@reqpaste) {
1477: next if ($suffix =~ /\D/);
1478: next unless (exists($pastebuffer{$suffix}));
1479: push(@topaste,$suffix);
1480: }
1481:
1482: # Early out if nothing available to paste
1483: if (@topaste == 0) {
1484: return();
1.329 droeschl 1485: }
1486:
1.538 raeburn 1487: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 ! raeburn 1488: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1489:
1490: foreach my $suffix (@topaste) {
1491: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1492: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 ! raeburn 1493: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1494: # Supplemental content may only include certain types of content
1495: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1496: if ($folder =~ /^supplemental/) {
1497: unless (&supp_pasteable($url)) {
1498: $notinsupp{$suffix} = 1;
1499: next;
1500: }
1.492 raeburn 1501: }
1.538 raeburn 1502: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1503: my $srcd = $1;
1504: my $srcn = $2;
1.492 raeburn 1505: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1506: # check for mdc privilege in the course from which the resource was pasted
1507: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1508: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1509: $notincrs{$suffix} = 1;
1510: next;
1511: }
1.491 raeburn 1512: }
1.538 raeburn 1513: $srcdom{$suffix} = $srcd;
1514: $srcnum{$suffix} = $srcn;
1.597 ! raeburn 1515: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
! 1516: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1517: my ($srcd,$srcn) = split(/_/,$cid);
1518: # When paste buffer was populated using an active role in a different course
1519: # check for mdc privilege in the course from which the resource was pasted
1520: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1521: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1522: $notincrs{$suffix} = 1;
1523: next;
1524: }
1525: }
1526: $srcdom{$suffix} = $srcd;
1527: $srcnum{$suffix} = $srcn;
1.491 raeburn 1528: }
1.597 ! raeburn 1529: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1530: push(@dopaste,$suffix);
1531: if ($url=~/\.(page|sequence)$/) {
1532: $is_map{$suffix} = 1;
1533: }
1534:
1535: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1536: my $oldprefix = $1;
1.492 raeburn 1537: # When pasting content from Main Content to Supplemental Content and vice versa
1538: # URLs will contain different paths (which depend on whether pasted item is
1.597 ! raeburn 1539: # a folder/page or a document).
1.538 raeburn 1540: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1541: $prefixchg{$suffix} = 'docstosupp';
1542: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1543: $prefixchg{$suffix} = 'supptodocs';
1544: }
1.491 raeburn 1545:
1.492 raeburn 1546: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1547: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1548: my @nested;
1549: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1550: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1551: my @deps = map { /\d+:([\d,]+$)/ } @items;
1552: foreach my $dep (@deps) {
1553: if ($dep =~ /,/) {
1554: push(@nested,split(/,/,$dep));
1555: } else {
1556: push(@nested,$dep);
1557: }
1.492 raeburn 1558: }
1.538 raeburn 1559: foreach my $item (@nested) {
1560: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1561: push(@{$marktomove{$suffix}},$type.'_'.$item);
1562: }
1.492 raeburn 1563: }
1564: }
1.488 raeburn 1565: }
1566: }
1567:
1.538 raeburn 1568: # Early out if nothing available to paste
1569: if (@dopaste == 0) {
1570: return ();
1571: }
1572:
1573: # Populate message hash and hashes used for main content <=> supplemental content
1574: # changes
1575:
1576: %msgs = &Apache::lonlocal::texthash (
1577: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1578: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1579: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1580: );
1581:
1582: %before = (
1583: docstosupp => {
1584: map => 'default',
1585: doc => 'docs',
1586: },
1587: supptodocs => {
1588: map => 'supplemental',
1589: doc => 'supplemental',
1590: },
1591: );
1592:
1593: %after = (
1594: docstosupp => {
1595: map => 'supplemental',
1596: doc => 'supplemental'
1597: },
1598: supptodocs => {
1599: map => 'default',
1600: doc => 'docs',
1601: },
1602: );
1603:
1604: # Retrieve information about all course maps in main content area
1605:
1606: my $allmaps = {};
1607: if ($folder =~ /^default/) {
1608: $allmaps =
1609: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1610: $env{"course.$env{'request.course.id'}.home"},
1611: $env{'request.course.id'});
1612: }
1613:
1614: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1615:
1616: # Loop over the items to paste
1617: foreach my $suffix (@dopaste) {
1.329 droeschl 1618: # Maps need to be copied first
1.538 raeburn 1619: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1620: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 ! raeburn 1621: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1622: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1623: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1624: }
1625: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1626: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1627: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1628: my $oldurl = $url;
1629: if ($is_map{$suffix}) {
1.491 raeburn 1630: # If pasting a map, check if map contains other maps
1.538 raeburn 1631: my (%hierarchy,%titles);
1632: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1633: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1634: if ($url=~ m{^/uploaded/}) {
1635: my $newurl;
1636: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1637: ($newurl,my $error) =
1638: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1639: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1640: \$title,$allmaps,\%newurls);
1641: if ($error) {
1642: $allerrors{$suffix} = $error;
1643: next;
1644: }
1645: if ($newurl ne '') {
1646: if ($newurl ne $url) {
1647: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1648: $newsubdir{$url} = $1;
1649: }
1650: $mapchanges{$url} = 1;
1.492 raeburn 1651: }
1.538 raeburn 1652: }
1653: }
1654: if (($srcdom{$suffix} ne $coursedom) ||
1655: ($srcnum{$suffix} ne $coursenum) ||
1656: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1657: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1658: $coursedom,$coursenum,$srcdom{$suffix},
1659: $srcnum{$suffix},$allmaps,\%rewrites,
1660: \%retitles,\%copies,\%dbcopies,
1661: \%zombies,\%params,\%mapmoves,
1662: \%mapchanges,\%tomove,\%newsubdir,
1.597 ! raeburn 1663: \%newurls,\%resdatacopy)) {
1.538 raeburn 1664: $mapmoves{$url} = 1;
1665: }
1666: $url = $newurl;
1667: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1668: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1669: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1670: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1671: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 ! raeburn 1672: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1673: }
1674: } elsif ($url=~m {^/res/}) {
1.597 ! raeburn 1675: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1676: push(@toclear,$suffix);
1677: # if pasting published map (main content area only) check map not already in course
1678: if ($folder =~ /^default/) {
1679: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1680: $duplicate{$suffix} = 1;
1681: next;
1.492 raeburn 1682: }
1.491 raeburn 1683: }
1684: }
1.538 raeburn 1685: }
1686: if ($url=~ m{/(bulletinboard|smppg)$}) {
1687: my $prefix = $1;
1.596 raeburn 1688: my $fromothercrs;
1.538 raeburn 1689: #need to copy the db contents to a new one, unless this is a move.
1690: my %info = (
1691: src => $url,
1692: cdom => $coursedom,
1693: cnum => $coursenum,
1.596 raeburn 1694: );
1695: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1696: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1697: $fromothercrs = 1;
1698: $info{'cdom'} = $srcdom{$suffix};
1699: $info{'cnum'} = $srcnum{$suffix};
1700: }
1701: }
1702: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1703: my (%lockerr,$msg);
1704: my ($newurl,$result,$errtext) =
1705: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1706: if ($result eq 'ok') {
1707: $url = $newurl;
1708: $title=&mt('Copy of').' '.$title;
1709: } else {
1710: if ($prefix eq 'smppg') {
1711: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1712: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1713: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1714: }
1715: $results{$suffix} = $result;
1716: $msgerrs{$suffix} = $msg;
1717: $lockerrs{$suffix} = $lockerr{$prefix};
1718: next;
1719: }
1720: if ($lockerr{$prefix}) {
1721: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1722: }
1.489 raeburn 1723: }
1724: }
1.538 raeburn 1725: $title = &LONCAPA::map::qtunescape($title);
1726: my $ext='false';
1727: if ($url=~m{^http(|s)://}) { $ext='true'; }
1728: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1729: if ($folder !~ /^supplemental/) {
1730: (undef,undef,$title) =
1731: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1732: }
1733: } else {
1734: if ($folder=~/^supplemental/) {
1735: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1736: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1737: }
1.533 raeburn 1738: }
1.491 raeburn 1739:
1740: # For uploaded files (excluding pages/sequences) path in copied file is changed
1741: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1742: # courses.
1743:
1.538 raeburn 1744: unless ($is_map{$suffix}) {
1745: my $newidx;
1.492 raeburn 1746: # Now insert the URL at the bottom
1.538 raeburn 1747: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1748: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1749: my $relpath = $1;
1750: if ($relpath ne '') {
1751: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1752: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1753: my $newprefix = $newloc;
1754: if ($newloc eq 'default') {
1755: $newprefix = 'docs';
1756: }
1757: if ($newdocsdir eq '') {
1758: $newdocsdir = 'default';
1759: }
1760: if (($prefixchg{$suffix}) ||
1761: ($srcdom{$suffix} ne $coursedom) ||
1762: ($srcnum{$suffix} ne $coursenum) ||
1763: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1764: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1765: $url =
1766: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1767: &Apache::lonnet::getfile($oldurl));
1768: if ($url eq '/adm/notfound.html') {
1769: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1770: next;
1771: } else {
1772: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1773: $newsubpath =~ s{/+$}{/};
1774: $docmoves{$oldurl} = $newsubpath;
1775: }
1.491 raeburn 1776: }
1777: }
1.597 ! raeburn 1778: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
! 1779: my $template = $1;
! 1780: if ($newidx) {
! 1781: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
! 1782: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
! 1783: }
1.491 raeburn 1784: }
1.538 raeburn 1785: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1786: ':'.$ext.':normal:res';
1787: push(@LONCAPA::map::order,$newidx);
1788: # Store the result
1789: my ($errtext,$fatal) =
1790: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1791: if ($fatal) {
1792: $save_err .= $errtext;
1793: $allresult = 'fail';
1794: }
1.488 raeburn 1795: }
1.538 raeburn 1796:
1.597 ! raeburn 1797: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
! 1798: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1799: unless ($allresult eq 'fail') {
1800: my %updated = (
1801: rewrites => \%rewrites,
1802: zombies => \%zombies,
1803: removefrommap => \%removefrommap,
1804: removeparam => \%removeparam,
1805: dbcopies => \%dbcopies,
1.597 ! raeburn 1806: resdatacopy => \%resdatacopy,
1.538 raeburn 1807: retitles => \%retitles,
1808: );
1809: my %info = (
1810: newsubdir => \%newsubdir,
1811: params => \%params,
1812: );
1813: if ($prefixchg{$suffix}) {
1814: $info{'before'} = $before{$prefixchg{$suffix}};
1815: $info{'after'} = $after{$prefixchg{$suffix}};
1816: }
1817: my %moves = (
1818: copies => \%copies,
1819: docmoves => \%docmoves,
1820: mapmoves => \%mapmoves,
1821: );
1822: (my $result,$msgs{$suffix},my $lockerror) =
1823: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1824: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1825: $url,'paste');
1826: $lockerrors .= $lockerror;
1827: if ($result eq 'ok') {
1828: if ($is_map{$suffix}) {
1829: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1830: $folder.'.'.$container);
1831: if ($fatal) {
1832: $allresult = 'failread';
1833: } else {
1834: if ($#LONCAPA::map::order<1) {
1835: my $idx=&LONCAPA::map::getresidx();
1836: if ($idx<=0) { $idx=1; }
1837: $LONCAPA::map::order[0]=$idx;
1838: $LONCAPA::map::resources[$idx]='';
1839: }
1840: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1841: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1842: ':'.$ext.':normal:res';
1843: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1844:
1845: # Store the result
1.538 raeburn 1846: my ($errtext,$fatal) =
1847: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1848: if ($fatal) {
1849: $save_err .= $errtext;
1850: $allresult = 'failstore';
1851: }
1852: }
1853: }
1854: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1855: push(@toclear,$suffix);
1856: }
1857: }
1.492 raeburn 1858: }
1859: }
1.538 raeburn 1860: &clear_from_buffer(\@toclear,\@currpaste);
1861: my $msgsarray;
1862: foreach my $suffix (keys(%msgs)) {
1863: if (ref($msgs{$suffix}) eq 'ARRAY') {
1864: $msgsarray .= join(',',@{$msgs{$suffix}});
1865: }
1866: }
1867: return ($allresult,$save_err,$msgsarray,$lockerrors);
1868: }
1.533 raeburn 1869:
1.538 raeburn 1870: sub do_buffer_empty {
1871: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1872: if (@currpaste == 0) {
1873: return &mt('Clipboard is already empty');
1874: }
1875: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1876: if (@toclear == 0) {
1877: return &mt('Nothing selected to clear from clipboard');
1878: }
1879: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1880: if ($numdel) {
1881: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1882: } else {
1883: return &mt('Clipboard unchanged');
1.492 raeburn 1884: }
1.538 raeburn 1885: return;
1886: }
1887:
1888: sub clear_from_buffer {
1889: my ($toclear,$currpaste) = @_;
1890: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1891: my %pastebuffer;
1892: map { $pastebuffer{$_} = 1; } @{$currpaste};
1893: my $numdel = 0;
1894: foreach my $suffix (@{$toclear}) {
1895: next if ($suffix =~ /\D/);
1896: next unless (exists($pastebuffer{$suffix}));
1897: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1898: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1899: delete($pastebuffer{$suffix});
1900: $numdel ++;
1901: }
1902: }
1903: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1904: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1905: return $numdel;
1.492 raeburn 1906: }
1907:
1908: sub get_newmap_url {
1909: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1910: $titleref,$allmaps,$newurls) = @_;
1911: my $newurl;
1912: if ($url=~ m{^/uploaded/}) {
1913: $$titleref=&mt('Copy of').' '.$$titleref;
1914: }
1915: my $now = time;
1916: my $suffix=$$.int(rand(100)).$now;
1917: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1918: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1919: my $path = $1;
1920: my $prefix = $2;
1921: my $ancestor = $3;
1922: if (length($ancestor) > 10) {
1923: $ancestor = substr($ancestor,-10,10);
1924: }
1925: my $newid;
1926: if ($prefixchg) {
1927: if ($folder =~ /^supplemental/) {
1928: $prefix =~ s/^default/supplemental/;
1929: } else {
1930: $prefix =~ s/^supplemental/default/;
1931: }
1932: }
1933: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1934: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1935: } else {
1936: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1937: }
1938: my $counter = 0;
1939: my $is_unique = &uniqueness_check($newurl);
1940: if ($folder =~ /^default/) {
1941: if ($allmaps->{$newurl}) {
1942: $is_unique = 0;
1943: }
1944: }
1945: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1946: $counter ++;
1947: $suffix ++;
1948: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1949: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1950: } else {
1951: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1952: }
1953: $is_unique = &uniqueness_check($newurl);
1954: }
1955: if ($is_unique) {
1956: $newurls->{$newurl} = 1;
1957: } else {
1958: if ($url=~/\.page$/) {
1959: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1960: } else {
1961: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1962: }
1963: }
1.329 droeschl 1964: }
1.492 raeburn 1965: return ($newurl);
1.329 droeschl 1966: }
1967:
1.488 raeburn 1968: sub dbcopy {
1.533 raeburn 1969: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
1970: my ($url,$result,$errtext);
1971: if (ref($dbref) eq 'HASH') {
1.596 raeburn 1972: $url = $dbref->{'src'};
1.533 raeburn 1973: if ($url =~ m{/(smppg|bulletinboard)$}) {
1974: my $prefix = $1;
1975: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1976: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1977: my $db_name;
1978: my $marker = (split(m{/},$url))[4];
1979: $marker=~s/\D//g;
1980: if ($dbref->{'src'} =~ m{/smppg$}) {
1981: $db_name =
1982: &Apache::lonsimplepage::get_db_name($url,$marker,
1983: $dbref->{'cdom'},
1984: $dbref->{'cnum'});
1985: } else {
1986: $db_name = 'bulletinpage_'.$marker;
1987: }
1988: my ($suffix,$freedlock,$error) =
1989: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
1990: $coursedom,$coursenum,
1991: 'concat');
1992: if (!$suffix) {
1993: if ($prefix eq 'smppg') {
1994: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1995: } else {
1.565 bisitz 1996: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 1997: }
1998: if ($error) {
1999: $errtext .= '<br />'.$error;
2000: }
2001: } else {
2002: #need to copy the db contents to a new one.
2003: my %contents=&Apache::lonnet::dump($db_name,
2004: $dbref->{'cdom'},
2005: $dbref->{'cnum'});
2006: if (exists($contents{'uploaded.photourl'})) {
2007: my $photo = $contents{'uploaded.photourl'};
2008: my ($subdir,$fname) =
2009: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2010: my $newphoto;
1.533 raeburn 2011: if ($fname ne '') {
2012: my $content = &Apache::lonnet::getfile($photo);
2013: unless ($content eq '-1') {
2014: $env{'form.'.$suffix.'.photourl'} = $content;
2015: $newphoto =
2016: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2017: delete($env{'form.'.$suffix.'.photourl'});
2018: }
2019: }
2020: if ($newphoto =~ m{^/uploaded/}) {
2021: $contents{'uploaded.photourl'} = $newphoto;
2022: }
2023: }
2024: $db_name =~ s{_\d*$ }{_$suffix}x;
2025: $result=&Apache::lonnet::put($db_name,\%contents,
2026: $coursedom,$coursenum);
2027: if ($result eq 'ok') {
2028: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2029: }
2030: }
2031: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2032: $lockerrorsref->{$prefix} =
1.533 raeburn 2033: '<div class="LC_error">'.
2034: &mt('There was a problem removing a lockfile.');
2035: if ($prefix eq 'smppg') {
1.560 raeburn 2036: $lockerrorsref->{$prefix} .=
1.559 raeburn 2037: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2038: } else {
1.565 bisitz 2039: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2040: }
1.560 raeburn 2041: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2042: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2043: '</div>';
1.533 raeburn 2044: }
2045: }
2046: } elsif ($url =~ m{/syllabus$}) {
2047: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2048: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2049: if (($dbref->{'cdom'} ne $coursedom) ||
2050: ($dbref->{'cnum'} ne $coursenum)) {
2051: my %contents=&Apache::lonnet::dump('syllabus',
2052: $dbref->{'cdom'},
2053: $dbref->{'cnum'});
2054: $result=&Apache::lonnet::put('syllabus',\%contents,
2055: $coursedom,$coursenum);
2056: }
2057: }
1.488 raeburn 2058: }
2059: }
1.533 raeburn 2060: return ($url,$result,$errtext);
1.488 raeburn 2061: }
2062:
1.597 ! raeburn 2063: sub copy_templated_files {
! 2064: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
! 2065: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
! 2066: my $srccontainer = 'sequence';
! 2067: if ($srcwaspage) {
! 2068: $srccontainer = 'page';
! 2069: }
! 2070: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
! 2071: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
! 2072: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
! 2073: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
! 2074: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
! 2075: $template.'.problem';
! 2076: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
! 2077: if ($template eq 'simpleproblem') {
! 2078: $srcprefix .= '.0.';
! 2079: my $weightprefix = $newprefix;
! 2080: $newprefix .= '.0.';
! 2081: my @simpleprobqtypes = qw(radio option string essay numerical);
! 2082: my $qtype=$srcparms{$srcprefix.'questiontype'};
! 2083: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
! 2084: my %newdata;
! 2085: foreach my $type (@simpleprobqtypes) {
! 2086: if ($type eq $qtype) {
! 2087: $newdata{"$weightprefix.$type.weight"}=1;
! 2088: } else {
! 2089: $newdata{"$weightprefix.$type.weight"}=0;
! 2090: }
! 2091: }
! 2092: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
! 2093: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
! 2094: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
! 2095: if ($qtype eq 'numerical') {
! 2096: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
! 2097: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
! 2098: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
! 2099: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
! 2100: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
! 2101: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
! 2102: unless (defined($maxfoils)) { $maxfoils=10; }
! 2103: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
! 2104: if ($maxfoils<=0) { $maxfoils=10; }
! 2105: my $randomize=$srcparms{$srcprefix.'randomize'};
! 2106: unless (defined($randomize)) { $randomize='yes'; }
! 2107: unless ($randomize eq 'no') { $randomize='yes'; }
! 2108: $newdata{$newprefix.'maxfoils'} = $maxfoils;
! 2109: $newdata{$newprefix.'randomize'} = $randomize;
! 2110: if ($qtype eq 'option') {
! 2111: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
! 2112: }
! 2113: for (my $i=1; $i<=10; $i++) {
! 2114: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
! 2115: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
! 2116: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
! 2117: }
! 2118:
! 2119: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
! 2120: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
! 2121: unless (defined($maxfoils)) { $maxfoils=10; }
! 2122: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
! 2123: if ($maxfoils<=0) { $maxfoils=10; }
! 2124: my $randomize=$srcparms{$srcprefix.'randomize'};
! 2125: unless (defined($randomize)) { $randomize='yes'; }
! 2126: unless ($randomize eq 'no') { $randomize='yes'; }
! 2127: $newdata{$newprefix.'maxfoils'} = $maxfoils;
! 2128: $newdata{$newprefix.'randomize'} = $randomize;
! 2129: if ($qtype eq 'option') {
! 2130: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
! 2131: }
! 2132: for (my $i=1; $i<=10; $i++) {
! 2133: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
! 2134: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
! 2135: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
! 2136: }
! 2137: } elsif ($qtype eq 'string') {
! 2138: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
! 2139: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
! 2140: }
! 2141: if (keys(%newdata)) {
! 2142: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
! 2143: $coursenum);
! 2144: if ($putres eq 'ok') {
! 2145: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
! 2146: }
! 2147: }
! 2148: }
! 2149: }
! 2150: }
! 2151:
1.329 droeschl 2152: sub uniqueness_check {
2153: my ($newurl) = @_;
2154: my $unique = 1;
2155: foreach my $res (@LONCAPA::map::order) {
2156: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2157: $url=&LONCAPA::map::qtescape($url);
2158: if ($newurl eq $url) {
2159: $unique = 0;
1.344 bisitz 2160: last;
1.329 droeschl 2161: }
2162: }
2163: return $unique;
2164: }
2165:
1.488 raeburn 2166: sub contained_map_check {
1.492 raeburn 2167: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2168: $allmaps) = @_;
1.488 raeburn 2169: my $content = &Apache::lonnet::getfile($url);
2170: unless ($content eq '-1') {
2171: my $parser = HTML::TokeParser->new(\$content);
2172: $parser->attr_encoded(1);
2173: while (my $token = $parser->get_token) {
2174: next if ($token->[0] ne 'S');
2175: if ($token->[1] eq 'resource') {
2176: next if ($token->[2]->{'type'} eq 'zombie');
2177: my $ressrc = $token->[2]->{'src'};
2178: if ($folder =~ /^supplemental/) {
2179: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2180: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2181: next;
2182: }
2183: }
1.492 raeburn 2184: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2185: if ($1 eq 'uploaded') {
2186: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2187: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2188: } else {
1.492 raeburn 2189: if ($allmaps->{$ressrc}) {
1.529 raeburn 2190: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2191: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2192: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2193: } else {
2194: $addedmaps->{$ressrc} = [$url];
2195: }
1.488 raeburn 2196: }
1.492 raeburn 2197: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2198: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2199: }
1.492 raeburn 2200: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2201: if ($folder =~ /^supplemental/) {
1.492 raeburn 2202: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2203: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2204: } else {
2205: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2206: }
1.488 raeburn 2207: }
2208: }
2209: }
2210: }
2211: return;
2212: }
2213:
2214: sub url_paste_fixups {
1.533 raeburn 2215: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2216: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 ! raeburn 2217: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2218: my $checktitle;
2219: if (($prefixchg) &&
1.492 raeburn 2220: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2221: $checktitle = 1;
2222: }
1.492 raeburn 2223: my $skip;
2224: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2225: my $mapid = $1.$2;
2226: if ($tomove->{$mapid}) {
2227: $skip = 1;
2228: }
2229: }
1.491 raeburn 2230: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2231: return if ($file eq '-1');
2232: my $parser = HTML::TokeParser->new(\$file);
2233: $parser->attr_encoded(1);
1.491 raeburn 2234: my $changed = 0;
1.488 raeburn 2235: while (my $token = $parser->get_token) {
2236: next if ($token->[0] ne 'S');
2237: if ($token->[1] eq 'resource') {
2238: my $ressrc = $token->[2]->{'src'};
2239: next if ($ressrc eq '');
1.491 raeburn 2240: my $id = $token->[2]->{'id'};
1.492 raeburn 2241: my $title = $token->[2]->{'title'};
1.491 raeburn 2242: if ($checktitle) {
2243: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2244: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2245: }
2246: }
1.488 raeburn 2247: next if ($token->[2]->{'type'} eq 'external');
2248: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2249: next if ($skip);
1.532 raeburn 2250: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2251: $changed = 1;
2252: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2253: my $srcdom = $1;
2254: my $srcnum = $2;
1.488 raeburn 2255: my $rem = $3;
1.492 raeburn 2256: my $newurl;
2257: my $mapname;
2258: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2259: my $prefix = $1;
2260: $mapname = $prefix.$2;
2261: if ($tomove->{$mapname}) {
1.533 raeburn 2262: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2263: $srcdom,$srcnum,$allmaps,$rewrites,
2264: $retitles,$copies,$dbcopies,$zombies,
2265: $params,$mapmoves,$mapchanges,$tomove,
1.597 ! raeburn 2266: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2267: next;
2268: } else {
2269: ($newurl,my $error) =
2270: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2271: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2272: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2273: $newsubdir->{$ressrc} = $1;
2274: }
2275: if ($error) {
2276: next;
2277: }
2278: }
2279: }
2280: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2281: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2282:
1.488 raeburn 2283: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2284: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2285: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2286: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2287: $cnum,$srcdom,$srcnum,$allmaps,
2288: $rewrites,$retitles,$copies,$dbcopies,
2289: $zombies,$params,$mapmoves,$mapchanges,
1.597 ! raeburn 2290: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2291: $mapmoves->{$ressrc} = 1;
2292: }
2293: $changed = 1;
1.488 raeburn 2294: } else {
1.532 raeburn 2295: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2296: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2297: $changed = 1;
1.488 raeburn 2298: }
2299: }
1.533 raeburn 2300: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2301: next if ($skip);
1.492 raeburn 2302: my $srcdom = $1;
2303: my $srcnum = $2;
2304: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2305: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2306: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2307: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2308: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2309: $changed = 1;
2310: }
2311: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2312: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2313: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2314: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2315: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2316: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2317: $changed = 1;
1.488 raeburn 2318: }
1.597 ! raeburn 2319: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
! 2320: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
! 2321: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
! 2322: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
! 2323: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
! 2324: }
1.488 raeburn 2325: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2326: next if ($skip);
2327: my $srcdom = $1;
2328: my $srcnum = $2;
2329: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2330: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2331: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2332: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2333: $changed = 1;
1.488 raeburn 2334: }
2335: }
2336: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2337: next if ($skip);
1.488 raeburn 2338: my $to = $token->[2]->{'to'};
2339: if ($to ne '') {
2340: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2341: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2342: } else {
2343: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2344: }
2345: }
2346: }
2347: }
1.491 raeburn 2348: return $changed;
1.488 raeburn 2349: }
2350:
2351: sub apply_fixups {
1.529 raeburn 2352: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2353: $oldurl,$url,$caller) = @_;
2354: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2355: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 ! raeburn 2356: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2357: if (ref($updated) eq 'HASH') {
2358: if (ref($updated->{'rewrites'}) eq 'HASH') {
2359: %rewrites = %{$updated->{'rewrites'}};
2360: }
2361: if (ref($updated->{'zombies'}) eq 'HASH') {
2362: %zombies = %{$updated->{'zombies'}};
2363: }
2364: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2365: %removefrommap = %{$updated->{'removefrommap'}};
2366: }
2367: if (ref($updated->{'removeparam'}) eq 'HASH') {
2368: %removeparam = %{$updated->{'removeparam'}};
2369: }
2370: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2371: %dbcopies = %{$updated->{'dbcopies'}};
2372: }
2373: if (ref($updated->{'retitles'}) eq 'HASH') {
2374: %retitles = %{$updated->{'retitles'}};
2375: }
1.597 ! raeburn 2376: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
! 2377: %resdatacopy = %{$updated->{'resdatacopy'}};
! 2378: }
1.529 raeburn 2379: }
2380: if (ref($info) eq 'HASH') {
2381: if (ref($info->{'newsubdir'}) eq 'HASH') {
2382: %newsubdir = %{$info->{'newsubdir'}};
2383: }
2384: if (ref($info->{'params'}) eq 'HASH') {
2385: %params = %{$info->{'params'}};
2386: }
2387: if (ref($info->{'before'}) eq 'HASH') {
2388: %before = %{$info->{'before'}};
2389: }
2390: if (ref($info->{'after'}) eq 'HASH') {
2391: %after = %{$info->{'after'}};
2392: }
2393: }
2394: if (ref($moves) eq 'HASH') {
2395: if (ref($moves->{'copies'}) eq 'HASH') {
2396: %copies = %{$moves->{'copies'}};
2397: }
2398: if (ref($moves->{'docmoves'}) eq 'HASH') {
2399: %docmoves = %{$moves->{'docmoves'}};
2400: }
2401: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2402: %mapmoves = %{$moves->{'mapmoves'}};
2403: }
2404: }
2405: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2406: my @allcopies;
1.529 raeburn 2407: if (exists($copies{$key})) {
2408: if (ref($copies{$key}) eq 'HASH') {
2409: my %added;
2410: foreach my $innerkey (keys(%{$copies{$key}})) {
2411: if (($innerkey ne '') && (!$added{$innerkey})) {
2412: push(@allcopies,$innerkey);
2413: $added{$innerkey} = 1;
2414: }
1.491 raeburn 2415: }
1.529 raeburn 2416: undef(%added);
1.491 raeburn 2417: }
2418: }
2419: if ($key eq $oldurl) {
1.529 raeburn 2420: if ((exists($docmoves{$key}))) {
1.532 raeburn 2421: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2422: push(@allcopies,$oldurl);
2423: }
2424: }
2425: }
2426: if (@allcopies > 0) {
2427: foreach my $item (@allcopies) {
1.492 raeburn 2428: my ($relpath,$oldsubdir,$fname) =
2429: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2430: if ($fname ne '') {
2431: my $content = &Apache::lonnet::getfile($item);
2432: unless ($content eq '-1') {
2433: my $storefn;
1.529 raeburn 2434: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2435: $storefn = $docmoves{$key};
1.491 raeburn 2436: } else {
2437: $storefn = $relpath;
2438: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2439: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2440: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2441: }
1.529 raeburn 2442: if ($newsubdir{$key}) {
1.532 raeburn 2443: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2444: }
2445: }
2446: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2447: my $copyurl =
2448: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2449: $storefn.$fname,$content);
2450: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2451: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2452: return &mt('Paste failed: an error occurred copying the file.');
2453: } elsif (ref($errors) eq 'HASH') {
2454: $errors->{$item} = 1;
1.489 raeburn 2455: }
2456: }
1.488 raeburn 2457: }
2458: }
1.491 raeburn 2459: }
2460: }
2461: }
1.529 raeburn 2462: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2463: my $storefn=$key;
2464: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2465: if ($prefixchg && $before{'map'} && $after{'map'}) {
2466: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2467: }
1.529 raeburn 2468: if ($newsubdir{$key}) {
2469: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2470: }
1.491 raeburn 2471: my $mapcontent = &Apache::lonnet::getfile($key);
2472: if ($mapcontent eq '-1') {
2473: if (ref($errors) eq 'HASH') {
2474: $errors->{$key} = 1;
2475: }
2476: } else {
2477: my $newmap =
2478: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2479: $mapcontent);
2480: if ($newmap eq '/adm/notfound.html') {
2481: if (ref($errors) eq 'HASH') {
2482: $errors->{$key} = 1;
1.489 raeburn 2483: }
1.488 raeburn 2484: }
2485: }
2486: }
1.491 raeburn 2487: my %updates;
2488: if ($is_map) {
1.529 raeburn 2489: if (ref($updated) eq 'HASH') {
2490: foreach my $type (keys(%{$updated})) {
2491: if (ref($updated->{$type}) eq 'HASH') {
2492: foreach my $key (keys(%{$updated->{$type}})) {
2493: $updates{$key} = 1;
2494: }
2495: }
2496: }
1.491 raeburn 2497: }
2498: foreach my $key (keys(%updates)) {
1.492 raeburn 2499: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2500: if (ref($rewrites{$key}) eq 'HASH') {
2501: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2502: }
1.529 raeburn 2503: if (ref($retitles{$key}) eq 'HASH') {
2504: %toretitle = %{$retitles{$key}};
1.491 raeburn 2505: }
1.529 raeburn 2506: if (ref($removefrommap{$key}) eq 'HASH') {
2507: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2508: }
1.529 raeburn 2509: if (ref($removeparam{$key}) eq 'HASH') {
2510: %remparam = %{$removeparam{$key}};
1.492 raeburn 2511: }
1.529 raeburn 2512: if (ref($zombies{$key}) eq 'HASH') {
2513: %zombie = %{$zombies{$key}};
1.491 raeburn 2514: }
1.529 raeburn 2515: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2516: foreach my $idx (keys(%{$dbcopies{$key}})) {
2517: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2518: my ($newurl,$result,$errtext) =
2519: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2520: if ($result eq 'ok') {
2521: $newdb{$idx} = $newurl;
2522: } elsif (ref($errors) eq 'HASH') {
2523: $errors->{$key} = 1;
2524: }
2525: push(@msgs,$errtext);
2526: }
1.491 raeburn 2527: }
2528: }
1.597 ! raeburn 2529: if (ref($resdatacopy{$key}) eq 'HASH') {
! 2530: if ($newsubdir{$key}) {
! 2531:
! 2532: }
! 2533: foreach my $idx (keys(%{$resdatacopy{$key}})) {
! 2534: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
! 2535: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
! 2536: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
! 2537: my $template = $1;
! 2538: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
! 2539: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
! 2540: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
! 2541: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
! 2542: my ($newmapname) = ($key =~ m{/([^/]+)$});
! 2543: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
! 2544: my $srcmapinfo = $srcfolder.':'.$idx;
! 2545: if ($srccontainer eq 'page') {
! 2546: $srcmapinfo .= ':1';
! 2547: }
! 2548: if ($newsubdir{$key}) {
! 2549: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
! 2550: }
! 2551: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
! 2552: $cnum,$template,$idx,$newmapname);
! 2553: }
! 2554: }
! 2555: }
! 2556: }
! 2557: }
1.529 raeburn 2558: if (ref($params{$key}) eq 'HASH') {
2559: %currparam = %{$params{$key}};
1.492 raeburn 2560: }
2561: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2562: if ($fatal) {
1.533 raeburn 2563: return ($errtext);
1.492 raeburn 2564: }
2565: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2566: if (defined($LONCAPA::map::zombies[$i])) {
2567: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2568: if ($zombie{$i} eq $src) {
1.492 raeburn 2569: undef($LONCAPA::map::zombies[$i]);
2570: }
2571: }
2572: }
1.529 raeburn 2573: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2574: my $idx = $LONCAPA::map::order[$i];
2575: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2576: my $changed;
1.529 raeburn 2577: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2578: if ((exists($toremove{$idx})) &&
2579: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2580: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2581: if (ref($currparam{$idx}) eq 'ARRAY') {
2582: foreach my $name (@{$currparam{$idx}}) {
2583: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2584: }
2585: }
2586: next;
2587: }
2588: my $origsrc = $src;
1.532 raeburn 2589: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2590: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2591: $changed = 1;
1.491 raeburn 2592: }
1.492 raeburn 2593: }
1.532 raeburn 2594: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2595: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2596: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2597: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2598: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2599: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2600: } else {
1.529 raeburn 2601: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2602: }
1.491 raeburn 2603: }
1.532 raeburn 2604: if ($origsrc =~ /\.(page|sequence)$/) {
2605: if ($newsubdir{$origsrc}) {
1.529 raeburn 2606: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2607: }
1.532 raeburn 2608: } elsif ($newsubdir{$key}) {
2609: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2610: }
2611: }
1.492 raeburn 2612: $changed = 1;
1.533 raeburn 2613: } elsif ($newdb{$idx} ne '') {
2614: $src = $newdb{$idx};
1.492 raeburn 2615: $changed = 1;
2616: }
2617: if ($changed) {
1.538 raeburn 2618: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2619: }
2620: }
2621: }
2622: foreach my $idx (keys(%remparam)) {
2623: if (ref($remparam{$idx}) eq 'ARRAY') {
2624: foreach my $name (@{$remparam{$idx}}) {
2625: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2626: }
2627: }
2628: }
1.533 raeburn 2629: if (values(%lockerrors) > 0) {
2630: $lockmsg = join('<br />',values(%lockerrors));
2631: }
1.491 raeburn 2632: my $storefn;
2633: if ($key eq $oldurl) {
2634: $storefn = $url;
2635: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2636: } else {
2637: $storefn = $key;
2638: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2639: if ($prefixchg && $before{'map'} && $after{'map'}) {
2640: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2641: }
1.529 raeburn 2642: if ($newsubdir{$key}) {
2643: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2644: }
1.491 raeburn 2645: }
1.492 raeburn 2646: my $report;
2647: if ($folder !~ /^supplemental/) {
2648: $report = 1;
2649: }
1.527 raeburn 2650: (my $outtext,$errtext) =
1.492 raeburn 2651: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2652: if ($errtext) {
1.529 raeburn 2653: if ($caller eq 'paste') {
1.533 raeburn 2654: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2655: }
1.491 raeburn 2656: }
2657: }
2658: }
1.533 raeburn 2659: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2660: }
2661:
2662: sub copy_dependencies {
2663: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2664: my $content;
2665: if (ref($contentref)) {
2666: $content = $$contentref;
2667: } else {
2668: $content = &Apache::lonnet::getfile($item);
2669: }
2670: unless ($content eq '-1') {
2671: my $mm = new File::MMagic;
2672: my $mimetype = $mm->checktype_contents($content);
2673: if ($mimetype eq 'text/html') {
2674: my (%allfiles,%codebase,$state);
2675: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2676: if ($res eq 'ok') {
2677: my ($numexisting,$numpathchanges,$existing);
2678: (undef,$numexisting,$numpathchanges,$existing) =
2679: &Apache::loncommon::ask_for_embedded_content(
2680: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2681: {'error_on_invalid_names' => 1,
2682: 'ignore_remote_references' => 1,
2683: 'docs_url' => $item,
2684: 'context' => 'paste'});
2685: if ($numexisting > 0) {
2686: if (ref($existing) eq 'HASH') {
2687: foreach my $dep (keys(%{$existing})) {
2688: my $depfile = $dep;
2689: unless ($depfile =~ m{^\Q$relpath\E}) {
2690: $depfile = $relpath.$dep;
2691: }
2692: my $depcontent = &Apache::lonnet::getfile($depfile);
2693: unless ($depcontent eq '-1') {
2694: my $storedep = $dep;
2695: $storedep =~ s{^\Q$relpath\E}{};
2696: my $dep_url =
2697: &Apache::lonclonecourse::writefile(
2698: $env{'request.course.id'},
2699: $storefn.$storedep,$depcontent);
2700: if ($dep_url eq '/adm/notfound.html') {
2701: if (ref($errors) eq 'HASH') {
2702: $errors->{$depfile} = 1;
2703: }
2704: } else {
2705: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2706: }
2707: }
2708: }
1.488 raeburn 2709: }
2710: }
2711: }
2712: }
2713: }
2714: return;
2715: }
2716:
1.329 droeschl 2717: my %parameter_type = ( 'randompick' => 'int_pos',
2718: 'hiddenresource' => 'string_yesno',
2719: 'encrypturl' => 'string_yesno',
2720: 'randomorder' => 'string_yesno',);
2721: my $valid_parameters_re = join('|',keys(%parameter_type));
2722: # set parameters
2723: sub update_parameter {
1.537 raeburn 2724: if ($env{'form.changeparms'} eq 'all') {
2725: my (@allidx,@allmapidx,%allchecked,%currchecked);
2726: %allchecked = (
2727: 'hiddenresource' => {},
2728: 'encrypturl' => {},
2729: 'randompick' => {},
2730: 'randomorder' => {},
2731: );
2732: foreach my $which (keys(%allchecked)) {
2733: $env{'form.all'.$which} =~ s/,$//;
2734: if ($which eq 'randompick') {
2735: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2736: my ($res,$value) = split(/:/,$item);
2737: if ($value =~ /^\d+$/) {
2738: $allchecked{$which}{$res} = $value;
2739: }
2740: }
2741: } else {
1.539 raeburn 2742: if ($env{'form.all'.$which}) {
2743: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2744: }
1.537 raeburn 2745: }
2746: }
2747: my $haschanges = 0;
2748: foreach my $res (@LONCAPA::map::order) {
2749: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2750: $name=&LONCAPA::map::qtescape($name);
2751: $url=&LONCAPA::map::qtescape($url);
2752: next unless ($name && $url);
2753: my $is_map;
2754: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2755: $is_map = 1;
2756: }
2757: foreach my $which (keys(%allchecked)) {
2758: if (($which eq 'randompick' || $which eq 'randomorder')) {
2759: next if (!$is_map);
2760: }
2761: my $oldvalue = 0;
2762: my $newvalue = 0;
2763: if ($allchecked{$which}{$res}) {
2764: $newvalue = $allchecked{$which}{$res};
2765: }
2766: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2767: if ($which eq 'randompick') {
2768: if ($current =~ /^(\d+)$/) {
2769: $oldvalue = $1;
2770: }
2771: } else {
2772: if ($current =~ /^yes$/i) {
2773: $oldvalue = 1;
2774: }
2775: }
2776: if ($oldvalue ne $newvalue) {
2777: $haschanges = 1;
2778: if ($newvalue) {
2779: my $storeval = 'yes';
2780: if ($which eq 'randompick') {
2781: $storeval = $newvalue;
2782: }
2783: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2784: $storeval,
2785: $parameter_type{$which});
2786: &remember_parms($res,$which,'set',$storeval);
2787: } elsif ($oldvalue) {
2788: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2789: &remember_parms($res,$which,'del');
2790: }
2791: }
2792: }
2793: }
2794: return $haschanges;
2795: } else {
1.588 raeburn 2796: my $haschanges = 0;
2797: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2798:
1.537 raeburn 2799: my $which = $env{'form.changeparms'};
2800: my $idx = $env{'form.setparms'};
1.588 raeburn 2801: my $oldvalue = 0;
2802: my $newvalue = 0;
2803: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2804: if ($which eq 'randompick') {
2805: if ($current =~ /^(\d+)$/) {
2806: $oldvalue = $1;
2807: }
2808: } elsif ($current =~ /^yes$/i) {
2809: $oldvalue = 1;
2810: }
1.537 raeburn 2811: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2812: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2813: : 1;
2814: }
2815: if ($oldvalue ne $newvalue) {
2816: $haschanges = 1;
2817: if ($newvalue) {
2818: my $storeval = 'yes';
2819: if ($which eq 'randompick') {
2820: $storeval = $newvalue;
2821: }
2822: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2823: $parameter_type{$which});
2824: &remember_parms($idx,$which,'set',$storeval);
2825: } else {
2826: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2827: &remember_parms($idx,$which,'del');
2828: }
1.537 raeburn 2829: }
1.588 raeburn 2830: return $haschanges;
1.329 droeschl 2831: }
2832: }
2833:
2834: sub handle_edit_cmd {
2835: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2836: if ($env{'form.cmd'} eq '') {
2837: return 0;
2838: }
1.329 droeschl 2839: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2840:
2841: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2842: my ($title, $url, @rrest) = split(':', $ratstr);
2843:
1.538 raeburn 2844: if ($cmd eq 'remove') {
1.329 droeschl 2845: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2846: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2847: &Apache::lonnet::removeuploadedurl($url);
2848: } else {
2849: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2850: }
2851: splice(@LONCAPA::map::order, $idx, 1);
2852:
2853: } elsif ($cmd eq 'cut') {
2854: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2855: splice(@LONCAPA::map::order, $idx, 1);
2856:
1.344 bisitz 2857: } elsif ($cmd eq 'up'
1.329 droeschl 2858: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2859: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2860:
2861: } elsif ($cmd eq 'down'
2862: && defined($LONCAPA::map::order[$idx+1])) {
2863: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2864:
2865: } elsif ($cmd eq 'rename') {
2866: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2867: if ($comment=~/\S/) {
2868: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2869: $comment.':'.join(':', $url, @rrest);
2870: }
2871: # Devalidate title cache
2872: my $renamed_url=&LONCAPA::map::qtescape($url);
2873: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 2874:
1.329 droeschl 2875: } else {
2876: return 0;
2877: }
2878: return 1;
2879: }
2880:
2881: sub editor {
1.458 raeburn 2882: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.508 raeburn 2883: $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
1.519 raeburn 2884: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 2885: if ($allowed) {
1.519 raeburn 2886: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2887: $is_random_order,$container) =
1.510 raeburn 2888: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2889: $r->print($breadcrumbtrail);
1.519 raeburn 2890: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2891: $container = 'page';
2892: } else {
2893: $container = 'sequence';
1.510 raeburn 2894: }
1.484 raeburn 2895:
1.525 raeburn 2896: my $jumpto;
2897:
2898: unless ($supplementalflag) {
1.546 raeburn 2899: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 2900: }
1.484 raeburn 2901:
2902: unless ($allowed) {
2903: $randompick = -1;
2904: }
2905:
1.329 droeschl 2906: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2907: $folder.'.'.$container);
2908: return $errtext if ($fatal);
2909:
2910: if ($#LONCAPA::map::order<1) {
2911: my $idx=&LONCAPA::map::getresidx();
2912: if ($idx<=0) { $idx=1; }
2913: $LONCAPA::map::order[0]=$idx;
2914: $LONCAPA::map::resources[$idx]='';
2915: }
1.364 bisitz 2916:
1.329 droeschl 2917: # ------------------------------------------------------------ Process commands
2918:
2919: # ---------------- if they are for this folder and user allowed to make changes
2920: if (($allowed) && ($env{'form.folder'} eq $folder)) {
2921: # set parameters and change order
2922: &snapshotbefore();
2923:
2924: if (&update_parameter()) {
1.588 raeburn 2925: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2926: return $errtext if ($fatal);
2927: }
2928:
2929: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2930: # change order
2931: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2932: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2933:
2934: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2935: return $errtext if ($fatal);
2936: }
1.364 bisitz 2937:
1.329 droeschl 2938: if ($env{'form.pastemarked'}) {
1.491 raeburn 2939: my %paste_errors;
1.533 raeburn 2940: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 2941: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2942: \%paste_errors);
1.541 raeburn 2943: if (ref($pastemsgarray) eq 'ARRAY') {
2944: if (@{$pastemsgarray} > 0) {
2945: $r->print('<p class="LC_info">'.
2946: join('<br />',@{$pastemsgarray}).
1.533 raeburn 2947: '</p>');
2948: }
1.541 raeburn 2949: }
2950: if ($lockerror) {
2951: $r->print('<p class="LC_error">'.
2952: $lockerror.
2953: '</p>');
2954: }
2955: if ($save_error ne '') {
2956: return $save_error;
2957: }
2958: if ($paste_res) {
2959: my %errortext = &Apache::lonlocal::texthash (
2960: fail => 'Storage of folder contents failed',
2961: failread => 'Reading folder contents failed',
2962: failstore => 'Storage of folder contents failed',
2963: );
2964: if ($errortext{$paste_res}) {
2965: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 2966: }
1.329 droeschl 2967: }
1.491 raeburn 2968: if (keys(%paste_errors) > 0) {
1.538 raeburn 2969: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 2970: &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".
2971: '<ul>'."\n");
2972: foreach my $key (sort(keys(%paste_errors))) {
2973: $r->print('<li>'.$key.'</li>'."\n");
2974: }
2975: $r->print('</ul></p>'."\n");
2976: }
1.538 raeburn 2977: } elsif ($env{'form.clearmarked'}) {
2978: my $output = &do_buffer_empty();
2979: if ($output) {
2980: $r->print('<p class="LC_info">'.$output.'</p>');
2981: }
2982: }
1.329 droeschl 2983:
2984: $r->print($upload_output);
2985:
1.538 raeburn 2986: # Rename, cut, copy or remove a single resource
1.329 droeschl 2987: if (&handle_edit_cmd()) {
1.492 raeburn 2988: my $contentchg;
1.592 raeburn 2989: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 2990: $contentchg = 1;
2991: }
2992: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 2993: return $errtext if ($fatal);
2994: }
1.538 raeburn 2995:
2996: # Cut, copy and/or remove multiple resources
2997: if ($env{'form.multichange'}) {
2998: my %allchecked = (
2999: cut => {},
3000: remove => {},
3001: );
3002: my $needsupdate;
3003: foreach my $which (keys(%allchecked)) {
3004: $env{'form.multi'.$which} =~ s/,$//;
3005: if ($env{'form.multi'.$which}) {
3006: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3007: if (ref($allchecked{$which}) eq 'HASH') {
3008: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3009: }
3010: }
3011: }
3012: if ($needsupdate) {
3013: my $haschanges = 0;
3014: my %curr_groups = &Apache::longroup::coursegroups();
3015: my $total = scalar(@LONCAPA::map::order) - 1;
3016: for (my $i=$total; $i>=0; $i--) {
3017: my $res = $LONCAPA::map::order[$i];
3018: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3019: $name=&LONCAPA::map::qtescape($name);
3020: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3021: next unless $url;
1.538 raeburn 3022: my %denied =
3023: &action_restrictions($coursenum,$coursedom,$url,
3024: $env{'form.folderpath'},\%curr_groups);
3025: foreach my $which (keys(%allchecked)) {
3026: next if ($denied{$which});
3027: next unless ($allchecked{$which}{$res});
3028: if ($which eq 'remove') {
3029: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3030: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3031: &Apache::lonnet::removeuploadedurl($url);
3032: } else {
3033: &LONCAPA::map::makezombie($res);
3034: }
3035: splice(@LONCAPA::map::order,$i,1);
3036: $haschanges ++;
3037: } elsif ($which eq 'cut') {
3038: &LONCAPA::map::makezombie($res);
3039: splice(@LONCAPA::map::order,$i,1);
3040: $haschanges ++;
3041: }
3042: }
3043: }
3044: if ($haschanges) {
3045: ($errtext,$fatal) =
3046: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3047: return $errtext if ($fatal);
3048: }
3049: }
3050: }
3051:
1.329 droeschl 3052: # Group import/search
3053: if ($env{'form.importdetail'}) {
3054: my @imports;
3055: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3056: if (defined($item)) {
3057: my ($name,$url,$residx)=
1.533 raeburn 3058: map { &unescape($_); } split(/\=/,$item);
3059: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3060: my ($suffix,$errortxt,$locknotfreed) =
3061: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3062: if ($locknotfreed) {
3063: $r->print($locknotfreed);
3064: }
3065: if ($suffix) {
3066: $url =~ s/_new\./_$suffix./;
3067: } else {
3068: return $errortxt;
3069: }
1.533 raeburn 3070: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3071: my $type = $1;
3072: my ($suffix,$errortxt,$locknotfreed) =
3073: &new_timebased_suffix($coursedom,$coursenum,$type);
3074: if ($locknotfreed) {
3075: $r->print($locknotfreed);
3076: }
3077: if ($suffix) {
3078: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3079: } else {
3080: return $errortxt;
3081: }
1.534 raeburn 3082: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3083: if ($supplementalflag) {
3084: next unless ($1 eq 'supplemental');
3085: if ($folder eq 'supplemental') {
3086: next unless ($2 eq 'default');
3087: } else {
3088: next unless ($folder eq 'supplemental_'.$2);
3089: }
3090: } else {
3091: next unless ($1 eq 'docs');
3092: if ($folder eq 'default') {
3093: next unless ($2 eq 'default');
3094: } else {
3095: next unless ($folder eq 'default_'.$2);
3096: }
3097: }
1.504 raeburn 3098: }
1.329 droeschl 3099: push(@imports, [$name, $url, $residx]);
3100: }
3101: }
1.530 raeburn 3102: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3103: &group_import($coursenum, $coursedom, $folder,$container,
3104: 'londocs',@imports);
1.329 droeschl 3105: return $errtext if ($fatal);
1.529 raeburn 3106: if ($fixuperrors) {
3107: $r->print($fixuperrors);
3108: }
1.329 droeschl 3109: }
3110: # Loading a complete map
3111: if ($env{'form.loadmap'}) {
3112: if ($env{'form.importmap'}=~/\w/) {
3113: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3114: my ($title,$url,$ext,$type)=split(/\:/,$res);
3115: my $idx=&LONCAPA::map::getresidx($url);
3116: $LONCAPA::map::resources[$idx]=$res;
3117: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3118: }
3119: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3120: $folder.'.'.$container,1);
1.329 droeschl 3121: return $errtext if ($fatal);
3122: } else {
3123: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3124:
1.329 droeschl 3125: }
3126: }
3127: &log_differences($plain);
3128: }
3129: # ---------------------------------------------------------------- End commands
3130: # ---------------------------------------------------------------- Print screen
3131: my $idx=0;
3132: my $shown=0;
3133: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3134: $r->print('<div class="LC_Box">'.
1.432 raeburn 3135: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3136: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3137: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3138: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3139: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3140: '</ol>');
1.381 bisitz 3141: if ($randompick>=0) {
3142: $r->print('<p class="LC_warning">'
3143: .&mt('Caution: this folder is set to randomly pick a subset'
3144: .' of resources. Adding or removing resources from this'
3145: .' folder will change the set of resources that the'
3146: .' students see, resulting in spurious or missing credit'
3147: .' for completed problems, not limited to ones you'
3148: .' modify. Do not modify the contents of this folder if'
3149: .' it is in active student use.')
3150: .'</p>'
3151: );
3152: }
3153: if ($is_random_order) {
3154: $r->print('<p class="LC_warning">'
3155: .&mt('Caution: this folder is set to randomly order its'
3156: .' contents. Adding or removing resources from this folder'
3157: .' will change the order of resources shown.')
3158: .'</p>'
3159: );
3160: }
3161: $r->print('</div>');
1.364 bisitz 3162: }
1.381 bisitz 3163:
1.538 raeburn 3164: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3165: %filters = (
1.543 raeburn 3166: canremove => [],
3167: cancut => [],
3168: cancopy => [],
3169: hiddenresource => [],
3170: encrypturl => [],
3171: randomorder => [],
3172: randompick => [],
1.538 raeburn 3173: );
3174: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3175: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3176: foreach my $res (@LONCAPA::map::order) {
3177: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3178: $name=&LONCAPA::map::qtescape($name);
3179: $url=&LONCAPA::map::qtescape($url);
3180: unless ($name) { $name=(split(/\//,$url))[-1]; }
3181: unless ($name) { $idx++; next; }
1.537 raeburn 3182: push(@allidx,$res);
3183: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3184: push(@allmapidx,$res);
3185: }
1.381 bisitz 3186: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3187: $coursenum,$coursedom,$crstype,
1.538 raeburn 3188: $pathitem,$supplementalflag,$container,
3189: \%filters,\%curr_groups);
1.381 bisitz 3190: $idx++;
3191: $shown++;
1.329 droeschl 3192: }
1.424 onken 3193: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3194:
1.538 raeburn 3195: my $need_save;
1.510 raeburn 3196: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3197: my $toolslink;
3198: if ($allowed || &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
3199: $toolslink = '<table><tr><td>'
1.520 raeburn 3200: .&Apache::loncommon::help_open_menu('Navigation Screen',
3201: 'Navigation_Screen',undef,'RAT')
3202: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3203: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3204: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3205: .'id="LC_content_toolbar_edittoplevel" '
3206: .'class="LC_toolbarItem" '
3207: .'title="'.&mt('Supplemental Content Editor').'">'
3208: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3209: }
1.510 raeburn 3210: if ($shown) {
3211: if ($allowed) {
3212: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3213: .&Apache::loncommon::start_data_table(undef,'contentlist')
3214: .&Apache::loncommon::start_data_table_header_row()
3215: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3216: .'<th colspan="2">'.&mt('Actions').'</th>'
3217: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3218: if ($folder !~ /^supplemental/) {
3219: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3220: }
1.537 raeburn 3221: $to_show .= &Apache::loncommon::end_data_table_header_row();
3222: if ($folder !~ /^supplemental/) {
1.538 raeburn 3223: $lists{'canhide'} = join(',',@allidx);
3224: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3225: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3226: 'randomorder','randompick');
3227: foreach my $item (@possfilters) {
1.538 raeburn 3228: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3229: if (@{$filters{$item}} > 0) {
3230: $lists{$item} = join(',',@{$filters{$item}});
3231: }
1.538 raeburn 3232: }
3233: }
1.537 raeburn 3234: if (@allidx > 0) {
3235: my $path;
3236: if ($env{'form.folderpath'}) {
3237: $path =
3238: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3239: }
1.538 raeburn 3240: if (@allidx > 1) {
3241: $to_show .=
3242: &Apache::loncommon::continue_data_table_row().
3243: '<td colspan="2"> </td>'.
3244: '<td>'.
3245: &multiple_check_form('actions',\%lists).
3246: '</td>'.
3247: '<td> </td>'.
3248: '<td> </td>'.
3249: '<td colspan="4">'.
3250: &multiple_check_form('settings',\%lists).
3251: '</td>'.
3252: &Apache::loncommon::end_data_table_row();
3253: $need_save = 1;
3254: }
1.537 raeburn 3255: }
3256: }
3257: $to_show .= $output.' '
1.510 raeburn 3258: .&Apache::loncommon::end_data_table()
3259: .'<br style="line-height:2px;" />'
3260: .&Apache::loncommon::end_scrollbox();
3261: } else {
1.520 raeburn 3262: $to_show .= $toolslink
1.510 raeburn 3263: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3264: .$output.' '
3265: .&Apache::loncommon::end_data_table();
1.393 raeburn 3266: }
1.510 raeburn 3267: } else {
1.520 raeburn 3268: if (!$allowed) {
3269: $to_show .= $toolslink;
3270: }
1.510 raeburn 3271: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3272: .'<div class="LC_info" id="contentlist">'
1.550 raeburn 3273: .&mt('Currently empty')
1.510 raeburn 3274: .'</div>'
3275: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3276: }
3277: } else {
1.510 raeburn 3278: if ($shown) {
3279: $to_show = '<div>'
3280: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3281: .$output
3282: .&Apache::loncommon::end_data_table()
3283: .'</div>';
3284: } else {
3285: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3286: .&mt('Currently empty')
1.510 raeburn 3287: .'</div>'
3288: }
1.458 raeburn 3289: }
3290: my $tid = 1;
3291: if ($supplementalflag) {
3292: $tid = 2;
1.329 droeschl 3293: }
3294: if ($allowed) {
1.484 raeburn 3295: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3296: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3297: $jumpto,$readfile,$need_save,"$folder.$container"));
1.492 raeburn 3298: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 3299: } else {
3300: $r->print($to_show);
1.329 droeschl 3301: }
3302: return;
3303: }
3304:
1.538 raeburn 3305: sub multiple_check_form {
3306: my ($caller,$listsref) = @_;
3307: return unless (ref($listsref) eq 'HASH');
3308: my $output =
3309: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3310: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3311: '<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>'.
3312: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3313: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3314: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3315: if ($caller eq 'settings') {
3316: $output .=
3317: '<table><tr>'.
3318: '<td class="LC_docs_entry_parameter">'.
3319: '<span class="LC_nobreak"><label>'.
3320: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').
3321: '</label></span></td>'.
3322: '<td class="LC_docs_entry_parameter">'.
3323: '<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'".');" />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
3324: '</span></td>'.
3325: '</tr>'."\n".
3326: '<tr>'.
3327: '<td class="LC_docs_entry_parameter">'.
3328: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')" />'.&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'".')" />'.&mt('Random Order').
3329: '</label></span>'.
3330: '</td></tr></table>'."\n";
3331: } else {
3332: $output .=
3333: '<table><tr>'.
3334: '<td class="LC_docs_entry_parameter">'.
3335: '<span class="LC_nobreak LC_docs_remove">'.
3336: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')" />'.&mt('Remove').
3337: '</label></span></td>'.
3338: '<td class="LC_docs_entry_parameter">'.
3339: '<span class="LC_nobreak LC_docs_cut">'.
3340: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');" />'.&mt('Cut').
3341: '</label></span></td>'."\n".
3342: '<td class="LC_docs_entry_parameter">'.
3343: '<span class="LC_nobreak LC_docs_copy">'.
3344: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')" />'.&mt('Copy').
3345: '</label></span></td>'.
3346: '</tr></table>'."\n";
3347: }
3348: $output .=
3349: '</fieldset>'.
3350: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3351: if ($caller eq 'settings') {
3352: $output .=
1.543 raeburn 3353: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3354: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3355: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3356: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3357: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3358: } elsif ($caller eq 'actions') {
3359: $output .=
3360: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3361: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3362: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3363: }
3364: $output .=
3365: '</form>'.
3366: '</div>';
3367: return $output;
3368: }
3369:
1.329 droeschl 3370: sub process_file_upload {
1.552 raeburn 3371: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3372: # upload a file, if present
1.552 raeburn 3373: my $filesize = length($env{'form.uploaddoc'});
3374: if (!$filesize) {
3375: $$upload_output = '<div class="LC_error">'.
3376: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3377: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3378: $filesize).'<br />'.
3379: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3380: '</div>';
3381: return;
3382: }
3383: my $quotatype = 'unofficial';
3384: if ($crstype eq 'Community') {
3385: $quotatype = 'community';
1.580 raeburn 3386: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3387: $quotatype = 'official';
1.573 raeburn 3388: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3389: $quotatype = 'textbook';
1.552 raeburn 3390: }
3391: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3392: $filesize = int($filesize/1000); #expressed in kb
3393: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3394: $env{'form.uploaddoc.filename'},$filesize,
3395: 'upload',$quotatype);
1.552 raeburn 3396: return if ($$upload_output);
3397: }
1.440 raeburn 3398: my ($parseaction,$showupload,$nextphase,$mimetype);
3399: if ($env{'form.parserflag'}) {
1.329 droeschl 3400: $parseaction = 'parse';
3401: }
3402: my $folder=$env{'form.folder'};
3403: if ($folder eq '') {
3404: $folder='default';
3405: }
3406: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3407: my $errtext='';
3408: my $fatal=0;
3409: my $container='sequence';
1.519 raeburn 3410: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3411: $container='page';
3412: }
3413: ($errtext,$fatal)=
1.534 raeburn 3414: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3415: if ($#LONCAPA::map::order<1) {
3416: $LONCAPA::map::order[0]=1;
3417: $LONCAPA::map::resources[1]='';
3418: }
3419: my $destination = 'docs/';
3420: if ($folder =~ /^supplemental/) {
3421: $destination = 'supplemental/';
3422: }
3423: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3424: $destination .= 'default/';
3425: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3426: $destination .= $2.'/';
3427: }
1.534 raeburn 3428: if ($fatal) {
3429: $$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>';
3430: return;
3431: }
1.440 raeburn 3432: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3433: my $newidx=&LONCAPA::map::getresidx();
3434: $destination .= $newidx;
1.439 raeburn 3435: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3436: $parseaction,$allfiles,
1.440 raeburn 3437: $codebase,undef,undef,undef,undef,
3438: undef,undef,\$mimetype);
3439: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3440: my $stored = $1;
3441: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3442: $stored.'</span>').'</p>';
3443: } else {
3444: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3445:
1.457 raeburn 3446: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3447: return;
3448: }
1.329 droeschl 3449: my $ext='false';
3450: if ($url=~m{^http://}) { $ext='true'; }
3451: $url = &LONCAPA::map::qtunescape($url);
3452: my $comment=$env{'form.comment'};
3453: $comment = &LONCAPA::map::qtunescape($comment);
3454: if ($folder=~/^supplemental/) {
3455: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3456: $env{'user.domain'}.'___&&&___'.$comment;
3457: }
3458:
3459: $LONCAPA::map::resources[$newidx]=
3460: $comment.':'.$url.':'.$ext.':normal:res';
3461: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3462: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3463: $folder.'.'.$container,1);
1.329 droeschl 3464: if ($fatal) {
1.457 raeburn 3465: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3466: return;
1.329 droeschl 3467: } else {
1.440 raeburn 3468: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3469: $$upload_output = $showupload;
1.384 raeburn 3470: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3471: if ($total_embedded > 0) {
1.440 raeburn 3472: my $uploadphase = 'upload_embedded';
3473: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3474: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3475: my ($embedded,$num) =
3476: &Apache::loncommon::ask_for_embedded_content(
3477: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3478: if ($embedded) {
3479: if ($num) {
3480: $$upload_output .=
3481: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3482: $nextphase = $uploadphase;
3483: } else {
3484: $$upload_output .= $embedded;
3485: }
3486: } else {
3487: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3488: }
1.329 droeschl 3489: } else {
1.440 raeburn 3490: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3491: }
1.457 raeburn 3492: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3493: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3494: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3495: $nextphase = 'decompress_uploaded';
3496: my $position = scalar(@LONCAPA::map::order)-1;
3497: my $noextract = &return_to_editor();
3498: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3499: my %archiveitems = (
3500: folderpath => $env{'form.folderpath'},
3501: cmd => $nextphase,
3502: newidx => $newidx,
3503: position => $position,
3504: phase => $nextphase,
1.477 raeburn 3505: comment => $comment,
1.480 raeburn 3506: );
3507: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3508: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3509: $$upload_output = $showupload.
3510: &Apache::loncommon::decompress_form($mimetype,
3511: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3512: \%archiveitems,\@current);
1.329 droeschl 3513: }
3514: }
3515: }
1.440 raeburn 3516: return $nextphase;
1.329 droeschl 3517: }
3518:
1.480 raeburn 3519: sub get_dir_list {
3520: my ($url,$coursenum,$coursedom,$newidx) = @_;
3521: my ($destination,$dir_root) = &embedded_destination();
3522: my ($dirlistref,$listerror) =
3523: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3524: my @dir_lines;
3525: my $dirptr=16384;
3526: if (ref($dirlistref) eq 'ARRAY') {
3527: foreach my $dir_line (sort
3528: {
3529: my ($afile)=split('&',$a,2);
3530: my ($bfile)=split('&',$b,2);
3531: return (lc($afile) cmp lc($bfile));
3532: } (@{$dirlistref})) {
3533: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3534: $filename =~ s/\s+$//;
3535: next if ($filename =~ /^\.\.?$/);
3536: my $isdir = 0;
3537: if ($dirptr&$testdir) {
3538: $isdir = 1;
3539: }
3540: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3541: }
3542: }
3543: return @dir_lines;
3544: }
3545:
1.329 droeschl 3546: sub is_supplemental_title {
3547: my ($title) = @_;
3548: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3549: }
3550:
3551: # --------------------------------------------------------------- An entry line
3552:
3553: sub entryline {
1.501 raeburn 3554: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.538 raeburn 3555: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
1.581 raeburn 3556: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3557: if (&is_supplemental_title($title)) {
1.488 raeburn 3558: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3559: } else {
3560: $title=&HTML::Entities::encode($title,'"<>&\'');
3561: $renametitle=$title;
3562: $foldertitle=$title;
3563: }
3564:
3565: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3566:
1.329 droeschl 3567: $renametitle=~s/\\/\\\\/g;
3568: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3569: $renametitle=~s/"/%22/g;
1.581 raeburn 3570: $renametitle=~s/ /%20/g;
3571: $oldtitle = $renametitle;
1.576 raeburn 3572: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3573: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3574: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3575: # Edit commands
1.535 raeburn 3576: my ($esc_path, $path, $symb);
1.329 droeschl 3577: if ($env{'form.folderpath'}) {
3578: $esc_path=&escape($env{'form.folderpath'});
3579: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3580: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3581: }
1.505 raeburn 3582: my $isexternal;
1.510 raeburn 3583: if ($residx) {
1.501 raeburn 3584: my $currurl = $url;
3585: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3586: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3587: $isexternal = 1;
3588: }
1.510 raeburn 3589: if (!$supplementalflag) {
3590: my $path = 'uploaded/'.
3591: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3592: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3593: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3594: $residx,
3595: &Apache::lonnet::declutter($currurl));
3596: }
1.501 raeburn 3597: }
1.538 raeburn 3598: my ($renamelink,%lt,$ishash);
3599: if (ref($filtersref) eq 'HASH') {
3600: $ishash = 1;
3601: }
3602:
1.329 droeschl 3603: if ($allowed) {
1.538 raeburn 3604: $form_start = '
3605: <form action="/adm/coursedocs" method="post">
3606: ';
3607: $form_common=(<<END);
3608: <input type="hidden" name="folderpath" value="$path" />
3609: <input type="hidden" name="symb" value="$symb" />
3610: END
3611: $form_param=(<<END);
3612: <input type="hidden" name="setparms" value="$orderidx" />
3613: <input type="hidden" name="changeparms" value="0" />
3614: END
3615: $form_end = '</form>';
3616:
1.329 droeschl 3617: my $incindex=$index+1;
3618: my $selectbox='';
1.471 raeburn 3619: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3620: ((split(/\:/,
1.344 bisitz 3621: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3622: ne '') &&
1.329 droeschl 3623: ((split(/\:/,
1.344 bisitz 3624: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3625: ne '')) {
3626: $selectbox=
3627: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 3628: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 3629: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3630: if ($i==$incindex) {
1.358 bisitz 3631: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3632: } else {
3633: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3634: }
3635: }
3636: $selectbox.='</select>';
3637: }
1.501 raeburn 3638: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3639: 'up' => 'Move Up',
3640: 'dw' => 'Move Down',
3641: 'rm' => 'Remove',
3642: 'ct' => 'Cut',
3643: 'rn' => 'Rename',
1.501 raeburn 3644: 'cp' => 'Copy',
3645: 'ex' => 'External Resource',
3646: 'ed' => 'Edit',
3647: 'pr' => 'Preview',
3648: 'sv' => 'Save',
3649: 'ul' => 'URL',
3650: 'ti' => 'Title',
3651: );
1.538 raeburn 3652: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3653: $env{'form.folderpath'},
3654: $currgroups);
1.517 raeburn 3655: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3656: my $skip_confirm = 0;
3657: if ( $folder =~ /^supplemental/
3658: || ($url =~ m{( /smppg$
3659: |/syllabus$
3660: |/aboutme$
3661: |/navmaps$
3662: |/bulletinboard$
1.505 raeburn 3663: |\.html$)}x)
3664: || $isexternal) {
1.329 droeschl 3665: $skip_confirm = 1;
3666: }
3667:
1.538 raeburn 3668: if ($denied{'copy'}) {
1.543 raeburn 3669: $copylink=(<<ENDCOPY)
1.507 raeburn 3670: <span style="visibility: hidden;">$lt{'cp'}</span>
3671: ENDCOPY
3672: } else {
1.538 raeburn 3673: my $formname = 'edit_copy_'.$orderidx;
3674: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3675: $copylink=(<<ENDCOPY);
1.538 raeburn 3676: <form name="$formname" method="post" action="/adm/coursedocs">
3677: $form_common
1.540 raeburn 3678: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3679: $form_end
1.329 droeschl 3680: ENDCOPY
1.538 raeburn 3681: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3682: push(@{$filtersref->{'cancopy'}},$orderidx);
3683: }
1.329 droeschl 3684: }
1.538 raeburn 3685: if ($denied{'cut'}) {
1.507 raeburn 3686: $cutlink=(<<ENDCUT);
3687: <span style="visibility: hidden;">$lt{'ct'}</span>
3688: ENDCUT
3689: } else {
1.538 raeburn 3690: my $formname = 'edit_cut_'.$orderidx;
3691: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3692: $cutlink=(<<ENDCUT);
1.538 raeburn 3693: <form name="$formname" method="post" action="/adm/coursedocs">
3694: $form_common
1.542 raeburn 3695: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.540 raeburn 3696: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3697: $form_end
1.329 droeschl 3698: ENDCUT
1.538 raeburn 3699: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3700: push(@{$filtersref->{'cancut'}},$orderidx);
3701: }
1.329 droeschl 3702: }
1.538 raeburn 3703: if ($denied{'remove'}) {
1.507 raeburn 3704: $removelink=(<<ENDREM);
3705: <span style="visibility: hidden;">$lt{'rm'}</a>
3706: ENDREM
3707: } else {
1.538 raeburn 3708: my $formname = 'edit_remove_'.$orderidx;
3709: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm);";
1.497 raeburn 3710: $removelink=(<<ENDREM);
1.538 raeburn 3711: <form name="$formname" method="post" action="/adm/coursedocs">
3712: $form_common
1.542 raeburn 3713: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.540 raeburn 3714: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3715: $form_end
1.497 raeburn 3716: ENDREM
1.538 raeburn 3717: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3718: push(@{$filtersref->{'canremove'}},$orderidx);
3719: }
1.497 raeburn 3720: }
1.551 raeburn 3721: $renamelink=(<<ENDREN);
1.581 raeburn 3722: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3723: ENDREN
1.329 droeschl 3724: $line.=(<<END);
3725: <td>
1.379 bisitz 3726: <div class="LC_docs_entry_move">
1.535 raeburn 3727: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3728: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3729: </a>
3730: </div>
3731: <div class="LC_docs_entry_move">
1.536 raeburn 3732: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3733: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3734: </a>
3735: </div>
1.329 droeschl 3736: </td>
3737: <td>
3738: $form_start
1.538 raeburn 3739: $form_param
1.478 raeburn 3740: $form_common
1.329 droeschl 3741: $selectbox
3742: $form_end
3743: </td>
1.540 raeburn 3744: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3745: $removelink
1.329 droeschl 3746: $cutlink
3747: $copylink
3748: </td>
3749: END
3750: }
3751: # Figure out what kind of a resource this is
3752: my ($extension)=($url=~/\.(\w+)$/);
3753: my $uploaded=($url=~/^\/*uploaded\//);
3754: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3755: my $isfolder;
3756: my $ispage;
3757: my $containerarg;
1.329 droeschl 3758: if ($uploaded) {
1.472 raeburn 3759: if (($extension eq 'sequence') || ($extension eq 'page')) {
3760: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3761: $containerarg = $1;
1.472 raeburn 3762: if ($extension eq 'sequence') {
3763: $icon=$iconpath.'navmap.folder.closed.gif';
3764: $isfolder=1;
3765: } else {
3766: $icon=$iconpath.'page.gif';
3767: $ispage=1;
3768: }
3769: if ($allowed) {
3770: $url='/adm/coursedocs?';
3771: } else {
3772: $url='/adm/supplemental?';
3773: }
1.329 droeschl 3774: } else {
3775: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3776: }
3777: }
1.364 bisitz 3778:
1.518 raeburn 3779: my ($editlink,$extresform);
1.329 droeschl 3780: my $orig_url = $url;
1.340 raeburn 3781: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3782: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3783: if (!$supplementalflag && $residx && $symb) {
3784: if ((!$isfolder) && (!$ispage)) {
3785: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3786: $url=&Apache::lonnet::clutter($url);
3787: if ($url=~/^\/*uploaded\//) {
3788: $url=~/\.(\w+)$/;
3789: my $embstyle=&Apache::loncommon::fileembstyle($1);
3790: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3791: $url='/adm/wrapper'.$url;
3792: } elsif ($embstyle eq 'ssi') {
3793: #do nothing with these
3794: } elsif ($url!~/\.(sequence|page)$/) {
3795: $url='/adm/coursedocs/showdoc'.$url;
3796: }
3797: } elsif ($url=~m|^/ext/|) {
3798: $url='/adm/wrapper'.$url;
1.329 droeschl 3799: }
1.501 raeburn 3800: if (&Apache::lonnet::symbverify($symb,$url)) {
3801: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
3802: } else {
3803: $url='';
3804: }
1.329 droeschl 3805: }
3806: }
1.478 raeburn 3807: my ($rand_pick_text,$rand_order_text);
1.519 raeburn 3808: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3809: my $foldername=&escape($foldertitle);
3810: my $folderpath=$env{'form.folderpath'};
3811: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 3812: if (!$allowed && $supplementalflag) {
1.519 raeburn 3813: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 3814: $url.='folderpath='.&escape($folderpath);
3815: } else {
1.344 bisitz 3816: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 3817: # so it gets transferred between levels
1.519 raeburn 3818: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 3819: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 3820: 'parameter_randompick'))[0]
3821: .':'.((&LONCAPA::map::getparameter($orderidx,
3822: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3823: .':'.((&LONCAPA::map::getparameter($orderidx,
3824: 'parameter_encrypturl'))[0]=~/^yes$/i)
3825: .':'.((&LONCAPA::map::getparameter($orderidx,
1.519 raeburn 3826: 'parameter_randomorder'))[0]=~/^yes$/i)
3827: .':'.$ispage;
1.510 raeburn 3828: $url.='folderpath='.&escape($folderpath);
3829: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3830: 'parameter_randompick'))[0];
3831: my $rpckchk;
3832: if ($rpicknum) {
3833: $rpckchk = ' checked="checked"';
1.543 raeburn 3834: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3835: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3836: }
1.510 raeburn 3837: }
1.537 raeburn 3838: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 3839: $rand_pick_text =
1.478 raeburn 3840: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3841: $form_param."\n".
1.478 raeburn 3842: $form_common."\n".
1.537 raeburn 3843: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.510 raeburn 3844: if ($rpicknum ne '') {
3845: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3846: }
1.537 raeburn 3847: $rand_pick_text .= '</span></span>'.
3848: $form_end;
1.543 raeburn 3849: my $ro_set;
3850: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
3851: $ro_set = 'checked="checked"';
3852: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3853: push(@{$filtersref->{'randomorder'}},$orderidx);
3854: }
3855: }
1.564 raeburn 3856: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 3857: $rand_order_text =
1.537 raeburn 3858: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3859: $form_param."\n".
1.537 raeburn 3860: $form_common."\n".
1.538 raeburn 3861: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.' /> '.&mt('Random Order').' </label></span>'.
1.537 raeburn 3862: $form_end;
1.510 raeburn 3863: }
1.509 raeburn 3864: } elsif ($supplementalflag && !$allowed) {
1.510 raeburn 3865: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 3866: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 3867: if ($title) {
3868: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3869: }
1.511 raeburn 3870: if ($isexternal && $orderidx) {
1.510 raeburn 3871: $url .= '&idx='.$orderidx;
3872: }
1.329 droeschl 3873: }
1.519 raeburn 3874: my ($tdalign,$tdwidth);
1.501 raeburn 3875: if ($allowed) {
3876: my $fileloc =
3877: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 3878: if ($isexternal) {
1.518 raeburn 3879: ($editlink,$extresform) =
1.510 raeburn 3880: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.511 raeburn 3881: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 3882: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
3883: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 3884: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 3885: my $jscall =
3886: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3887: $switchserver,
1.503 raeburn 3888: $forceedit,
1.511 raeburn 3889: undef,$symb,
3890: &escape($env{'form.folderpath'}),
1.524 raeburn 3891: $renametitle,'','',1);
1.501 raeburn 3892: if ($jscall) {
1.518 raeburn 3893: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3894: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 3895: }
3896: }
3897: }
1.519 raeburn 3898: $tdalign = ' align="right" valign="top"';
3899: $tdwidth = ' width="80%"';
1.329 droeschl 3900: }
1.408 raeburn 3901: my $reinit;
3902: if ($crstype eq 'Community') {
3903: $reinit = &mt('(re-initialize community to access)');
3904: } else {
3905: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 3906: }
3907: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 3908: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3909: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3910: } elsif ($url) {
1.484 raeburn 3911: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3912: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 3913: } else {
3914: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3915: }
1.519 raeburn 3916: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3917: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3918: $line.='<a href="'.$url.'">'.$title.'</a>';
3919: } elsif ($url) {
1.484 raeburn 3920: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3921: $title,600,500);
1.469 www 3922: } else {
3923: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
3924: }
1.518 raeburn 3925: $line.="$extresform</td>";
1.478 raeburn 3926: $rand_pick_text = ' ' if ($rand_pick_text eq '');
3927: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 3928: if (($allowed) && ($folder!~/^supplemental/)) {
3929: my %lt=&Apache::lonlocal::texthash(
3930: 'hd' => 'Hidden',
3931: 'ec' => 'URL hidden');
1.543 raeburn 3932: my ($enctext,$hidtext);
3933: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
3934: $enctext = ' checked="checked"';
3935: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
3936: push(@{$filtersref->{'encrypturl'}},$orderidx);
3937: }
3938: }
3939: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3940: $hidtext = ' checked="checked"';
3941: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3942: push(@{$filtersref->{'hiddenresource'}},$orderidx);
3943: }
3944: }
1.537 raeburn 3945: my $formhidden = 'edit_hiddenresource_'.$orderidx;
3946: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 3947: $line.=(<<ENDPARMS);
3948: <td class="LC_docs_entry_parameter">
1.537 raeburn 3949: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 3950: $form_param
1.478 raeburn 3951: $form_common
1.538 raeburn 3952: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 3953: $form_end
1.458 raeburn 3954: <br />
1.537 raeburn 3955: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 3956: $form_param
1.478 raeburn 3957: $form_common
1.538 raeburn 3958: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext /> $lt{'ec'}</label>
1.329 droeschl 3959: $form_end
3960: </td>
1.478 raeburn 3961: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
3962: $rand_order_text</td>
1.329 droeschl 3963: ENDPARMS
3964: }
1.379 bisitz 3965: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 3966: return $line;
3967: }
3968:
1.538 raeburn 3969: sub action_restrictions {
3970: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
3971: my %denied = (
3972: cut => 0,
3973: copy => 0,
3974: remove => 0,
3975: );
3976: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
3977: # no copy for published maps
3978: $denied{'copy'} = 1;
1.597 ! raeburn 3979: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
! 3980: unless ($1 eq 'simpleproblem') {
! 3981: $denied{'copy'} = 1;
! 3982: }
! 3983: $denied{'cut'} = 1;
1.538 raeburn 3984: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
3985: if ($folderpath =~ /^default&[^\&]+$/) {
3986: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
3987: $denied{'remove'} = 1;
3988: }
3989: $denied{'cut'} = 1;
3990: $denied{'copy'} = 1;
3991: }
3992: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
3993: my $group = $1;
3994: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
3995: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3996: $denied{'remove'} = 1;
3997: }
3998: }
3999: $denied{'cut'} = 1;
4000: $denied{'copy'} = 1;
4001: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4002: my $group = $1;
4003: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4004: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4005: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4006: if (keys(%groupsettings) > 0) {
4007: $denied{'remove'} = 1;
4008: }
4009: $denied{'cut'} = 1;
4010: $denied{'copy'} = 1;
4011: }
4012: }
4013: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4014: my $group = $1;
4015: if ($url =~ /group_boards_\Q$group\E/) {
4016: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4017: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4018: if (keys(%groupsettings) > 0) {
4019: if (ref($groupsettings{'functions'}) eq 'HASH') {
4020: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4021: $denied{'remove'} = 1;
4022: }
4023: }
4024: }
4025: $denied{'cut'} = 1;
4026: $denied{'copy'} = 1;
4027: }
4028: }
4029: }
4030: return %denied;
4031: }
4032:
1.533 raeburn 4033: sub new_timebased_suffix {
1.538 raeburn 4034: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4035: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4036: if ($type eq 'paste') {
4037: $prefix = $type;
4038: $namespace = 'courseeditor';
1.587 raeburn 4039: $idtype = 'addcode';
1.538 raeburn 4040: } elsif ($type eq 'map') {
1.533 raeburn 4041: $prefix = 'docs';
4042: if ($area eq 'supplemental') {
4043: $prefix = 'supp';
4044: }
4045: $prefix .= $container;
4046: $namespace = 'uploadedmaps';
4047: } else {
4048: $prefix = $type;
4049: $namespace = 'templated';
1.504 raeburn 4050: }
4051: my ($suffix,$freedlock,$error) =
1.587 raeburn 4052: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4053: if (!$suffix) {
1.538 raeburn 4054: if ($type eq 'paste') {
4055: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4056: } elsif ($type eq 'map') {
1.533 raeburn 4057: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4058: } elsif ($type eq 'smppg') {
4059: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4060: } else {
1.565 bisitz 4061: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4062: }
1.504 raeburn 4063: if ($error) {
4064: $errtext .= '<br />'.$error;
4065: }
4066: }
4067: if ($freedlock ne 'ok') {
1.533 raeburn 4068: $locknotfreed =
4069: '<div class="LC_error">'.
4070: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4071: if ($type eq 'paste') {
1.591 raeburn 4072: if ($freedlock eq 'nolock') {
4073: $locknotfreed =
4074: '<div class="LC_error">'.
4075: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4076:
1.593 droeschl 4077: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4078: } else {
4079: $locknotfreed .=
4080: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4081: }
1.538 raeburn 4082: } elsif ($type eq 'map') {
1.591 raeburn 4083: $locknotfreed .=
4084: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4085: } elsif ($type eq 'smppg') {
4086: $locknotfreed .=
4087: &mt('This will prevent creation of additional simple pages in this course.');
4088: } else {
4089: $locknotfreed .=
1.565 bisitz 4090: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4091: }
1.538 raeburn 4092: unless ($type eq 'paste') {
4093: $locknotfreed .=
1.560 raeburn 4094: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4095: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4096: }
4097: $locknotfreed .= '</div>';
1.504 raeburn 4098: }
4099: return ($suffix,$errtext,$locknotfreed);
4100: }
4101:
1.329 droeschl 4102: =pod
4103:
4104: =item tiehash()
4105:
4106: tie the hash
4107:
4108: =cut
4109:
4110: sub tiehash {
4111: my ($mode)=@_;
4112: $hashtied=0;
4113: if ($env{'request.course.fn'}) {
4114: if ($mode eq 'write') {
4115: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4116: &GDBM_WRCREAT(),0640)) {
4117: $hashtied=2;
4118: }
4119: } else {
4120: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4121: &GDBM_READER(),0640)) {
4122: $hashtied=1;
4123: }
4124: }
1.364 bisitz 4125: }
1.329 droeschl 4126: }
4127:
4128: sub untiehash {
4129: if ($hashtied) { untie %hash; }
4130: $hashtied=0;
4131: return OK;
4132: }
4133:
4134:
4135:
4136:
4137: sub checkonthis {
4138: my ($r,$url,$level,$title)=@_;
4139: $url=&unescape($url);
4140: $alreadyseen{$url}=1;
4141: $r->rflush();
4142: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4143: $r->print("\n<br />");
4144: if ($level==0) {
4145: $r->print("<br />");
4146: }
4147: for (my $i=0;$i<=$level*5;$i++) {
4148: $r->print(' ');
4149: }
4150: $r->print('<a href="'.$url.'" target="cat">'.
4151: ($title?$title:$url).'</a> ');
4152: if ($url=~/^\/res\//) {
4153: my $result=&Apache::lonnet::repcopy(
4154: &Apache::lonnet::filelocation('',$url));
4155: if ($result eq 'ok') {
4156: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4157: $r->rflush();
4158: &Apache::lonnet::countacc($url);
4159: $url=~/\.(\w+)$/;
4160: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4161: $r->print('<br />');
4162: $r->rflush();
4163: for (my $i=0;$i<=$level*5;$i++) {
4164: $r->print(' ');
4165: }
4166: $r->print('- '.&mt('Rendering:').' ');
4167: my ($errorcount,$warningcount)=split(/:/,
4168: &Apache::lonnet::ssi_body($url,
4169: ('grade_target'=>'web',
4170: 'return_only_error_and_warning_counts' => 1)));
4171: if (($errorcount) ||
4172: ($warningcount)) {
4173: if ($errorcount) {
1.369 bisitz 4174: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4175: &mt('[quant,_1,error]',$errorcount).'</span>');
4176: }
4177: if ($warningcount) {
4178: $r->print('<span class="LC_warning">'.
4179: &mt('[quant,_1,warning]',$warningcount).'</span>');
4180: }
4181: } else {
4182: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4183: }
4184: $r->rflush();
4185: }
4186: my $dependencies=
4187: &Apache::lonnet::metadata($url,'dependencies');
4188: foreach my $dep (split(/\,/,$dependencies)) {
4189: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4190: &checkonthis($r,$dep,$level+1);
4191: }
4192: }
4193: } elsif ($result eq 'unavailable') {
4194: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4195: } elsif ($result eq 'not_found') {
4196: unless ($url=~/\$/) {
1.521 bisitz 4197: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4198: } else {
1.366 bisitz 4199: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4200: }
4201: } else {
4202: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4203: }
4204: }
4205: }
4206: }
4207:
4208:
4209:
4210: =pod
4211:
4212: =item list_symbs()
4213:
1.485 raeburn 4214: List Content Identifiers
1.329 droeschl 4215:
4216: =cut
4217:
4218: sub list_symbs {
4219: my ($r) = @_;
4220:
1.408 raeburn 4221: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4222: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4223: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4224: $r->print(&startContentScreen('tools'));
1.329 droeschl 4225: my $navmap = Apache::lonnavmaps::navmap->new();
4226: if (!defined($navmap)) {
4227: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4228: '<div class="LC_error">'.
4229: &mt('Unable to retrieve information about course contents').
4230: '</div>');
1.408 raeburn 4231: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4232: } else {
1.484 raeburn 4233: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4234: &Apache::loncommon::start_data_table().
4235: &Apache::loncommon::start_data_table_header_row().
4236: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4237: &Apache::loncommon::end_data_table_header_row()."\n");
4238: my $count;
1.329 droeschl 4239: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4240: $r->print(&Apache::loncommon::start_data_table_row().
4241: '<td>'.$res->compTitle().'</td>'.
4242: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4243: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4244: $count ++;
4245: }
4246: if (!$count) {
4247: $r->print(&Apache::loncommon::start_data_table_row().
4248: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4249: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4250: }
1.484 raeburn 4251: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4252: }
1.521 bisitz 4253: $r->print(&endContentScreen());
1.329 droeschl 4254: }
4255:
4256:
4257: sub verifycontent {
4258: my ($r) = @_;
1.408 raeburn 4259: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4260: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4261: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4262: $r->print(&startContentScreen('tools'));
4263: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4264: $hashtied=0;
4265: undef %alreadyseen;
4266: %alreadyseen=();
4267: &tiehash();
1.484 raeburn 4268:
1.329 droeschl 4269: foreach my $key (keys(%hash)) {
4270: if ($hash{$key}=~/\.(page|sequence)$/) {
4271: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4272: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4273: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4274: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4275: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4276: }
4277: }
4278: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4279: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4280: }
4281: }
4282: &untiehash();
1.442 www 4283: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4284: $r->print(&endContentScreen());
1.329 droeschl 4285: }
4286:
4287:
4288: sub devalidateversioncache {
4289: my $src=shift;
4290: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4291: &Apache::lonnet::clutter($src));
4292: }
4293:
4294: sub checkversions {
4295: my ($r) = @_;
1.408 raeburn 4296: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4297: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4298: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4299: $r->print(&startContentScreen('tools'));
1.442 www 4300:
1.329 droeschl 4301: my $header='';
4302: my $startsel='';
4303: my $monthsel='';
4304: my $weeksel='';
4305: my $daysel='';
4306: my $allsel='';
4307: my %changes=();
4308: my $starttime=0;
4309: my $haschanged=0;
4310: my %setversions=&Apache::lonnet::dump('resourceversions',
4311: $env{'course.'.$env{'request.course.id'}.'.domain'},
4312: $env{'course.'.$env{'request.course.id'}.'.num'});
4313:
4314: $hashtied=0;
4315: &tiehash();
4316: my %newsetversions=();
4317: if ($env{'form.setmostrecent'}) {
4318: $haschanged=1;
4319: foreach my $key (keys(%hash)) {
4320: if ($key=~/^ids\_(\/res\/.+)$/) {
4321: $newsetversions{$1}='mostrecent';
4322: &devalidateversioncache($1);
4323: }
4324: }
4325: } elsif ($env{'form.setcurrent'}) {
4326: $haschanged=1;
4327: foreach my $key (keys(%hash)) {
4328: if ($key=~/^ids\_(\/res\/.+)$/) {
4329: my $getvers=&Apache::lonnet::getversion($1);
4330: if ($getvers>0) {
4331: $newsetversions{$1}=$getvers;
4332: &devalidateversioncache($1);
4333: }
4334: }
4335: }
4336: } elsif ($env{'form.setversions'}) {
4337: $haschanged=1;
4338: foreach my $key (keys(%env)) {
4339: if ($key=~/^form\.set_version_(.+)$/) {
4340: my $src=$1;
4341: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4342: $newsetversions{$src}=$env{$key};
4343: &devalidateversioncache($src);
4344: }
4345: }
4346: }
4347: }
4348: if ($haschanged) {
4349: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4350: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 4351: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 4352: $r->print(&Apache::loncommon::confirmwrapper(
4353: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 4354: } else {
1.479 golterma 4355: $r->print(&Apache::loncommon::confirmwrapper(
4356: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4357: }
4358: &mark_hash_old();
4359: }
4360: &changewarning($r,'');
4361: if ($env{'form.timerange'} eq 'all') {
4362: # show all documents
1.549 raeburn 4363: $header=&mt('All content in '.$crstype);
1.521 bisitz 4364: $allsel=' selected="selected"';
1.329 droeschl 4365: foreach my $key (keys(%hash)) {
4366: if ($key=~/^ids\_(\/res\/.+)$/) {
4367: my $src=$1;
4368: $changes{$src}=1;
4369: }
4370: }
4371: } else {
4372: # show documents which changed
4373: %changes=&Apache::lonnet::dump
4374: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4375: $env{'course.'.$env{'request.course.id'}.'.num'});
4376: my $firstkey=(keys(%changes))[0];
4377: unless ($firstkey=~/^error\:/) {
4378: unless ($env{'form.timerange'}) {
4379: $env{'form.timerange'}=604800;
4380: }
4381: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4382: .&mt('seconds');
4383: if ($env{'form.timerange'}==-1) {
4384: $seltext='since start of course';
1.521 bisitz 4385: $startsel=' selected="selected"';
1.329 droeschl 4386: $env{'form.timerange'}=time;
4387: }
4388: $starttime=time-$env{'form.timerange'};
4389: if ($env{'form.timerange'}==2592000) {
4390: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4391: $monthsel=' selected="selected"';
1.329 droeschl 4392: } elsif ($env{'form.timerange'}==604800) {
4393: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4394: $weeksel=' selected="selected"';
1.329 droeschl 4395: } elsif ($env{'form.timerange'}==86400) {
4396: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4397: $daysel=' selected="selected"';
1.329 droeschl 4398: }
4399: $header=&mt('Content changed').' '.$seltext;
4400: } else {
4401: $header=&mt('No content modifications yet.');
4402: }
4403: }
4404: %setversions=&Apache::lonnet::dump('resourceversions',
4405: $env{'course.'.$env{'request.course.id'}.'.domain'},
4406: $env{'course.'.$env{'request.course.id'}.'.num'});
4407: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4408: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4409: 'lm' => 'Version changes since last Month',
4410: 'lw' => 'Version changes since last Week',
4411: 'sy' => 'Version changes since Yesterday',
4412: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4413: 'cd' => 'Change display',
1.329 droeschl 4414: 'sd' => 'Display',
4415: 'fi' => 'File',
4416: 'md' => 'Modification Date',
4417: 'mr' => 'Most recently published Version',
1.408 raeburn 4418: 've' => 'Version used in '.$crstype,
4419: 'vu' => 'Set Version to be used in '.$crstype,
4420: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4421: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4422: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4423: 'di' => 'Differences',
1.484 raeburn 4424: 'save' => 'Save changes',
4425: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4426: 'act' => 'Actions');
1.329 droeschl 4427: $r->print(<<ENDHEADERS);
1.484 raeburn 4428: <h4 class="LC_info">$header</h4>
1.329 droeschl 4429: <form action="/adm/coursedocs" method="post">
4430: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4431: <div class="LC_left_float">
1.479 golterma 4432: <fieldset>
1.484 raeburn 4433: <legend>$lt{'cd'}</legend>
1.329 droeschl 4434: <select name="timerange">
1.521 bisitz 4435: <option value='all'$allsel>$lt{'al'}</option>
4436: <option value="-1"$startsel>$lt{'st'}</option>
4437: <option value="2592000"$monthsel>$lt{'lm'}</option>
4438: <option value="604800"$weeksel>$lt{'lw'}</option>
4439: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4440: </select>
4441: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4442: </fieldset>
4443: </div>
4444: <div class="LC_left_float">
4445: <fieldset>
4446: <legend>$lt{'act'}</legend>
4447: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
4448: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
4449: </fieldset>
4450: </div>
4451: <br clear="all" />
4452: <hr />
4453: <h4>$lt{'vers'}</h4>
1.329 droeschl 4454: ENDHEADERS
1.479 golterma 4455: #number of columns for version history
1.571 raeburn 4456: my %changedbytime;
4457: foreach my $key (keys(%changes)) {
4458: #excludes not versionable problems from resource version history:
4459: next if ($key =~ /^\/res\/lib\/templates/);
4460: my $chg;
4461: if ($env{'form.timerange'} eq 'all') {
4462: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4463: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4464: } else {
4465: $chg = $changes{$key};
4466: next if ($chg < $starttime);
4467: }
4468: push(@{$changedbytime{$chg}},$key);
4469: }
4470: if (keys(%changedbytime) == 0) {
4471: &untiehash();
4472: $r->print(&mt('No content changes in imported content in specified time frame').
4473: &endContentScreen());
4474: return;
4475: }
1.479 golterma 4476: $r->print(
1.571 raeburn 4477: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
1.521 bisitz 4478: &Apache::loncommon::start_data_table().
4479: &Apache::loncommon::start_data_table_header_row().
4480: '<th>'.&mt('Resources').'</th>'.
4481: "<th>$lt{'mr'}</th>".
4482: "<th>$lt{'ve'}</th>".
4483: "<th>$lt{'vu'}</th>".
4484: '<th>'.&mt('History').'</th>'.
4485: &Apache::loncommon::end_data_table_header_row()
4486: );
1.571 raeburn 4487: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4488: foreach my $key (sort(@{$changedbytime{$chg}})) {
4489: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4490: my $currentversion=&Apache::lonnet::getversion($key);
4491: if ($currentversion<0) {
4492: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4493: }
4494: my $linkurl=&Apache::lonnet::clutter($key);
4495: $r->print(
4496: &Apache::loncommon::start_data_table_row().
4497: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4498: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4499: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4500: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4501: '<td align="right">'
4502: );
4503: # Used in course
4504: my $usedversion=$hash{'version_'.$linkurl};
4505: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4506: if ($usedversion != $currentversion) {
1.479 golterma 4507: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4508: } else {
1.479 golterma 4509: $r->print($usedversion);
4510: }
1.329 droeschl 4511: } else {
1.521 bisitz 4512: $r->print($currentversion);
1.329 droeschl 4513: }
1.571 raeburn 4514: $r->print('</td><td title="'.$lt{'vu'}.'">');
4515: # Set version
4516: $r->print(&Apache::loncommon::select_form(
4517: $setversions{$linkurl},
4518: 'set_version_'.$linkurl,
4519: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4520: '' => '',
4521: 'mostrecent' => &mt('most recent'),
4522: map {$_,$_} (1..$currentversion)}));
4523: my $lastold=1;
4524: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4525: my $url=$root.'.'.$prevvers.'.'.$extension;
4526: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4527: $lastold=$prevvers;
4528: }
4529: }
4530: $r->print('</td>');
4531: # List all available versions
4532: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4533: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4534: my $url=$root.'.'.$prevvers.'.'.$extension;
4535: $r->print(
4536: '<span class="LC_nobreak">'
4537: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4538: .&mt('Version [_1]',$prevvers).'</a>'
4539: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4540: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4541: .')');
4542: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4543: $r->print(
4544: ' <a href="/adm/diff?filename='.
4545: &Apache::lonnet::clutter($root.'.'.$extension).
4546: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4547: '" target="diffs">'.&mt('Diffs').'</a>');
4548: }
4549: $r->print('</span><br />');
1.329 droeschl 4550: }
1.571 raeburn 4551: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4552: }
1.329 droeschl 4553: }
1.521 bisitz 4554: $r->print(
4555: &Apache::loncommon::end_data_table().
4556: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
4557: '</form>'
4558: );
1.329 droeschl 4559:
4560: &untiehash();
1.521 bisitz 4561: $r->print(&endContentScreen());
1.571 raeburn 4562: return;
1.329 droeschl 4563: }
4564:
4565: sub mark_hash_old {
4566: my $retie_hash=0;
4567: if ($hashtied) {
4568: $retie_hash=1;
4569: &untiehash();
4570: }
4571: &tiehash('write');
4572: $hash{'old'}=1;
4573: &untiehash();
4574: if ($retie_hash) { &tiehash(); }
4575: }
4576:
4577: sub is_hash_old {
4578: my $untie_hash=0;
4579: if (!$hashtied) {
4580: $untie_hash=1;
4581: &tiehash();
4582: }
4583: my $return=$hash{'old'};
4584: if ($untie_hash) { &untiehash(); }
4585: return $return;
4586: }
4587:
4588: sub changewarning {
4589: my ($r,$postexec,$message,$url)=@_;
4590: if (!&is_hash_old()) { return; }
4591: my $pathvar='folderpath';
4592: my $path=&escape($env{'form.folderpath'});
4593: if (!defined($url)) {
4594: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4595: }
4596: my $course_type = &Apache::loncommon::course_type();
4597: if (!defined($message)) {
4598: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4599: }
4600: $r->print("\n\n".
1.372 bisitz 4601: '<script type="text/javascript">'."\n".
4602: '// <![CDATA['."\n".
4603: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4604: '// ]]>'."\n".
1.369 bisitz 4605: '</script>'."\n".
1.375 tempelho 4606: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4607: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4608: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4609: &mt($message,' <input type="hidden" name="'.
4610: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4611: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4612: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4613: }
4614:
4615:
4616: sub init_breadcrumbs {
1.571 raeburn 4617: my ($form,$text,$help)=@_;
1.329 droeschl 4618: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4619: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4620: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4621: faq=>273,
4622: bug=>'Instructor Interface',
1.571 raeburn 4623: help => $help});
1.329 droeschl 4624: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4625: text=>$text,
4626: faq=>273,
4627: bug=>'Instructor Interface'});
4628: }
4629:
1.441 www 4630: # subroutine to list form elements
4631: sub create_list_elements {
4632: my @formarr = @_;
4633: my $list = '';
1.501 raeburn 4634: foreach my $button (@formarr){
4635: foreach my $picture (keys(%{$button})) {
4636: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4637: }
4638: }
4639: return $list;
4640: }
1.329 droeschl 4641:
1.441 www 4642: # subroutine to create ul from list elements
4643: sub create_form_ul {
4644: my $list = shift;
4645: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4646: return $ul;
4647: }
1.329 droeschl 4648:
1.442 www 4649: #
4650: # Start tabs
4651: #
4652:
4653: sub startContentScreen {
1.484 raeburn 4654: my ($mode) = @_;
4655: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4656: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4657: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4658: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4659: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4660: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4661: } else {
1.549 raeburn 4662: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
1.484 raeburn 4663: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4664: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4665: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4666: }
4667: $output .= "\n".'</ul>'."\n";
4668: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4669: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4670: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4671: return $output;
1.442 www 4672: }
4673:
4674: #
4675: # End tabs
4676: #
4677:
4678: sub endContentScreen {
1.484 raeburn 4679: return '</div></div></div>';
1.442 www 4680: }
1.329 droeschl 4681:
1.446 www 4682: sub supplemental_base {
1.548 raeburn 4683: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4684: }
4685:
1.329 droeschl 4686: sub handler {
4687: my $r = shift;
4688: &Apache::loncommon::content_type($r,'text/html');
4689: $r->send_http_header;
4690: return OK if $r->header_only;
1.484 raeburn 4691:
4692: # get course data
1.408 raeburn 4693: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4694: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4695: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4696:
4697: # graphics settings
4698: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4699:
1.443 www 4700: #
1.329 droeschl 4701: # --------------------------------------------- Initialize help topics for this
4702: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4703: 'Adding_External_Resource','Navigate_Content',
4704: 'Adding_Folders','Docs_Overview', 'Load_Map',
4705: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 4706: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 4707: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 4708: 'Dropbox','Simple_Problem') {
1.329 droeschl 4709: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4710: }
4711: # Composite help files
4712: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4713: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4714: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4715: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4716: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4717: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4718: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4719: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4720: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4721: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 4722:
1.472 raeburn 4723: my $allowed;
4724: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4725: unless ($r->uri eq '/adm/supplemental') {
4726: # does this user have privileges to modify content.
4727: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4728: }
4729:
1.582 raeburn 4730: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4731: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 4732: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4733: &verifycontent($r);
4734: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4735: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4736: &list_symbs($r);
4737: } elsif ($allowed && $env{'form.docslog'}) {
4738: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4739: my $folder = $env{'form.folder'};
4740: if ($folder eq '') {
4741: $folder='default';
4742: }
4743: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 4744: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 4745: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.329 droeschl 4746: &checkversions($r);
4747: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.568 raeburn 4748: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4749: &dumpcourse($r);
4750: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4751: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4752: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4753: } else {
1.445 www 4754: #
4755: # Done catching special calls
1.484 raeburn 4756: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4757: # Get the parameters that may be needed
4758: #
4759: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 4760: ['folderpath',
4761: 'forcesupplement','forcestandard',
1.510 raeburn 4762: 'tools','symb','command','supppath']);
1.445 www 4763:
4764: # standard=1: this is a "new-style" course with an uploaded map as top level
4765: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4766:
4767: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4768:
1.484 raeburn 4769: # Decide whether this should display supplemental or main content or utilities
1.445 www 4770: # supplementalflag=1: show supplemental documents
4771: # supplementalflag=0: show standard documents
1.484 raeburn 4772: # toolsflag=1: show utilities
1.445 www 4773:
1.561 raeburn 4774: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4775: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4776: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4777: $supplementalflag=0;
4778: }
4779: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4780: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4781: unless ($allowed) { $supplementalflag=1; }
4782: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4783: my $toolsflag=0;
4784: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4785:
1.329 droeschl 4786: my $script='';
4787: my $showdoc=0;
1.457 raeburn 4788: my $addentries = {};
1.475 raeburn 4789: my $container;
1.329 droeschl 4790: my $containertag;
1.508 raeburn 4791: my $pathitem;
1.329 droeschl 4792:
1.464 www 4793: # Do we directly jump somewhere?
1.466 www 4794:
1.525 raeburn 4795: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4796: if ($env{'form.symb'} ne '') {
1.522 raeburn 4797: $env{'form.folderpath'}=
4798: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 4799: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4800: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4801: } elsif ($env{'form.supppath'} ne '') {
4802: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 4803: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4804: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4805: }
1.472 raeburn 4806: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 4807: $env{'form.folderpath'} = 'default&'.
1.548 raeburn 4808: &escape(&mt('Main Content').':::::');
1.525 raeburn 4809: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4810: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 4811: $env{'form.folderpath'} = 'supplemental&'.
1.538 raeburn 4812: &escape('Supplemental Content');
1.525 raeburn 4813: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4814: } elsif ($env{'form.command'} eq 'contents') {
4815: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4816: } elsif ($env{'form.command'} eq 'home') {
4817: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4818: }
4819:
1.525 raeburn 4820:
1.445 www 4821: # Where do we store these for when we come back?
4822: my $stored_folderpath='docs_folderpath';
4823: if ($supplementalflag) {
4824: $stored_folderpath='docs_sup_folderpath';
4825: }
1.464 www 4826:
1.519 raeburn 4827: # No folderpath, and in edit mode, see if we have something stored
4828: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4829: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 4830: {'folderpath' => 'scalar'});
1.523 raeburn 4831: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4832: undef($env{'form.folderpath'});
4833: }
1.329 droeschl 4834: }
1.446 www 4835:
4836: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4837: if (!$allowed) {
1.446 www 4838: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4839: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4840: }
4841: }
1.446 www 4842: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4843: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4844: $env{'form.folderpath'} = &supplemental_base()
4845: .'&'.
1.329 droeschl 4846: $env{'form.folderpath'};
4847: }
1.446 www 4848: # If after all of this, we still don't have any paths, make them
1.519 raeburn 4849: unless ($env{'form.folderpath'}) {
1.446 www 4850: if ($supplementalflag) {
4851: $env{'form.folderpath'}=&supplemental_base();
4852: } else {
1.548 raeburn 4853: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
1.538 raeburn 4854: ':::::');
1.446 www 4855: }
1.472 raeburn 4856: }
1.446 www 4857:
1.445 www 4858: # Store this
1.484 raeburn 4859: unless ($toolsflag) {
1.510 raeburn 4860: if ($allowed) {
4861: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 4862: {'folderpath' => 'scalar'});
1.510 raeburn 4863: }
1.519 raeburn 4864: my $folderpath;
1.484 raeburn 4865: if ($env{'form.folderpath'}) {
1.519 raeburn 4866: $folderpath = $env{'form.folderpath'};
4867: my (@folders)=split('&',$env{'form.folderpath'});
4868: $env{'form.foldername'}=&unescape(pop(@folders));
4869: if ($env{'form.foldername'} =~ /\:1$/) {
4870: $container = 'page';
4871: } else {
4872: $container = 'sequence';
4873: }
4874: $env{'form.folder'}=pop(@folders);
1.484 raeburn 4875: } else {
1.519 raeburn 4876: if ($env{'form.folder'} eq '' ||
4877: $env{'form.folder'} eq 'supplemental') {
4878: $folderpath='default&'.
1.548 raeburn 4879: &escape(&mt('Main Content').':::::');
1.484 raeburn 4880: }
4881: }
1.519 raeburn 4882: $containertag = '<input type="hidden" name="folderpath" value="" />';
4883: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 4884: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4885: $showdoc='/'.$1;
4886: }
4887: if ($showdoc) { # got called in sequence from course
4888: $allowed=0;
4889: } else {
4890: if ($allowed) {
4891: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4892: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 4893: }
4894: }
1.329 droeschl 4895: }
4896:
1.344 bisitz 4897: # get personal data
1.329 droeschl 4898: my $uname=$env{'user.name'};
4899: my $udom=$env{'user.domain'};
4900: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
4901:
4902: if ($allowed) {
1.484 raeburn 4903: if ($toolsflag) {
4904: $script .= &inject_data_js();
4905: my ($home,$other,%outhash)=&authorhosts();
4906: if (!$home && $other) {
4907: my @hosts;
4908: foreach my $aurole (keys(%outhash)) {
4909: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4910: push(@hosts,$outhash{$aurole});
4911: }
4912: }
4913: $script .= &dump_switchserver_js(@hosts);
4914: }
1.458 raeburn 4915: } else {
1.570 raeburn 4916: my $tid = 1;
1.484 raeburn 4917: my @tabids;
4918: if ($supplementalflag) {
4919: @tabids = ('002','ee2','ff2');
1.570 raeburn 4920: $tid = 2;
1.484 raeburn 4921: } else {
4922: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 4923: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 4924: unshift(@tabids,'001');
4925: push(@tabids,('dd1','ee1'));
4926: }
1.458 raeburn 4927: }
1.484 raeburn 4928: my $tabidstr = join("','",@tabids);
4929: $script .= &editing_js($udom,$uname,$supplementalflag).
4930: &history_tab_js().
4931: &inject_data_js().
1.570 raeburn 4932: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.510 raeburn 4933: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 4934: $addentries = {
1.485 raeburn 4935: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 4936: };
1.458 raeburn 4937: }
1.538 raeburn 4938: $script .= &paste_popup_js();
1.501 raeburn 4939: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
4940: &mt('Switch server?');
4941:
4942:
1.329 droeschl 4943: }
4944: # -------------------------------------------------------------------- Body tag
1.369 bisitz 4945: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 4946: .'// <![CDATA['."\n"
4947: .$script."\n"
4948: .'// ]]>'."\n"
1.595 musolffc 4949: .'</script>'."\n"
4950: .'<script type="text/javascript"
4951: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 4952:
4953: # Breadcrumbs
4954: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 4955:
4956: if ($showdoc) {
4957: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
4958: {'force_register' => $showdoc,}));
1.571 raeburn 4959: } elsif ($toolsflag) {
4960: &Apache::lonhtmlcommon::add_breadcrumb({
4961: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4962: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
4963: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4964: .&Apache::lonhtmlcommon::breadcrumbs(
4965: 'Editing Course Contents')
4966: );
1.510 raeburn 4967: } elsif ($r->uri eq '/adm/supplemental') {
4968: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
4969: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
4970: {'bread_crumbs' => $brcrum,}));
4971: } else {
1.392 raeburn 4972: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 4973: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4974: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 4975: {'add_entries' => $addentries}
4976: )
1.392 raeburn 4977: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4978: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 4979: 'Editing '.$crstype.' Contents',
1.392 raeburn 4980: 'Docs_Adding_Course_Doc')
4981: );
4982: }
1.364 bisitz 4983:
1.329 droeschl 4984: my %allfiles = ();
4985: my %codebase = ();
1.440 raeburn 4986: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 4987: if ($allowed) {
4988: if (($env{'form.uploaddoc.filename'}) &&
4989: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 4990: my $context = $1;
4991: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 4992: undef($hadchanges);
1.440 raeburn 4993: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 4994: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 4995: if ($hadchanges) {
4996: &mark_hash_old();
4997: }
1.440 raeburn 4998: $r->print($upload_output);
4999: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5000: # Process file upload - phase two - upload embedded objects
5001: $uploadphase = 'check_embedded';
5002: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5003: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5004: $env{'form.newidx'});
5005: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5006: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5007: my ($destination,$dir_root) = &embedded_destination();
5008: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5009: my $actionurl = '/adm/coursedocs';
5010: my ($result,$flag) =
5011: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5012: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5013: $actionurl);
5014: $r->print($result.&return_to_editor());
5015: } elsif ($env{'form.phase'} eq 'check_embedded') {
5016: # Process file upload - phase three - modify references in HTML file
5017: $uploadphase = 'modified_orightml';
5018: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5019: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5020: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5021: my $result =
5022: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5023: $docuname,$docudom,undef,
5024: $dir_root);
5025: $r->print($result.&return_to_editor());
1.476 raeburn 5026: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5027: $uploadphase = 'decompress_phase_one';
5028: $r->print(&decompression_phase_one().
5029: &return_to_editor());
5030: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5031: $uploadphase = 'decompress_phase_two';
5032: $r->print(&decompression_phase_two().
5033: &return_to_editor());
1.329 droeschl 5034: }
5035: }
5036:
1.484 raeburn 5037: if ($allowed && $toolsflag) {
5038: $r->print(&startContentScreen('tools'));
5039: $r->print(&generate_admin_menu($crstype));
5040: $r->print(&endContentScreen());
5041: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5042: # -----------------------------------------------------------------------------
5043: my %lt=&Apache::lonlocal::texthash(
5044: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5045: 'upfi' => 'Upload File',
1.553 raeburn 5046: 'upld' => 'Upload Content',
1.329 droeschl 5047: 'srch' => 'Search',
5048: 'impo' => 'Import',
1.487 raeburn 5049: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5050: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5051: 'selm' => 'Select Map',
5052: 'load' => 'Load Map',
5053: 'newf' => 'New Folder',
5054: 'newp' => 'New Composite Page',
5055: 'syll' => 'Syllabus',
1.425 raeburn 5056: 'navc' => 'Table of Contents',
1.343 biermanm 5057: 'sipa' => 'Simple Course Page',
1.329 droeschl 5058: 'sipr' => 'Simple Problem',
1.534 raeburn 5059: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5060: 'drbx' => 'Drop Box',
1.451 www 5061: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5062: 'bull' => 'Discussion Board',
1.347 weissno 5063: 'mypi' => 'My Personal Information Page',
1.353 weissno 5064: 'grpo' => 'Group Portfolio',
1.329 droeschl 5065: 'rost' => 'Course Roster',
1.528 raeburn 5066: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5067: 'imsf' => 'IMS Upload',
5068: 'imsl' => 'Upload IMS package',
1.501 raeburn 5069: 'cms' => 'Origin of IMS package',
5070: 'se' => 'Select',
1.329 droeschl 5071: 'file' => 'File',
5072: 'title' => 'Title',
5073: 'comment' => 'Comment',
1.403 raeburn 5074: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5075: 'bb5' => 'Blackboard 5',
5076: 'bb6' => 'Blackboard 6',
5077: 'angel5' => 'ANGEL 5.5',
5078: 'webctce4' => 'WebCT 4 Campus Edition',
5079: );
1.329 droeschl 5080: # -----------------------------------------------------------------------------
1.595 musolffc 5081:
5082: # Calculate free quota space for a user or course. A javascript function checks
5083: # file size to determine if upload should be allowed.
5084: my $quotatype = 'unofficial';
5085: if ($crstype eq 'Community') {
5086: $quotatype = 'community';
5087: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5088: $quotatype = 'official';
5089: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5090: $quotatype = 'textbook';
5091: }
5092: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5093: 'course',$quotatype); # expressed in MB
5094: my $current_disk_usage = 0;
5095: foreach my $subdir ('docs','supplemental') {
5096: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5097: "userfiles/$subdir",1); # expressed in kB
5098: }
5099: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5100:
1.329 droeschl 5101: my $fileupload=(<<FIUP);
5102: $lt{'file'}:<br />
1.595 musolffc 5103: <input type="file" name="uploaddoc" class="flUpload" size="40" />
5104: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5105: FIUP
5106:
5107: my $checkbox=(<<CHBO);
5108: <!-- <label>$lt{'parse'}?
5109: <input type="checkbox" name="parserflag" />
5110: </label> -->
5111: <label>
5112: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
5113: </label>
5114: CHBO
1.501 raeburn 5115: my $imsfolder = $env{'form.folder'};
5116: if ($imsfolder eq '') {
5117: $imsfolder = 'default';
5118: }
5119: my $imspform=(<<IMSFORM);
5120: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5121: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5122: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5123: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5124: <legend>$lt{'imsf'}</legend>
5125: $fileupload
5126: <br />
5127: <p>
5128: $lt{'cms'}:
5129: <select name="source">
5130: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5131: <option value="bb5">$lt{'bb5'}</option>
5132: <option value="bb6">$lt{'bb6'}</option>
5133: <option value="angel5">$lt{'angel5'}</option>
5134: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5135: </select>
5136: <input type="hidden" name="folder" value="$imsfolder" />
5137: </p>
5138: <input type="hidden" name="phase" value="one" />
5139: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
5140: </fieldset>
5141: </form>
5142: IMSFORM
1.329 droeschl 5143:
5144: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5145: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5146: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5147: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5148: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5149: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5150: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5151: $fileupload
1.329 droeschl 5152: <br />
5153: $lt{'title'}:<br />
1.458 raeburn 5154: <input type="text" size="60" name="comment" />
1.508 raeburn 5155: $pathitem
1.329 droeschl 5156: <input type="hidden" name="cmd" value="upload_default" />
5157: <br />
1.458 raeburn 5158: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5159: $checkbox
5160: </span>
1.501 raeburn 5161: <br clear="all" />
5162: <input type="submit" value="$lt{'upld'}" />
5163: </fieldset>
5164: </form>
1.383 tempelho 5165: FUFORM
1.329 droeschl 5166:
1.502 raeburn 5167: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5168: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5169: $lt{'impm'}</a>$help{'Load_Map'}
5170: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5171: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5172: <legend>$lt{'impm'}</legend>
1.371 tempelho 5173: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5174: $lt{'copm'}<br />
5175: <span class="LC_nobreak">
5176: <input type="text" name="importmap" size="40" value=""
5177: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 5178: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 5179: <input type="submit" name="loadmap" value="$lt{'load'}" />
5180: </fieldset>
5181: </form>
5182:
1.383 tempelho 5183: SEDFFORM
1.502 raeburn 5184: my @importpubforma = (
1.508 raeburn 5185: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
1.423 onken 5186: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.487 raeburn 5187: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.514 raeburn 5188: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
1.383 tempelho 5189: );
1.502 raeburn 5190: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5191: my $extresourcesform =
5192: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5193: $help{'Adding_External_Resource'});
1.329 droeschl 5194: if ($allowed) {
1.492 raeburn 5195: my $folder = $env{'form.folder'};
5196: if ($folder eq '') {
5197: $folder='default';
5198: }
1.538 raeburn 5199: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5200: if ($output) {
5201: $r->print($output);
5202: }
1.337 ehlerst 5203: $r->print(<<HIDDENFORM);
5204: <form name="renameform" method="post" action="/adm/coursedocs">
5205: <input type="hidden" name="title" />
5206: <input type="hidden" name="cmd" />
5207: <input type="hidden" name="markcopy" />
5208: <input type="hidden" name="copyfolder" />
5209: $containertag
5210: </form>
1.484 raeburn 5211:
1.337 ehlerst 5212: HIDDENFORM
1.508 raeburn 5213: $r->print(&makesimpleeditform($pathitem)."\n".
5214: &makedocslogform($pathitem."\n".
1.484 raeburn 5215: '<input type="hidden" name="folder" value="'.
5216: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5217: }
1.442 www 5218:
5219: # Generate the tabs
1.510 raeburn 5220: my ($mode,$needs_end);
1.472 raeburn 5221: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5222: my @folders = split('&',$env{'form.folderpath'});
5223: unless (@folders > 2) {
5224: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5225: $needs_end = 1;
5226: }
1.472 raeburn 5227: } else {
1.484 raeburn 5228: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5229: $needs_end = 1;
1.472 raeburn 5230: }
1.443 www 5231:
1.442 www 5232: #
5233:
5234: my $savefolderpath;
5235:
1.395 raeburn 5236: if ($allowed) {
1.329 droeschl 5237: my $folder=$env{'form.folder'};
1.443 www 5238: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 5239: $folder='default';
1.356 tempelho 5240: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5241: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5242: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5243: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5244: }
5245: my $postexec='';
5246: if ($folder eq 'default') {
1.372 bisitz 5247: $r->print('<script type="text/javascript">'."\n"
5248: .'// <![CDATA['."\n"
5249: .'this.window.name="loncapaclient";'."\n"
5250: .'// ]]>'."\n"
5251: .'</script>'."\n"
1.369 bisitz 5252: );
1.329 droeschl 5253: } else {
5254: #$postexec='self.close();';
5255: }
1.504 raeburn 5256: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5257: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5258: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5259:
5260: my $newnavform=(<<NNFORM);
5261: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5262: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5263: $pathitem
1.329 droeschl 5264: <input type="hidden" name="importdetail"
5265: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 5266: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 5267: $help{'Navigate_Content'}
5268: </form>
5269: NNFORM
5270: my $newsmppageform=(<<NSPFORM);
5271: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5272: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5273: $pathitem
1.329 droeschl 5274: <input type="hidden" name="importdetail" value="" />
1.423 onken 5275: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5276: $help{'Simple Page'}
1.329 droeschl 5277: </form>
5278: NSPFORM
5279:
5280: my $newsmpproblemform=(<<NSPROBFORM);
5281: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5282: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5283: $pathitem
1.329 droeschl 5284: <input type="hidden" name="importdetail" value="" />
1.423 onken 5285: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5286: $help{'Simple_Problem'}
1.329 droeschl 5287: </form>
5288:
5289: NSPROBFORM
5290:
5291: my $newdropboxform=(<<NDBFORM);
5292: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5293: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5294: $pathitem
1.329 droeschl 5295: <input type="hidden" name="importdetail" value="" />
1.423 onken 5296: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5297: $help{'Dropbox'}
1.344 bisitz 5298: </form>
1.329 droeschl 5299: NDBFORM
5300:
5301: my $newexuploadform=(<<NEXUFORM);
5302: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5303: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5304: $pathitem
1.329 droeschl 5305: <input type="hidden" name="importdetail" value="" />
1.423 onken 5306: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5307: $help{'Score_Upload_Form'}
5308: </form>
5309: NEXUFORM
5310:
5311: my $newbulform=(<<NBFORM);
5312: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5313: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5314: $pathitem
1.329 droeschl 5315: <input type="hidden" name="importdetail" value="" />
1.423 onken 5316: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5317: $help{'Bulletin Board'}
5318: </form>
5319: NBFORM
5320:
5321: my $newaboutmeform=(<<NAMFORM);
5322: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5323: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5324: $pathitem
1.329 droeschl 5325: <input type="hidden" name="importdetail"
5326: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5327: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5328: $help{'My Personal Information Page'}
1.329 droeschl 5329: </form>
5330: NAMFORM
5331:
5332: my $newaboutsomeoneform=(<<NASOFORM);
5333: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5334: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5335: $pathitem
1.329 droeschl 5336: <input type="hidden" name="importdetail" value="" />
1.423 onken 5337: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5338: </form>
5339: NASOFORM
5340:
5341: my $newrosterform=(<<NROSTFORM);
5342: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5343: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5344: $pathitem
1.329 droeschl 5345: <input type="hidden" name="importdetail"
5346: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 5347: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.556 raeburn 5348: $help{'Course_Roster'}
1.329 droeschl 5349: </form>
5350: NROSTFORM
5351:
1.534 raeburn 5352: my $newwebpage;
5353: if ($folder =~ /^default_?(\d*)$/) {
5354: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5355: if ($1) {
5356: $newwebpage .= $1;
5357: } else {
5358: $newwebpage .= 'default';
5359: }
5360: $newwebpage .= '/new.html';
5361: }
5362: my $newwebpageform =(<<NWEBFORM);
5363: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5364: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5365: $pathitem
5366: <input type="hidden" name="importdetail" value="$newwebpage" />
5367: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5368: $help{'Web_Page'}
1.534 raeburn 5369: </form>
5370: NWEBFORM
5371:
5372:
1.342 ehlerst 5373: my $specialdocumentsform;
1.383 tempelho 5374: my @specialdocumentsforma;
1.451 www 5375: my $gradingform;
5376: my @gradingforma;
5377: my $communityform;
5378: my @communityforma;
1.351 ehlerst 5379: my $newfolderform;
1.390 tempelho 5380: my $newfolderb;
1.342 ehlerst 5381:
1.451 www 5382: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5383:
1.329 droeschl 5384: my $newpageform=(<<NPFORM);
5385: <form action="/adm/coursedocs" method="post" name="newpage">
5386: <input type="hidden" name="folderpath" value="$path" />
5387: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5388: <input type="hidden" name="active" value="ee" />
1.423 onken 5389: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5390: $help{'Adding_Pages'}
1.329 droeschl 5391: </form>
5392: NPFORM
1.390 tempelho 5393:
5394:
1.351 ehlerst 5395: $newfolderform=(<<NFFORM);
1.329 droeschl 5396: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 5397: $pathitem
1.329 droeschl 5398: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5399: <input type="hidden" name="active" value="" />
1.422 onken 5400: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5401: </form>
5402: NFFORM
5403:
5404: my $newsylform=(<<NSYLFORM);
5405: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 5406: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5407: $pathitem
1.329 droeschl 5408: <input type="hidden" name="importdetail"
5409: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5410: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5411: $help{'Syllabus'}
1.383 tempelho 5412:
1.329 droeschl 5413: </form>
5414: NSYLFORM
1.364 bisitz 5415:
1.329 droeschl 5416: my $newgroupfileform=(<<NGFFORM);
5417: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 5418: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5419: $pathitem
1.329 droeschl 5420: <input type="hidden" name="importdetail"
5421: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 5422: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 5423: $help{'Group Portfolio'}
1.329 droeschl 5424: </form>
5425: NGFFORM
1.383 tempelho 5426: @specialdocumentsforma=(
1.421 onken 5427: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.417 droeschl 5428: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 5429: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
5430: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 5431: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5432: );
5433: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5434:
1.434 raeburn 5435:
5436: my @importdoc = (
1.519 raeburn 5437: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5438: );
5439: unless ($container eq 'page') {
5440: push(@importdoc,
5441: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5442: );
5443: }
5444: push(@importdoc,
1.558 raeburn 5445: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 5446: );
1.501 raeburn 5447: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5448:
1.451 www 5449: @gradingforma=(
5450: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5451: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5452: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5453:
5454: );
5455: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5456:
5457: @communityforma=(
5458: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5459: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5460: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
5461: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
5462: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
5463: );
5464: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5465:
1.330 tempelho 5466: my %orderhash = (
1.553 raeburn 5467: 'aa' => ['Upload',$fileuploadform],
5468: 'bb' => ['Import',$importpubform],
5469: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5470: );
1.519 raeburn 5471: unless ($container eq 'page') {
1.434 raeburn 5472: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5473: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 5474: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5475: }
5476:
1.341 ehlerst 5477: $hadchanges=0;
1.484 raeburn 5478: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5479: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5480: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 5481: if ($error) {
5482: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5483: }
5484: if ($hadchanges) {
5485: &mark_hash_old();
5486: }
1.341 ehlerst 5487:
1.443 www 5488: &changewarning($r,'');
5489: }
1.458 raeburn 5490: }
1.442 www 5491:
1.443 www 5492: # Supplemental documents start here
5493:
1.329 droeschl 5494: my $folder=$env{'form.folder'};
1.443 www 5495: unless ($supplementalflag) {
1.329 droeschl 5496: $folder='supplemental';
5497: }
5498: if ($folder =~ /^supplemental$/ &&
5499: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5500: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5501: } elsif ($allowed) {
1.356 tempelho 5502: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5503: }
1.508 raeburn 5504: $pathitem = '<input type="hidden" name="folderpath" value="'.
5505: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5506: if ($allowed) {
5507: my $folderseq=
1.504 raeburn 5508: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5509:
5510: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 5511: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5512: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5513: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 5514: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 5515: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5516: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5517: $fileupload
5518: <br />
5519: <br />
5520: <span class="LC_nobreak">
5521: $checkbox
5522: </span>
5523: <br /><br />
5524: $lt{'comment'}:<br />
1.383 tempelho 5525: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5526: <br />
1.508 raeburn 5527: $pathitem
1.329 droeschl 5528: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 5529: <input type='submit' value="$lt{'upld'}" />
5530: </form>
1.329 droeschl 5531: SUPDOCFORM
5532:
5533: my $supnewfolderform=(<<SNFFORM);
5534: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 5535: <input type="hidden" name="active" value="" />
1.508 raeburn 5536: $pathitem
1.329 droeschl 5537: <input type="hidden" name="importdetail" value="" />
1.423 onken 5538: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5539: $help{'Adding_Folders'}
1.329 droeschl 5540: </form>
5541: SNFFORM
1.383 tempelho 5542:
1.510 raeburn 5543: my $supextform =
5544: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
5545: $help{'Adding_External_Resource'});
1.329 droeschl 5546:
5547: my $supnewsylform=(<<SNSFORM);
5548: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5549: <input type="hidden" name="active" value="ff" />
1.508 raeburn 5550: $pathitem
1.329 droeschl 5551: <input type="hidden" name="importdetail"
5552: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5553: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5554: $help{'Syllabus'}
5555: </form>
5556: SNSFORM
5557:
5558: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5559: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5560: <input type="hidden" name="active" value="ff" />
1.508 raeburn 5561: $pathitem
1.329 droeschl 5562: <input type="hidden" name="importdetail"
5563: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5564: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5565: $help{'My Personal Information Page'}
1.329 droeschl 5566: </form>
5567: SNAMFORM
5568:
1.534 raeburn 5569: my $supwebpage;
5570: if ($folder =~ /^supplemental_?(\d*)$/) {
5571: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5572: if ($1) {
5573: $supwebpage .= $1;
5574: } else {
5575: $supwebpage .= 'default';
5576: }
5577: $supwebpage .= '/new.html';
5578: }
5579: my $supwebpageform =(<<SWEBFORM);
5580: <form action="/adm/coursedocs" method="post" name="supwebpage">
5581: <input type="hidden" name="active" value="cc" />
5582: $pathitem
5583: <input type="hidden" name="importdetail" value="$supwebpage" />
5584: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 5585: $help{'Web_Page'}
1.534 raeburn 5586: </form>
5587: SWEBFORM
5588:
1.333 muellerd 5589:
1.383 tempelho 5590: my @specialdocs = (
1.417 droeschl 5591: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
5592: =>$supnewsylform},
5593: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
5594: =>$supnewaboutmeform},
1.534 raeburn 5595: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5596:
1.383 tempelho 5597: );
1.417 droeschl 5598: my @supimportdoc = (
1.515 raeburn 5599: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.501 raeburn 5600: =>$supextform},
5601: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5602: =>$supupdocform},
5603: );
5604:
5605: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5606: my %suporderhash = (
1.390 tempelho 5607: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 5608: 'ee' => ['Upload',$supupdocform],
5609: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5610: );
1.443 www 5611: if ($supplementalflag) {
1.458 raeburn 5612: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5613: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 5614: if ($error) {
5615: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 5616: } else {
5617: if ($suppchanges) {
5618: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5619: my @ids=&Apache::lonnet::current_machine_ids();
5620: foreach my $server (keys(%servers)) {
5621: next if (grep(/^\Q$server\E$/,@ids));
5622: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 5623: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5624: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 5625: }
5626: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5627: undef($suppchanges);
5628: }
5629: }
1.393 raeburn 5630: }
1.443 www 5631: } elsif ($supplementalflag) {
1.458 raeburn 5632: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5633: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5634: if ($error) {
5635: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5636: }
1.393 raeburn 5637: }
1.389 tempelho 5638:
1.510 raeburn 5639: if ($needs_end) {
5640: $r->print(&endContentScreen());
5641: }
1.383 tempelho 5642:
1.329 droeschl 5643: if ($allowed) {
5644: $r->print('
5645: <form method="post" name="extimport" action="/adm/coursedocs">
5646: <input type="hidden" name="title" />
5647: <input type="hidden" name="url" />
5648: <input type="hidden" name="useform" />
5649: <input type="hidden" name="residx" />
5650: </form>');
5651: }
1.484 raeburn 5652: } elsif ($showdoc) {
1.329 droeschl 5653: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5654: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 5655: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5656: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5657: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5658: }
5659: }
5660: $r->print(&Apache::loncommon::end_page());
5661: return OK;
1.364 bisitz 5662: }
1.329 droeschl 5663:
1.440 raeburn 5664: sub embedded_form_elems {
5665: my ($phase,$primaryurl,$newidx) = @_;
5666: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5667: return <<STATE;
5668: <input type="hidden" name="folderpath" value="$folderpath" />
5669: <input type="hidden" name="cmd" value="upload_embedded" />
5670: <input type="hidden" name="newidx" value="$newidx" />
5671: <input type="hidden" name="phase" value="$phase" />
5672: <input type="hidden" name="primaryurl" value="$primaryurl" />
5673: STATE
5674: }
5675:
5676: sub embedded_destination {
5677: my $folder=$env{'form.folder'};
5678: my $destination = 'docs/';
5679: if ($folder =~ /^supplemental/) {
5680: $destination = 'supplemental/';
5681: }
5682: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5683: $destination .= 'default/';
5684: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5685: $destination .= $2.'/';
5686: }
5687: $destination .= $env{'form.newidx'};
5688: my $dir_root = '/userfiles';
5689: return ($destination,$dir_root);
5690: }
5691:
5692: sub return_to_editor {
5693: my $actionurl = '/adm/coursedocs';
5694: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5695: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5696: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5697: '</a></p>';
5698: }
5699:
1.476 raeburn 5700: sub decompression_info {
5701: my ($destination,$dir_root) = &embedded_destination();
5702: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5703: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5704: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5705: my $container='sequence';
1.480 raeburn 5706: my ($pathitem,$hiddenelem);
1.583 raeburn 5707: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 5708: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5709: $container='page';
5710: }
1.480 raeburn 5711: unshift(@hiddens,$pathitem);
5712: foreach my $item (@hiddens) {
5713: if ($env{'form.'.$item}) {
5714: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 5715: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 5716: }
1.477 raeburn 5717: }
1.476 raeburn 5718: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5719: $hiddenelem);
5720: }
5721:
5722: sub decompression_phase_one {
5723: my ($dir,$file,$warning,$error,$output);
5724: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5725: &decompression_info();
1.490 raeburn 5726: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5727: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5728: } else {
5729: my $file = $1;
1.481 raeburn 5730: $output =
5731: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5732: $destination,$dir_root,
5733: $hiddenelem);
5734: if ($env{'form.autoextract_camtasia'}) {
5735: $output .= &remove_archive($docudom,$docuname,$container);
5736: }
1.476 raeburn 5737: }
5738: if ($error) {
5739: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5740: $error.'</p>'."\n";
5741: }
5742: if ($warning) {
5743: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5744: }
5745: return $output;
5746: }
5747:
5748: sub decompression_phase_two {
5749: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5750: &decompression_info();
1.481 raeburn 5751: my $output;
1.480 raeburn 5752: if ($env{'form.archivedelete'}) {
1.481 raeburn 5753: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5754: }
5755: $output .=
1.481 raeburn 5756: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5757: $destination,$dir_root,$hiddenelem);
5758: return $output;
5759: }
5760:
1.480 raeburn 5761: sub remove_archive {
5762: my ($docudom,$docuname,$container) = @_;
5763: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5764: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5765: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5766: if ($fatal) {
5767: if ($container eq 'page') {
5768: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5769: } else {
5770: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5771: }
1.583 raeburn 5772: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5773: } else {
5774: my $currcmd = $env{'form.cmd'};
5775: my $position = $env{'form.position'};
1.583 raeburn 5776: my $archiveidx = $position;
1.563 raeburn 5777: if ($position > 0) {
1.583 raeburn 5778: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
5779: $archiveidx = $position-1;
5780: }
5781: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 5782: my ($title,$url,@rrest) =
1.583 raeburn 5783: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
5784: if ($url eq $env{'form.archiveurl'}) {
5785: if (&handle_edit_cmd($docuname,$docudom)) {
5786: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5787: if ($fatal) {
5788: if ($container eq 'page') {
5789: $delwarning = &mt('An error occurred updating the contents of the current page.');
5790: } else {
5791: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5792: }
1.480 raeburn 5793: } else {
1.583 raeburn 5794: $delresult = &mt('Archive file removed.');
1.480 raeburn 5795: }
5796: }
1.583 raeburn 5797: } else {
5798: $delwarning .= &mt('Archive file had unexpected item number in folder.').
5799: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5800: }
5801: }
5802: $env{'form.cmd'} = $currcmd;
5803: }
5804: if ($delwarning) {
5805: $output = '<p class="LC_warning">'.
5806: $delwarning.
5807: '</p>';
5808: }
5809: if ($delresult) {
5810: $output .= '<p class="LC_info">'.
5811: $delresult.
5812: '</p>';
5813: }
1.481 raeburn 5814: return $output;
1.480 raeburn 5815: }
5816:
1.484 raeburn 5817: sub generate_admin_menu {
5818: my ($crstype) = @_;
5819: my $lc_crstype = lc($crstype);
5820: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 5821: my %lt= ( # do not translate here
1.484 raeburn 5822: 'vc' => 'Verify Content',
5823: 'cv' => 'Check/Set Resource Versions',
5824: 'ls' => 'List Resource Identifiers',
5825: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 5826: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 5827: );
1.484 raeburn 5828: my ($candump,$dumpurl);
5829: if ($home + $other > 0) {
5830: $candump = 'F';
5831: if ($home) {
5832: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5833: } else {
5834: my @hosts;
5835: foreach my $aurole (keys(%outhash)) {
5836: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5837: push(@hosts,$outhash{$aurole});
1.538 raeburn 5838: }
1.484 raeburn 5839: }
5840: if (@hosts == 1) {
5841: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5842: '&role='.
5843: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5844: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5845: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5846: } else {
5847: $dumpurl = "javascript:choose_switchserver_window()";
5848: }
5849: }
5850: }
5851: my @menu=
5852: ({ categorytitle=>'Administration',
5853: items =>[
5854: { linktext => $lt{'vc'},
5855: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
5856: permission => 'F',
1.571 raeburn 5857: help => 'Docs_Verify_Content',
1.484 raeburn 5858: icon => 'verify.png',
5859: linktitle => 'Verify contents can be retrieved/rendered',
5860: },
5861: { linktext => $lt{'cv'},
5862: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
5863: permission => 'F',
1.571 raeburn 5864: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 5865: icon => 'resversion.png',
5866: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
5867: },
5868: { linktext => $lt{'ls'},
5869: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
5870: permission => 'F',
5871: #help => '',
5872: icon => 'symbs.png',
5873: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
5874: },
5875: ]
5876: },
5877: { categorytitle=>'Export',
5878: items =>[
5879: { linktext => $lt{'imse'},
5880: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
5881: permission => 'F',
5882: help => 'Docs_Export_Course_Docs',
5883: icon => 'imsexport.png',
5884: linktitle => $lt{'imse'},
5885: },
5886: { linktext => $lt{'dcd'},
5887: url => $dumpurl,
5888: permission => $candump,
1.571 raeburn 5889: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 5890: icon => 'dump.png',
5891: linktitle => $lt{'dcd'},
5892: },
5893: ]
5894: });
5895: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
5896: '<input type="hidden" id="dummy" />'."\n".
5897: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
5898: '</form>';
1.329 droeschl 5899: }
5900:
5901: sub generate_edit_table {
1.538 raeburn 5902: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
5903: $need_save,$copyfolder) = @_;
1.406 raeburn 5904: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 5905: my %orderhash = %{$orderhash_ref};
1.344 bisitz 5906: my $form;
1.371 tempelho 5907: my $activetab;
5908: my $active;
1.570 raeburn 5909: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 5910: $activetab = $env{'form.active'};
5911: }
1.472 raeburn 5912: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 5913: my $backtext = &mt('Exit Editor');
1.458 raeburn 5914: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 5915: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
5916: '<li class="goback">'.
1.546 raeburn 5917: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 5918: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
5919: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
5920: '<li>'.
5921: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
5922: &mt('Undo Delete').'</a></li>'."\n";
5923: if ($env{'form.docslog'}) {
5924: $form .= '<li class="active">';
5925: } else {
5926: $form .= '<li>';
5927: }
5928: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
5929: &mt('History').'</a></li>'."\n";
5930: if ($env{'form.docslog'}) {
5931: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
5932: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 5933: }
1.458 raeburn 5934: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 5935: if($name ne '00'){
1.371 tempelho 5936: if($activetab eq '' || $activetab ne $name){
5937: $active = '';
5938: }elsif($activetab eq $name){
5939: $active = 'class="active"';
5940: }
1.458 raeburn 5941: $form .= '<li style="float:right" '.$active
1.484 raeburn 5942: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
1.390 tempelho 5943: } else {
1.570 raeburn 5944: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 5945:
5946: }
1.329 droeschl 5947: }
1.484 raeburn 5948: $form .= '</ul>'."\n";
5949: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 5950:
5951: if ($to_show ne '') {
1.538 raeburn 5952: my $saveform;
5953: if ($need_save) {
5954: my $button = &mt('Make changes');
5955: my $path;
5956: if ($env{'form.folderpath'}) {
5957: $path =
5958: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5959: }
5960: $saveform = <<"END";
5961: <div id="multisave" style="display:none; clear:both;" >
5962: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
5963: <input type="hidden" name="folderpath" value="$path" />
5964: <input type="hidden" name="symb" value="$env{'form.symb'}" />
5965: <input type="hidden" name="allhiddenresource" value="" />
5966: <input type="hidden" name="allencrypturl" value="" />
5967: <input type="hidden" name="allrandompick" value="" />
5968: <input type="hidden" name="allrandomorder" value="" />
5969: <input type="hidden" name="changeparms" value="" />
5970: <input type="hidden" name="multiremove" value="" />
5971: <input type="hidden" name="multicut" value="" />
5972: <input type="hidden" name="multicopy" value="" />
5973: <input type="hidden" name="multichange" value="" />
5974: <input type="hidden" name="copyfolder" value="$copyfolder" />
5975: <input type="submit" name="savemultiples" value="$button" />
5976: </form>
5977: </div>
5978: END
5979: }
5980: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 5981: }
1.363 ehlerst 5982: foreach my $field (keys(%orderhash)){
1.390 tempelho 5983: if($field ne '00'){
1.422 onken 5984: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 5985: $active = 'style="display: none;float:left"';
1.422 onken 5986: }elsif($activetab eq $field){
1.458 raeburn 5987: $active = 'style="display:block;float:left"';
1.422 onken 5988: }
5989: $form .= '<div id="'.$field.$tid.'"'
5990: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 5991: .'</div>'."\n";
1.363 ehlerst 5992: }
5993: }
1.484 raeburn 5994: unless ($env{'form.docslog'}) {
5995: $form .= '</div></div>'."\n";
5996: }
1.329 droeschl 5997: return $form;
5998: }
5999:
6000: sub editing_js {
1.472 raeburn 6001: my ($udom,$uname,$supplementalflag) = @_;
1.594 damieng 6002: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6003: p_mnf => 'Name of New Folder',
6004: t_mnf => 'New Folder',
6005: p_mnp => 'Name of New Page',
6006: t_mnp => 'New Page',
1.451 www 6007: p_mxu => 'Title for the External Score',
1.349 biermanm 6008: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6009: p_msb => 'Title for the Problem',
6010: p_mdb => 'Title for the Drop Box',
1.336 schafran 6011: p_mbb => 'Title for the Discussion Board',
1.534 raeburn 6012: p_mwp => 'Title for Web Page',
1.348 weissno 6013: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6014: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6015: p_mab_alrt1 => 'Not a valid user:domain',
6016: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6017: p_chn => 'New Title',
6018: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
6019: p_rmr2a => 'Remove[_99]',
6020: p_rmr2b => '?[_99]',
1.542 raeburn 6021: p_rmr3a => 'Remove those [_2]',
6022: p_rmr3b => 'items?[_2]',
1.329 droeschl 6023: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6024: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
6025: p_ctr2a => 'Cut[_98]',
1.478 raeburn 6026: p_ctr2b => '?[_98]',
1.542 raeburn 6027: p_ctr3a => 'Cut those[_2]',
6028: p_ctr3b => 'items?[_2]',
1.478 raeburn 6029: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6030: imsfile => 'You must choose an IMS package for import',
6031: imscms => 'You must select which Course Management System was the source of the IMS package',
6032: invurl => 'Invalid URL',
6033: titbl => 'Title is blank',
1.538 raeburn 6034: more => '(More ...)',
6035: less => '(Less ...)',
1.543 raeburn 6036: noor => 'No actions selected or changes to settings specified.',
6037: noch => 'No changes to settings specified.',
6038: noac => 'No actions selected.',
1.329 droeschl 6039: );
1.594 damieng 6040: &js_escape(\%js_lt);
1.433 raeburn 6041: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6042: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6043: my $main_container_page;
1.519 raeburn 6044: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6045: $main_container_page = 1;
1.434 raeburn 6046: }
1.538 raeburn 6047: my $toplevelmain =
1.548 raeburn 6048: &escape(&mt('Main Content').':::::');
1.446 www 6049: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6050:
1.525 raeburn 6051: my $backtourl;
1.530 raeburn 6052: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6053: my $caller = $1;
1.525 raeburn 6054: if ($caller =~ /^supplemental/) {
6055: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6056: } else {
6057: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6058: $res = &Apache::lonnet::clutter($res);
6059: if (&Apache::lonnet::is_on_map($res)) {
6060: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
6061: &HTML::Entities::encode($caller,'<>&"');
1.590 raeburn 6062: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6063: } else {
6064: $backtourl = '/adm/navmaps';
1.525 raeburn 6065: }
6066: }
6067: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6068: $backtourl = '/adm/menu';
6069: } elsif ($supplementalflag) {
1.472 raeburn 6070: $backtourl = '/adm/supplemental';
1.525 raeburn 6071: } else {
6072: $backtourl = '/adm/navmaps';
1.472 raeburn 6073: }
6074:
1.519 raeburn 6075: my $fieldsets = "'ext','doc'";
6076: unless ($main_container_page) {
6077: $fieldsets .=",'ims'";
6078: }
1.501 raeburn 6079: if ($supplementalflag) {
6080: $fieldsets = "'suppext','suppdoc'";
6081: }
6082:
1.329 droeschl 6083: return <<ENDNEWSCRIPT;
6084: function makenewfolder(targetform,folderseq) {
1.594 damieng 6085: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6086: if (foldername) {
6087: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6088: targetform.submit();
6089: }
6090: }
6091:
6092: function makenewpage(targetform,folderseq) {
1.594 damieng 6093: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6094: if (pagename) {
6095: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6096: targetform.submit();
6097: }
6098: }
6099:
6100: function makeexamupload() {
1.594 damieng 6101: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6102: if (title) {
1.329 droeschl 6103: this.document.forms.newexamupload.importdetail.value=
6104: escape(title)+'=/res/lib/templates/examupload.problem';
6105: this.document.forms.newexamupload.submit();
6106: }
6107: }
6108:
6109: function makesmppage() {
1.594 damieng 6110: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6111: if (title) {
1.329 droeschl 6112: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6113: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6114: this.document.forms.newsmppg.submit();
6115: }
6116: }
6117:
1.534 raeburn 6118: function makewebpage(type) {
1.594 damieng 6119: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6120: var formname;
6121: if (type == 'supp') {
6122: formname = this.document.forms.supwebpage;
6123: } else {
6124: formname = this.document.forms.newwebpage;
6125: }
6126: if (title) {
6127: var webpage = formname.importdetail.value;
6128: formname.importdetail.value = escape(title)+'='+webpage;
6129: formname.submit();
6130: }
6131: }
6132:
1.329 droeschl 6133: function makesmpproblem() {
1.594 damieng 6134: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6135: if (title) {
1.329 droeschl 6136: this.document.forms.newsmpproblem.importdetail.value=
6137: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6138: this.document.forms.newsmpproblem.submit();
6139: }
6140: }
6141:
6142: function makedropbox() {
1.594 damieng 6143: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6144: if (title) {
1.329 droeschl 6145: this.document.forms.newdropbox.importdetail.value=
6146: escape(title)+'=/res/lib/templates/DropBox.problem';
6147: this.document.forms.newdropbox.submit();
6148: }
6149: }
6150:
6151: function makebulboard() {
1.594 damieng 6152: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6153: if (title) {
6154: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6155: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6156: this.document.forms.newbul.submit();
6157: }
6158: }
6159:
6160: function makeabout() {
1.594 damieng 6161: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6162: if (user) {
6163: var comp=new Array();
6164: comp=user.split(':');
6165: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6166: if ((comp[0]) && (comp[1])) {
6167: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 6168: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 6169: this.document.forms.newaboutsomeone.submit();
6170: } else {
1.594 damieng 6171: alert("$js_lt{'p_mab_alrt1'}");
1.329 droeschl 6172: }
1.335 ehlerst 6173: } else {
1.594 damieng 6174: alert("$js_lt{'p_mab_alrt2'}");
1.335 ehlerst 6175: }
6176: }
1.329 droeschl 6177: }
6178:
1.501 raeburn 6179: function toggleUpload(caller) {
6180: var blocks = Array($fieldsets);
6181: for (var i=0; i<blocks.length; i++) {
6182: var disp = 'none';
6183: if (caller == blocks[i]) {
6184: var curr = document.getElementById('upload'+caller+'form').style.display;
6185: if (curr == 'none') {
6186: disp='block';
6187: }
6188: }
6189: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6190: }
1.502 raeburn 6191: resize_scrollbox('contentscroll','1','1');
6192: return;
6193: }
6194:
1.514 raeburn 6195: function toggleMap(caller) {
1.502 raeburn 6196: var disp = 'none';
1.510 raeburn 6197: if (document.getElementById('importmapform')) {
1.514 raeburn 6198: if (caller == 'map') {
6199: var curr = document.getElementById('importmapform').style.display;
6200: if (curr == 'none') {
6201: disp='block';
6202: }
1.510 raeburn 6203: }
6204: document.getElementById('importmapform').style.display=disp;
6205: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 6206: }
1.501 raeburn 6207: return;
1.329 droeschl 6208: }
6209:
1.501 raeburn 6210: function makeims(imsform) {
6211: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 6212: alert("$js_lt{'imsfile'}");
1.501 raeburn 6213: return;
6214: }
6215: if (imsform.source.selectedIndex == 0) {
1.594 damieng 6216: alert("$js_lt{'imscms'}");
1.501 raeburn 6217: return;
6218: }
6219: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6220: imsform.submit();
6221: }
6222:
1.519 raeburn 6223: function changename(folderpath,index,oldtitle) {
1.594 damieng 6224: var title=prompt('$js_lt{"p_chn"}',oldtitle);
1.335 ehlerst 6225: if (title) {
1.538 raeburn 6226: this.document.forms.renameform.markcopy.value='';
1.335 ehlerst 6227: this.document.forms.renameform.title.value=title;
6228: this.document.forms.renameform.cmd.value='rename_'+index;
1.519 raeburn 6229: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 6230: this.document.forms.renameform.submit();
6231: }
1.329 droeschl 6232: }
6233:
1.478 raeburn 6234: function updatePick(targetform,index,caller) {
1.537 raeburn 6235: var pickitem;
6236: var picknumitem;
6237: var picknumtext;
6238: if (index == 'all') {
6239: pickitem = document.getElementById('randompickall');
6240: picknumitem = document.getElementById('rpicknumall');
6241: picknumtext = document.getElementById('rpicktextall');
6242: } else {
6243: pickitem = document.getElementById('randompick_'+index);
6244: picknumitem = document.getElementById('rpicknum_'+index);
6245: picknumtext = document.getElementById('randompicknum_'+index);
6246: }
1.478 raeburn 6247: if (pickitem.checked) {
1.594 damieng 6248: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6249: if (picknum == '' || picknum == null) {
6250: if (caller == 'check') {
6251: pickitem.checked=false;
1.537 raeburn 6252: if (index == 'all') {
6253: picknumtext.innerHTML = '';
6254: if (caller == 'link') {
6255: propagateState(targetform,'rpicknum');
6256: }
6257: } else {
1.538 raeburn 6258: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6259: }
1.478 raeburn 6260: }
6261: } else {
6262: picknum.toString();
6263: var regexdigit=/^\\d+\$/;
6264: if (regexdigit.test(picknum)) {
6265: picknumitem.value = picknum;
1.537 raeburn 6266: if (index == 'all') {
1.538 raeburn 6267: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 6268: if (caller == 'link') {
6269: propagateState(targetform,'rpicknum');
6270: }
6271: } else {
6272: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 6273: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6274: }
1.478 raeburn 6275: } else {
6276: if (caller == 'check') {
1.537 raeburn 6277: if (index == 'all') {
6278: picknumtext.innerHTML = '';
6279: if (caller == 'link') {
6280: propagateState(targetform,'rpicknum');
6281: }
6282: } else {
6283: pickitem.checked=false;
1.538 raeburn 6284: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6285: }
1.478 raeburn 6286: }
6287: return;
6288: }
6289: }
6290: } else {
1.537 raeburn 6291: picknumitem.value = '';
6292: picknumtext.innerHTML = '';
6293: if (index == 'all') {
6294: if (caller == 'link') {
6295: propagateState(targetform,'rpicknum');
6296: }
6297: } else {
1.538 raeburn 6298: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6299: }
6300: }
6301: }
6302:
6303: function propagateState(form,param) {
6304: if (document.getElementById(param+'all')) {
6305: var setcheck = 0;
6306: var rpick = 0;
6307: if (param == 'rpicknum') {
6308: if (document.getElementById('randompickall')) {
6309: if (document.getElementById('randompickall').checked) {
6310: if (document.getElementById('rpicknumall')) {
6311: rpick = document.getElementById('rpicknumall').value;
6312: }
6313: }
6314: }
6315: } else {
6316: if (document.getElementById(param+'all').checked) {
6317: setcheck = 1;
6318: }
6319: }
1.538 raeburn 6320: var allidxlist;
6321: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6322: if (document.getElementById('all'+param+'idx')) {
6323: allidxlist = document.getElementById('all'+param+'idx').value;
6324: }
6325: var actions = new Array ('remove','cut','copy');
6326: for (var i=0; i<actions.length; i++) {
6327: if (actions[i] != param) {
6328: if (document.getElementById(actions[i]+'all')) {
6329: document.getElementById(actions[i]+'all').checked = false;
6330: }
6331: }
6332: }
6333: }
1.537 raeburn 6334: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 6335: allidxlist = form.allidx.value;
6336: }
6337: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6338: allidxlist = form.allmapidx.value;
6339: }
6340: if ((allidxlist != '') && (allidxlist != null)) {
6341: var allidxs = allidxlist.split(',');
6342: if (allidxs.length > 1) {
6343: for (var i=0; i<allidxs.length; i++) {
6344: if (document.getElementById(param+'_'+allidxs[i])) {
6345: if (param == 'rpicknum') {
6346: if (document.getElementById('randompick_'+allidxs[i])) {
6347: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6348: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6349: if (rpick > 0) {
6350: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6351: } else {
6352: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6353: }
6354: }
6355: }
6356: } else {
1.537 raeburn 6357: if (setcheck == 1) {
6358: document.getElementById(param+'_'+allidxs[i]).checked = true;
6359: } else {
6360: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 6361: if (param == 'randompick') {
6362: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6363: }
1.537 raeburn 6364: }
6365: }
6366: }
6367: }
1.538 raeburn 6368: if (setcheck == 1) {
6369: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6370: var actions = new Array('copy','cut','remove');
6371: for (var i=0; i<actions.length; i++) {
6372: var otheractions;
6373: var otheridxs;
6374: if (actions[i] === param) {
6375: continue;
6376: } else {
6377: if (document.getElementById('all'+actions[i]+'idx')) {
6378: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6379: otheridxs = otheractions.split(',');
6380: if (otheridxs.length > 1) {
6381: for (var j=0; j<otheridxs.length; j++) {
6382: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6383: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6384: }
1.537 raeburn 6385: }
6386: }
6387: }
1.538 raeburn 6388: }
6389: }
6390: }
6391: }
6392: }
6393: }
6394: }
6395: return;
6396: }
6397:
6398: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder) {
1.539 raeburn 6399: var dosettings;
6400: var doaction;
1.538 raeburn 6401: var control = document.togglemultsettings;
6402: if (context == 'actions') {
6403: control = document.togglemultactions;
1.539 raeburn 6404: doaction = 1;
6405: } else {
6406: dosettings = 1;
1.538 raeburn 6407: }
1.539 raeburn 6408: if (control) {
6409: if (control.showmultpick.length) {
6410: for (var i=0; i<control.showmultpick.length; i++) {
6411: if (control.showmultpick[i].checked) {
6412: if (control.showmultpick[i].value == 1) {
6413: if (context == 'settings') {
6414: dosettings = 0;
6415: } else {
6416: doaction = 0;
1.538 raeburn 6417: }
6418: }
6419: }
1.537 raeburn 6420: }
6421: }
1.539 raeburn 6422: }
6423: if (context == 'settings') {
6424: if (dosettings == 1) {
1.538 raeburn 6425: targetform.changeparms.value=param;
6426: targetform.submit();
6427: }
1.537 raeburn 6428: }
1.539 raeburn 6429: if (context == 'actions') {
6430: if (doaction == 1) {
6431: targetform.cmd.value=param+'_'+index;
6432: targetform.folderpath.value=folderpath;
6433: targetform.markcopy.value=idx+':'+param;
6434: targetform.copyfolder.value=folder+'.'+container;
6435: if (param == 'remove') {
1.594 damieng 6436: if (skip_confirm || confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
1.539 raeburn 6437: targetform.markcopy.value='';
6438: targetform.copyfolder.value='';
6439: targetform.submit();
6440: }
6441: }
6442: if (param == 'cut') {
1.594 damieng 6443: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
1.539 raeburn 6444: targetform.submit();
6445: return;
6446: }
6447: }
6448: if (param == 'copy') {
6449: targetform.submit();
6450: return;
6451: }
6452: targetform.markcopy.value='';
6453: targetform.copyfolder.value='';
6454: targetform.cmd.value='';
6455: targetform.folderpath.value='';
6456: return;
6457: } else {
6458: if (document.getElementById(param+'_'+idx)) {
6459: item = document.getElementById(param+'_'+idx);
6460: if (item.type == 'checkbox') {
6461: if (item.checked) {
6462: item.checked = false;
6463: } else {
6464: item.checked = true;
6465: singleCheck(item,idx,param);
6466: }
6467: }
6468: }
6469: }
6470: }
1.537 raeburn 6471: return;
6472: }
6473:
1.538 raeburn 6474: function singleCheck(caller,idx,action) {
6475: actions = new Array('cut','copy','remove');
6476: if (caller.checked) {
6477: for (var i=0; i<actions.length; i++) {
6478: if (actions[i] != action) {
6479: if (document.getElementById(actions[i]+'_'+idx)) {
6480: if (document.getElementById(actions[i]+'_'+idx).checked) {
6481: document.getElementById(actions[i]+'_'+idx).checked = false;
6482: }
1.537 raeburn 6483: }
6484: }
6485: }
1.478 raeburn 6486: }
1.537 raeburn 6487: return;
1.478 raeburn 6488: }
6489:
1.334 muellerd 6490: function unselectInactive(nav) {
1.335 ehlerst 6491: currentNav = document.getElementById(nav);
6492: currentLis = currentNav.getElementsByTagName('LI');
6493: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6494: if (currentLis[i].className == 'goback') {
6495: currentLis[i].className = 'goback';
6496: } else {
6497: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6498: currentLis[i].className = 'right';
1.472 raeburn 6499: } else {
1.374 tempelho 6500: currentLis[i].className = 'i';
1.472 raeburn 6501: }
6502: }
1.335 ehlerst 6503: }
1.332 tempelho 6504: }
6505:
1.334 muellerd 6506: function hideAll(current, nav, data) {
1.335 ehlerst 6507: unselectInactive(nav);
1.570 raeburn 6508: if (current) {
6509: if (current.className == 'right'){
6510: current.className = 'right active'
6511: } else {
6512: current.className = 'active';
6513: }
1.374 tempelho 6514: }
1.335 ehlerst 6515: currentData = document.getElementById(data);
6516: currentDivs = currentData.getElementsByTagName('DIV');
6517: for (i = 0; i < currentDivs.length; i++) {
6518: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6519: currentDivs[i].style.display = 'none';
1.330 tempelho 6520: }
6521: }
1.335 ehlerst 6522: }
1.330 tempelho 6523:
1.374 tempelho 6524: function openTabs(pageId) {
6525: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6526: if(tabnav.length > 2 ){
1.389 tempelho 6527: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6528: currentLis = currentNav.getElementsByTagName('LI');
6529: for(i = 0; i< currentLis.length; i++){
6530: if(currentLis[i].className == 'active') {
1.375 tempelho 6531: funcString = currentLis[i].onclick.toString();
6532: tab = funcString.split('"');
1.420 onken 6533: if(tab.length < 2) {
6534: tab = funcString.split("'");
6535: }
1.375 tempelho 6536: currentData = document.getElementById(tab[1]);
6537: currentData.style.display = 'block';
1.374 tempelho 6538: }
6539: }
6540: }
6541: }
6542:
1.334 muellerd 6543: function showPage(current, pageId, nav, data) {
1.570 raeburn 6544: currstate = current.className;
1.334 muellerd 6545: hideAll(current, nav, data);
1.375 tempelho 6546: openTabs(pageId);
1.334 muellerd 6547: unselectInactive(nav);
1.570 raeburn 6548: if ((currstate == 'active') || (currstate == 'right active')) {
6549: if (currstate == 'active') {
6550: current.className = '';
6551: } else {
6552: current.className = 'right';
6553: }
6554: activeTab = '';
6555: toggleUpload();
6556: toggleMap();
6557: resize_scrollbox('contentscroll','1','0');
6558: return;
6559: } else {
6560: current.className = 'active';
6561: }
1.330 tempelho 6562: currentData = document.getElementById(pageId);
6563: currentData.style.display = 'block';
1.458 raeburn 6564: activeTab = pageId;
1.501 raeburn 6565: toggleUpload();
1.503 raeburn 6566: toggleMap();
1.433 raeburn 6567: if (nav == 'mainnav') {
6568: var storedpath = "$docs_folderpath";
1.434 raeburn 6569: var storedpage = "$main_container_page";
1.433 raeburn 6570: var reg = new RegExp("^supplemental");
6571: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6572: if (storedpage == 1) {
6573: document.simpleedit.folderpath.value = '';
6574: document.uploaddocument.folderpath.value = '';
6575: } else {
6576: if (reg.test(storedpath)) {
6577: document.simpleedit.folderpath.value = '$toplevelmain';
6578: document.uploaddocument.folderpath.value = '$toplevelmain';
6579: document.newext.folderpath.value = '$toplevelmain';
6580: } else {
6581: document.simpleedit.folderpath.value = storedpath;
6582: document.uploaddocument.folderpath.value = storedpath;
6583: document.newext.folderpath.value = storedpath;
6584: }
1.433 raeburn 6585: }
6586: } else {
1.434 raeburn 6587: if (reg.test(storedpath)) {
6588: document.simpleedit.folderpath.value = storedpath;
6589: document.supuploaddocument.folderpath.value = storedpath;
6590: document.supnewext.folderpath.value = storedpath;
6591: } else {
1.433 raeburn 6592: document.simpleedit.folderpath.value = '$toplevelsupp';
6593: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6594: document.supnewext.folderpath.value = '$toplevelsupp';
6595: }
6596: }
6597: }
1.485 raeburn 6598: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6599: return false;
6600: }
1.329 droeschl 6601:
1.472 raeburn 6602: function toContents(jumpto) {
6603: var newurl = '$backtourl';
1.525 raeburn 6604: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6605: newurl = newurl+'?postdata='+jumpto;
6606: }
6607: location.href=newurl;
6608: }
6609:
1.538 raeburn 6610: function togglePick(caller,value) {
6611: var disp = 'none';
6612: if (document.getElementById('multi'+caller)) {
6613: var curr = document.getElementById('multi'+caller).style.display;
6614: if (value == 1) {
6615: disp='block';
6616: }
6617: if (curr == disp) {
6618: return;
6619: }
6620: document.getElementById('multi'+caller).style.display=disp;
6621: if (value == 1) {
1.594 damieng 6622: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 6623: } else {
6624: document.getElementById('more'+caller).innerHTML = '';
6625: }
6626: if (caller == 'actions') {
6627: setClass(value);
6628: setBoxes(value);
6629: }
6630: }
6631: var showButton = multiSettings();
6632: if (showButton != 1) {
6633: showButton = multiActions();
6634: }
6635: if (document.getElementById('multisave')) {
6636: if (showButton == 1) {
6637: document.getElementById('multisave').style.display='block';
6638: } else {
6639: document.getElementById('multisave').style.display='none';
6640: }
6641: }
6642: resize_scrollbox('contentscroll','1','1');
6643: return;
6644: }
6645:
6646: function toggleCheckUncheck(caller,more) {
6647: if (more == 1) {
1.594 damieng 6648: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 6649: document.getElementById('allfields'+caller).style.display='block';
6650: } else {
1.594 damieng 6651: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 6652: document.getElementById('allfields'+caller).style.display='none';
6653: }
6654: resize_scrollbox('contentscroll','1','1');
6655: }
6656:
6657: function multiSettings() {
6658: var inuse = 0;
6659: var settingsform = document.togglemultsettings;
6660: if (settingsform.showmultpick.length > 1) {
6661: for (var i=0; i<settingsform.showmultpick.length; i++) {
6662: if (settingsform.showmultpick[i].checked) {
6663: if (settingsform.showmultpick[i].value == 1) {
6664: inuse = 1;
6665: }
6666: }
6667: }
6668: }
6669: return inuse;
6670: }
6671:
6672: function multiActions() {
6673: var inuse = 0;
6674: var actionsform = document.togglemultactions;
6675: if (actionsform.showmultpick.length > 1) {
6676: for (var i=0; i<actionsform.showmultpick.length; i++) {
6677: if (actionsform.showmultpick[i].checked) {
6678: if (actionsform.showmultpick[i].value == 1) {
6679: inuse = 1;
6680: }
6681: }
6682: }
6683: }
6684: return inuse;
6685: }
6686:
6687: function checkSubmits() {
6688: var numchanges = 0;
6689: var form = document.saveactions;
6690: var doactions = multiActions();
1.542 raeburn 6691: var cutwarnings = 0;
6692: var remwarnings = 0;
1.538 raeburn 6693: if (doactions == 1) {
6694: var remidxlist = document.cumulativeactions.allremoveidx.value;
6695: if ((remidxlist != '') && (remidxlist != null)) {
6696: var remidxs = remidxlist.split(',');
6697: for (var i=0; i<remidxs.length; i++) {
6698: if (document.getElementById('remove_'+remidxs[i])) {
6699: if (document.getElementById('remove_'+remidxs[i]).checked) {
6700: form.multiremove.value += remidxs[i]+',';
6701: numchanges ++;
1.542 raeburn 6702: if (document.getElementById('skip_remove_'+remidxs[i])) {
6703: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6704: remwarnings ++;
6705: }
6706: }
1.537 raeburn 6707: }
6708: }
1.538 raeburn 6709: }
6710: }
6711: var cutidxlist = document.cumulativeactions.allcutidx.value;
6712: if ((cutidxlist != '') && (cutidxlist != null)) {
6713: var cutidxs = cutidxlist.split(',');
6714: for (var i=0; i<cutidxs.length; i++) {
6715: if (document.getElementById('cut_'+cutidxs[i])) {
6716: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6717: form.multicut.value += cutidxs[i]+',';
6718: numchanges ++;
1.542 raeburn 6719: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6720: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6721: cutwarnings ++;
6722: }
6723: }
1.537 raeburn 6724: }
6725: }
6726: }
6727: }
1.538 raeburn 6728: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6729: if ((copyidxlist != '') && (copyidxlist != null)) {
6730: var copyidxs = copyidxlist.split(',');
6731: for (var i=0; i<copyidxs.length; i++) {
6732: if (document.getElementById('copy_'+copyidxs[i])) {
6733: if (document.getElementById('copy_'+copyidxs[i]).checked) {
6734: form.multicopy.value += copyidxs[i]+',';
6735: numchanges ++;
6736: }
6737: }
6738: }
6739: }
6740: if (numchanges > 0) {
6741: form.multichange.value = numchanges;
6742: }
1.537 raeburn 6743: }
1.538 raeburn 6744: var dosettings = multiSettings();
1.543 raeburn 6745: var haschanges = 0;
1.538 raeburn 6746: if (dosettings == 1) {
6747: form.allencrypturl.value = '';
6748: form.allhiddenresource.value = '';
1.543 raeburn 6749: form.changeparms.value = 'all';
6750: var patt=new RegExp(",\$");
1.538 raeburn 6751: var allidxlist = document.cumulativesettings.allidx.value;
6752: if ((allidxlist != '') && (allidxlist != null)) {
6753: var allidxs = allidxlist.split(',');
6754: if (allidxs.length > 1) {
6755: for (var i=0; i<allidxs.length; i++) {
6756: if (document.getElementById('hiddenresource_'+allidxs[i])) {
6757: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
6758: form.allhiddenresource.value += allidxs[i]+',';
6759: }
6760: }
6761: if (document.getElementById('encrypturl_'+allidxs[i])) {
6762: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
6763: form.allencrypturl.value += allidxs[i]+',';
6764: }
6765: }
6766: }
1.543 raeburn 6767: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
6768: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 6769: }
1.538 raeburn 6770: }
6771: form.allrandompick.value = '';
6772: form.allrandomorder.value = '';
6773: var allmapidxlist = document.cumulativesettings.allmapidx.value;
6774: if ((allmapidxlist != '') && (allmapidxlist != null)) {
6775: var allmapidxs = allmapidxlist.split(',');
6776: for (var i=0; i<allmapidxs.length; i++) {
6777: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
6778: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
6779: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
6780: if ((randompick.checked) && (rpicknum.value != '')) {
6781: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
6782: }
6783: if (randorder.checked) {
6784: form.allrandomorder.value += allmapidxs[i]+',';
6785: }
1.537 raeburn 6786: }
1.543 raeburn 6787: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
6788: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
6789: }
6790: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
6791: haschanges = 1;
6792: }
6793: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
6794: haschanges = 1;
6795: }
6796: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
6797: haschanges = 1;
6798: }
6799: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
6800: haschanges = 1;
1.537 raeburn 6801: }
6802: }
1.543 raeburn 6803: if (doactions == 1) {
1.542 raeburn 6804: if (numchanges > 0) {
6805: if ((cutwarnings > 0) || (remwarnings > 0)) {
6806: if (remwarnings > 0) {
1.594 damieng 6807: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 6808: return false;
6809: }
6810: }
6811: if (cutwarnings > 0) {
1.594 damieng 6812: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.542 raeburn 6813: return false;
6814: }
6815: }
6816: }
6817: form.submit();
6818: return true;
1.543 raeburn 6819: }
6820: }
6821: if (dosettings == 1) {
6822: if (haschanges == 1) {
1.542 raeburn 6823: form.submit();
6824: return true;
6825: }
1.543 raeburn 6826: }
6827: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 6828: alert("$js_lt{'noor'}");
1.543 raeburn 6829: } else {
6830: if (dosettings == 1) {
1.594 damieng 6831: alert("$js_lt{'noch'}");
1.543 raeburn 6832: } else {
1.594 damieng 6833: alert("$js_lt{'noac'}");
1.543 raeburn 6834: }
6835: }
1.538 raeburn 6836: return false;
6837: }
6838:
6839: function setClass(value) {
6840: var cutclass = 'LC_docs_cut';
6841: var copyclass = 'LC_docs_copy';
6842: var removeclass = 'LC_docs_remove';
6843: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
6844: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
6845: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
6846: var links = document.getElementsByTagName('a');
6847: for (var i=0; i<links.length; i++) {
6848: var classes = links[i].className;
6849: if (cutreg.test(classes)) {
6850: links[i].className = cutclass;
6851: if (value == 1) {
6852: links[i].className += " LC_menubuttons_link";
6853: }
6854: } else {
6855: if (copyreg.test(classes)) {
6856: links[i].className = copyclass;
6857: if (value == 1) {
6858: links[i].className += " LC_menubuttons_link";
6859: }
6860: } else {
6861: if (removereg.test(classes)) {
6862: links[i].className = removeclass;
6863: if (value == 1) {
6864: links[i].className += " LC_menubuttons_link";
6865: }
6866: }
6867: }
6868: }
6869: }
6870: return;
1.537 raeburn 6871: }
6872:
1.538 raeburn 6873: function setBoxes(value) {
6874: var remidxlist = document.cumulativeactions.allremoveidx.value;
6875: if ((remidxlist != '') && (remidxlist != null)) {
6876: var remidxs = remidxlist.split(',');
6877: for (var i=0; i<remidxs.length; i++) {
6878: if (document.getElementById('remove_'+remidxs[i])) {
6879: var item = document.getElementById('remove_'+remidxs[i]);
6880: if (value == 1) {
6881: item.className = 'LC_docs_remove';
6882: } else {
6883: item.className = 'LC_hidden';
6884: }
6885: }
6886: }
6887: }
6888: var cutidxlist = document.cumulativeactions.allcutidx.value;
6889: if ((cutidxlist != '') && (cutidxlist != null)) {
6890: var cutidxs = cutidxlist.split(',');
6891: for (var i=0; i<cutidxs.length; i++) {
6892: if (document.getElementById('cut_'+cutidxs[i])) {
6893: var item = document.getElementById('cut_'+cutidxs[i]);
6894: if (value == 1) {
6895: item.className = 'LC_docs_cut';
6896: } else {
6897: item.className = 'LC_hidden';
6898: }
6899: }
1.537 raeburn 6900: }
6901: }
1.538 raeburn 6902: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6903: if ((copyidxlist != '') && (copyidxlist != null)) {
6904: var copyidxs = copyidxlist.split(',');
6905: for (var i=0; i<copyidxs.length; i++) {
6906: if (document.getElementById('copy_'+copyidxs[i])) {
6907: var item = document.getElementById('copy_'+copyidxs[i]);
6908: if (value == 1) {
6909: item.className = 'LC_docs_copy';
6910: } else {
6911: item.className = 'LC_hidden';
6912: }
6913: }
1.537 raeburn 6914: }
6915: }
6916: return;
6917: }
6918:
1.329 droeschl 6919: ENDNEWSCRIPT
6920: }
1.457 raeburn 6921:
1.483 raeburn 6922: sub history_tab_js {
6923: return <<"ENDHIST";
6924: function toggleHistoryDisp(choice) {
6925: document.docslogform.docslog.value = choice;
6926: document.docslogform.submit();
6927: return;
6928: }
6929:
6930: ENDHIST
6931: }
6932:
1.484 raeburn 6933: sub inject_data_js {
6934: return <<ENDINJECT;
6935:
6936: function injectData(current, hiddenField, name, value) {
6937: currentElement = document.getElementById(hiddenField);
6938: currentElement.name = name;
6939: currentElement.value = value;
6940: current.submit();
6941: }
6942:
6943: ENDINJECT
6944: }
6945:
6946: sub dump_switchserver_js {
6947: my @hosts = @_;
1.594 damieng 6948: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 6949: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 6950: swit => 'Switch server?',
1.594 damieng 6951: );
6952: my %html_js_lt = &Apache::lonlocal::texthash(
6953: swit => 'Switch server?',
1.568 raeburn 6954: duco => 'Copying Content to Authoring Space',
1.484 raeburn 6955: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
6956: chos => 'Choose server',
6957: );
1.594 damieng 6958: &js_escape(\%js_lt);
6959: &html_escape(\%html_js_lt);
6960: &js_escape(\%html_js_lt);
1.484 raeburn 6961: my $role = $env{'request.role'};
6962: my $js = <<"ENDSWJS";
6963: <script type="text/javascript">
6964: function write_switchserver() {
6965: var server;
6966: if (document.setserver.posshosts.length > 0) {
6967: for (var i=0; i<document.setserver.posshosts.length; i++) {
6968: if (document.setserver.posshosts[i].checked) {
6969: server = document.setserver.posshosts[i].value;
6970: }
6971: }
6972: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
6973: }
6974: window.close();
6975: }
6976: </script>
6977:
6978: ENDSWJS
6979:
6980: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
6981: {'only_body' => 1,
6982: 'js_ready' => 1,});
6983: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
6984:
6985: my $hostpicker;
6986: my $count = 0;
6987: foreach my $host (sort(@hosts)) {
6988: my $checked;
6989: if ($count == 0) {
6990: $checked = ' checked="checked"';
6991: }
6992: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
6993: $host.'"'.$checked.' />'.$host.'</label> ';
6994: $count++;
6995: }
6996:
6997: return <<"ENDSWITCHJS";
6998:
6999: function dump_needs_switchserver(url) {
7000: if (url!='' && url!= null) {
1.594 damieng 7001: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7002: go(url);
7003: }
7004: }
7005: return;
7006: }
7007:
7008: function choose_switchserver_window() {
7009: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7010: newWindow.document.open();
7011: newWindow.document.writeln('$startpage');
1.594 damieng 7012: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7013: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7014: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7015: '<form name="setserver" method="post" action="" \\/>\\n'+
7016: '$hostpicker\\n'+
7017: '<br \\/><br \\/>\\n'+
1.594 damieng 7018: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7019: 'onclick="write_switchserver();" \\/>\\n'+
7020: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7021: newWindow.document.writeln('$endpage');
7022: newWindow.document.close();
7023: newWindow.focus();
7024: }
7025:
7026: ENDSWITCHJS
7027: }
7028:
7029: sub makedocslogform {
7030: my ($formelems,$docslog) = @_;
7031: return <<"LOGSFORM";
7032: <form action="/adm/coursedocs" method="post" name="docslogform">
7033: <input type="hidden" name="docslog" value="$docslog" />
7034: $formelems
7035: </form>
7036: LOGSFORM
7037: }
7038:
7039: sub makesimpleeditform {
7040: my ($formelems) = @_;
7041: return <<"SIMPFORM";
7042: <form name="simpleedit" method="post" action="/adm/coursedocs">
7043: <input type="hidden" name="importdetail" value="" />
7044: $formelems
7045: </form>
7046: SIMPFORM
7047: }
7048:
1.329 droeschl 7049: 1;
7050: __END__
7051:
7052:
7053: =head1 NAME
7054:
7055: Apache::londocs.pm
7056:
7057: =head1 SYNOPSIS
7058:
7059: This is part of the LearningOnline Network with CAPA project
7060: described at http://www.lon-capa.org.
7061:
7062: =head1 SUBROUTINES
7063:
7064: =over
7065:
7066: =item %help=()
7067:
7068: Available help topics
7069:
7070: =item mapread()
7071:
1.344 bisitz 7072: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7073: @order and @resources, determines status
7074: sets @order - pointer to resources in right order
7075: sets @resources - array with the resources with correct idx
7076:
7077: =item authorhosts()
7078:
7079: Return hash with valid author names
7080:
7081: =item clean()
7082:
7083: =item dumpcourse()
7084:
7085: Actually dump course
7086:
7087: =item group_import()
7088:
7089: Imports the given (name, url) resources into the course
7090: coursenum, coursedom, and folder must precede the list
7091:
7092: =item breadcrumbs()
7093:
7094: =item log_docs()
7095:
7096: =item docs_change_log()
7097:
7098: =item update_paste_buffer()
7099:
7100: =item print_paste_buffer()
7101:
7102: =item do_paste_from_buffer()
7103:
1.538 raeburn 7104: =item do_buffer_empty()
7105:
7106: =item clear_from_buffer()
7107:
1.492 raeburn 7108: =item get_newmap_url()
7109:
7110: =item dbcopy()
7111:
7112: =item uniqueness_check()
7113:
7114: =item contained_map_check()
7115:
7116: =item url_paste_fixups()
7117:
7118: =item apply_fixups()
7119:
7120: =item copy_dependencies()
7121:
1.329 droeschl 7122: =item update_parameter()
7123:
7124: =item handle_edit_cmd()
7125:
7126: =item editor()
7127:
7128: =item process_file_upload()
7129:
7130: =item process_secondary_uploads()
7131:
7132: =item is_supplemental_title()
7133:
7134: =item entryline()
7135:
7136: =item tiehash()
7137:
7138: =item untiehash()
7139:
7140: =item checkonthis()
7141:
7142: check on this
7143:
7144: =item verifycontent()
7145:
7146: Verify Content
7147:
7148: =item devalidateversioncache() & checkversions()
7149:
7150: Check Versions
7151:
7152: =item mark_hash_old()
7153:
7154: =item is_hash_old()
7155:
7156: =item changewarning()
7157:
7158: =item init_breadcrumbs()
7159:
7160: Breadcrumbs for special functions
7161:
1.484 raeburn 7162: =item create_list_elements()
7163:
7164: =item create_form_ul()
7165:
7166: =item startContentScreen()
7167:
7168: =item endContentScreen()
7169:
7170: =item supplemental_base()
7171:
7172: =item embedded_form_elems()
7173:
7174: =item embedded_destination()
7175:
7176: =item return_to_editor()
7177:
7178: =item decompression_info()
7179:
7180: =item decompression_phase_one()
7181:
7182: =item decompression_phase_two()
7183:
7184: =item remove_archive()
7185:
7186: =item generate_admin_menu()
7187:
7188: =item generate_edit_table()
7189:
7190: =item editing_js()
7191:
7192: =item history_tab_js()
7193:
7194: =item inject_data_js()
7195:
7196: =item dump_switchserver_js()
7197:
1.485 raeburn 7198: =item resize_scrollbox_js()
1.484 raeburn 7199:
7200: =item makedocslogform()
7201:
1.485 raeburn 7202: =item makesimpleeditform()
7203:
1.329 droeschl 7204: =back
7205:
7206: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>