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