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