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