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