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