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