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