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