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