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