Annotation of loncom/interface/londocs.pm, revision 1.603
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.603 ! raeburn 4: # $Id: londocs.pm,v 1.602 2016/05/08 18:39:27 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.488 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.578 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.557 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.492 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.557 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
142:
143:
144: sub dumpcourse {
145: my ($r) = @_;
1.408 raeburn 146: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 147: my ($starthash,$js);
148: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
149: $js = <<"ENDJS";
150: <script type="text/javascript">
151: // <![CDATA[
152:
153: function hide_searching() {
154: if (document.getElementById('searching')) {
155: document.getElementById('searching').style.display = 'none';
156: }
157: return;
158: }
159:
160: // ]]>
161: </script>
162: ENDJS
163: $starthash = {
164: add_entries => {'onload' => "hide_searching();"},
165: };
166: }
1.568 raeburn 167: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
168: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 169: $r->print(&startContentScreen('tools'));
1.329 droeschl 170: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 171: unless ($home) {
172: $r->print(&endContentScreen());
173: return '';
174: }
1.329 droeschl 175: my $origcrsid=$env{'request.course.id'};
176: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
177: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
178: # Do the dumping
1.484 raeburn 179: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
180: $r->print(&endContentScreen());
181: return '';
182: }
1.531 raeburn 183: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 184: $r->print('<h3>'.&mt('Copying Files').'</h3>');
185: my $title=$env{'form.authorfolder'};
186: $title=&clean($title);
1.567 raeburn 187: my ($navmap,$errormsg) =
188: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
189: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
190: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
191: my (%maps,%resources,%titles);
192: if (!ref($navmap)) {
193: $r->print($errormsg.
194: &endContentScreen());
195: return '';
196: } else {
197: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
198: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 199: }
1.567 raeburn 200: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
201: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
202: %newcontent,%has_simpleprobs);
203: foreach my $item (sort {$a <=> $b} (@todump)) {
204: my $name = $env{'form.namefor_'.$item};
205: if ($resources{$item}) {
206: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
207: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
208: $tocopy{$1} = $name;
209: $display{$item} = $1;
210: $lookup{$1} = $item;
211: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
212: $simpleproblems{$item} = {
213: symb => $resources{$item},
214: name => $name,
215: };
216: $display{$item} = 'simpleproblem_'.$name;
217: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
218: $has_simpleprobs{$1}{$id} = $item;
219: }
220: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
221: my $marker = $1;
222: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
223: $simplepages{$item} = {
224: res => $res,
225: title => $titles{$item},
226: db => $db_name,
227: marker => $marker,
228: symb => $resources{$item},
229: name => $name,
230: };
231: $display{$item} = '/'.$res;
232: }
233: } elsif ($maps{$item}) {
234: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
235: $tocopy{$1} = $name;
236: $display{$item} = $1;
237: $lookup{$1} = $item;
238: }
239: } else {
240: next;
241: }
242: }
1.329 droeschl 243: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
244: $crs=~s/\_/\//g;
1.567 raeburn 245: my $mm = new File::MMagic;
246: my $prefix = "/uploaded/$cdom/$cnum/";
247: %replacehash = %tocopy;
248: foreach my $item (sort(keys(%simpleproblems))) {
249: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
250: $newcontent{$display{$item}} = $content;
251: }
252: my $gateway = Apache::lonhtmlgateway->new('web');
253: foreach my $item (sort(keys(%simplepages))) {
254: if (ref($simplepages{$item}) eq 'HASH') {
255: my $pagetitle = $simplepages{$item}{'title'};
256: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
257: my %contents;
258: foreach my $field (keys(%fields)) {
259: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
260: my $name = $1;
261: my $msg = $fields{$field};
262: if ($name eq 'webreferences') {
263: if ($msg =~ m{^https?://}) {
264: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
265: }
266: } else {
267: $msg = &Encode::decode('utf8',$msg);
268: $msg = $gateway->process_outgoing_html($msg,1);
269: $contents{$name} = $msg;
270: }
271: } elsif ($field eq 'uploaded.photourl') {
272: my $marker = $simplepages{$item}{marker};
273: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
274: my $filepath = $1;
275: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
276: if ($fname ne '') {
277: $fname=~s/\.(\w+)$//;
278: my $ext=$1;
279: $fname = &clean($fname);
280: $fname.='.'.$ext;
281: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
282: $replacehash{$filepath} = $relpath.$fname;
283: $deps{$item}{$filepath} = 1;
284: }
285: }
286: }
287: }
288: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
289: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
290: my $content = '
291: <html>
292: <head>
293: <title>'.$pagetitle.'</title>
294: </head>
295: <body bgcolor="#ffffff">';
296: if ($contents{title}) {
297: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
298: }
299: if ($contents{image}) {
300: $content .= "\n".$contents{image};
301: }
302: if ($contents{content}) {
303: $content .= '
304: <div class="LC_Box">
1.577 bisitz 305: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 306: $contents{content}.'
307: </div>';
308: }
309: if ($contents{webreferences}) {
310: $content .= '
311: <div class="LC_Box">
1.577 bisitz 312: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 313: $contents{webreferences}.'
314: </div>';
315: }
316: $content .= '
317: </body>
318: </html>
319: ';
320: $newcontent{'/'.$simplepages{$item}{res}} = $content;
321: }
322: }
323: foreach my $item (keys(%tocopy)) {
324: unless ($item=~/\.(sequence|page)$/) {
325: my $currurlpath = $prefix.$item;
326: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
327: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
328: }
329: }
330: foreach my $num (sort {$a <=> $b} (@todump)) {
331: my $src = $display{$num};
332: next if ($src eq '');
333: my @needcopy = ();
334: if ($replacehash{$src}) {
335: push(@needcopy,$src);
336: if (ref($deps{$num}) eq 'HASH') {
337: foreach my $dep (sort(keys(%{$deps{$num}}))) {
338: if ($replacehash{$dep}) {
339: push(@needcopy,$dep);
340: }
341: }
342: }
343: } elsif ($src =~ /^simpleproblem_/) {
344: push(@needcopy,$src);
345: }
346: next if (@needcopy == 0);
347: my ($result,$depresult);
348: for (my $i=0; $i<@needcopy; $i++) {
349: my $item = $needcopy[$i];
350: my $newfilename;
351: if ($simpleproblems{$num}) {
352: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
353: } else {
354: $newfilename=$title.'/'.$replacehash{$item};
355: }
356: $newfilename=~s/\.(\w+)$//;
357: my $ext=$1;
358: $newfilename=&clean($newfilename);
359: $newfilename.='.'.$ext;
360: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
361: if ($newrelpath ne $replacehash{$item}) {
362: $replacehash{$item} = $newrelpath;
363: }
364: my @dirs=split(/\//,$newfilename);
365: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
366: my $makepath=$path;
367: my $fail;
368: my $origin;
369: for (my $i=0;$i<$#dirs;$i++) {
370: $makepath.='/'.$dirs[$i];
371: unless (-e $makepath) {
372: unless(mkdir($makepath,0755)) {
373: $fail = &mt('Directory creation failed.');
374: }
375: }
376: }
377: if ($i == 0) {
378: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
379: } else {
380: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
381: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
382: &mt('(dependency)').'</span>: ';
383: }
384: if (-e $path.'/'.$newfilename) {
385: $fail = &mt('Destination already exists -- not overwriting.');
386: } else {
387: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
388: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
389: ($item =~ /^simpleproblem_/)) {
390: print $fh $newcontent{$item};
391: } else {
392: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
393: if (-e $fileloc) {
394: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
395: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
396: (ref($has_simpleprobs{$item}) eq 'HASH')) {
397: my %changes = %{$has_simpleprobs{$item}};
398: my $content = &Apache::lonclonecourse::rewritefile(
399: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
400: (%replacehash,$crs => '')
401: );
402: my $updatedcontent = '';
403: my $parser = HTML::TokeParser->new(\$content);
404: $parser->attr_encoded(1);
405: while (my $token = $parser->get_token) {
406: if ($token->[0] eq 'S') {
407: if (($token->[1] eq 'resource') &&
408: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
409: ($changes{$token->[2]->{'id'}})) {
410: my $id = $token->[2]->{'id'};
411: $updatedcontent .= '<'.$token->[1];
412: foreach my $attrib (@{$token->[3]}) {
413: next unless ($attrib =~ /^(src|type|title|id)$/);
414: if ($attrib eq 'src') {
415: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
416: if ($file) {
417: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
418: } else {
419: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
420: }
421: } else {
422: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
423: }
424: }
425: $updatedcontent .= ' />'."\n";
426: } else {
427: $updatedcontent .= $token->[4]."\n";
428: }
429: } else {
430: $updatedcontent .= $token->[2];
431: }
432: }
433: print $fh $updatedcontent;
434: } else {
435: print $fh &Apache::lonclonecourse::rewritefile(
436: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
437: (%replacehash,$crs => '')
438: );
439: }
440: } else {
441: print $fh
442: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
443: }
444: } else {
445: $fail = &mt('Source does not exist.');
446: }
447: }
448: $fh->close();
449: } else {
450: $fail = &mt('Could not write to destination.');
451: }
452: }
453: my $text;
454: if ($fail) {
455: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
456: } else {
457: $text = '<span class="LC_success">'.&mt('ok').'</span>';
458: }
459: if ($i == 0) {
460: $result .= $text;
461: } else {
462: $depresult .= $text.'</li>';
463: }
464: }
465: $r->print($result);
466: if ($depresult) {
467: $r->print('<ul>'.$depresult.'</ul>');
468: }
469: }
470: } else {
471: my ($navmap,$errormsg) =
472: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
473: if (!ref($navmap)) {
474: $r->print($errormsg);
475: } else {
476: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
477: $r->rflush();
478: my ($preamble,$formname);
479: $formname = 'dumpdoc';
480: unless ($home==1) {
481: $preamble = '<div class="LC_left_float">'.
482: '<fieldset><legend>'.
483: &mt('Select the Authoring Space').
484: '</legend><select name="authorspace">';
1.329 droeschl 485: }
1.567 raeburn 486: my @orderspaces = ();
487: foreach my $key (sort(keys(%outhash))) {
488: if ($key=~/^home_(.+)$/) {
489: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
490: unshift(@orderspaces,$1);
491: } else {
492: push(@orderspaces,$1);
493: }
494: }
495: }
1.569 raeburn 496: if ($home>1) {
497: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
498: }
1.567 raeburn 499: foreach my $user (@orderspaces) {
1.329 droeschl 500: if ($home==1) {
1.567 raeburn 501: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 502: } else {
1.567 raeburn 503: $preamble .= '<option value="'.$user.'">'.$user.' - '.
504: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
505: }
1.329 droeschl 506: }
1.567 raeburn 507: unless ($home==1) {
508: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 509: }
1.567 raeburn 510: my $title=$origcrsdata{'description'};
511: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 512: $title=&clean($title);
1.567 raeburn 513: $preamble .= '<div class="LC_left_float">'.
514: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
515: '<input type="text" size="50" name="authorfolder" value="'.
516: $title.'" />'.
517: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
518: my %uploadedfiles;
519: &tiehash();
520: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
521: my ($ext)=($file=~/\.(\w+)$/);
522: # FIXME Check supplemental here
523: my $title=$hash{'title_'.$hash{
524: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
525: if (!$title) {
526: $title=$file;
527: } else {
528: $title=~s|/|_|g;
529: }
530: $title=~s/\.(\w+)$//;
531: $title=&clean($title);
532: $title.='.'.$ext;
533: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
534: $uploadedfiles{$file} = $title;
535: }
536: &untiehash();
537: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
538: undef,undef,$preamble,$home,\%uploadedfiles));
539: }
1.329 droeschl 540: }
1.484 raeburn 541: $r->print(&endContentScreen());
1.329 droeschl 542: }
543:
1.567 raeburn 544: sub recurse_html {
545: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
546: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
547: my (%allfiles,%codebase);
548: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
549: if (keys(%allfiles)) {
550: foreach my $dependency (keys(%allfiles)) {
551: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
552: my ($depurl,$relfile,$newcontainer);
553: if ($dependency =~ m{^/}) {
554: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
555: $relfile = $1;
556: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
557: $newcontainer = $1;
558: next if ($replacehash->{$newcontainer});
559: }
560: $depurl = $dependency;
561: } else {
562: next;
563: }
564: } else {
565: $relfile = $dependency;
566: $depurl = $currurlpath;
567: $depurl =~ s{[^/]+$}{};
568: $depurl .= $dependency;
569: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
570: }
571: next if ($relfile eq '');
572: my $newname = $replacehash->{$container};
573: $newname =~ s{[^/]+$}{};
574: $replacehash->{$newcontainer} = $newname.$relfile;
575: $deps->{$item}{$newcontainer} = 1;
576: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
577: my $depfile = &Apache::lonnet::filelocation('',$depurl);
578: my $type = $mm->checktype_filename($depfile);
579: if ($type eq 'text/html') {
580: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
581: }
582: }
583: }
584: }
585: return;
586: }
587:
1.329 droeschl 588: sub group_import {
1.598 raeburn 589: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 590: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
591: %removeparam,$importuploaded,$fixuperrors);
592: $allmaps = {};
1.329 droeschl 593: while (@files) {
594: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 595: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 596: && ($caller eq 'londocs')
597: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 598:
1.329 droeschl 599: my $errtext = '';
600: my $fatal = 0;
601: my $newmapstr = '<map>'."\n".
602: '<resource id="1" src="" type="start"></resource>'."\n".
603: '<link from="1" to="2" index="1"></link>'."\n".
604: '<resource id="2" src="" type="finish"></resource>'."\n".
605: '</map>';
606: $env{'form.output'}=$newmapstr;
607: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
608: 'output',$1.$2);
1.534 raeburn 609: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 610: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
611: $fatal = 2;
612: }
613: if ($fatal) {
614: return ($errtext,$fatal);
615: }
616: }
617: if ($url) {
1.598 raeburn 618: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
619: $url = $1;
620: my $marker = $2;
621: my $info = $3;
622: my ($toolid,%toolhash);
623: my @toolinfo = split(/:/,$info);
624: if ($residx) {
625: my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
626: $toolid = $toolsettings{'id'};
627: } else {
628: $toolid = shift(@toolinfo);
629: }
630: $toolid =~ s/\D//g;
631: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}) = @toolinfo;
632: if (ref($ltitoolsref) eq 'HASH') {
633: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
634: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
635: $url =~ s/exttool$/exttools/;
636: }
637: $toolhash{'id'} = $toolid;
638: if ($toolhash{'target'} eq 'iframe') {
639: delete($toolhash{'width'});
640: delete($toolhash{'height'});
641: } elsif ($toolhash{'target'} eq 'window') {
642: foreach my $item ('width','height') {
643: $toolhash{$item} =~ s/^\s+//;
644: $toolhash{$item} =~ s/\s+$//;
645: }
646: }
647: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
648: }
649: }
650: }
1.529 raeburn 651: if (($caller eq 'londocs') &&
652: ($folder =~ /^default/)) {
1.534 raeburn 653: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 654: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
655: my $cid = $coursedom.'_'.$coursenum;
656: $allmaps =
657: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
658: $chome,$cid);
659: $donechk = 1;
660: }
661: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
662: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
663: \%addedmaps,\%hierarchy,\%titles,$allmaps);
664: $importuploaded = 1;
665: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
666: next if ($allmaps->{$url});
667: }
668: }
1.344 bisitz 669: if (!$residx
1.329 droeschl 670: || defined($LONCAPA::map::zombies[$residx])) {
671: $residx = &LONCAPA::map::getresidx($url,$residx);
672: push(@LONCAPA::map::order, $residx);
673: }
674: my $ext = 'false';
675: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
676: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 677: if ($name eq '') {
1.538 raeburn 678: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 679: }
680: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
681: my $filepath = $1;
682: my $fname = $name;
683: if ($fname =~ /^\W+$/) {
684: $fname = 'web';
685: } else {
686: $fname =~ s/\W/_/g;
687: }
1.599 damieng 688: if (length($fname) > 15) {
1.534 raeburn 689: $fname = substr($fname,0,14);
690: }
691: my $initialtext = &mt('Replace with your own content.');
692: my $newhtml = <<END;
1.545 raeburn 693: <html>
1.534 raeburn 694: <head>
695: <title>$name</title>
696: </head>
697: <body bgcolor="#ffffff">
698: $initialtext
699: </body>
700: </html>
701: END
702: $env{'form.output'}=$newhtml;
703: my $result =
704: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
705: 'output',
706: "$filepath/$residx/$fname.html");
707: if ($result =~ m{^/uploaded/}) {
708: $url = $result;
709: if ($filepath =~ /^supplemental/) {
710: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
711: $env{'user.domain'}.'___&&&___'.$name;
712: }
713: } else {
714: return (&mt('Failed to save new web page.'),1);
715: }
716: }
1.538 raeburn 717: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 718: $LONCAPA::map::resources[$residx] =
1.329 droeschl 719: join(':', ($name, $url, $ext, 'normal', 'res'));
720: }
721: }
1.529 raeburn 722: if ($importuploaded) {
723: my %import_errors;
724: my %updated = (
725: removefrommap => \%removefrommap,
726: removeparam => \%removeparam,
727: );
1.533 raeburn 728: my ($result,$msgsarray,$lockerror) =
729: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 730: if (keys(%import_errors) > 0) {
1.530 raeburn 731: $fixuperrors =
1.529 raeburn 732: '<p span class="LC_warning">'."\n".
733: &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".
734: '<ul>'."\n";
735: foreach my $key (sort(keys(%import_errors))) {
736: $fixuperrors .= '<li>'.$key.'</li>'."\n";
737: }
738: $fixuperrors .= '</ul></p>'."\n";
739: }
1.533 raeburn 740: if (ref($msgsarray) eq 'ARRAY') {
741: if (@{$msgsarray} > 0) {
742: $fixuperrors .= '<p class="LC_info">'.
743: join('<br />',@{$msgsarray}).
744: '</p>';
745: }
746: }
747: if ($lockerror) {
748: $fixuperrors .= '<p class="LC_error">'.
749: $lockerror.
750: '</p>';
751: }
1.529 raeburn 752: }
753: my ($errtext,$fatal) =
754: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 755: unless ($fatal) {
756: if ($folder =~ /^supplemental/) {
757: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 758: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
759: $folder.'.'.$container);
1.557 raeburn 760: }
761: }
1.529 raeburn 762: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 763: }
764:
765: sub log_docs {
1.494 raeburn 766: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 767: }
768:
769: {
770: my @oldresources=();
771: my @oldorder=();
772: my $parmidx;
773: my %parmaction=();
774: my %parmvalue=();
775: my $changedflag;
776:
777: sub snapshotbefore {
778: @oldresources=@LONCAPA::map::resources;
779: @oldorder=@LONCAPA::map::order;
780: $parmidx=undef;
781: %parmaction=();
782: %parmvalue=();
783: $changedflag=0;
784: }
785:
786: sub remember_parms {
787: my ($idx,$parameter,$action,$value)=@_;
788: $parmidx=$idx;
789: $parmaction{$parameter}=$action;
790: $parmvalue{$parameter}=$value;
791: $changedflag=1;
792: }
793:
794: sub log_differences {
795: my ($plain)=@_;
796: my %storehash=('folder' => $plain,
797: 'currentfolder' => $env{'form.folder'});
798: if ($parmidx) {
799: $storehash{'parameter_res'}=$oldresources[$parmidx];
800: foreach my $parm (keys(%parmaction)) {
801: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
802: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
803: }
804: }
805: my $maxidx=$#oldresources;
806: if ($#LONCAPA::map::resources>$#oldresources) {
807: $maxidx=$#LONCAPA::map::resources;
808: }
809: for (my $idx=0; $idx<=$maxidx; $idx++) {
810: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
811: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
812: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
813: $changedflag=1;
814: }
815: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
816: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
817: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
818: $changedflag=1;
819: }
820: }
821: $storehash{'maxidx'}=$maxidx;
822: if ($changedflag) { &log_docs(\%storehash); }
823: }
824: }
825:
826: sub docs_change_log {
1.484 raeburn 827: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486 raeburn 828: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 829: my $js = '<script type="text/javascript">'."\n".
830: '// <![CDATA['."\n".
831: &Apache::loncommon::display_filter_js('docslog')."\n".
1.486 raeburn 832: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
1.483 raeburn 833: &history_tab_js()."\n".
1.484 raeburn 834: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 835: '// ]]>'."\n".
836: '</script>'."\n";
1.484 raeburn 837: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
838: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 839: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 840: my %orderhash;
841: my $container='sequence';
842: my $pathitem;
1.519 raeburn 843: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 844: $container='page';
845: }
1.519 raeburn 846: my $folderpath=$env{'form.folderpath'};
847: if ($folderpath eq '') {
1.548 raeburn 848: $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
1.519 raeburn 849: }
850: $pathitem = '<input type="hidden" name="folderpath" value="'.
851: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 852: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
853: my $jumpto = $readfile;
854: $jumpto =~ s{^/}{};
855: my $tid = 1;
1.489 raeburn 856: if ($supplementalflag) {
857: $tid = 2;
858: }
1.509 raeburn 859: my ($breadcrumbtrail) =
860: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 861: $r->print($breadcrumbtrail.
862: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
863: $readfile));
1.329 droeschl 864: my %docslog=&Apache::lonnet::dump('nohist_docslog',
865: $env{'course.'.$env{'request.course.id'}.'.domain'},
866: $env{'course.'.$env{'request.course.id'}.'.num'});
867:
868: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
869:
870: my %saveable_parameters = ('show' => 'scalar',);
871: &Apache::loncommon::store_course_settings('docs_log',
872: \%saveable_parameters);
873: &Apache::loncommon::restore_course_settings('docs_log',
874: \%saveable_parameters);
875: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 876: # FIXME: internationalization seems wrong here
1.329 droeschl 877: my %lt=('hiddenresource' => 'Resources hidden',
878: 'encrypturl' => 'URL hidden',
879: 'randompick' => 'Randomly pick',
880: 'randomorder' => 'Randomly ordered',
881: 'set' => 'set to',
882: 'del' => 'deleted');
1.484 raeburn 883: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
884: $pathitem."\n".
885: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
886: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
887: $r->print('<div class="LC_left_float">'.
888: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
889: &makedocslogform($filter,1).
890: '</fieldset></div><br clear="all" />');
1.329 droeschl 891: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
892: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
893: &mt('After').'</th>'.
894: &Apache::loncommon::end_data_table_header_row());
895: my $shown=0;
896: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
897: if ($env{'form.displayfilter'} eq 'currentfolder') {
898: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
899: }
900: my @changes=keys(%{$docslog{$id}{'logentry'}});
901: if ($env{'form.displayfilter'} eq 'containing') {
902: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
903: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
904: foreach my $key (@changes) {
905: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
906: }
1.344 bisitz 907: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 908: }
909: my $count = 0;
910: my $time =
911: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
912: my $plainname =
913: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
914: $docslog{$id}{'exe_udom'});
915: my $about_me_link =
916: &Apache::loncommon::aboutmewrapper($plainname,
917: $docslog{$id}{'exe_uname'},
918: $docslog{$id}{'exe_udom'});
919: my $send_msg_link='';
920: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
921: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
922: $send_msg_link ='<br />'.
923: &Apache::loncommon::messagewrapper(&mt('Send message'),
924: $docslog{$id}{'exe_uname'},
925: $docslog{$id}{'exe_udom'});
926: }
927: $r->print(&Apache::loncommon::start_data_table_row());
928: $r->print('<td>'.$time.'</td>
929: <td>'.$about_me_link.
930: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
931: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
932: $send_msg_link.'</td><td>'.
933: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 934: my $is_supp = 0;
935: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
936: $is_supp = 1;
937: }
1.329 droeschl 938: # Before
939: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
940: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
941: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
942: if ($oldname ne $newname) {
1.488 raeburn 943: my $shown = &LONCAPA::map::qtescape($oldname);
944: if ($is_supp) {
945: $shown = &Apache::loncommon::parse_supplemental_title($shown);
946: }
947: $r->print($shown);
1.329 droeschl 948: }
949: }
950: $r->print('<ul>');
951: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
952: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 953: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
954: if ($is_supp) {
955: $shown = &Apache::loncommon::parse_supplemental_title($shown);
956: }
957: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 958: }
959: }
960: $r->print('</ul>');
961: # After
962: $r->print('</td><td>');
963:
964: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
965: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
966: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
967: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 968: my $shown = &LONCAPA::map::qtescape($newname);
969: if ($is_supp) {
970: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
971: }
972: $r->print($shown);
1.329 droeschl 973: }
1.364 bisitz 974: }
1.329 droeschl 975: $r->print('<ul>');
976: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
977: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 978: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
979: if ($is_supp) {
980: $shown = &Apache::loncommon::parse_supplemental_title($shown);
981: }
982: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 983: }
984: }
985: $r->print('</ul>');
986: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
987: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
988: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
989: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 990: # FIXME: internationalization seems wrong here
1.329 droeschl 991: $r->print('<li>'.
992: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
993: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
994: .'</li>');
995: }
996: }
997: $r->print('</ul>');
998: }
999: # End
1000: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1001: $shown++;
1002: if (!($env{'form.show'} eq &mt('all')
1003: || $shown<=$env{'form.show'})) { last; }
1004: }
1.484 raeburn 1005: $r->print(&Apache::loncommon::end_data_table()."\n".
1006: &makesimpleeditform($pathitem)."\n".
1007: '</div></div>');
1008: $r->print(&endContentScreen());
1.329 droeschl 1009: }
1010:
1011: sub update_paste_buffer {
1.492 raeburn 1012: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1013: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1014: if ($env{'form.multiremove'}) {
1015: $env{'form.multiremove'} =~ s/,$//;
1016: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1017: }
1018: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1019: if ($env{'form.multicut'}) {
1020: $env{'form.multicut'} =~ s/,$//;
1021: foreach my $item (split(/,/,$env{'form.multicut'})) {
1022: unless ($removals{$item}) {
1023: $cuts{$item} = 1;
1024: push(@possibles,$item.':cut');
1025: }
1026: }
1027: }
1028: if ($env{'form.multicopy'}) {
1029: $env{'form.multicopy'} =~ s/,$//;
1030: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1031: unless ($removals{$item} || $cuts{$item}) {
1032: push(@possibles,$item.':copy');
1033: }
1034: }
1035: }
1036: } elsif ($env{'form.markcopy'}) {
1037: @possibles = split(/,/,$env{'form.markcopy'});
1038: }
1.329 droeschl 1039:
1.538 raeburn 1040: return if (@possibles == 0);
1.329 droeschl 1041: return if (!defined($env{'form.copyfolder'}));
1042:
1043: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1044: $env{'form.copyfolder'});
1.538 raeburn 1045: return if ($fatal);
1046:
1047: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1048:
1.538 raeburn 1049: # Retrieve current paste buffer suffixes.
1050: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1051: my (%pasteurls,@newpaste);
1052:
1053: # Construct identifiers for current contents of user's paste buffer
1054: if (@currpaste) {
1055: foreach my $suffix (@currpaste) {
1056: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1057: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1058: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1059: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1060: ($url ne '')) {
1.597 raeburn 1061: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1062: }
1063: }
1064: }
1065:
1066: # Mark items for copying (skip any items already in user's paste buffer)
1067: my %addtoenv;
1.597 raeburn 1068:
1069: my @pathitems = split(/\&/,$env{'form.folderpath'});
1070: my @folderconf = split(/\:/,$pathitems[-1]);
1071: my $ispage = $folderconf[4];
1072:
1.538 raeburn 1073: foreach my $item (@possibles) {
1074: my ($orderidx,$cmd) = split(/:/,$item);
1075: next if ($orderidx =~ /\D/);
1076: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1077: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1078: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1079: my %denied = &action_restrictions($coursenum,$coursedom,
1080: &LONCAPA::map::qtescape($url),
1081: $env{'form.folderpath'},\%curr_groups);
1082: next if ($denied{'copy'});
1083: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1084: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1085: my ($suffix,$errortxt,$locknotfreed) =
1086: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1087: if ($suffix ne '') {
1088: push(@newpaste,$suffix);
1089: } else {
1090: if ($locknotfreed) {
1091: return $locknotfreed;
1092: }
1.538 raeburn 1093: }
1094: if (&is_supplemental_title($title)) {
1095: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1096: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1097: }
1.329 droeschl 1098:
1.538 raeburn 1099: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1100: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1101: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1102: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1103: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1104: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1105: my $prefix = $1;
1106: my $subdir =$2;
1107: if ($subdir eq '') {
1108: $subdir = $prefix;
1.492 raeburn 1109: }
1.538 raeburn 1110: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1111: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1112: \%hierarchy,\%titles,\%allmaps);
1113: if (ref($hierarchy{$url}) eq 'HASH') {
1114: my ($nested,$nestednames);
1115: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1116: $nested =~ s/\&$//;
1117: $nestednames =~ s/\Q___&&&___\E$//;
1118: if ($nested ne '') {
1119: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1120: }
1121: if ($nestednames ne '') {
1122: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1123: }
1.492 raeburn 1124: }
1125: }
1.591 raeburn 1126: if ($locknotfreed) {
1127: $output = $locknotfreed;
1128: last;
1129: }
1.492 raeburn 1130: }
1.538 raeburn 1131: if (@newpaste) {
1132: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1133: }
1.492 raeburn 1134: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1135: delete($env{'form.markcopy'});
1.591 raeburn 1136: return $output;
1.329 droeschl 1137: }
1138:
1.492 raeburn 1139: sub recurse_uploaded_maps {
1140: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1141: if (ref($hierarchy->{$url}) eq 'HASH') {
1142: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1143: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1144: my (@uploaded,@names,%shorter);
1145: for (my $i=0; $i<@maps; $i++) {
1146: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1147: if ($inner ne '') {
1148: push(@uploaded,$inner);
1149: push(@names,&escape($titles[$i]));
1150: $shorter{$maps[$i]} = $inner;
1151: }
1152: }
1153: $$nestref .= "$dir:".join(',',@uploaded).'&';
1154: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1155: foreach my $map (@maps) {
1156: if ($shorter{$map} ne '') {
1157: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1158: }
1159: }
1160: }
1161: return;
1162: }
1163:
1.329 droeschl 1164: sub print_paste_buffer {
1.492 raeburn 1165: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1166: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1167:
1.538 raeburn 1168: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1169: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1170: }
1171:
1.538 raeburn 1172: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1173: my ($pasteitems,@pasteable);
1.575 raeburn 1174: my $clipboardcount = 0;
1.488 raeburn 1175:
1.538 raeburn 1176: # Construct identifiers for current contents of user's paste buffer
1177: foreach my $suffix (@currpaste) {
1178: next if ($suffix =~ /\D/);
1179: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1180: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1181: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1182: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1183: ($url ne '')) {
1.575 raeburn 1184: $clipboardcount ++;
1.538 raeburn 1185: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1186: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1187: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1188: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1189: $is_external = 1;
1.598 raeburn 1190: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1191: $is_exttool = 1;
1.538 raeburn 1192: }
1193: if ($folder =~ /^supplemental/) {
1194: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1195: unless ($canpaste) {
1196: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1197: }
1198: } else {
1199: $canpaste = 1;
1200: }
1201: if ($canpaste) {
1202: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1203: my $srcdom = $1;
1204: my $srcnum = $2;
1205: my $rem = $3;
1206: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1207: $othercourse = 1;
1208: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1209: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1210: } else {
1211: $canpaste = 0;
1212: $nopaste = &mt('Paste from another course unavailable.');
1213: }
1214: }
1215: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1216: my $prefix = $1;
1217: $parent = $2;
1218: if ($folder !~ /^\Q$prefix\E/) {
1219: $areachange = 1;
1220: }
1221: $is_uploaded_map = 1;
1.492 raeburn 1222: }
1.597 raeburn 1223: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1224: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1225: if ($cid ne $env{'request.course.id'}) {
1226: my ($srcdom,$srcnum) = split(/_/,$cid);
1227: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1228: $othercrs = '<br />'.&mt('(from another course)');
1229: } else {
1230: $canpaste = 0;
1231: $nopaste = &mt('Paste from another course unavailable.');
1232: }
1233: }
1.492 raeburn 1234: }
1.596 raeburn 1235: if ($canpaste) {
1236: push(@pasteable,$suffix);
1237: }
1.538 raeburn 1238: }
1239: my $buffer;
1.598 raeburn 1240: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1241: $buffer = &mt('External Resource').': '.
1242: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1243: &LONCAPA::map::qtescape($url).')';
1244: } else {
1245: my $icon = &Apache::loncommon::icon($extension);
1246: if ($extension eq 'sequence' &&
1247: $url =~ m{/default_\d+\.sequence$}x) {
1248: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1249: $icon .= '/navmap.folder.closed.gif';
1250: }
1.589 raeburn 1251: my $title = $env{'docs.markedcopy_title_'.$suffix};
1252: if ($title eq '') {
1253: ($title) = ($url =~ m{/([^/]+)$});
1254: }
1.538 raeburn 1255: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1256: ': '.
1257: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1258: &LONCAPA::map::qtescape($title));
1.538 raeburn 1259: }
1260: $pasteitems .= '<div class="LC_left_float">';
1261: my ($options,$onclick);
1262: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1263: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1264: if (($is_uploaded_map) ||
1265: ($url =~ /(bulletinboard|smppg)$/) ||
1266: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1267: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1268: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1269: }
1270: }
1271: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1272: if ($nopaste) {
1273: $pasteitems .= $nopaste;
1274: } else {
1275: if ($othercrs) {
1276: $pasteitems .= $othercrs;
1277: }
1278: if ($options) {
1279: $pasteitems .= $options;
1.492 raeburn 1280: }
1281: }
1.538 raeburn 1282: $pasteitems .= '</div>';
1283: }
1284: }
1285: if ($pasteitems eq '') {
1286: &Apache::lonnet::delenv('docs.markedcopies');
1287: }
1288: my ($pasteform,$form_start,$buttons,$form_end);
1289: if ($pasteitems) {
1290: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1291: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1292: if (@pasteable) {
1.575 raeburn 1293: my $value = &mt('Paste to current folder');
1294: if ($container eq 'page') {
1295: $value = &mt('Paste to current page');
1296: }
1297: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1298: }
1299: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1300: if ($clipboardcount > 1) {
1301: $buttons .=
1302: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1303: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1304: (' 'x2).
1305: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1306: (' 'x2);
1.492 raeburn 1307: }
1.575 raeburn 1308: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1309: '</form>';
1.538 raeburn 1310: } else {
1311: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1312: }
1.538 raeburn 1313: $r->print($form_start
1314: .'<fieldset>'
1315: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1316: .$pasteitems
1317: .'</fieldset>'
1318: .$form_end);
1319: }
1320:
1321: sub paste_options {
1322: my ($suffix,$is_uploaded_map,$parent) = @_;
1323: my ($copytext,$movetext);
1324: if ($is_uploaded_map) {
1325: $copytext = &mt('Copy to new folder');
1326: $movetext = &mt('Move old');
1327: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1328: $copytext = &mt('Copy to new board');
1329: $movetext = &mt('Move (not posts)');
1330: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1331: $copytext = &mt('Copy to new page');
1332: $movetext = &mt('Move');
1.533 raeburn 1333: } else {
1.538 raeburn 1334: $copytext = &mt('Copy to new file');
1335: $movetext = &mt('Move');
1336: }
1337: my $output = '<br />'.
1338: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1339: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1340: '<label>'.
1341: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1342: $copytext.'</label></span>'.(' 'x2).' '.
1343: '<span class="LC_nobreak"><label>'.
1344: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1345: $movetext.'</label></span>';
1346: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1347: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1348: '</legend><table border="0">';
1349: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1350: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1351: my $lastdir = $parent;
1352: my %depths = (
1353: $lastdir => 0,
1354: );
1355: my (%display,%deps);
1356: for (my $i=0; $i<@pastemaps; $i++) {
1357: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1358: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1359: my @subfolders = split(/,/,$subfolderstr);
1360: $deps{$lastdir} = \@subfolders;
1361: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1362: my $depth = $depths{$lastdir} + 1;
1363: my $offset = int($depth * 4);
1364: my $indent = (' ' x $offset);
1365: for (my $j=0; $j<@subfolders; $j++) {
1366: $depths{$subfolders[$j]} = $depth;
1367: $display{$subfolders[$j]} =
1368: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1369: '<td><label>'.
1370: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1371: '<label>'.
1372: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1373: &mt('Move old').'</label>'.
1374: '</td></tr>';
1375: }
1.492 raeburn 1376: }
1.538 raeburn 1377: &recurse_print(\$output,$parent,\%deps,\%display);
1378: $output .= '</table></fieldset>';
1.329 droeschl 1379: }
1.538 raeburn 1380: $output .= '</div>';
1381: return $output;
1.488 raeburn 1382: }
1383:
1.492 raeburn 1384: sub recurse_print {
1.538 raeburn 1385: my ($outputref,$dir,$deps,$display) = @_;
1386: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1387: if (ref($deps->{$dir}) eq 'ARRAY') {
1388: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1389: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1390: }
1391: }
1392: }
1393:
1.488 raeburn 1394: sub supp_pasteable {
1395: my ($url) = @_;
1396: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1397: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1398: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1399: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1400: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1401: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1.488 raeburn 1402: return 1;
1403: }
1404: return;
1.329 droeschl 1405: }
1406:
1.492 raeburn 1407: sub paste_popup_js {
1.594 damieng 1408: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1409: show => 'Show Options',
1410: hide => 'Hide Options',
1.594 damieng 1411: );
1412: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1413: none => 'No items selected from clipboard.',
1.492 raeburn 1414: );
1.594 damieng 1415: &html_escape(\%html_js_lt);
1416: &js_escape(\%html_js_lt);
1417: &js_escape(\%js_lt);
1.492 raeburn 1418: return <<"END";
1419:
1.538 raeburn 1420: function showPasteOptions(suffix) {
1421: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1422: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1423: return;
1424: }
1425:
1.538 raeburn 1426: function hidePasteOptions(suffix) {
1427: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1428: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1429: return;
1430: }
1431:
1432: function showOptions(caller,suffix) {
1433: if (document.getElementById('pasteoptionstext_'+suffix)) {
1434: if (caller.checked) {
1.594 damieng 1435: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1436: } else {
1437: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1438: }
1439: if (document.getElementById('pasteoptions_'+suffix)) {
1440: document.getElementById('pasteoptions_'+suffix).style.display='none';
1441: }
1442: }
1.492 raeburn 1443: return;
1444: }
1445:
1.541 raeburn 1446: function validateClipboard() {
1447: var numchk = 0;
1448: if (document.pasteform.pasting.length > 1) {
1449: for (var i=0; i<document.pasteform.pasting.length; i++) {
1450: if (document.pasteform.pasting[i].checked) {
1451: numchk ++;
1452: }
1453: }
1454: } else {
1455: if (document.pasteform.pasting.type == 'checkbox') {
1456: if (document.pasteform.pasting.checked) {
1457: numchk ++;
1458: }
1459: }
1460: }
1461: if (numchk > 0) {
1462: return true;
1463: } else {
1.594 damieng 1464: alert("$js_lt{'none'}");
1.541 raeburn 1465: return false;
1466: }
1467: }
1468:
1.575 raeburn 1469: function checkClipboard() {
1470: if (document.pasteform.pasting.length > 1) {
1471: for (var i=0; i<document.pasteform.pasting.length; i++) {
1472: document.pasteform.pasting[i].checked = true;
1473: }
1474: }
1475: return;
1476: }
1477:
1478: function uncheckClipboard() {
1479: if (document.pasteform.pasting.length >1) {
1480: for (var i=0; i<document.pasteform.pasting.length; i++) {
1481: document.pasteform.pasting[i].checked = false;
1482: }
1483: }
1484: return;
1485: }
1486:
1.492 raeburn 1487: END
1488:
1489: }
1490:
1.329 droeschl 1491: sub do_paste_from_buffer {
1.492 raeburn 1492: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1493:
1.538 raeburn 1494: # Array of items in paste buffer
1495: my (@currpaste,%pastebuffer,%allerrors);
1496: @currpaste = split(/,/,$env{'docs.markedcopies'});
1497:
1.492 raeburn 1498: # Early out if paste buffer is empty
1.538 raeburn 1499: if (@currpaste == 0) {
1.492 raeburn 1500: return ();
1.538 raeburn 1501: }
1502: map { $pastebuffer{$_} = 1; } @currpaste;
1503:
1504: # Array of items selected items to paste
1505: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1506:
1507: # Early out if nothing selected to paste
1508: if (@reqpaste == 0) {
1509: return();
1510: }
1511: my @topaste;
1512: foreach my $suffix (@reqpaste) {
1513: next if ($suffix =~ /\D/);
1514: next unless (exists($pastebuffer{$suffix}));
1515: push(@topaste,$suffix);
1516: }
1517:
1518: # Early out if nothing available to paste
1519: if (@topaste == 0) {
1520: return();
1.329 droeschl 1521: }
1522:
1.538 raeburn 1523: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1524: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1525:
1526: foreach my $suffix (@topaste) {
1527: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1528: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1529: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1530: # Supplemental content may only include certain types of content
1531: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1532: if ($folder =~ /^supplemental/) {
1533: unless (&supp_pasteable($url)) {
1534: $notinsupp{$suffix} = 1;
1535: next;
1536: }
1.492 raeburn 1537: }
1.538 raeburn 1538: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1539: my $srcd = $1;
1540: my $srcn = $2;
1.492 raeburn 1541: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1542: # check for mdc privilege in the course from which the resource was pasted
1543: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1544: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1545: $notincrs{$suffix} = 1;
1546: next;
1547: }
1.491 raeburn 1548: }
1.538 raeburn 1549: $srcdom{$suffix} = $srcd;
1550: $srcnum{$suffix} = $srcn;
1.597 raeburn 1551: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1552: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1553: my ($srcd,$srcn) = split(/_/,$cid);
1554: # When paste buffer was populated using an active role in a different course
1555: # check for mdc privilege in the course from which the resource was pasted
1556: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1557: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1558: $notincrs{$suffix} = 1;
1559: next;
1560: }
1561: }
1562: $srcdom{$suffix} = $srcd;
1563: $srcnum{$suffix} = $srcn;
1.491 raeburn 1564: }
1.597 raeburn 1565: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1566: push(@dopaste,$suffix);
1567: if ($url=~/\.(page|sequence)$/) {
1568: $is_map{$suffix} = 1;
1569: }
1570:
1571: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1572: my $oldprefix = $1;
1.492 raeburn 1573: # When pasting content from Main Content to Supplemental Content and vice versa
1574: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1575: # a folder/page or a document).
1.538 raeburn 1576: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1577: $prefixchg{$suffix} = 'docstosupp';
1578: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1579: $prefixchg{$suffix} = 'supptodocs';
1580: }
1.491 raeburn 1581:
1.492 raeburn 1582: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1583: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1584: my @nested;
1585: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1586: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1587: my @deps = map { /\d+:([\d,]+$)/ } @items;
1588: foreach my $dep (@deps) {
1589: if ($dep =~ /,/) {
1590: push(@nested,split(/,/,$dep));
1591: } else {
1592: push(@nested,$dep);
1593: }
1.492 raeburn 1594: }
1.538 raeburn 1595: foreach my $item (@nested) {
1596: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1597: push(@{$marktomove{$suffix}},$type.'_'.$item);
1598: }
1.492 raeburn 1599: }
1600: }
1.488 raeburn 1601: }
1602: }
1603:
1.538 raeburn 1604: # Early out if nothing available to paste
1605: if (@dopaste == 0) {
1606: return ();
1607: }
1608:
1609: # Populate message hash and hashes used for main content <=> supplemental content
1610: # changes
1611:
1612: %msgs = &Apache::lonlocal::texthash (
1613: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1614: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1615: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1616: );
1617:
1618: %before = (
1619: docstosupp => {
1620: map => 'default',
1621: doc => 'docs',
1622: },
1623: supptodocs => {
1624: map => 'supplemental',
1625: doc => 'supplemental',
1626: },
1627: );
1628:
1629: %after = (
1630: docstosupp => {
1631: map => 'supplemental',
1632: doc => 'supplemental'
1633: },
1634: supptodocs => {
1635: map => 'default',
1636: doc => 'docs',
1637: },
1638: );
1639:
1640: # Retrieve information about all course maps in main content area
1641:
1642: my $allmaps = {};
1643: if ($folder =~ /^default/) {
1644: $allmaps =
1645: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1646: $env{"course.$env{'request.course.id'}.home"},
1647: $env{'request.course.id'});
1648: }
1649:
1650: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1651:
1652: # Loop over the items to paste
1653: foreach my $suffix (@dopaste) {
1.329 droeschl 1654: # Maps need to be copied first
1.538 raeburn 1655: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1656: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1657: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1658: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1659: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1660: }
1661: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1662: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1663: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1664: my $oldurl = $url;
1665: if ($is_map{$suffix}) {
1.491 raeburn 1666: # If pasting a map, check if map contains other maps
1.538 raeburn 1667: my (%hierarchy,%titles);
1668: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1669: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1670: if ($url=~ m{^/uploaded/}) {
1671: my $newurl;
1672: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1673: ($newurl,my $error) =
1674: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1675: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1676: \$title,$allmaps,\%newurls);
1677: if ($error) {
1678: $allerrors{$suffix} = $error;
1679: next;
1680: }
1681: if ($newurl ne '') {
1682: if ($newurl ne $url) {
1683: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1684: $newsubdir{$url} = $1;
1685: }
1686: $mapchanges{$url} = 1;
1.492 raeburn 1687: }
1.538 raeburn 1688: }
1689: }
1690: if (($srcdom{$suffix} ne $coursedom) ||
1691: ($srcnum{$suffix} ne $coursenum) ||
1692: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1693: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1694: $coursedom,$coursenum,$srcdom{$suffix},
1695: $srcnum{$suffix},$allmaps,\%rewrites,
1696: \%retitles,\%copies,\%dbcopies,
1697: \%zombies,\%params,\%mapmoves,
1698: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1699: \%newurls,\%resdatacopy)) {
1.538 raeburn 1700: $mapmoves{$url} = 1;
1701: }
1702: $url = $newurl;
1703: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1704: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1705: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1706: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1707: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1708: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1709: }
1710: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1711: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1712: push(@toclear,$suffix);
1713: # if pasting published map (main content area only) check map not already in course
1714: if ($folder =~ /^default/) {
1715: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1716: $duplicate{$suffix} = 1;
1717: next;
1.492 raeburn 1718: }
1.491 raeburn 1719: }
1720: }
1.538 raeburn 1721: }
1722: if ($url=~ m{/(bulletinboard|smppg)$}) {
1723: my $prefix = $1;
1.596 raeburn 1724: my $fromothercrs;
1.538 raeburn 1725: #need to copy the db contents to a new one, unless this is a move.
1726: my %info = (
1727: src => $url,
1728: cdom => $coursedom,
1729: cnum => $coursenum,
1.596 raeburn 1730: );
1731: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1732: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1733: $fromothercrs = 1;
1734: $info{'cdom'} = $srcdom{$suffix};
1735: $info{'cnum'} = $srcnum{$suffix};
1736: }
1737: }
1738: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1739: my (%lockerr,$msg);
1740: my ($newurl,$result,$errtext) =
1741: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1742: if ($result eq 'ok') {
1743: $url = $newurl;
1744: $title=&mt('Copy of').' '.$title;
1745: } else {
1746: if ($prefix eq 'smppg') {
1747: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1748: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1749: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1750: }
1751: $results{$suffix} = $result;
1752: $msgerrs{$suffix} = $msg;
1753: $lockerrs{$suffix} = $lockerr{$prefix};
1754: next;
1755: }
1756: if ($lockerr{$prefix}) {
1757: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1758: }
1.489 raeburn 1759: }
1760: }
1.538 raeburn 1761: $title = &LONCAPA::map::qtunescape($title);
1762: my $ext='false';
1763: if ($url=~m{^http(|s)://}) { $ext='true'; }
1764: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1765: if ($folder !~ /^supplemental/) {
1766: (undef,undef,$title) =
1767: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1768: }
1769: } else {
1770: if ($folder=~/^supplemental/) {
1771: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1772: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1773: }
1.533 raeburn 1774: }
1.491 raeburn 1775:
1776: # For uploaded files (excluding pages/sequences) path in copied file is changed
1777: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1778: # courses.
1779:
1.538 raeburn 1780: unless ($is_map{$suffix}) {
1781: my $newidx;
1.492 raeburn 1782: # Now insert the URL at the bottom
1.538 raeburn 1783: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1784: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1785: my $relpath = $1;
1786: if ($relpath ne '') {
1787: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1788: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1789: my $newprefix = $newloc;
1790: if ($newloc eq 'default') {
1791: $newprefix = 'docs';
1792: }
1793: if ($newdocsdir eq '') {
1794: $newdocsdir = 'default';
1795: }
1796: if (($prefixchg{$suffix}) ||
1797: ($srcdom{$suffix} ne $coursedom) ||
1798: ($srcnum{$suffix} ne $coursenum) ||
1799: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1800: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1801: $url =
1802: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1803: &Apache::lonnet::getfile($oldurl));
1804: if ($url eq '/adm/notfound.html') {
1805: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1806: next;
1807: } else {
1808: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1809: $newsubpath =~ s{/+$}{/};
1810: $docmoves{$oldurl} = $newsubpath;
1811: }
1.491 raeburn 1812: }
1813: }
1.597 raeburn 1814: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1815: my $template = $1;
1816: if ($newidx) {
1817: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1818: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1819: }
1.491 raeburn 1820: }
1.538 raeburn 1821: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1822: ':'.$ext.':normal:res';
1823: push(@LONCAPA::map::order,$newidx);
1824: # Store the result
1825: my ($errtext,$fatal) =
1826: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1827: if ($fatal) {
1828: $save_err .= $errtext;
1829: $allresult = 'fail';
1830: }
1.488 raeburn 1831: }
1.538 raeburn 1832:
1.597 raeburn 1833: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1834: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1835: unless ($allresult eq 'fail') {
1836: my %updated = (
1837: rewrites => \%rewrites,
1838: zombies => \%zombies,
1839: removefrommap => \%removefrommap,
1840: removeparam => \%removeparam,
1841: dbcopies => \%dbcopies,
1.597 raeburn 1842: resdatacopy => \%resdatacopy,
1.538 raeburn 1843: retitles => \%retitles,
1844: );
1845: my %info = (
1846: newsubdir => \%newsubdir,
1847: params => \%params,
1848: );
1849: if ($prefixchg{$suffix}) {
1850: $info{'before'} = $before{$prefixchg{$suffix}};
1851: $info{'after'} = $after{$prefixchg{$suffix}};
1852: }
1853: my %moves = (
1854: copies => \%copies,
1855: docmoves => \%docmoves,
1856: mapmoves => \%mapmoves,
1857: );
1858: (my $result,$msgs{$suffix},my $lockerror) =
1859: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1860: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1861: $url,'paste');
1862: $lockerrors .= $lockerror;
1863: if ($result eq 'ok') {
1864: if ($is_map{$suffix}) {
1865: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1866: $folder.'.'.$container);
1867: if ($fatal) {
1868: $allresult = 'failread';
1869: } else {
1870: if ($#LONCAPA::map::order<1) {
1871: my $idx=&LONCAPA::map::getresidx();
1872: if ($idx<=0) { $idx=1; }
1873: $LONCAPA::map::order[0]=$idx;
1874: $LONCAPA::map::resources[$idx]='';
1875: }
1876: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1877: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1878: ':'.$ext.':normal:res';
1879: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1880:
1881: # Store the result
1.538 raeburn 1882: my ($errtext,$fatal) =
1883: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1884: if ($fatal) {
1885: $save_err .= $errtext;
1886: $allresult = 'failstore';
1887: }
1888: }
1889: }
1890: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1891: push(@toclear,$suffix);
1892: }
1893: }
1.492 raeburn 1894: }
1895: }
1.538 raeburn 1896: &clear_from_buffer(\@toclear,\@currpaste);
1897: my $msgsarray;
1898: foreach my $suffix (keys(%msgs)) {
1899: if (ref($msgs{$suffix}) eq 'ARRAY') {
1900: $msgsarray .= join(',',@{$msgs{$suffix}});
1901: }
1902: }
1903: return ($allresult,$save_err,$msgsarray,$lockerrors);
1904: }
1.533 raeburn 1905:
1.538 raeburn 1906: sub do_buffer_empty {
1907: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1908: if (@currpaste == 0) {
1909: return &mt('Clipboard is already empty');
1910: }
1911: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1912: if (@toclear == 0) {
1913: return &mt('Nothing selected to clear from clipboard');
1914: }
1915: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1916: if ($numdel) {
1917: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1918: } else {
1919: return &mt('Clipboard unchanged');
1.492 raeburn 1920: }
1.538 raeburn 1921: return;
1922: }
1923:
1924: sub clear_from_buffer {
1925: my ($toclear,$currpaste) = @_;
1926: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1927: my %pastebuffer;
1928: map { $pastebuffer{$_} = 1; } @{$currpaste};
1929: my $numdel = 0;
1930: foreach my $suffix (@{$toclear}) {
1931: next if ($suffix =~ /\D/);
1932: next unless (exists($pastebuffer{$suffix}));
1933: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1934: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1935: delete($pastebuffer{$suffix});
1936: $numdel ++;
1937: }
1938: }
1939: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1940: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1941: return $numdel;
1.492 raeburn 1942: }
1943:
1944: sub get_newmap_url {
1945: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1946: $titleref,$allmaps,$newurls) = @_;
1947: my $newurl;
1948: if ($url=~ m{^/uploaded/}) {
1949: $$titleref=&mt('Copy of').' '.$$titleref;
1950: }
1951: my $now = time;
1952: my $suffix=$$.int(rand(100)).$now;
1953: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1954: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1955: my $path = $1;
1956: my $prefix = $2;
1957: my $ancestor = $3;
1958: if (length($ancestor) > 10) {
1959: $ancestor = substr($ancestor,-10,10);
1960: }
1961: my $newid;
1962: if ($prefixchg) {
1963: if ($folder =~ /^supplemental/) {
1964: $prefix =~ s/^default/supplemental/;
1965: } else {
1966: $prefix =~ s/^supplemental/default/;
1967: }
1968: }
1969: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1970: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1971: } else {
1972: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1973: }
1974: my $counter = 0;
1975: my $is_unique = &uniqueness_check($newurl);
1976: if ($folder =~ /^default/) {
1977: if ($allmaps->{$newurl}) {
1978: $is_unique = 0;
1979: }
1980: }
1981: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1982: $counter ++;
1983: $suffix ++;
1984: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1985: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1986: } else {
1987: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1988: }
1989: $is_unique = &uniqueness_check($newurl);
1990: }
1991: if ($is_unique) {
1992: $newurls->{$newurl} = 1;
1993: } else {
1994: if ($url=~/\.page$/) {
1995: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1996: } else {
1997: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1998: }
1999: }
1.329 droeschl 2000: }
1.492 raeburn 2001: return ($newurl);
1.329 droeschl 2002: }
2003:
1.488 raeburn 2004: sub dbcopy {
1.533 raeburn 2005: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2006: my ($url,$result,$errtext);
2007: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2008: $url = $dbref->{'src'};
1.533 raeburn 2009: if ($url =~ m{/(smppg|bulletinboard)$}) {
2010: my $prefix = $1;
2011: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2012: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2013: my $db_name;
2014: my $marker = (split(m{/},$url))[4];
2015: $marker=~s/\D//g;
2016: if ($dbref->{'src'} =~ m{/smppg$}) {
2017: $db_name =
2018: &Apache::lonsimplepage::get_db_name($url,$marker,
2019: $dbref->{'cdom'},
2020: $dbref->{'cnum'});
2021: } else {
2022: $db_name = 'bulletinpage_'.$marker;
2023: }
2024: my ($suffix,$freedlock,$error) =
2025: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2026: $coursedom,$coursenum,
2027: 'concat');
2028: if (!$suffix) {
2029: if ($prefix eq 'smppg') {
2030: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2031: } else {
1.565 bisitz 2032: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2033: }
2034: if ($error) {
2035: $errtext .= '<br />'.$error;
2036: }
2037: } else {
2038: #need to copy the db contents to a new one.
2039: my %contents=&Apache::lonnet::dump($db_name,
2040: $dbref->{'cdom'},
2041: $dbref->{'cnum'});
2042: if (exists($contents{'uploaded.photourl'})) {
2043: my $photo = $contents{'uploaded.photourl'};
2044: my ($subdir,$fname) =
2045: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2046: my $newphoto;
1.533 raeburn 2047: if ($fname ne '') {
2048: my $content = &Apache::lonnet::getfile($photo);
2049: unless ($content eq '-1') {
2050: $env{'form.'.$suffix.'.photourl'} = $content;
2051: $newphoto =
2052: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2053: delete($env{'form.'.$suffix.'.photourl'});
2054: }
2055: }
2056: if ($newphoto =~ m{^/uploaded/}) {
2057: $contents{'uploaded.photourl'} = $newphoto;
2058: }
2059: }
2060: $db_name =~ s{_\d*$ }{_$suffix}x;
2061: $result=&Apache::lonnet::put($db_name,\%contents,
2062: $coursedom,$coursenum);
2063: if ($result eq 'ok') {
2064: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2065: }
2066: }
2067: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2068: $lockerrorsref->{$prefix} =
1.533 raeburn 2069: '<div class="LC_error">'.
2070: &mt('There was a problem removing a lockfile.');
2071: if ($prefix eq 'smppg') {
1.560 raeburn 2072: $lockerrorsref->{$prefix} .=
1.559 raeburn 2073: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2074: } else {
1.565 bisitz 2075: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2076: }
1.560 raeburn 2077: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2078: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2079: '</div>';
1.533 raeburn 2080: }
2081: }
2082: } elsif ($url =~ m{/syllabus$}) {
2083: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2084: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2085: if (($dbref->{'cdom'} ne $coursedom) ||
2086: ($dbref->{'cnum'} ne $coursenum)) {
2087: my %contents=&Apache::lonnet::dump('syllabus',
2088: $dbref->{'cdom'},
2089: $dbref->{'cnum'});
2090: $result=&Apache::lonnet::put('syllabus',\%contents,
2091: $coursedom,$coursenum);
2092: }
2093: }
1.488 raeburn 2094: }
2095: }
1.533 raeburn 2096: return ($url,$result,$errtext);
1.488 raeburn 2097: }
2098:
1.597 raeburn 2099: sub copy_templated_files {
2100: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2101: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2102: my $srccontainer = 'sequence';
2103: if ($srcwaspage) {
2104: $srccontainer = 'page';
2105: }
2106: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2107: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2108: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2109: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2110: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2111: $template.'.problem';
2112: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2113: if ($template eq 'simpleproblem') {
2114: $srcprefix .= '.0.';
2115: my $weightprefix = $newprefix;
2116: $newprefix .= '.0.';
2117: my @simpleprobqtypes = qw(radio option string essay numerical);
2118: my $qtype=$srcparms{$srcprefix.'questiontype'};
2119: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2120: my %newdata;
2121: foreach my $type (@simpleprobqtypes) {
2122: if ($type eq $qtype) {
2123: $newdata{"$weightprefix.$type.weight"}=1;
2124: } else {
2125: $newdata{"$weightprefix.$type.weight"}=0;
2126: }
2127: }
2128: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2129: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2130: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2131: if ($qtype eq 'numerical') {
2132: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2133: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2134: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2135: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2136: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2137: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2138: unless (defined($maxfoils)) { $maxfoils=10; }
2139: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2140: if ($maxfoils<=0) { $maxfoils=10; }
2141: my $randomize=$srcparms{$srcprefix.'randomize'};
2142: unless (defined($randomize)) { $randomize='yes'; }
2143: unless ($randomize eq 'no') { $randomize='yes'; }
2144: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2145: $newdata{$newprefix.'randomize'} = $randomize;
2146: if ($qtype eq 'option') {
2147: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2148: }
2149: for (my $i=1; $i<=10; $i++) {
2150: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2151: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2152: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2153: }
2154:
2155: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2156: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2157: unless (defined($maxfoils)) { $maxfoils=10; }
2158: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2159: if ($maxfoils<=0) { $maxfoils=10; }
2160: my $randomize=$srcparms{$srcprefix.'randomize'};
2161: unless (defined($randomize)) { $randomize='yes'; }
2162: unless ($randomize eq 'no') { $randomize='yes'; }
2163: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2164: $newdata{$newprefix.'randomize'} = $randomize;
2165: if ($qtype eq 'option') {
2166: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2167: }
2168: for (my $i=1; $i<=10; $i++) {
2169: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2170: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2171: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2172: }
2173: } elsif ($qtype eq 'string') {
2174: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2175: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2176: }
2177: if (keys(%newdata)) {
2178: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2179: $coursenum);
2180: if ($putres eq 'ok') {
2181: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2182: }
2183: }
2184: }
2185: }
2186: }
2187:
1.329 droeschl 2188: sub uniqueness_check {
2189: my ($newurl) = @_;
2190: my $unique = 1;
2191: foreach my $res (@LONCAPA::map::order) {
2192: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2193: $url=&LONCAPA::map::qtescape($url);
2194: if ($newurl eq $url) {
2195: $unique = 0;
1.344 bisitz 2196: last;
1.329 droeschl 2197: }
2198: }
2199: return $unique;
2200: }
2201:
1.488 raeburn 2202: sub contained_map_check {
1.492 raeburn 2203: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2204: $allmaps) = @_;
1.488 raeburn 2205: my $content = &Apache::lonnet::getfile($url);
2206: unless ($content eq '-1') {
2207: my $parser = HTML::TokeParser->new(\$content);
2208: $parser->attr_encoded(1);
2209: while (my $token = $parser->get_token) {
2210: next if ($token->[0] ne 'S');
2211: if ($token->[1] eq 'resource') {
2212: next if ($token->[2]->{'type'} eq 'zombie');
2213: my $ressrc = $token->[2]->{'src'};
2214: if ($folder =~ /^supplemental/) {
2215: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2216: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2217: next;
2218: }
2219: }
1.492 raeburn 2220: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2221: if ($1 eq 'uploaded') {
2222: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2223: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2224: } else {
1.492 raeburn 2225: if ($allmaps->{$ressrc}) {
1.529 raeburn 2226: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2227: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2228: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2229: } else {
2230: $addedmaps->{$ressrc} = [$url];
2231: }
1.488 raeburn 2232: }
1.492 raeburn 2233: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2234: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2235: }
1.492 raeburn 2236: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2237: if ($folder =~ /^supplemental/) {
1.492 raeburn 2238: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2239: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2240: } else {
2241: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2242: }
1.488 raeburn 2243: }
2244: }
2245: }
2246: }
2247: return;
2248: }
2249:
2250: sub url_paste_fixups {
1.533 raeburn 2251: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2252: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2253: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2254: my $checktitle;
2255: if (($prefixchg) &&
1.492 raeburn 2256: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2257: $checktitle = 1;
2258: }
1.492 raeburn 2259: my $skip;
2260: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2261: my $mapid = $1.$2;
2262: if ($tomove->{$mapid}) {
2263: $skip = 1;
2264: }
2265: }
1.491 raeburn 2266: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2267: return if ($file eq '-1');
2268: my $parser = HTML::TokeParser->new(\$file);
2269: $parser->attr_encoded(1);
1.491 raeburn 2270: my $changed = 0;
1.488 raeburn 2271: while (my $token = $parser->get_token) {
2272: next if ($token->[0] ne 'S');
2273: if ($token->[1] eq 'resource') {
2274: my $ressrc = $token->[2]->{'src'};
2275: next if ($ressrc eq '');
1.491 raeburn 2276: my $id = $token->[2]->{'id'};
1.492 raeburn 2277: my $title = $token->[2]->{'title'};
1.491 raeburn 2278: if ($checktitle) {
2279: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2280: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2281: }
2282: }
1.488 raeburn 2283: next if ($token->[2]->{'type'} eq 'external');
2284: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2285: next if ($skip);
1.532 raeburn 2286: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2287: $changed = 1;
2288: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2289: my $srcdom = $1;
2290: my $srcnum = $2;
1.488 raeburn 2291: my $rem = $3;
1.492 raeburn 2292: my $newurl;
2293: my $mapname;
2294: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2295: my $prefix = $1;
2296: $mapname = $prefix.$2;
2297: if ($tomove->{$mapname}) {
1.533 raeburn 2298: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2299: $srcdom,$srcnum,$allmaps,$rewrites,
2300: $retitles,$copies,$dbcopies,$zombies,
2301: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2302: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2303: next;
2304: } else {
2305: ($newurl,my $error) =
2306: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2307: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2308: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2309: $newsubdir->{$ressrc} = $1;
2310: }
2311: if ($error) {
2312: next;
2313: }
2314: }
2315: }
2316: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2317: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2318:
1.488 raeburn 2319: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2320: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2321: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2322: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2323: $cnum,$srcdom,$srcnum,$allmaps,
2324: $rewrites,$retitles,$copies,$dbcopies,
2325: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2326: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2327: $mapmoves->{$ressrc} = 1;
2328: }
2329: $changed = 1;
1.488 raeburn 2330: } else {
1.532 raeburn 2331: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2332: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2333: $changed = 1;
1.488 raeburn 2334: }
2335: }
1.533 raeburn 2336: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2337: next if ($skip);
1.492 raeburn 2338: my $srcdom = $1;
2339: my $srcnum = $2;
2340: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2341: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2342: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2343: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2344: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2345: $changed = 1;
2346: }
2347: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2348: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2349: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2350: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2351: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2352: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2353: $changed = 1;
1.488 raeburn 2354: }
1.597 raeburn 2355: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2356: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2357: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2358: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2359: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2360: }
1.488 raeburn 2361: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2362: next if ($skip);
2363: my $srcdom = $1;
2364: my $srcnum = $2;
2365: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2366: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2367: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2368: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2369: $changed = 1;
1.488 raeburn 2370: }
2371: }
2372: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2373: next if ($skip);
1.488 raeburn 2374: my $to = $token->[2]->{'to'};
2375: if ($to ne '') {
2376: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2377: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2378: } else {
2379: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2380: }
2381: }
2382: }
2383: }
1.491 raeburn 2384: return $changed;
1.488 raeburn 2385: }
2386:
2387: sub apply_fixups {
1.529 raeburn 2388: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2389: $oldurl,$url,$caller) = @_;
2390: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2391: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2392: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2393: if (ref($updated) eq 'HASH') {
2394: if (ref($updated->{'rewrites'}) eq 'HASH') {
2395: %rewrites = %{$updated->{'rewrites'}};
2396: }
2397: if (ref($updated->{'zombies'}) eq 'HASH') {
2398: %zombies = %{$updated->{'zombies'}};
2399: }
2400: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2401: %removefrommap = %{$updated->{'removefrommap'}};
2402: }
2403: if (ref($updated->{'removeparam'}) eq 'HASH') {
2404: %removeparam = %{$updated->{'removeparam'}};
2405: }
2406: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2407: %dbcopies = %{$updated->{'dbcopies'}};
2408: }
2409: if (ref($updated->{'retitles'}) eq 'HASH') {
2410: %retitles = %{$updated->{'retitles'}};
2411: }
1.597 raeburn 2412: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2413: %resdatacopy = %{$updated->{'resdatacopy'}};
2414: }
1.529 raeburn 2415: }
2416: if (ref($info) eq 'HASH') {
2417: if (ref($info->{'newsubdir'}) eq 'HASH') {
2418: %newsubdir = %{$info->{'newsubdir'}};
2419: }
2420: if (ref($info->{'params'}) eq 'HASH') {
2421: %params = %{$info->{'params'}};
2422: }
2423: if (ref($info->{'before'}) eq 'HASH') {
2424: %before = %{$info->{'before'}};
2425: }
2426: if (ref($info->{'after'}) eq 'HASH') {
2427: %after = %{$info->{'after'}};
2428: }
2429: }
2430: if (ref($moves) eq 'HASH') {
2431: if (ref($moves->{'copies'}) eq 'HASH') {
2432: %copies = %{$moves->{'copies'}};
2433: }
2434: if (ref($moves->{'docmoves'}) eq 'HASH') {
2435: %docmoves = %{$moves->{'docmoves'}};
2436: }
2437: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2438: %mapmoves = %{$moves->{'mapmoves'}};
2439: }
2440: }
2441: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2442: my @allcopies;
1.529 raeburn 2443: if (exists($copies{$key})) {
2444: if (ref($copies{$key}) eq 'HASH') {
2445: my %added;
2446: foreach my $innerkey (keys(%{$copies{$key}})) {
2447: if (($innerkey ne '') && (!$added{$innerkey})) {
2448: push(@allcopies,$innerkey);
2449: $added{$innerkey} = 1;
2450: }
1.491 raeburn 2451: }
1.529 raeburn 2452: undef(%added);
1.491 raeburn 2453: }
2454: }
2455: if ($key eq $oldurl) {
1.529 raeburn 2456: if ((exists($docmoves{$key}))) {
1.532 raeburn 2457: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2458: push(@allcopies,$oldurl);
2459: }
2460: }
2461: }
2462: if (@allcopies > 0) {
2463: foreach my $item (@allcopies) {
1.492 raeburn 2464: my ($relpath,$oldsubdir,$fname) =
2465: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2466: if ($fname ne '') {
2467: my $content = &Apache::lonnet::getfile($item);
2468: unless ($content eq '-1') {
2469: my $storefn;
1.529 raeburn 2470: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2471: $storefn = $docmoves{$key};
1.491 raeburn 2472: } else {
2473: $storefn = $relpath;
2474: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2475: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2476: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2477: }
1.529 raeburn 2478: if ($newsubdir{$key}) {
1.532 raeburn 2479: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2480: }
2481: }
2482: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2483: my $copyurl =
2484: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2485: $storefn.$fname,$content);
2486: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2487: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2488: return &mt('Paste failed: an error occurred copying the file.');
2489: } elsif (ref($errors) eq 'HASH') {
2490: $errors->{$item} = 1;
1.489 raeburn 2491: }
2492: }
1.488 raeburn 2493: }
2494: }
1.491 raeburn 2495: }
2496: }
2497: }
1.529 raeburn 2498: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2499: my $storefn=$key;
2500: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2501: if ($prefixchg && $before{'map'} && $after{'map'}) {
2502: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2503: }
1.529 raeburn 2504: if ($newsubdir{$key}) {
2505: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2506: }
1.491 raeburn 2507: my $mapcontent = &Apache::lonnet::getfile($key);
2508: if ($mapcontent eq '-1') {
2509: if (ref($errors) eq 'HASH') {
2510: $errors->{$key} = 1;
2511: }
2512: } else {
2513: my $newmap =
2514: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2515: $mapcontent);
2516: if ($newmap eq '/adm/notfound.html') {
2517: if (ref($errors) eq 'HASH') {
2518: $errors->{$key} = 1;
1.489 raeburn 2519: }
1.488 raeburn 2520: }
2521: }
2522: }
1.491 raeburn 2523: my %updates;
2524: if ($is_map) {
1.529 raeburn 2525: if (ref($updated) eq 'HASH') {
2526: foreach my $type (keys(%{$updated})) {
2527: if (ref($updated->{$type}) eq 'HASH') {
2528: foreach my $key (keys(%{$updated->{$type}})) {
2529: $updates{$key} = 1;
2530: }
2531: }
2532: }
1.491 raeburn 2533: }
2534: foreach my $key (keys(%updates)) {
1.492 raeburn 2535: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2536: if (ref($rewrites{$key}) eq 'HASH') {
2537: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2538: }
1.529 raeburn 2539: if (ref($retitles{$key}) eq 'HASH') {
2540: %toretitle = %{$retitles{$key}};
1.491 raeburn 2541: }
1.529 raeburn 2542: if (ref($removefrommap{$key}) eq 'HASH') {
2543: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2544: }
1.529 raeburn 2545: if (ref($removeparam{$key}) eq 'HASH') {
2546: %remparam = %{$removeparam{$key}};
1.492 raeburn 2547: }
1.529 raeburn 2548: if (ref($zombies{$key}) eq 'HASH') {
2549: %zombie = %{$zombies{$key}};
1.491 raeburn 2550: }
1.529 raeburn 2551: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2552: foreach my $idx (keys(%{$dbcopies{$key}})) {
2553: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2554: my ($newurl,$result,$errtext) =
2555: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2556: if ($result eq 'ok') {
2557: $newdb{$idx} = $newurl;
2558: } elsif (ref($errors) eq 'HASH') {
2559: $errors->{$key} = 1;
2560: }
2561: push(@msgs,$errtext);
2562: }
1.491 raeburn 2563: }
2564: }
1.597 raeburn 2565: if (ref($resdatacopy{$key}) eq 'HASH') {
2566: if ($newsubdir{$key}) {
2567:
2568: }
2569: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2570: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2571: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2572: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2573: my $template = $1;
2574: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2575: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2576: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2577: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2578: my ($newmapname) = ($key =~ m{/([^/]+)$});
2579: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2580: my $srcmapinfo = $srcfolder.':'.$idx;
2581: if ($srccontainer eq 'page') {
2582: $srcmapinfo .= ':1';
2583: }
2584: if ($newsubdir{$key}) {
2585: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2586: }
2587: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2588: $cnum,$template,$idx,$newmapname);
2589: }
2590: }
2591: }
2592: }
2593: }
1.529 raeburn 2594: if (ref($params{$key}) eq 'HASH') {
2595: %currparam = %{$params{$key}};
1.492 raeburn 2596: }
2597: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2598: if ($fatal) {
1.533 raeburn 2599: return ($errtext);
1.492 raeburn 2600: }
2601: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2602: if (defined($LONCAPA::map::zombies[$i])) {
2603: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2604: if ($zombie{$i} eq $src) {
1.492 raeburn 2605: undef($LONCAPA::map::zombies[$i]);
2606: }
2607: }
2608: }
1.529 raeburn 2609: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2610: my $idx = $LONCAPA::map::order[$i];
2611: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2612: my $changed;
1.529 raeburn 2613: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2614: if ((exists($toremove{$idx})) &&
2615: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2616: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2617: if (ref($currparam{$idx}) eq 'ARRAY') {
2618: foreach my $name (@{$currparam{$idx}}) {
2619: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2620: }
2621: }
2622: next;
2623: }
2624: my $origsrc = $src;
1.532 raeburn 2625: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2626: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2627: $changed = 1;
1.491 raeburn 2628: }
1.492 raeburn 2629: }
1.532 raeburn 2630: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2631: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2632: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2633: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2634: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2635: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2636: } else {
1.529 raeburn 2637: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2638: }
1.491 raeburn 2639: }
1.532 raeburn 2640: if ($origsrc =~ /\.(page|sequence)$/) {
2641: if ($newsubdir{$origsrc}) {
1.529 raeburn 2642: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2643: }
1.532 raeburn 2644: } elsif ($newsubdir{$key}) {
2645: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2646: }
2647: }
1.492 raeburn 2648: $changed = 1;
1.533 raeburn 2649: } elsif ($newdb{$idx} ne '') {
2650: $src = $newdb{$idx};
1.492 raeburn 2651: $changed = 1;
2652: }
2653: if ($changed) {
1.538 raeburn 2654: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2655: }
2656: }
2657: }
2658: foreach my $idx (keys(%remparam)) {
2659: if (ref($remparam{$idx}) eq 'ARRAY') {
2660: foreach my $name (@{$remparam{$idx}}) {
2661: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2662: }
2663: }
2664: }
1.533 raeburn 2665: if (values(%lockerrors) > 0) {
2666: $lockmsg = join('<br />',values(%lockerrors));
2667: }
1.491 raeburn 2668: my $storefn;
2669: if ($key eq $oldurl) {
2670: $storefn = $url;
2671: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2672: } else {
2673: $storefn = $key;
2674: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2675: if ($prefixchg && $before{'map'} && $after{'map'}) {
2676: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2677: }
1.529 raeburn 2678: if ($newsubdir{$key}) {
2679: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2680: }
1.491 raeburn 2681: }
1.492 raeburn 2682: my $report;
2683: if ($folder !~ /^supplemental/) {
2684: $report = 1;
2685: }
1.527 raeburn 2686: (my $outtext,$errtext) =
1.492 raeburn 2687: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2688: if ($errtext) {
1.529 raeburn 2689: if ($caller eq 'paste') {
1.533 raeburn 2690: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2691: }
1.491 raeburn 2692: }
2693: }
2694: }
1.533 raeburn 2695: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2696: }
2697:
2698: sub copy_dependencies {
2699: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2700: my $content;
2701: if (ref($contentref)) {
2702: $content = $$contentref;
2703: } else {
2704: $content = &Apache::lonnet::getfile($item);
2705: }
2706: unless ($content eq '-1') {
2707: my $mm = new File::MMagic;
2708: my $mimetype = $mm->checktype_contents($content);
2709: if ($mimetype eq 'text/html') {
2710: my (%allfiles,%codebase,$state);
2711: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2712: if ($res eq 'ok') {
2713: my ($numexisting,$numpathchanges,$existing);
2714: (undef,$numexisting,$numpathchanges,$existing) =
2715: &Apache::loncommon::ask_for_embedded_content(
2716: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2717: {'error_on_invalid_names' => 1,
2718: 'ignore_remote_references' => 1,
2719: 'docs_url' => $item,
2720: 'context' => 'paste'});
2721: if ($numexisting > 0) {
2722: if (ref($existing) eq 'HASH') {
2723: foreach my $dep (keys(%{$existing})) {
2724: my $depfile = $dep;
2725: unless ($depfile =~ m{^\Q$relpath\E}) {
2726: $depfile = $relpath.$dep;
2727: }
2728: my $depcontent = &Apache::lonnet::getfile($depfile);
2729: unless ($depcontent eq '-1') {
2730: my $storedep = $dep;
2731: $storedep =~ s{^\Q$relpath\E}{};
2732: my $dep_url =
2733: &Apache::lonclonecourse::writefile(
2734: $env{'request.course.id'},
2735: $storefn.$storedep,$depcontent);
2736: if ($dep_url eq '/adm/notfound.html') {
2737: if (ref($errors) eq 'HASH') {
2738: $errors->{$depfile} = 1;
2739: }
2740: } else {
2741: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2742: }
2743: }
2744: }
1.488 raeburn 2745: }
2746: }
2747: }
2748: }
2749: }
2750: return;
2751: }
2752:
1.329 droeschl 2753: my %parameter_type = ( 'randompick' => 'int_pos',
2754: 'hiddenresource' => 'string_yesno',
2755: 'encrypturl' => 'string_yesno',
2756: 'randomorder' => 'string_yesno',);
2757: my $valid_parameters_re = join('|',keys(%parameter_type));
2758: # set parameters
2759: sub update_parameter {
1.537 raeburn 2760: if ($env{'form.changeparms'} eq 'all') {
2761: my (@allidx,@allmapidx,%allchecked,%currchecked);
2762: %allchecked = (
2763: 'hiddenresource' => {},
2764: 'encrypturl' => {},
2765: 'randompick' => {},
2766: 'randomorder' => {},
2767: );
2768: foreach my $which (keys(%allchecked)) {
2769: $env{'form.all'.$which} =~ s/,$//;
2770: if ($which eq 'randompick') {
2771: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2772: my ($res,$value) = split(/:/,$item);
2773: if ($value =~ /^\d+$/) {
2774: $allchecked{$which}{$res} = $value;
2775: }
2776: }
2777: } else {
1.539 raeburn 2778: if ($env{'form.all'.$which}) {
2779: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2780: }
1.537 raeburn 2781: }
2782: }
2783: my $haschanges = 0;
2784: foreach my $res (@LONCAPA::map::order) {
2785: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2786: $name=&LONCAPA::map::qtescape($name);
2787: $url=&LONCAPA::map::qtescape($url);
2788: next unless ($name && $url);
2789: my $is_map;
2790: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2791: $is_map = 1;
2792: }
2793: foreach my $which (keys(%allchecked)) {
2794: if (($which eq 'randompick' || $which eq 'randomorder')) {
2795: next if (!$is_map);
2796: }
2797: my $oldvalue = 0;
2798: my $newvalue = 0;
2799: if ($allchecked{$which}{$res}) {
2800: $newvalue = $allchecked{$which}{$res};
2801: }
2802: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2803: if ($which eq 'randompick') {
2804: if ($current =~ /^(\d+)$/) {
2805: $oldvalue = $1;
2806: }
2807: } else {
2808: if ($current =~ /^yes$/i) {
2809: $oldvalue = 1;
2810: }
2811: }
2812: if ($oldvalue ne $newvalue) {
2813: $haschanges = 1;
2814: if ($newvalue) {
2815: my $storeval = 'yes';
2816: if ($which eq 'randompick') {
2817: $storeval = $newvalue;
2818: }
2819: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2820: $storeval,
2821: $parameter_type{$which});
2822: &remember_parms($res,$which,'set',$storeval);
2823: } elsif ($oldvalue) {
2824: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2825: &remember_parms($res,$which,'del');
2826: }
2827: }
2828: }
2829: }
2830: return $haschanges;
2831: } else {
1.588 raeburn 2832: my $haschanges = 0;
2833: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2834:
1.537 raeburn 2835: my $which = $env{'form.changeparms'};
2836: my $idx = $env{'form.setparms'};
1.588 raeburn 2837: my $oldvalue = 0;
2838: my $newvalue = 0;
2839: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2840: if ($which eq 'randompick') {
2841: if ($current =~ /^(\d+)$/) {
2842: $oldvalue = $1;
2843: }
2844: } elsif ($current =~ /^yes$/i) {
2845: $oldvalue = 1;
2846: }
1.537 raeburn 2847: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2848: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2849: : 1;
2850: }
2851: if ($oldvalue ne $newvalue) {
2852: $haschanges = 1;
2853: if ($newvalue) {
2854: my $storeval = 'yes';
2855: if ($which eq 'randompick') {
2856: $storeval = $newvalue;
2857: }
2858: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2859: $parameter_type{$which});
2860: &remember_parms($idx,$which,'set',$storeval);
2861: } else {
2862: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2863: &remember_parms($idx,$which,'del');
2864: }
1.537 raeburn 2865: }
1.588 raeburn 2866: return $haschanges;
1.329 droeschl 2867: }
2868: }
2869:
2870: sub handle_edit_cmd {
2871: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2872: if ($env{'form.cmd'} eq '') {
2873: return 0;
2874: }
1.329 droeschl 2875: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2876:
2877: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2878: my ($title, $url, @rrest) = split(':', $ratstr);
2879:
1.538 raeburn 2880: if ($cmd eq 'remove') {
1.329 droeschl 2881: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2882: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2883: &Apache::lonnet::removeuploadedurl($url);
2884: } else {
2885: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2886: }
2887: splice(@LONCAPA::map::order, $idx, 1);
2888:
2889: } elsif ($cmd eq 'cut') {
2890: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2891: splice(@LONCAPA::map::order, $idx, 1);
2892:
1.344 bisitz 2893: } elsif ($cmd eq 'up'
1.329 droeschl 2894: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2895: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2896:
2897: } elsif ($cmd eq 'down'
2898: && defined($LONCAPA::map::order[$idx+1])) {
2899: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2900:
2901: } elsif ($cmd eq 'rename') {
2902: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2903: if ($comment=~/\S/) {
2904: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2905: $comment.':'.join(':', $url, @rrest);
2906: }
2907: # Devalidate title cache
2908: my $renamed_url=&LONCAPA::map::qtescape($url);
2909: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 2910:
1.329 droeschl 2911: } else {
2912: return 0;
2913: }
2914: return 1;
2915: }
2916:
2917: sub editor {
1.458 raeburn 2918: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.598 raeburn 2919: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref)=@_;
1.519 raeburn 2920: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 2921: if ($allowed) {
1.519 raeburn 2922: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2923: $is_random_order,$container) =
1.510 raeburn 2924: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2925: $r->print($breadcrumbtrail);
1.519 raeburn 2926: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2927: $container = 'page';
2928: } else {
2929: $container = 'sequence';
1.510 raeburn 2930: }
1.484 raeburn 2931:
1.525 raeburn 2932: my $jumpto;
2933:
2934: unless ($supplementalflag) {
1.546 raeburn 2935: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 2936: }
1.484 raeburn 2937:
2938: unless ($allowed) {
2939: $randompick = -1;
2940: }
2941:
1.329 droeschl 2942: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2943: $folder.'.'.$container);
2944: return $errtext if ($fatal);
2945:
2946: if ($#LONCAPA::map::order<1) {
2947: my $idx=&LONCAPA::map::getresidx();
2948: if ($idx<=0) { $idx=1; }
2949: $LONCAPA::map::order[0]=$idx;
2950: $LONCAPA::map::resources[$idx]='';
2951: }
1.364 bisitz 2952:
1.329 droeschl 2953: # ------------------------------------------------------------ Process commands
2954:
2955: # ---------------- if they are for this folder and user allowed to make changes
2956: if (($allowed) && ($env{'form.folder'} eq $folder)) {
2957: # set parameters and change order
2958: &snapshotbefore();
2959:
2960: if (&update_parameter()) {
1.588 raeburn 2961: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2962: return $errtext if ($fatal);
2963: }
2964:
2965: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2966: # change order
2967: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2968: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2969:
2970: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2971: return $errtext if ($fatal);
2972: }
1.364 bisitz 2973:
1.329 droeschl 2974: if ($env{'form.pastemarked'}) {
1.491 raeburn 2975: my %paste_errors;
1.533 raeburn 2976: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 2977: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2978: \%paste_errors);
1.541 raeburn 2979: if (ref($pastemsgarray) eq 'ARRAY') {
2980: if (@{$pastemsgarray} > 0) {
2981: $r->print('<p class="LC_info">'.
2982: join('<br />',@{$pastemsgarray}).
1.533 raeburn 2983: '</p>');
2984: }
1.541 raeburn 2985: }
2986: if ($lockerror) {
2987: $r->print('<p class="LC_error">'.
2988: $lockerror.
2989: '</p>');
2990: }
2991: if ($save_error ne '') {
2992: return $save_error;
2993: }
2994: if ($paste_res) {
2995: my %errortext = &Apache::lonlocal::texthash (
2996: fail => 'Storage of folder contents failed',
2997: failread => 'Reading folder contents failed',
2998: failstore => 'Storage of folder contents failed',
2999: );
3000: if ($errortext{$paste_res}) {
3001: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3002: }
1.329 droeschl 3003: }
1.491 raeburn 3004: if (keys(%paste_errors) > 0) {
1.538 raeburn 3005: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3006: &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".
3007: '<ul>'."\n");
3008: foreach my $key (sort(keys(%paste_errors))) {
3009: $r->print('<li>'.$key.'</li>'."\n");
3010: }
3011: $r->print('</ul></p>'."\n");
3012: }
1.538 raeburn 3013: } elsif ($env{'form.clearmarked'}) {
3014: my $output = &do_buffer_empty();
3015: if ($output) {
3016: $r->print('<p class="LC_info">'.$output.'</p>');
3017: }
3018: }
1.329 droeschl 3019:
3020: $r->print($upload_output);
3021:
1.538 raeburn 3022: # Rename, cut, copy or remove a single resource
1.602 raeburn 3023: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3024: my $contentchg;
1.592 raeburn 3025: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3026: $contentchg = 1;
3027: }
3028: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3029: return $errtext if ($fatal);
3030: }
1.538 raeburn 3031:
3032: # Cut, copy and/or remove multiple resources
3033: if ($env{'form.multichange'}) {
3034: my %allchecked = (
3035: cut => {},
3036: remove => {},
3037: );
3038: my $needsupdate;
3039: foreach my $which (keys(%allchecked)) {
3040: $env{'form.multi'.$which} =~ s/,$//;
3041: if ($env{'form.multi'.$which}) {
3042: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3043: if (ref($allchecked{$which}) eq 'HASH') {
3044: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3045: }
3046: }
3047: }
3048: if ($needsupdate) {
3049: my $haschanges = 0;
3050: my %curr_groups = &Apache::longroup::coursegroups();
3051: my $total = scalar(@LONCAPA::map::order) - 1;
3052: for (my $i=$total; $i>=0; $i--) {
3053: my $res = $LONCAPA::map::order[$i];
3054: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3055: $name=&LONCAPA::map::qtescape($name);
3056: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3057: next unless $url;
1.538 raeburn 3058: my %denied =
3059: &action_restrictions($coursenum,$coursedom,$url,
3060: $env{'form.folderpath'},\%curr_groups);
3061: foreach my $which (keys(%allchecked)) {
3062: next if ($denied{$which});
3063: next unless ($allchecked{$which}{$res});
3064: if ($which eq 'remove') {
3065: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3066: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3067: &Apache::lonnet::removeuploadedurl($url);
3068: } else {
3069: &LONCAPA::map::makezombie($res);
3070: }
3071: splice(@LONCAPA::map::order,$i,1);
3072: $haschanges ++;
3073: } elsif ($which eq 'cut') {
3074: &LONCAPA::map::makezombie($res);
3075: splice(@LONCAPA::map::order,$i,1);
3076: $haschanges ++;
3077: }
3078: }
3079: }
3080: if ($haschanges) {
3081: ($errtext,$fatal) =
3082: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3083: return $errtext if ($fatal);
3084: }
3085: }
3086: }
3087:
1.329 droeschl 3088: # Group import/search
3089: if ($env{'form.importdetail'}) {
3090: my @imports;
3091: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3092: if (defined($item)) {
3093: my ($name,$url,$residx)=
1.533 raeburn 3094: map { &unescape($_); } split(/\=/,$item);
3095: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3096: my ($suffix,$errortxt,$locknotfreed) =
3097: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3098: if ($locknotfreed) {
3099: $r->print($locknotfreed);
3100: }
3101: if ($suffix) {
3102: $url =~ s/_new\./_$suffix./;
3103: } else {
3104: return $errortxt;
3105: }
1.533 raeburn 3106: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3107: my $type = $1;
3108: my ($suffix,$errortxt,$locknotfreed) =
3109: &new_timebased_suffix($coursedom,$coursenum,$type);
3110: if ($locknotfreed) {
3111: $r->print($locknotfreed);
3112: }
3113: if ($suffix) {
3114: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3115: } else {
3116: return $errortxt;
3117: }
1.598 raeburn 3118: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3119: my ($suffix,$errortxt,$locknotfreed) =
3120: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3121: if ($locknotfreed) {
3122: $r->print($locknotfreed);
3123: }
3124: if ($suffix) {
3125: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3126: } else {
3127: return $errortxt;
3128: }
1.534 raeburn 3129: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3130: if ($supplementalflag) {
3131: next unless ($1 eq 'supplemental');
3132: if ($folder eq 'supplemental') {
3133: next unless ($2 eq 'default');
3134: } else {
3135: next unless ($folder eq 'supplemental_'.$2);
3136: }
3137: } else {
3138: next unless ($1 eq 'docs');
3139: if ($folder eq 'default') {
3140: next unless ($2 eq 'default');
3141: } else {
3142: next unless ($folder eq 'default_'.$2);
3143: }
3144: }
1.504 raeburn 3145: }
1.329 droeschl 3146: push(@imports, [$name, $url, $residx]);
3147: }
3148: }
1.530 raeburn 3149: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3150: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3151: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3152: return $errtext if ($fatal);
1.529 raeburn 3153: if ($fixuperrors) {
3154: $r->print($fixuperrors);
3155: }
1.329 droeschl 3156: }
3157: # Loading a complete map
3158: if ($env{'form.loadmap'}) {
3159: if ($env{'form.importmap'}=~/\w/) {
3160: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3161: my ($title,$url,$ext,$type)=split(/\:/,$res);
3162: my $idx=&LONCAPA::map::getresidx($url);
3163: $LONCAPA::map::resources[$idx]=$res;
3164: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3165: }
3166: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3167: $folder.'.'.$container,1);
1.329 droeschl 3168: return $errtext if ($fatal);
3169: } else {
3170: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3171:
1.329 droeschl 3172: }
3173: }
3174: &log_differences($plain);
3175: }
3176: # ---------------------------------------------------------------- End commands
3177: # ---------------------------------------------------------------- Print screen
3178: my $idx=0;
3179: my $shown=0;
3180: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3181: $r->print('<div class="LC_Box">'.
1.432 raeburn 3182: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3183: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3184: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3185: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3186: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3187: '</ol>');
1.381 bisitz 3188: if ($randompick>=0) {
3189: $r->print('<p class="LC_warning">'
3190: .&mt('Caution: this folder is set to randomly pick a subset'
3191: .' of resources. Adding or removing resources from this'
3192: .' folder will change the set of resources that the'
3193: .' students see, resulting in spurious or missing credit'
3194: .' for completed problems, not limited to ones you'
3195: .' modify. Do not modify the contents of this folder if'
3196: .' it is in active student use.')
3197: .'</p>'
3198: );
3199: }
3200: if ($is_random_order) {
3201: $r->print('<p class="LC_warning">'
3202: .&mt('Caution: this folder is set to randomly order its'
3203: .' contents. Adding or removing resources from this folder'
3204: .' will change the order of resources shown.')
3205: .'</p>'
3206: );
3207: }
3208: $r->print('</div>');
1.364 bisitz 3209: }
1.381 bisitz 3210:
1.538 raeburn 3211: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3212: %filters = (
1.543 raeburn 3213: canremove => [],
3214: cancut => [],
3215: cancopy => [],
3216: hiddenresource => [],
3217: encrypturl => [],
3218: randomorder => [],
3219: randompick => [],
1.538 raeburn 3220: );
3221: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3222: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3223: foreach my $res (@LONCAPA::map::order) {
3224: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3225: $name=&LONCAPA::map::qtescape($name);
3226: $url=&LONCAPA::map::qtescape($url);
3227: unless ($name) { $name=(split(/\//,$url))[-1]; }
3228: unless ($name) { $idx++; next; }
1.537 raeburn 3229: push(@allidx,$res);
3230: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3231: push(@allmapidx,$res);
3232: }
1.381 bisitz 3233: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3234: $coursenum,$coursedom,$crstype,
1.538 raeburn 3235: $pathitem,$supplementalflag,$container,
1.598 raeburn 3236: \%filters,\%curr_groups,$ltitoolsref);
1.381 bisitz 3237: $idx++;
3238: $shown++;
1.329 droeschl 3239: }
1.424 onken 3240: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3241:
1.538 raeburn 3242: my $need_save;
1.510 raeburn 3243: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3244: my $toolslink;
3245: if ($allowed || &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
3246: $toolslink = '<table><tr><td>'
1.520 raeburn 3247: .&Apache::loncommon::help_open_menu('Navigation Screen',
3248: 'Navigation_Screen',undef,'RAT')
3249: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3250: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3251: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3252: .'id="LC_content_toolbar_edittoplevel" '
3253: .'class="LC_toolbarItem" '
3254: .'title="'.&mt('Supplemental Content Editor').'">'
3255: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3256: }
1.510 raeburn 3257: if ($shown) {
3258: if ($allowed) {
3259: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3260: .&Apache::loncommon::start_data_table(undef,'contentlist')
3261: .&Apache::loncommon::start_data_table_header_row()
3262: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3263: .'<th colspan="2">'.&mt('Actions').'</th>'
3264: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3265: if ($folder !~ /^supplemental/) {
3266: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3267: }
1.537 raeburn 3268: $to_show .= &Apache::loncommon::end_data_table_header_row();
3269: if ($folder !~ /^supplemental/) {
1.538 raeburn 3270: $lists{'canhide'} = join(',',@allidx);
3271: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3272: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3273: 'randomorder','randompick');
3274: foreach my $item (@possfilters) {
1.538 raeburn 3275: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3276: if (@{$filters{$item}} > 0) {
3277: $lists{$item} = join(',',@{$filters{$item}});
3278: }
1.538 raeburn 3279: }
3280: }
1.537 raeburn 3281: if (@allidx > 0) {
3282: my $path;
3283: if ($env{'form.folderpath'}) {
3284: $path =
3285: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3286: }
1.538 raeburn 3287: if (@allidx > 1) {
3288: $to_show .=
3289: &Apache::loncommon::continue_data_table_row().
3290: '<td colspan="2"> </td>'.
3291: '<td>'.
3292: &multiple_check_form('actions',\%lists).
3293: '</td>'.
3294: '<td> </td>'.
3295: '<td> </td>'.
3296: '<td colspan="4">'.
3297: &multiple_check_form('settings',\%lists).
3298: '</td>'.
3299: &Apache::loncommon::end_data_table_row();
3300: $need_save = 1;
3301: }
1.537 raeburn 3302: }
3303: }
3304: $to_show .= $output.' '
1.510 raeburn 3305: .&Apache::loncommon::end_data_table()
3306: .'<br style="line-height:2px;" />'
3307: .&Apache::loncommon::end_scrollbox();
3308: } else {
1.520 raeburn 3309: $to_show .= $toolslink
1.510 raeburn 3310: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3311: .$output.' '
3312: .&Apache::loncommon::end_data_table();
1.393 raeburn 3313: }
1.510 raeburn 3314: } else {
1.520 raeburn 3315: if (!$allowed) {
3316: $to_show .= $toolslink;
3317: }
1.510 raeburn 3318: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3319: .'<div class="LC_info" id="contentlist">'
1.550 raeburn 3320: .&mt('Currently empty')
1.510 raeburn 3321: .'</div>'
3322: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3323: }
3324: } else {
1.510 raeburn 3325: if ($shown) {
3326: $to_show = '<div>'
3327: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3328: .$output
3329: .&Apache::loncommon::end_data_table()
3330: .'</div>';
3331: } else {
3332: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3333: .&mt('Currently empty')
1.510 raeburn 3334: .'</div>'
3335: }
1.458 raeburn 3336: }
3337: my $tid = 1;
3338: if ($supplementalflag) {
3339: $tid = 2;
1.329 droeschl 3340: }
3341: if ($allowed) {
1.484 raeburn 3342: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3343: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3344: $jumpto,$readfile,$need_save,"$folder.$container"));
1.492 raeburn 3345: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 3346: } else {
3347: $r->print($to_show);
1.329 droeschl 3348: }
3349: return;
3350: }
3351:
1.538 raeburn 3352: sub multiple_check_form {
3353: my ($caller,$listsref) = @_;
3354: return unless (ref($listsref) eq 'HASH');
3355: my $output =
3356: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3357: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3358: '<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>'.
3359: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3360: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3361: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3362: if ($caller eq 'settings') {
3363: $output .=
3364: '<table><tr>'.
3365: '<td class="LC_docs_entry_parameter">'.
3366: '<span class="LC_nobreak"><label>'.
3367: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').
3368: '</label></span></td>'.
3369: '<td class="LC_docs_entry_parameter">'.
3370: '<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="" />'.
3371: '</span></td>'.
3372: '</tr>'."\n".
3373: '<tr>'.
3374: '<td class="LC_docs_entry_parameter">'.
3375: '<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').
3376: '</label></span>'.
3377: '</td></tr></table>'."\n";
3378: } else {
3379: $output .=
3380: '<table><tr>'.
3381: '<td class="LC_docs_entry_parameter">'.
3382: '<span class="LC_nobreak LC_docs_remove">'.
3383: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')" />'.&mt('Remove').
3384: '</label></span></td>'.
3385: '<td class="LC_docs_entry_parameter">'.
3386: '<span class="LC_nobreak LC_docs_cut">'.
3387: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');" />'.&mt('Cut').
3388: '</label></span></td>'."\n".
3389: '<td class="LC_docs_entry_parameter">'.
3390: '<span class="LC_nobreak LC_docs_copy">'.
3391: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')" />'.&mt('Copy').
3392: '</label></span></td>'.
3393: '</tr></table>'."\n";
3394: }
3395: $output .=
3396: '</fieldset>'.
3397: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3398: if ($caller eq 'settings') {
3399: $output .=
1.543 raeburn 3400: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3401: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3402: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3403: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3404: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3405: } elsif ($caller eq 'actions') {
3406: $output .=
3407: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3408: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3409: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3410: }
3411: $output .=
3412: '</form>'.
3413: '</div>';
3414: return $output;
3415: }
3416:
1.329 droeschl 3417: sub process_file_upload {
1.552 raeburn 3418: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3419: # upload a file, if present
1.552 raeburn 3420: my $filesize = length($env{'form.uploaddoc'});
3421: if (!$filesize) {
3422: $$upload_output = '<div class="LC_error">'.
3423: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3424: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3425: $filesize).'<br />'.
3426: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3427: '</div>';
3428: return;
3429: }
3430: my $quotatype = 'unofficial';
3431: if ($crstype eq 'Community') {
1.601 raeburn 3432: $quotatype = 'community';
3433: } elsif ($crstype eq 'Placement') {
3434: $quotatype = 'placement';
1.580 raeburn 3435: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3436: $quotatype = 'official';
1.573 raeburn 3437: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3438: $quotatype = 'textbook';
1.552 raeburn 3439: }
3440: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3441: $filesize = int($filesize/1000); #expressed in kb
3442: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3443: $env{'form.uploaddoc.filename'},$filesize,
3444: 'upload',$quotatype);
1.552 raeburn 3445: return if ($$upload_output);
3446: }
1.440 raeburn 3447: my ($parseaction,$showupload,$nextphase,$mimetype);
3448: if ($env{'form.parserflag'}) {
1.329 droeschl 3449: $parseaction = 'parse';
3450: }
3451: my $folder=$env{'form.folder'};
3452: if ($folder eq '') {
3453: $folder='default';
3454: }
3455: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3456: my $errtext='';
3457: my $fatal=0;
3458: my $container='sequence';
1.519 raeburn 3459: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3460: $container='page';
3461: }
3462: ($errtext,$fatal)=
1.534 raeburn 3463: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3464: if ($#LONCAPA::map::order<1) {
3465: $LONCAPA::map::order[0]=1;
3466: $LONCAPA::map::resources[1]='';
3467: }
3468: my $destination = 'docs/';
3469: if ($folder =~ /^supplemental/) {
3470: $destination = 'supplemental/';
3471: }
3472: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3473: $destination .= 'default/';
3474: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3475: $destination .= $2.'/';
3476: }
1.534 raeburn 3477: if ($fatal) {
3478: $$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>';
3479: return;
3480: }
1.440 raeburn 3481: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3482: my $newidx=&LONCAPA::map::getresidx();
3483: $destination .= $newidx;
1.439 raeburn 3484: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3485: $parseaction,$allfiles,
1.440 raeburn 3486: $codebase,undef,undef,undef,undef,
3487: undef,undef,\$mimetype);
3488: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3489: my $stored = $1;
3490: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3491: $stored.'</span>').'</p>';
3492: } else {
3493: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3494:
1.457 raeburn 3495: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3496: return;
3497: }
1.329 droeschl 3498: my $ext='false';
3499: if ($url=~m{^http://}) { $ext='true'; }
3500: $url = &LONCAPA::map::qtunescape($url);
3501: my $comment=$env{'form.comment'};
3502: $comment = &LONCAPA::map::qtunescape($comment);
3503: if ($folder=~/^supplemental/) {
3504: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3505: $env{'user.domain'}.'___&&&___'.$comment;
3506: }
3507:
3508: $LONCAPA::map::resources[$newidx]=
3509: $comment.':'.$url.':'.$ext.':normal:res';
3510: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3511: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3512: $folder.'.'.$container,1);
1.329 droeschl 3513: if ($fatal) {
1.457 raeburn 3514: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3515: return;
1.329 droeschl 3516: } else {
1.440 raeburn 3517: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3518: $$upload_output = $showupload;
1.384 raeburn 3519: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3520: if ($total_embedded > 0) {
1.440 raeburn 3521: my $uploadphase = 'upload_embedded';
3522: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3523: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3524: my ($embedded,$num) =
3525: &Apache::loncommon::ask_for_embedded_content(
3526: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3527: if ($embedded) {
3528: if ($num) {
3529: $$upload_output .=
3530: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3531: $nextphase = $uploadphase;
3532: } else {
3533: $$upload_output .= $embedded;
3534: }
3535: } else {
3536: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3537: }
1.329 droeschl 3538: } else {
1.440 raeburn 3539: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3540: }
1.457 raeburn 3541: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3542: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3543: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3544: $nextphase = 'decompress_uploaded';
3545: my $position = scalar(@LONCAPA::map::order)-1;
3546: my $noextract = &return_to_editor();
3547: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3548: my %archiveitems = (
3549: folderpath => $env{'form.folderpath'},
3550: cmd => $nextphase,
3551: newidx => $newidx,
3552: position => $position,
3553: phase => $nextphase,
1.477 raeburn 3554: comment => $comment,
1.480 raeburn 3555: );
3556: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3557: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3558: $$upload_output = $showupload.
3559: &Apache::loncommon::decompress_form($mimetype,
3560: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3561: \%archiveitems,\@current);
1.329 droeschl 3562: }
3563: }
3564: }
1.440 raeburn 3565: return $nextphase;
1.329 droeschl 3566: }
3567:
1.480 raeburn 3568: sub get_dir_list {
3569: my ($url,$coursenum,$coursedom,$newidx) = @_;
3570: my ($destination,$dir_root) = &embedded_destination();
3571: my ($dirlistref,$listerror) =
3572: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3573: my @dir_lines;
3574: my $dirptr=16384;
3575: if (ref($dirlistref) eq 'ARRAY') {
3576: foreach my $dir_line (sort
3577: {
3578: my ($afile)=split('&',$a,2);
3579: my ($bfile)=split('&',$b,2);
3580: return (lc($afile) cmp lc($bfile));
3581: } (@{$dirlistref})) {
3582: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3583: $filename =~ s/\s+$//;
3584: next if ($filename =~ /^\.\.?$/);
3585: my $isdir = 0;
3586: if ($dirptr&$testdir) {
3587: $isdir = 1;
3588: }
3589: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3590: }
3591: }
3592: return @dir_lines;
3593: }
3594:
1.329 droeschl 3595: sub is_supplemental_title {
3596: my ($title) = @_;
3597: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3598: }
3599:
3600: # --------------------------------------------------------------- An entry line
3601:
3602: sub entryline {
1.501 raeburn 3603: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3604: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3605: $ltitoolsref)=@_;
1.581 raeburn 3606: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3607: if (&is_supplemental_title($title)) {
1.488 raeburn 3608: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3609: } else {
3610: $title=&HTML::Entities::encode($title,'"<>&\'');
3611: $renametitle=$title;
3612: $foldertitle=$title;
3613: }
3614:
3615: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3616:
1.329 droeschl 3617: $renametitle=~s/\\/\\\\/g;
3618: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3619: $renametitle=~s/"/%22/g;
1.581 raeburn 3620: $renametitle=~s/ /%20/g;
3621: $oldtitle = $renametitle;
1.576 raeburn 3622: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3623: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3624: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3625: # Edit commands
1.535 raeburn 3626: my ($esc_path, $path, $symb);
1.329 droeschl 3627: if ($env{'form.folderpath'}) {
3628: $esc_path=&escape($env{'form.folderpath'});
3629: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3630: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3631: }
1.505 raeburn 3632: my $isexternal;
1.510 raeburn 3633: if ($residx) {
1.501 raeburn 3634: my $currurl = $url;
3635: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3636: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3637: $isexternal = 1;
3638: }
1.510 raeburn 3639: if (!$supplementalflag) {
3640: my $path = 'uploaded/'.
3641: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3642: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3643: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3644: $residx,
3645: &Apache::lonnet::declutter($currurl));
3646: }
1.501 raeburn 3647: }
1.538 raeburn 3648: my ($renamelink,%lt,$ishash);
3649: if (ref($filtersref) eq 'HASH') {
3650: $ishash = 1;
3651: }
3652:
1.329 droeschl 3653: if ($allowed) {
1.538 raeburn 3654: $form_start = '
3655: <form action="/adm/coursedocs" method="post">
3656: ';
3657: $form_common=(<<END);
3658: <input type="hidden" name="folderpath" value="$path" />
3659: <input type="hidden" name="symb" value="$symb" />
3660: END
3661: $form_param=(<<END);
3662: <input type="hidden" name="setparms" value="$orderidx" />
3663: <input type="hidden" name="changeparms" value="0" />
3664: END
3665: $form_end = '</form>';
3666:
1.329 droeschl 3667: my $incindex=$index+1;
3668: my $selectbox='';
1.471 raeburn 3669: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3670: ((split(/\:/,
1.344 bisitz 3671: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3672: ne '') &&
1.329 droeschl 3673: ((split(/\:/,
1.344 bisitz 3674: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3675: ne '')) {
3676: $selectbox=
3677: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 3678: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 3679: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3680: if ($i==$incindex) {
1.358 bisitz 3681: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3682: } else {
3683: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3684: }
3685: }
3686: $selectbox.='</select>';
3687: }
1.501 raeburn 3688: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3689: 'up' => 'Move Up',
3690: 'dw' => 'Move Down',
3691: 'rm' => 'Remove',
3692: 'ct' => 'Cut',
3693: 'rn' => 'Rename',
1.501 raeburn 3694: 'cp' => 'Copy',
3695: 'ex' => 'External Resource',
1.598 raeburn 3696: 'et' => 'External Tool',
1.501 raeburn 3697: 'ed' => 'Edit',
3698: 'pr' => 'Preview',
3699: 'sv' => 'Save',
3700: 'ul' => 'URL',
3701: 'ti' => 'Title',
3702: );
1.538 raeburn 3703: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3704: $env{'form.folderpath'},
3705: $currgroups);
1.517 raeburn 3706: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3707: my $skip_confirm = 0;
1.603 ! raeburn 3708: my $confirm_removal = 0;
1.329 droeschl 3709: if ( $folder =~ /^supplemental/
3710: || ($url =~ m{( /smppg$
3711: |/syllabus$
3712: |/aboutme$
3713: |/navmaps$
3714: |/bulletinboard$
1.598 raeburn 3715: |/exttools?$
1.505 raeburn 3716: |\.html$)}x)
3717: || $isexternal) {
1.329 droeschl 3718: $skip_confirm = 1;
3719: }
1.603 ! raeburn 3720: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
! 3721: ($url!~/$LONCAPA::assess_page_seq_re/)) {
! 3722: $confirm_removal = 1;
! 3723: }
1.329 droeschl 3724:
1.538 raeburn 3725: if ($denied{'copy'}) {
1.543 raeburn 3726: $copylink=(<<ENDCOPY)
1.507 raeburn 3727: <span style="visibility: hidden;">$lt{'cp'}</span>
3728: ENDCOPY
3729: } else {
1.538 raeburn 3730: my $formname = 'edit_copy_'.$orderidx;
3731: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3732: $copylink=(<<ENDCOPY);
1.538 raeburn 3733: <form name="$formname" method="post" action="/adm/coursedocs">
3734: $form_common
1.540 raeburn 3735: <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 3736: $form_end
1.329 droeschl 3737: ENDCOPY
1.538 raeburn 3738: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3739: push(@{$filtersref->{'cancopy'}},$orderidx);
3740: }
1.329 droeschl 3741: }
1.538 raeburn 3742: if ($denied{'cut'}) {
1.507 raeburn 3743: $cutlink=(<<ENDCUT);
3744: <span style="visibility: hidden;">$lt{'ct'}</span>
3745: ENDCUT
3746: } else {
1.538 raeburn 3747: my $formname = 'edit_cut_'.$orderidx;
3748: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3749: $cutlink=(<<ENDCUT);
1.538 raeburn 3750: <form name="$formname" method="post" action="/adm/coursedocs">
3751: $form_common
1.542 raeburn 3752: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.540 raeburn 3753: <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 3754: $form_end
1.329 droeschl 3755: ENDCUT
1.538 raeburn 3756: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3757: push(@{$filtersref->{'cancut'}},$orderidx);
3758: }
1.329 droeschl 3759: }
1.538 raeburn 3760: if ($denied{'remove'}) {
1.507 raeburn 3761: $removelink=(<<ENDREM);
3762: <span style="visibility: hidden;">$lt{'rm'}</a>
3763: ENDREM
3764: } else {
1.538 raeburn 3765: my $formname = 'edit_remove_'.$orderidx;
1.603 ! raeburn 3766: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3767: $removelink=(<<ENDREM);
1.538 raeburn 3768: <form name="$formname" method="post" action="/adm/coursedocs">
3769: $form_common
1.542 raeburn 3770: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 ! raeburn 3771: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.540 raeburn 3772: <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 3773: $form_end
1.497 raeburn 3774: ENDREM
1.538 raeburn 3775: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3776: push(@{$filtersref->{'canremove'}},$orderidx);
3777: }
1.497 raeburn 3778: }
1.551 raeburn 3779: $renamelink=(<<ENDREN);
1.581 raeburn 3780: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3781: ENDREN
1.329 droeschl 3782: $line.=(<<END);
3783: <td>
1.379 bisitz 3784: <div class="LC_docs_entry_move">
1.535 raeburn 3785: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3786: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3787: </a>
3788: </div>
3789: <div class="LC_docs_entry_move">
1.536 raeburn 3790: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3791: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3792: </a>
3793: </div>
1.329 droeschl 3794: </td>
3795: <td>
3796: $form_start
1.538 raeburn 3797: $form_param
1.478 raeburn 3798: $form_common
1.329 droeschl 3799: $selectbox
3800: $form_end
3801: </td>
1.540 raeburn 3802: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3803: $removelink
1.329 droeschl 3804: $cutlink
3805: $copylink
3806: </td>
3807: END
3808: }
3809: # Figure out what kind of a resource this is
3810: my ($extension)=($url=~/\.(\w+)$/);
3811: my $uploaded=($url=~/^\/*uploaded\//);
3812: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3813: my $isfolder;
3814: my $ispage;
3815: my $containerarg;
1.329 droeschl 3816: if ($uploaded) {
1.472 raeburn 3817: if (($extension eq 'sequence') || ($extension eq 'page')) {
3818: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3819: $containerarg = $1;
1.472 raeburn 3820: if ($extension eq 'sequence') {
3821: $icon=$iconpath.'navmap.folder.closed.gif';
3822: $isfolder=1;
3823: } else {
3824: $icon=$iconpath.'page.gif';
3825: $ispage=1;
3826: }
3827: if ($allowed) {
3828: $url='/adm/coursedocs?';
3829: } else {
3830: $url='/adm/supplemental?';
3831: }
1.329 droeschl 3832: } else {
3833: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3834: }
3835: }
1.364 bisitz 3836:
1.518 raeburn 3837: my ($editlink,$extresform);
1.329 droeschl 3838: my $orig_url = $url;
1.340 raeburn 3839: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3840: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3841: if (!$supplementalflag && $residx && $symb) {
3842: if ((!$isfolder) && (!$ispage)) {
3843: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3844: $url=&Apache::lonnet::clutter($url);
3845: if ($url=~/^\/*uploaded\//) {
3846: $url=~/\.(\w+)$/;
3847: my $embstyle=&Apache::loncommon::fileembstyle($1);
3848: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3849: $url='/adm/wrapper'.$url;
3850: } elsif ($embstyle eq 'ssi') {
3851: #do nothing with these
3852: } elsif ($url!~/\.(sequence|page)$/) {
3853: $url='/adm/coursedocs/showdoc'.$url;
3854: }
3855: } elsif ($url=~m|^/ext/|) {
3856: $url='/adm/wrapper'.$url;
1.598 raeburn 3857: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3858: $url='/adm/wrapper'.$url;
3859: }
1.501 raeburn 3860: if (&Apache::lonnet::symbverify($symb,$url)) {
3861: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
3862: } else {
3863: $url='';
3864: }
1.329 droeschl 3865: }
3866: }
1.478 raeburn 3867: my ($rand_pick_text,$rand_order_text);
1.519 raeburn 3868: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3869: my $foldername=&escape($foldertitle);
3870: my $folderpath=$env{'form.folderpath'};
3871: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 3872: if (!$allowed && $supplementalflag) {
1.519 raeburn 3873: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 3874: $url.='folderpath='.&escape($folderpath);
3875: } else {
1.344 bisitz 3876: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 3877: # so it gets transferred between levels
1.519 raeburn 3878: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 3879: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 3880: 'parameter_randompick'))[0]
3881: .':'.((&LONCAPA::map::getparameter($orderidx,
3882: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3883: .':'.((&LONCAPA::map::getparameter($orderidx,
3884: 'parameter_encrypturl'))[0]=~/^yes$/i)
3885: .':'.((&LONCAPA::map::getparameter($orderidx,
1.519 raeburn 3886: 'parameter_randomorder'))[0]=~/^yes$/i)
3887: .':'.$ispage;
1.510 raeburn 3888: $url.='folderpath='.&escape($folderpath);
3889: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3890: 'parameter_randompick'))[0];
3891: my $rpckchk;
3892: if ($rpicknum) {
3893: $rpckchk = ' checked="checked"';
1.543 raeburn 3894: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3895: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3896: }
1.510 raeburn 3897: }
1.537 raeburn 3898: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 3899: $rand_pick_text =
1.478 raeburn 3900: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3901: $form_param."\n".
1.478 raeburn 3902: $form_common."\n".
1.537 raeburn 3903: '<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 3904: if ($rpicknum ne '') {
3905: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3906: }
1.537 raeburn 3907: $rand_pick_text .= '</span></span>'.
3908: $form_end;
1.543 raeburn 3909: my $ro_set;
3910: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
3911: $ro_set = 'checked="checked"';
3912: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3913: push(@{$filtersref->{'randomorder'}},$orderidx);
3914: }
3915: }
1.564 raeburn 3916: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 3917: $rand_order_text =
1.537 raeburn 3918: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3919: $form_param."\n".
1.537 raeburn 3920: $form_common."\n".
1.538 raeburn 3921: '<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 3922: $form_end;
1.510 raeburn 3923: }
1.509 raeburn 3924: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 3925: my $isexttool;
3926: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3927: $url='/adm/wrapper'.$url;
3928: $isexttool = 1;
3929: }
1.510 raeburn 3930: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 3931: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 3932: if ($title) {
3933: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3934: }
1.598 raeburn 3935: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 3936: $url .= '&idx='.$orderidx;
3937: }
1.329 droeschl 3938: }
1.519 raeburn 3939: my ($tdalign,$tdwidth);
1.501 raeburn 3940: if ($allowed) {
3941: my $fileloc =
3942: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 3943: if ($isexternal) {
1.518 raeburn 3944: ($editlink,$extresform) =
1.510 raeburn 3945: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.598 raeburn 3946: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3947: ($editlink,$extresform) =
3948: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
3949: undef,undef,undef,'tool',$coursedom,
3950: $coursenum,$ltitoolsref);
1.511 raeburn 3951: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 3952: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
3953: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 3954: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 3955: my $jscall =
3956: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3957: $switchserver,
1.503 raeburn 3958: $forceedit,
1.511 raeburn 3959: undef,$symb,
3960: &escape($env{'form.folderpath'}),
1.524 raeburn 3961: $renametitle,'','',1);
1.501 raeburn 3962: if ($jscall) {
1.518 raeburn 3963: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3964: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 3965: }
3966: }
3967: }
1.519 raeburn 3968: $tdalign = ' align="right" valign="top"';
3969: $tdwidth = ' width="80%"';
1.329 droeschl 3970: }
1.408 raeburn 3971: my $reinit;
3972: if ($crstype eq 'Community') {
3973: $reinit = &mt('(re-initialize community to access)');
3974: } else {
3975: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 3976: }
3977: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 3978: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3979: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3980: } elsif ($url) {
1.484 raeburn 3981: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3982: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 3983: } else {
3984: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3985: }
1.519 raeburn 3986: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3987: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3988: $line.='<a href="'.$url.'">'.$title.'</a>';
3989: } elsif ($url) {
1.484 raeburn 3990: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3991: $title,600,500);
1.469 www 3992: } else {
3993: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
3994: }
1.518 raeburn 3995: $line.="$extresform</td>";
1.478 raeburn 3996: $rand_pick_text = ' ' if ($rand_pick_text eq '');
3997: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 3998: if (($allowed) && ($folder!~/^supplemental/)) {
3999: my %lt=&Apache::lonlocal::texthash(
4000: 'hd' => 'Hidden',
4001: 'ec' => 'URL hidden');
1.543 raeburn 4002: my ($enctext,$hidtext);
4003: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4004: $enctext = ' checked="checked"';
4005: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4006: push(@{$filtersref->{'encrypturl'}},$orderidx);
4007: }
4008: }
4009: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4010: $hidtext = ' checked="checked"';
4011: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4012: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4013: }
4014: }
1.537 raeburn 4015: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4016: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4017: $line.=(<<ENDPARMS);
4018: <td class="LC_docs_entry_parameter">
1.537 raeburn 4019: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4020: $form_param
1.478 raeburn 4021: $form_common
1.538 raeburn 4022: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 4023: $form_end
1.458 raeburn 4024: <br />
1.537 raeburn 4025: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4026: $form_param
1.478 raeburn 4027: $form_common
1.538 raeburn 4028: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext /> $lt{'ec'}</label>
1.329 droeschl 4029: $form_end
4030: </td>
1.478 raeburn 4031: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4032: $rand_order_text</td>
1.329 droeschl 4033: ENDPARMS
4034: }
1.379 bisitz 4035: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4036: return $line;
4037: }
4038:
1.538 raeburn 4039: sub action_restrictions {
4040: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4041: my %denied = (
4042: cut => 0,
4043: copy => 0,
4044: remove => 0,
4045: );
4046: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4047: # no copy for published maps
4048: $denied{'copy'} = 1;
1.597 raeburn 4049: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4050: unless ($1 eq 'simpleproblem') {
4051: $denied{'copy'} = 1;
4052: }
4053: $denied{'cut'} = 1;
1.538 raeburn 4054: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4055: if ($folderpath =~ /^default&[^\&]+$/) {
4056: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4057: $denied{'remove'} = 1;
4058: }
4059: $denied{'cut'} = 1;
4060: $denied{'copy'} = 1;
4061: }
4062: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4063: my $group = $1;
4064: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4065: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4066: $denied{'remove'} = 1;
4067: }
4068: }
4069: $denied{'cut'} = 1;
4070: $denied{'copy'} = 1;
4071: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4072: my $group = $1;
4073: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4074: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4075: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4076: if (keys(%groupsettings) > 0) {
4077: $denied{'remove'} = 1;
4078: }
4079: $denied{'cut'} = 1;
4080: $denied{'copy'} = 1;
4081: }
4082: }
4083: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4084: my $group = $1;
4085: if ($url =~ /group_boards_\Q$group\E/) {
4086: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4087: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4088: if (keys(%groupsettings) > 0) {
4089: if (ref($groupsettings{'functions'}) eq 'HASH') {
4090: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4091: $denied{'remove'} = 1;
4092: }
4093: }
4094: }
4095: $denied{'cut'} = 1;
4096: $denied{'copy'} = 1;
4097: }
4098: }
4099: }
4100: return %denied;
4101: }
4102:
1.533 raeburn 4103: sub new_timebased_suffix {
1.538 raeburn 4104: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4105: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4106: if ($type eq 'paste') {
4107: $prefix = $type;
4108: $namespace = 'courseeditor';
1.587 raeburn 4109: $idtype = 'addcode';
1.538 raeburn 4110: } elsif ($type eq 'map') {
1.533 raeburn 4111: $prefix = 'docs';
4112: if ($area eq 'supplemental') {
4113: $prefix = 'supp';
4114: }
4115: $prefix .= $container;
4116: $namespace = 'uploadedmaps';
4117: } else {
4118: $prefix = $type;
4119: $namespace = 'templated';
1.504 raeburn 4120: }
4121: my ($suffix,$freedlock,$error) =
1.587 raeburn 4122: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4123: if (!$suffix) {
1.538 raeburn 4124: if ($type eq 'paste') {
4125: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4126: } elsif ($type eq 'map') {
1.533 raeburn 4127: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4128: } elsif ($type eq 'smppg') {
4129: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4130: } else {
1.565 bisitz 4131: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4132: }
1.504 raeburn 4133: if ($error) {
4134: $errtext .= '<br />'.$error;
4135: }
4136: }
4137: if ($freedlock ne 'ok') {
1.533 raeburn 4138: $locknotfreed =
4139: '<div class="LC_error">'.
4140: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4141: if ($type eq 'paste') {
1.591 raeburn 4142: if ($freedlock eq 'nolock') {
4143: $locknotfreed =
4144: '<div class="LC_error">'.
4145: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4146:
1.593 droeschl 4147: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4148: } else {
4149: $locknotfreed .=
4150: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4151: }
1.538 raeburn 4152: } elsif ($type eq 'map') {
1.591 raeburn 4153: $locknotfreed .=
4154: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4155: } elsif ($type eq 'smppg') {
4156: $locknotfreed .=
4157: &mt('This will prevent creation of additional simple pages in this course.');
4158: } else {
4159: $locknotfreed .=
1.565 bisitz 4160: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4161: }
1.538 raeburn 4162: unless ($type eq 'paste') {
4163: $locknotfreed .=
1.560 raeburn 4164: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4165: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4166: }
4167: $locknotfreed .= '</div>';
1.504 raeburn 4168: }
4169: return ($suffix,$errtext,$locknotfreed);
4170: }
4171:
1.329 droeschl 4172: =pod
4173:
4174: =item tiehash()
4175:
4176: tie the hash
4177:
4178: =cut
4179:
4180: sub tiehash {
4181: my ($mode)=@_;
4182: $hashtied=0;
4183: if ($env{'request.course.fn'}) {
4184: if ($mode eq 'write') {
4185: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4186: &GDBM_WRCREAT(),0640)) {
4187: $hashtied=2;
4188: }
4189: } else {
4190: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4191: &GDBM_READER(),0640)) {
4192: $hashtied=1;
4193: }
4194: }
1.364 bisitz 4195: }
1.329 droeschl 4196: }
4197:
4198: sub untiehash {
4199: if ($hashtied) { untie %hash; }
4200: $hashtied=0;
4201: return OK;
4202: }
4203:
4204:
4205:
4206:
4207: sub checkonthis {
4208: my ($r,$url,$level,$title)=@_;
4209: $url=&unescape($url);
4210: $alreadyseen{$url}=1;
4211: $r->rflush();
4212: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4213: $r->print("\n<br />");
4214: if ($level==0) {
4215: $r->print("<br />");
4216: }
4217: for (my $i=0;$i<=$level*5;$i++) {
4218: $r->print(' ');
4219: }
4220: $r->print('<a href="'.$url.'" target="cat">'.
4221: ($title?$title:$url).'</a> ');
4222: if ($url=~/^\/res\//) {
4223: my $result=&Apache::lonnet::repcopy(
4224: &Apache::lonnet::filelocation('',$url));
4225: if ($result eq 'ok') {
4226: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4227: $r->rflush();
4228: &Apache::lonnet::countacc($url);
4229: $url=~/\.(\w+)$/;
4230: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4231: $r->print('<br />');
4232: $r->rflush();
4233: for (my $i=0;$i<=$level*5;$i++) {
4234: $r->print(' ');
4235: }
4236: $r->print('- '.&mt('Rendering:').' ');
4237: my ($errorcount,$warningcount)=split(/:/,
4238: &Apache::lonnet::ssi_body($url,
4239: ('grade_target'=>'web',
4240: 'return_only_error_and_warning_counts' => 1)));
4241: if (($errorcount) ||
4242: ($warningcount)) {
4243: if ($errorcount) {
1.369 bisitz 4244: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4245: &mt('[quant,_1,error]',$errorcount).'</span>');
4246: }
4247: if ($warningcount) {
4248: $r->print('<span class="LC_warning">'.
4249: &mt('[quant,_1,warning]',$warningcount).'</span>');
4250: }
4251: } else {
4252: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4253: }
4254: $r->rflush();
4255: }
4256: my $dependencies=
4257: &Apache::lonnet::metadata($url,'dependencies');
4258: foreach my $dep (split(/\,/,$dependencies)) {
4259: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4260: &checkonthis($r,$dep,$level+1);
4261: }
4262: }
4263: } elsif ($result eq 'unavailable') {
4264: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4265: } elsif ($result eq 'not_found') {
4266: unless ($url=~/\$/) {
1.521 bisitz 4267: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4268: } else {
1.366 bisitz 4269: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4270: }
4271: } else {
4272: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4273: }
4274: }
4275: }
4276: }
4277:
4278:
4279:
4280: =pod
4281:
4282: =item list_symbs()
4283:
1.485 raeburn 4284: List Content Identifiers
1.329 droeschl 4285:
4286: =cut
4287:
4288: sub list_symbs {
4289: my ($r) = @_;
4290:
1.408 raeburn 4291: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4292: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4293: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4294: $r->print(&startContentScreen('tools'));
1.329 droeschl 4295: my $navmap = Apache::lonnavmaps::navmap->new();
4296: if (!defined($navmap)) {
4297: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4298: '<div class="LC_error">'.
4299: &mt('Unable to retrieve information about course contents').
4300: '</div>');
1.408 raeburn 4301: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4302: } else {
1.484 raeburn 4303: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4304: &Apache::loncommon::start_data_table().
4305: &Apache::loncommon::start_data_table_header_row().
4306: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4307: &Apache::loncommon::end_data_table_header_row()."\n");
4308: my $count;
1.329 droeschl 4309: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4310: $r->print(&Apache::loncommon::start_data_table_row().
4311: '<td>'.$res->compTitle().'</td>'.
4312: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4313: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4314: $count ++;
4315: }
4316: if (!$count) {
4317: $r->print(&Apache::loncommon::start_data_table_row().
4318: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4319: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4320: }
1.484 raeburn 4321: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4322: }
1.521 bisitz 4323: $r->print(&endContentScreen());
1.329 droeschl 4324: }
4325:
4326:
4327: sub verifycontent {
4328: my ($r) = @_;
1.408 raeburn 4329: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4330: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4331: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4332: $r->print(&startContentScreen('tools'));
4333: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4334: $hashtied=0;
4335: undef %alreadyseen;
4336: %alreadyseen=();
4337: &tiehash();
1.484 raeburn 4338:
1.329 droeschl 4339: foreach my $key (keys(%hash)) {
4340: if ($hash{$key}=~/\.(page|sequence)$/) {
4341: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4342: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4343: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4344: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4345: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4346: }
4347: }
4348: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4349: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4350: }
4351: }
4352: &untiehash();
1.442 www 4353: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4354: $r->print(&endContentScreen());
1.329 droeschl 4355: }
4356:
4357:
4358: sub devalidateversioncache {
4359: my $src=shift;
4360: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4361: &Apache::lonnet::clutter($src));
4362: }
4363:
4364: sub checkversions {
4365: my ($r) = @_;
1.408 raeburn 4366: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4367: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4368: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4369: $r->print(&startContentScreen('tools'));
1.442 www 4370:
1.329 droeschl 4371: my $header='';
4372: my $startsel='';
4373: my $monthsel='';
4374: my $weeksel='';
4375: my $daysel='';
4376: my $allsel='';
4377: my %changes=();
4378: my $starttime=0;
4379: my $haschanged=0;
4380: my %setversions=&Apache::lonnet::dump('resourceversions',
4381: $env{'course.'.$env{'request.course.id'}.'.domain'},
4382: $env{'course.'.$env{'request.course.id'}.'.num'});
4383:
4384: $hashtied=0;
4385: &tiehash();
4386: my %newsetversions=();
4387: if ($env{'form.setmostrecent'}) {
4388: $haschanged=1;
4389: foreach my $key (keys(%hash)) {
4390: if ($key=~/^ids\_(\/res\/.+)$/) {
4391: $newsetversions{$1}='mostrecent';
4392: &devalidateversioncache($1);
4393: }
4394: }
4395: } elsif ($env{'form.setcurrent'}) {
4396: $haschanged=1;
4397: foreach my $key (keys(%hash)) {
4398: if ($key=~/^ids\_(\/res\/.+)$/) {
4399: my $getvers=&Apache::lonnet::getversion($1);
4400: if ($getvers>0) {
4401: $newsetversions{$1}=$getvers;
4402: &devalidateversioncache($1);
4403: }
4404: }
4405: }
4406: } elsif ($env{'form.setversions'}) {
4407: $haschanged=1;
4408: foreach my $key (keys(%env)) {
4409: if ($key=~/^form\.set_version_(.+)$/) {
4410: my $src=$1;
4411: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4412: $newsetversions{$src}=$env{$key};
4413: &devalidateversioncache($src);
4414: }
4415: }
4416: }
4417: }
4418: if ($haschanged) {
4419: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4420: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 4421: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 4422: $r->print(&Apache::loncommon::confirmwrapper(
4423: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 4424: } else {
1.479 golterma 4425: $r->print(&Apache::loncommon::confirmwrapper(
4426: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4427: }
4428: &mark_hash_old();
4429: }
4430: &changewarning($r,'');
4431: if ($env{'form.timerange'} eq 'all') {
4432: # show all documents
1.549 raeburn 4433: $header=&mt('All content in '.$crstype);
1.521 bisitz 4434: $allsel=' selected="selected"';
1.329 droeschl 4435: foreach my $key (keys(%hash)) {
4436: if ($key=~/^ids\_(\/res\/.+)$/) {
4437: my $src=$1;
4438: $changes{$src}=1;
4439: }
4440: }
4441: } else {
4442: # show documents which changed
4443: %changes=&Apache::lonnet::dump
4444: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4445: $env{'course.'.$env{'request.course.id'}.'.num'});
4446: my $firstkey=(keys(%changes))[0];
4447: unless ($firstkey=~/^error\:/) {
4448: unless ($env{'form.timerange'}) {
4449: $env{'form.timerange'}=604800;
4450: }
4451: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4452: .&mt('seconds');
4453: if ($env{'form.timerange'}==-1) {
4454: $seltext='since start of course';
1.521 bisitz 4455: $startsel=' selected="selected"';
1.329 droeschl 4456: $env{'form.timerange'}=time;
4457: }
4458: $starttime=time-$env{'form.timerange'};
4459: if ($env{'form.timerange'}==2592000) {
4460: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4461: $monthsel=' selected="selected"';
1.329 droeschl 4462: } elsif ($env{'form.timerange'}==604800) {
4463: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4464: $weeksel=' selected="selected"';
1.329 droeschl 4465: } elsif ($env{'form.timerange'}==86400) {
4466: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4467: $daysel=' selected="selected"';
1.329 droeschl 4468: }
4469: $header=&mt('Content changed').' '.$seltext;
4470: } else {
4471: $header=&mt('No content modifications yet.');
4472: }
4473: }
4474: %setversions=&Apache::lonnet::dump('resourceversions',
4475: $env{'course.'.$env{'request.course.id'}.'.domain'},
4476: $env{'course.'.$env{'request.course.id'}.'.num'});
4477: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4478: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4479: 'lm' => 'Version changes since last Month',
4480: 'lw' => 'Version changes since last Week',
4481: 'sy' => 'Version changes since Yesterday',
4482: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4483: 'cd' => 'Change display',
1.329 droeschl 4484: 'sd' => 'Display',
4485: 'fi' => 'File',
4486: 'md' => 'Modification Date',
4487: 'mr' => 'Most recently published Version',
1.408 raeburn 4488: 've' => 'Version used in '.$crstype,
4489: 'vu' => 'Set Version to be used in '.$crstype,
4490: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4491: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4492: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4493: 'di' => 'Differences',
1.484 raeburn 4494: 'save' => 'Save changes',
4495: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4496: 'act' => 'Actions');
1.329 droeschl 4497: $r->print(<<ENDHEADERS);
1.484 raeburn 4498: <h4 class="LC_info">$header</h4>
1.329 droeschl 4499: <form action="/adm/coursedocs" method="post">
4500: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4501: <div class="LC_left_float">
1.479 golterma 4502: <fieldset>
1.484 raeburn 4503: <legend>$lt{'cd'}</legend>
1.329 droeschl 4504: <select name="timerange">
1.521 bisitz 4505: <option value='all'$allsel>$lt{'al'}</option>
4506: <option value="-1"$startsel>$lt{'st'}</option>
4507: <option value="2592000"$monthsel>$lt{'lm'}</option>
4508: <option value="604800"$weeksel>$lt{'lw'}</option>
4509: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4510: </select>
4511: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4512: </fieldset>
4513: </div>
4514: <div class="LC_left_float">
4515: <fieldset>
4516: <legend>$lt{'act'}</legend>
4517: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
4518: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
4519: </fieldset>
4520: </div>
4521: <br clear="all" />
4522: <hr />
4523: <h4>$lt{'vers'}</h4>
1.329 droeschl 4524: ENDHEADERS
1.479 golterma 4525: #number of columns for version history
1.571 raeburn 4526: my %changedbytime;
4527: foreach my $key (keys(%changes)) {
4528: #excludes not versionable problems from resource version history:
4529: next if ($key =~ /^\/res\/lib\/templates/);
4530: my $chg;
4531: if ($env{'form.timerange'} eq 'all') {
4532: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4533: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4534: } else {
4535: $chg = $changes{$key};
4536: next if ($chg < $starttime);
4537: }
4538: push(@{$changedbytime{$chg}},$key);
4539: }
4540: if (keys(%changedbytime) == 0) {
4541: &untiehash();
4542: $r->print(&mt('No content changes in imported content in specified time frame').
4543: &endContentScreen());
4544: return;
4545: }
1.479 golterma 4546: $r->print(
1.571 raeburn 4547: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
1.521 bisitz 4548: &Apache::loncommon::start_data_table().
4549: &Apache::loncommon::start_data_table_header_row().
4550: '<th>'.&mt('Resources').'</th>'.
4551: "<th>$lt{'mr'}</th>".
4552: "<th>$lt{'ve'}</th>".
4553: "<th>$lt{'vu'}</th>".
4554: '<th>'.&mt('History').'</th>'.
4555: &Apache::loncommon::end_data_table_header_row()
4556: );
1.571 raeburn 4557: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4558: foreach my $key (sort(@{$changedbytime{$chg}})) {
4559: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4560: my $currentversion=&Apache::lonnet::getversion($key);
4561: if ($currentversion<0) {
4562: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4563: }
4564: my $linkurl=&Apache::lonnet::clutter($key);
4565: $r->print(
4566: &Apache::loncommon::start_data_table_row().
4567: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4568: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4569: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4570: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4571: '<td align="right">'
4572: );
4573: # Used in course
4574: my $usedversion=$hash{'version_'.$linkurl};
4575: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4576: if ($usedversion != $currentversion) {
1.479 golterma 4577: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4578: } else {
1.479 golterma 4579: $r->print($usedversion);
4580: }
1.329 droeschl 4581: } else {
1.521 bisitz 4582: $r->print($currentversion);
1.329 droeschl 4583: }
1.571 raeburn 4584: $r->print('</td><td title="'.$lt{'vu'}.'">');
4585: # Set version
4586: $r->print(&Apache::loncommon::select_form(
4587: $setversions{$linkurl},
4588: 'set_version_'.$linkurl,
4589: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4590: '' => '',
4591: 'mostrecent' => &mt('most recent'),
4592: map {$_,$_} (1..$currentversion)}));
4593: my $lastold=1;
4594: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4595: my $url=$root.'.'.$prevvers.'.'.$extension;
4596: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4597: $lastold=$prevvers;
4598: }
4599: }
4600: $r->print('</td>');
4601: # List all available versions
4602: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4603: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4604: my $url=$root.'.'.$prevvers.'.'.$extension;
4605: $r->print(
4606: '<span class="LC_nobreak">'
4607: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4608: .&mt('Version [_1]',$prevvers).'</a>'
4609: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4610: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4611: .')');
4612: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4613: $r->print(
4614: ' <a href="/adm/diff?filename='.
4615: &Apache::lonnet::clutter($root.'.'.$extension).
4616: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4617: '" target="diffs">'.&mt('Diffs').'</a>');
4618: }
4619: $r->print('</span><br />');
1.329 droeschl 4620: }
1.571 raeburn 4621: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4622: }
1.329 droeschl 4623: }
1.521 bisitz 4624: $r->print(
4625: &Apache::loncommon::end_data_table().
4626: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
4627: '</form>'
4628: );
1.329 droeschl 4629:
4630: &untiehash();
1.521 bisitz 4631: $r->print(&endContentScreen());
1.571 raeburn 4632: return;
1.329 droeschl 4633: }
4634:
4635: sub mark_hash_old {
4636: my $retie_hash=0;
4637: if ($hashtied) {
4638: $retie_hash=1;
4639: &untiehash();
4640: }
4641: &tiehash('write');
4642: $hash{'old'}=1;
4643: &untiehash();
4644: if ($retie_hash) { &tiehash(); }
4645: }
4646:
4647: sub is_hash_old {
4648: my $untie_hash=0;
4649: if (!$hashtied) {
4650: $untie_hash=1;
4651: &tiehash();
4652: }
4653: my $return=$hash{'old'};
4654: if ($untie_hash) { &untiehash(); }
4655: return $return;
4656: }
4657:
4658: sub changewarning {
4659: my ($r,$postexec,$message,$url)=@_;
4660: if (!&is_hash_old()) { return; }
4661: my $pathvar='folderpath';
4662: my $path=&escape($env{'form.folderpath'});
4663: if (!defined($url)) {
4664: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4665: }
4666: my $course_type = &Apache::loncommon::course_type();
4667: if (!defined($message)) {
4668: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4669: }
4670: $r->print("\n\n".
1.372 bisitz 4671: '<script type="text/javascript">'."\n".
4672: '// <![CDATA['."\n".
4673: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4674: '// ]]>'."\n".
1.369 bisitz 4675: '</script>'."\n".
1.375 tempelho 4676: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4677: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4678: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4679: &mt($message,' <input type="hidden" name="'.
4680: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4681: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4682: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4683: }
4684:
4685:
4686: sub init_breadcrumbs {
1.571 raeburn 4687: my ($form,$text,$help)=@_;
1.329 droeschl 4688: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4689: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4690: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4691: faq=>273,
4692: bug=>'Instructor Interface',
1.571 raeburn 4693: help => $help});
1.329 droeschl 4694: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4695: text=>$text,
4696: faq=>273,
4697: bug=>'Instructor Interface'});
4698: }
4699:
1.441 www 4700: # subroutine to list form elements
4701: sub create_list_elements {
4702: my @formarr = @_;
4703: my $list = '';
1.501 raeburn 4704: foreach my $button (@formarr){
4705: foreach my $picture (keys(%{$button})) {
4706: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4707: }
4708: }
4709: return $list;
4710: }
1.329 droeschl 4711:
1.441 www 4712: # subroutine to create ul from list elements
4713: sub create_form_ul {
4714: my $list = shift;
4715: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4716: return $ul;
4717: }
1.329 droeschl 4718:
1.442 www 4719: #
4720: # Start tabs
4721: #
4722:
4723: sub startContentScreen {
1.484 raeburn 4724: my ($mode) = @_;
4725: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4726: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4727: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4728: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4729: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4730: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4731: } else {
1.549 raeburn 4732: $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 4733: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4734: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4735: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4736: }
4737: $output .= "\n".'</ul>'."\n";
4738: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4739: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4740: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4741: return $output;
1.442 www 4742: }
4743:
4744: #
4745: # End tabs
4746: #
4747:
4748: sub endContentScreen {
1.484 raeburn 4749: return '</div></div></div>';
1.442 www 4750: }
1.329 droeschl 4751:
1.446 www 4752: sub supplemental_base {
1.548 raeburn 4753: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4754: }
4755:
1.329 droeschl 4756: sub handler {
4757: my $r = shift;
4758: &Apache::loncommon::content_type($r,'text/html');
4759: $r->send_http_header;
4760: return OK if $r->header_only;
1.484 raeburn 4761:
4762: # get course data
1.408 raeburn 4763: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4764: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4765: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4766:
4767: # graphics settings
4768: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4769:
1.443 www 4770: #
1.329 droeschl 4771: # --------------------------------------------- Initialize help topics for this
4772: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4773: 'Adding_External_Resource','Navigate_Content',
4774: 'Adding_Folders','Docs_Overview', 'Load_Map',
4775: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 4776: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 4777: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 4778: 'Dropbox','Simple_Problem') {
1.329 droeschl 4779: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4780: }
4781: # Composite help files
4782: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4783: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4784: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4785: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4786: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4787: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4788: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4789: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4790: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4791: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 4792:
1.472 raeburn 4793: my $allowed;
4794: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4795: unless ($r->uri eq '/adm/supplemental') {
4796: # does this user have privileges to modify content.
4797: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4798: }
4799:
1.582 raeburn 4800: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4801: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 4802: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4803: &verifycontent($r);
4804: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4805: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4806: &list_symbs($r);
4807: } elsif ($allowed && $env{'form.docslog'}) {
4808: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4809: my $folder = $env{'form.folder'};
4810: if ($folder eq '') {
4811: $folder='default';
4812: }
4813: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 4814: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 4815: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.329 droeschl 4816: &checkversions($r);
4817: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.568 raeburn 4818: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4819: &dumpcourse($r);
4820: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4821: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4822: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4823: } else {
1.445 www 4824: #
4825: # Done catching special calls
1.484 raeburn 4826: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4827: # Get the parameters that may be needed
4828: #
4829: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 4830: ['folderpath',
4831: 'forcesupplement','forcestandard',
1.510 raeburn 4832: 'tools','symb','command','supppath']);
1.445 www 4833:
4834: # standard=1: this is a "new-style" course with an uploaded map as top level
4835: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4836:
4837: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4838:
1.484 raeburn 4839: # Decide whether this should display supplemental or main content or utilities
1.445 www 4840: # supplementalflag=1: show supplemental documents
4841: # supplementalflag=0: show standard documents
1.484 raeburn 4842: # toolsflag=1: show utilities
1.445 www 4843:
1.561 raeburn 4844: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4845: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4846: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4847: $supplementalflag=0;
4848: }
4849: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4850: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4851: unless ($allowed) { $supplementalflag=1; }
4852: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4853: my $toolsflag=0;
4854: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4855:
1.329 droeschl 4856: my $script='';
4857: my $showdoc=0;
1.457 raeburn 4858: my $addentries = {};
1.475 raeburn 4859: my $container;
1.329 droeschl 4860: my $containertag;
1.508 raeburn 4861: my $pathitem;
1.598 raeburn 4862: my %ltitools;
1.329 droeschl 4863:
1.464 www 4864: # Do we directly jump somewhere?
1.466 www 4865:
1.525 raeburn 4866: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4867: if ($env{'form.symb'} ne '') {
1.522 raeburn 4868: $env{'form.folderpath'}=
4869: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 4870: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4871: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4872: } elsif ($env{'form.supppath'} ne '') {
4873: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 4874: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4875: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4876: }
1.472 raeburn 4877: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 4878: $env{'form.folderpath'} = 'default&'.
1.548 raeburn 4879: &escape(&mt('Main Content').':::::');
1.525 raeburn 4880: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4881: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 4882: $env{'form.folderpath'} = 'supplemental&'.
1.538 raeburn 4883: &escape('Supplemental Content');
1.525 raeburn 4884: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4885: } elsif ($env{'form.command'} eq 'contents') {
4886: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4887: } elsif ($env{'form.command'} eq 'home') {
4888: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4889: }
4890:
1.525 raeburn 4891:
1.445 www 4892: # Where do we store these for when we come back?
4893: my $stored_folderpath='docs_folderpath';
4894: if ($supplementalflag) {
4895: $stored_folderpath='docs_sup_folderpath';
4896: }
1.464 www 4897:
1.519 raeburn 4898: # No folderpath, and in edit mode, see if we have something stored
4899: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4900: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 4901: {'folderpath' => 'scalar'});
1.523 raeburn 4902: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4903: undef($env{'form.folderpath'});
4904: }
1.329 droeschl 4905: }
1.446 www 4906:
4907: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4908: if (!$allowed) {
1.446 www 4909: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4910: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4911: }
4912: }
1.446 www 4913: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4914: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4915: $env{'form.folderpath'} = &supplemental_base()
4916: .'&'.
1.329 droeschl 4917: $env{'form.folderpath'};
4918: }
1.446 www 4919: # If after all of this, we still don't have any paths, make them
1.519 raeburn 4920: unless ($env{'form.folderpath'}) {
1.446 www 4921: if ($supplementalflag) {
4922: $env{'form.folderpath'}=&supplemental_base();
4923: } else {
1.548 raeburn 4924: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
1.538 raeburn 4925: ':::::');
1.446 www 4926: }
1.472 raeburn 4927: }
1.446 www 4928:
1.445 www 4929: # Store this
1.484 raeburn 4930: unless ($toolsflag) {
1.510 raeburn 4931: if ($allowed) {
4932: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 4933: {'folderpath' => 'scalar'});
1.510 raeburn 4934: }
1.519 raeburn 4935: my $folderpath;
1.484 raeburn 4936: if ($env{'form.folderpath'}) {
1.519 raeburn 4937: $folderpath = $env{'form.folderpath'};
4938: my (@folders)=split('&',$env{'form.folderpath'});
4939: $env{'form.foldername'}=&unescape(pop(@folders));
4940: if ($env{'form.foldername'} =~ /\:1$/) {
4941: $container = 'page';
4942: } else {
4943: $container = 'sequence';
4944: }
4945: $env{'form.folder'}=pop(@folders);
1.484 raeburn 4946: } else {
1.519 raeburn 4947: if ($env{'form.folder'} eq '' ||
4948: $env{'form.folder'} eq 'supplemental') {
4949: $folderpath='default&'.
1.548 raeburn 4950: &escape(&mt('Main Content').':::::');
1.484 raeburn 4951: }
4952: }
1.519 raeburn 4953: $containertag = '<input type="hidden" name="folderpath" value="" />';
4954: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 4955: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4956: $showdoc='/'.$1;
4957: }
4958: if ($showdoc) { # got called in sequence from course
4959: $allowed=0;
4960: } else {
4961: if ($allowed) {
4962: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4963: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 4964: }
4965: }
1.329 droeschl 4966: }
4967:
1.344 bisitz 4968: # get personal data
1.329 droeschl 4969: my $uname=$env{'user.name'};
4970: my $udom=$env{'user.domain'};
4971: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
4972:
4973: if ($allowed) {
1.484 raeburn 4974: if ($toolsflag) {
4975: $script .= &inject_data_js();
4976: my ($home,$other,%outhash)=&authorhosts();
4977: if (!$home && $other) {
4978: my @hosts;
4979: foreach my $aurole (keys(%outhash)) {
4980: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4981: push(@hosts,$outhash{$aurole});
4982: }
4983: }
4984: $script .= &dump_switchserver_js(@hosts);
4985: }
1.458 raeburn 4986: } else {
1.570 raeburn 4987: my $tid = 1;
1.484 raeburn 4988: my @tabids;
4989: if ($supplementalflag) {
4990: @tabids = ('002','ee2','ff2');
1.570 raeburn 4991: $tid = 2;
1.484 raeburn 4992: } else {
4993: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 4994: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 4995: unshift(@tabids,'001');
4996: push(@tabids,('dd1','ee1'));
4997: }
1.458 raeburn 4998: }
1.484 raeburn 4999: my $tabidstr = join("','",@tabids);
1.598 raeburn 5000: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5001: my $posslti = keys(%ltitools);
1.598 raeburn 5002: my $exttoolurl = "/adm/$coursedom/$coursenum/new/exttool";
1.600 raeburn 5003: $script .= &editing_js($udom,$uname,$supplementalflag,$posslti).
1.484 raeburn 5004: &history_tab_js().
5005: &inject_data_js().
1.570 raeburn 5006: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5007: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5008: $addentries = {
1.485 raeburn 5009: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5010: };
1.458 raeburn 5011: }
1.538 raeburn 5012: $script .= &paste_popup_js();
1.501 raeburn 5013: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5014: &mt('Switch server?');
5015:
5016:
1.329 droeschl 5017: }
5018: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5019: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5020: .'// <![CDATA['."\n"
5021: .$script."\n"
5022: .'// ]]>'."\n"
1.595 musolffc 5023: .'</script>'."\n"
5024: .'<script type="text/javascript"
5025: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5026:
5027: # Breadcrumbs
5028: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5029:
5030: if ($showdoc) {
5031: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5032: {'force_register' => $showdoc,}));
1.571 raeburn 5033: } elsif ($toolsflag) {
5034: &Apache::lonhtmlcommon::add_breadcrumb({
5035: href=>"/adm/coursedocs",text=>"$crstype Contents"});
5036: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5037: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5038: .&Apache::lonhtmlcommon::breadcrumbs(
5039: 'Editing Course Contents')
5040: );
1.510 raeburn 5041: } elsif ($r->uri eq '/adm/supplemental') {
5042: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5043: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5044: {'bread_crumbs' => $brcrum,}));
5045: } else {
1.392 raeburn 5046: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 5047: href=>"/adm/coursedocs",text=>"$crstype Contents"});
5048: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5049: {'add_entries' => $addentries}
5050: )
1.392 raeburn 5051: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5052: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 5053: 'Editing '.$crstype.' Contents',
1.392 raeburn 5054: 'Docs_Adding_Course_Doc')
5055: );
5056: }
1.364 bisitz 5057:
1.329 droeschl 5058: my %allfiles = ();
5059: my %codebase = ();
1.440 raeburn 5060: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 5061: if ($allowed) {
5062: if (($env{'form.uploaddoc.filename'}) &&
5063: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5064: my $context = $1;
5065: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5066: undef($hadchanges);
1.440 raeburn 5067: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5068: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5069: if ($hadchanges) {
5070: &mark_hash_old();
5071: }
1.440 raeburn 5072: $r->print($upload_output);
5073: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5074: # Process file upload - phase two - upload embedded objects
5075: $uploadphase = 'check_embedded';
5076: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5077: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5078: $env{'form.newidx'});
5079: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5080: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5081: my ($destination,$dir_root) = &embedded_destination();
5082: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5083: my $actionurl = '/adm/coursedocs';
5084: my ($result,$flag) =
5085: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5086: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5087: $actionurl);
5088: $r->print($result.&return_to_editor());
5089: } elsif ($env{'form.phase'} eq 'check_embedded') {
5090: # Process file upload - phase three - modify references in HTML file
5091: $uploadphase = 'modified_orightml';
5092: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5093: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5094: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5095: my $result =
5096: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5097: $docuname,$docudom,undef,
5098: $dir_root);
5099: $r->print($result.&return_to_editor());
1.476 raeburn 5100: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5101: $uploadphase = 'decompress_phase_one';
5102: $r->print(&decompression_phase_one().
5103: &return_to_editor());
5104: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5105: $uploadphase = 'decompress_phase_two';
5106: $r->print(&decompression_phase_two().
5107: &return_to_editor());
1.329 droeschl 5108: }
5109: }
5110:
1.484 raeburn 5111: if ($allowed && $toolsflag) {
5112: $r->print(&startContentScreen('tools'));
5113: $r->print(&generate_admin_menu($crstype));
5114: $r->print(&endContentScreen());
5115: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5116: # -----------------------------------------------------------------------------
5117: my %lt=&Apache::lonlocal::texthash(
5118: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5119: 'upfi' => 'Upload File',
1.553 raeburn 5120: 'upld' => 'Upload Content',
1.329 droeschl 5121: 'srch' => 'Search',
5122: 'impo' => 'Import',
1.487 raeburn 5123: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5124: 'impm' => 'Import from Assembled Map',
1.598 raeburn 5125: 'extr' => 'External Resource',
5126: 'extt' => 'External Tool',
1.329 droeschl 5127: 'selm' => 'Select Map',
5128: 'load' => 'Load Map',
5129: 'newf' => 'New Folder',
5130: 'newp' => 'New Composite Page',
5131: 'syll' => 'Syllabus',
1.425 raeburn 5132: 'navc' => 'Table of Contents',
1.343 biermanm 5133: 'sipa' => 'Simple Course Page',
1.329 droeschl 5134: 'sipr' => 'Simple Problem',
1.534 raeburn 5135: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5136: 'drbx' => 'Drop Box',
1.451 www 5137: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5138: 'bull' => 'Discussion Board',
1.347 weissno 5139: 'mypi' => 'My Personal Information Page',
1.353 weissno 5140: 'grpo' => 'Group Portfolio',
1.329 droeschl 5141: 'rost' => 'Course Roster',
1.528 raeburn 5142: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5143: 'imsf' => 'IMS Upload',
5144: 'imsl' => 'Upload IMS package',
1.501 raeburn 5145: 'cms' => 'Origin of IMS package',
5146: 'se' => 'Select',
1.329 droeschl 5147: 'file' => 'File',
5148: 'title' => 'Title',
5149: 'comment' => 'Comment',
1.403 raeburn 5150: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5151: 'bb5' => 'Blackboard 5',
5152: 'bb6' => 'Blackboard 6',
5153: 'angel5' => 'ANGEL 5.5',
5154: 'webctce4' => 'WebCT 4 Campus Edition',
5155: );
1.329 droeschl 5156: # -----------------------------------------------------------------------------
1.595 musolffc 5157:
5158: # Calculate free quota space for a user or course. A javascript function checks
5159: # file size to determine if upload should be allowed.
5160: my $quotatype = 'unofficial';
5161: if ($crstype eq 'Community') {
1.601 raeburn 5162: $quotatype = 'community';
5163: } elsif ($crstype eq 'Placement') {
5164: $quotatype = 'placement';
1.595 musolffc 5165: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5166: $quotatype = 'official';
5167: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5168: $quotatype = 'textbook';
5169: }
5170: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5171: 'course',$quotatype); # expressed in MB
5172: my $current_disk_usage = 0;
5173: foreach my $subdir ('docs','supplemental') {
5174: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5175: "userfiles/$subdir",1); # expressed in kB
5176: }
5177: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5178:
1.329 droeschl 5179: my $fileupload=(<<FIUP);
5180: $lt{'file'}:<br />
1.595 musolffc 5181: <input type="file" name="uploaddoc" class="flUpload" size="40" />
5182: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5183: FIUP
5184:
5185: my $checkbox=(<<CHBO);
5186: <!-- <label>$lt{'parse'}?
5187: <input type="checkbox" name="parserflag" />
5188: </label> -->
5189: <label>
5190: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
5191: </label>
5192: CHBO
1.501 raeburn 5193: my $imsfolder = $env{'form.folder'};
5194: if ($imsfolder eq '') {
5195: $imsfolder = 'default';
5196: }
5197: my $imspform=(<<IMSFORM);
5198: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5199: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5200: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5201: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5202: <legend>$lt{'imsf'}</legend>
5203: $fileupload
5204: <br />
5205: <p>
5206: $lt{'cms'}:
5207: <select name="source">
5208: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5209: <option value="bb5">$lt{'bb5'}</option>
5210: <option value="bb6">$lt{'bb6'}</option>
5211: <option value="angel5">$lt{'angel5'}</option>
5212: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5213: </select>
5214: <input type="hidden" name="folder" value="$imsfolder" />
5215: </p>
5216: <input type="hidden" name="phase" value="one" />
5217: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
5218: </fieldset>
5219: </form>
5220: IMSFORM
1.329 droeschl 5221:
5222: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5223: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5224: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5225: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5226: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5227: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5228: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5229: $fileupload
1.329 droeschl 5230: <br />
5231: $lt{'title'}:<br />
1.458 raeburn 5232: <input type="text" size="60" name="comment" />
1.508 raeburn 5233: $pathitem
1.329 droeschl 5234: <input type="hidden" name="cmd" value="upload_default" />
5235: <br />
1.458 raeburn 5236: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5237: $checkbox
5238: </span>
1.501 raeburn 5239: <br clear="all" />
5240: <input type="submit" value="$lt{'upld'}" />
5241: </fieldset>
5242: </form>
1.383 tempelho 5243: FUFORM
1.329 droeschl 5244:
1.502 raeburn 5245: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5246: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5247: $lt{'impm'}</a>$help{'Load_Map'}
5248: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5249: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5250: <legend>$lt{'impm'}</legend>
1.371 tempelho 5251: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5252: $lt{'copm'}<br />
5253: <span class="LC_nobreak">
5254: <input type="text" name="importmap" size="40" value=""
5255: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 5256: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 5257: <input type="submit" name="loadmap" value="$lt{'load'}" />
5258: </fieldset>
5259: </form>
5260:
1.383 tempelho 5261: SEDFFORM
1.502 raeburn 5262: my @importpubforma = (
1.508 raeburn 5263: { '<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 5264: { '<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 5265: { '<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 5266: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
1.383 tempelho 5267: );
1.502 raeburn 5268: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5269: my $extresourcesform =
5270: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5271: $help{'Adding_External_Resource'});
1.598 raeburn 5272: my $exttoolform =
5273: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5274: $help{'Adding_External_Tool'},undef,
5275: undef,'tool',$coursedom,$coursenum,
5276: \%ltitools);
1.329 droeschl 5277: if ($allowed) {
1.492 raeburn 5278: my $folder = $env{'form.folder'};
5279: if ($folder eq '') {
5280: $folder='default';
5281: }
1.538 raeburn 5282: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5283: if ($output) {
5284: $r->print($output);
5285: }
1.337 ehlerst 5286: $r->print(<<HIDDENFORM);
5287: <form name="renameform" method="post" action="/adm/coursedocs">
5288: <input type="hidden" name="title" />
5289: <input type="hidden" name="cmd" />
5290: <input type="hidden" name="markcopy" />
5291: <input type="hidden" name="copyfolder" />
5292: $containertag
5293: </form>
1.484 raeburn 5294:
1.337 ehlerst 5295: HIDDENFORM
1.508 raeburn 5296: $r->print(&makesimpleeditform($pathitem)."\n".
5297: &makedocslogform($pathitem."\n".
1.484 raeburn 5298: '<input type="hidden" name="folder" value="'.
5299: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5300: }
1.442 www 5301:
5302: # Generate the tabs
1.510 raeburn 5303: my ($mode,$needs_end);
1.472 raeburn 5304: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5305: my @folders = split('&',$env{'form.folderpath'});
5306: unless (@folders > 2) {
5307: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5308: $needs_end = 1;
5309: }
1.472 raeburn 5310: } else {
1.484 raeburn 5311: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5312: $needs_end = 1;
1.472 raeburn 5313: }
1.443 www 5314:
1.442 www 5315: #
5316:
5317: my $savefolderpath;
5318:
1.395 raeburn 5319: if ($allowed) {
1.329 droeschl 5320: my $folder=$env{'form.folder'};
1.443 www 5321: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 5322: $folder='default';
1.356 tempelho 5323: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5324: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5325: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5326: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5327: }
5328: my $postexec='';
5329: if ($folder eq 'default') {
1.372 bisitz 5330: $r->print('<script type="text/javascript">'."\n"
5331: .'// <![CDATA['."\n"
5332: .'this.window.name="loncapaclient";'."\n"
5333: .'// ]]>'."\n"
5334: .'</script>'."\n"
1.369 bisitz 5335: );
1.329 droeschl 5336: } else {
5337: #$postexec='self.close();';
5338: }
1.504 raeburn 5339: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5340: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5341: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5342:
5343: my $newnavform=(<<NNFORM);
5344: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5345: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5346: $pathitem
1.329 droeschl 5347: <input type="hidden" name="importdetail"
5348: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 5349: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 5350: $help{'Navigate_Content'}
5351: </form>
5352: NNFORM
5353: my $newsmppageform=(<<NSPFORM);
5354: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5355: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5356: $pathitem
1.329 droeschl 5357: <input type="hidden" name="importdetail" value="" />
1.423 onken 5358: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5359: $help{'Simple Page'}
1.329 droeschl 5360: </form>
5361: NSPFORM
5362:
5363: my $newsmpproblemform=(<<NSPROBFORM);
5364: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5365: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5366: $pathitem
1.329 droeschl 5367: <input type="hidden" name="importdetail" value="" />
1.423 onken 5368: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5369: $help{'Simple_Problem'}
1.329 droeschl 5370: </form>
5371:
5372: NSPROBFORM
5373:
5374: my $newdropboxform=(<<NDBFORM);
5375: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5376: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5377: $pathitem
1.329 droeschl 5378: <input type="hidden" name="importdetail" value="" />
1.423 onken 5379: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5380: $help{'Dropbox'}
1.344 bisitz 5381: </form>
1.329 droeschl 5382: NDBFORM
5383:
5384: my $newexuploadform=(<<NEXUFORM);
5385: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5386: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5387: $pathitem
1.329 droeschl 5388: <input type="hidden" name="importdetail" value="" />
1.423 onken 5389: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5390: $help{'Score_Upload_Form'}
5391: </form>
5392: NEXUFORM
5393:
5394: my $newbulform=(<<NBFORM);
5395: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5396: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5397: $pathitem
1.329 droeschl 5398: <input type="hidden" name="importdetail" value="" />
1.423 onken 5399: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5400: $help{'Bulletin Board'}
5401: </form>
5402: NBFORM
5403:
5404: my $newaboutmeform=(<<NAMFORM);
5405: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5406: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5407: $pathitem
1.329 droeschl 5408: <input type="hidden" name="importdetail"
5409: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5410: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5411: $help{'My Personal Information Page'}
1.329 droeschl 5412: </form>
5413: NAMFORM
5414:
5415: my $newaboutsomeoneform=(<<NASOFORM);
5416: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5417: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5418: $pathitem
1.329 droeschl 5419: <input type="hidden" name="importdetail" value="" />
1.423 onken 5420: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5421: </form>
5422: NASOFORM
5423:
5424: my $newrosterform=(<<NROSTFORM);
5425: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5426: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5427: $pathitem
1.329 droeschl 5428: <input type="hidden" name="importdetail"
5429: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 5430: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.556 raeburn 5431: $help{'Course_Roster'}
1.329 droeschl 5432: </form>
5433: NROSTFORM
5434:
1.534 raeburn 5435: my $newwebpage;
5436: if ($folder =~ /^default_?(\d*)$/) {
5437: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5438: if ($1) {
5439: $newwebpage .= $1;
5440: } else {
5441: $newwebpage .= 'default';
5442: }
5443: $newwebpage .= '/new.html';
5444: }
5445: my $newwebpageform =(<<NWEBFORM);
5446: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5447: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5448: $pathitem
5449: <input type="hidden" name="importdetail" value="$newwebpage" />
5450: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5451: $help{'Web_Page'}
1.534 raeburn 5452: </form>
5453: NWEBFORM
5454:
5455:
1.342 ehlerst 5456: my $specialdocumentsform;
1.383 tempelho 5457: my @specialdocumentsforma;
1.451 www 5458: my $gradingform;
5459: my @gradingforma;
5460: my $communityform;
5461: my @communityforma;
1.351 ehlerst 5462: my $newfolderform;
1.390 tempelho 5463: my $newfolderb;
1.342 ehlerst 5464:
1.451 www 5465: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5466:
1.329 droeschl 5467: my $newpageform=(<<NPFORM);
5468: <form action="/adm/coursedocs" method="post" name="newpage">
5469: <input type="hidden" name="folderpath" value="$path" />
5470: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5471: <input type="hidden" name="active" value="ee" />
1.423 onken 5472: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5473: $help{'Adding_Pages'}
1.329 droeschl 5474: </form>
5475: NPFORM
1.390 tempelho 5476:
5477:
1.351 ehlerst 5478: $newfolderform=(<<NFFORM);
1.329 droeschl 5479: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 5480: $pathitem
1.329 droeschl 5481: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5482: <input type="hidden" name="active" value="" />
1.422 onken 5483: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5484: </form>
5485: NFFORM
5486:
5487: my $newsylform=(<<NSYLFORM);
5488: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 5489: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5490: $pathitem
1.329 droeschl 5491: <input type="hidden" name="importdetail"
5492: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5493: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5494: $help{'Syllabus'}
1.383 tempelho 5495:
1.329 droeschl 5496: </form>
5497: NSYLFORM
1.364 bisitz 5498:
1.329 droeschl 5499: my $newgroupfileform=(<<NGFFORM);
5500: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 5501: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5502: $pathitem
1.329 droeschl 5503: <input type="hidden" name="importdetail"
5504: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 5505: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 5506: $help{'Group Portfolio'}
1.329 droeschl 5507: </form>
5508: NGFFORM
1.383 tempelho 5509: @specialdocumentsforma=(
1.421 onken 5510: {'<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 5511: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 5512: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
5513: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 5514: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5515: );
5516: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5517:
1.434 raeburn 5518:
5519: my @importdoc = (
1.519 raeburn 5520: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5521: );
1.598 raeburn 5522: if (keys(%ltitools)) {
5523: push(@importdoc,
5524: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
5525: );
5526: }
1.519 raeburn 5527: unless ($container eq 'page') {
5528: push(@importdoc,
5529: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5530: );
5531: }
5532: push(@importdoc,
1.558 raeburn 5533: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 5534: );
1.501 raeburn 5535: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5536:
1.451 www 5537: @gradingforma=(
5538: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5539: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5540: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5541:
5542: );
5543: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5544:
5545: @communityforma=(
5546: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5547: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5548: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
5549: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
5550: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
5551: );
5552: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5553:
1.330 tempelho 5554: my %orderhash = (
1.553 raeburn 5555: 'aa' => ['Upload',$fileuploadform],
5556: 'bb' => ['Import',$importpubform],
5557: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5558: );
1.519 raeburn 5559: unless ($container eq 'page') {
1.434 raeburn 5560: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5561: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 5562: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5563: }
5564:
1.341 ehlerst 5565: $hadchanges=0;
1.484 raeburn 5566: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5567: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.598 raeburn 5568: $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools);
1.443 www 5569: if ($error) {
5570: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5571: }
5572: if ($hadchanges) {
5573: &mark_hash_old();
5574: }
1.341 ehlerst 5575:
1.443 www 5576: &changewarning($r,'');
5577: }
1.458 raeburn 5578: }
1.442 www 5579:
1.443 www 5580: # Supplemental documents start here
5581:
1.329 droeschl 5582: my $folder=$env{'form.folder'};
1.443 www 5583: unless ($supplementalflag) {
1.329 droeschl 5584: $folder='supplemental';
5585: }
5586: if ($folder =~ /^supplemental$/ &&
5587: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5588: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5589: } elsif ($allowed) {
1.356 tempelho 5590: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5591: }
1.508 raeburn 5592: $pathitem = '<input type="hidden" name="folderpath" value="'.
5593: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5594: if ($allowed) {
5595: my $folderseq=
1.504 raeburn 5596: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5597:
5598: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 5599: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5600: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5601: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 5602: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 5603: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5604: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5605: $fileupload
5606: <br />
5607: <br />
5608: <span class="LC_nobreak">
5609: $checkbox
5610: </span>
5611: <br /><br />
5612: $lt{'comment'}:<br />
1.383 tempelho 5613: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5614: <br />
1.508 raeburn 5615: $pathitem
1.329 droeschl 5616: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 5617: <input type='submit' value="$lt{'upld'}" />
5618: </form>
1.329 droeschl 5619: SUPDOCFORM
5620:
5621: my $supnewfolderform=(<<SNFFORM);
5622: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 5623: <input type="hidden" name="active" value="" />
1.508 raeburn 5624: $pathitem
1.329 droeschl 5625: <input type="hidden" name="importdetail" value="" />
1.423 onken 5626: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5627: $help{'Adding_Folders'}
1.329 droeschl 5628: </form>
5629: SNFFORM
1.383 tempelho 5630:
1.510 raeburn 5631: my $supextform =
5632: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
5633: $help{'Adding_External_Resource'});
1.329 droeschl 5634:
1.598 raeburn 5635: my $supexttoolform =
5636: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
5637: $help{'Adding_External_Tool'},
5638: undef,undef,'tool',$coursedom,
5639: $coursenum,\%ltitools);
5640:
1.329 droeschl 5641: my $supnewsylform=(<<SNSFORM);
5642: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5643: <input type="hidden" name="active" value="ff" />
1.508 raeburn 5644: $pathitem
1.329 droeschl 5645: <input type="hidden" name="importdetail"
5646: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5647: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5648: $help{'Syllabus'}
5649: </form>
5650: SNSFORM
5651:
5652: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5653: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5654: <input type="hidden" name="active" value="ff" />
1.508 raeburn 5655: $pathitem
1.329 droeschl 5656: <input type="hidden" name="importdetail"
5657: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5658: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5659: $help{'My Personal Information Page'}
1.329 droeschl 5660: </form>
5661: SNAMFORM
5662:
1.534 raeburn 5663: my $supwebpage;
5664: if ($folder =~ /^supplemental_?(\d*)$/) {
5665: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5666: if ($1) {
5667: $supwebpage .= $1;
5668: } else {
5669: $supwebpage .= 'default';
5670: }
5671: $supwebpage .= '/new.html';
5672: }
5673: my $supwebpageform =(<<SWEBFORM);
5674: <form action="/adm/coursedocs" method="post" name="supwebpage">
5675: <input type="hidden" name="active" value="cc" />
5676: $pathitem
5677: <input type="hidden" name="importdetail" value="$supwebpage" />
5678: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 5679: $help{'Web_Page'}
1.534 raeburn 5680: </form>
5681: SWEBFORM
5682:
1.333 muellerd 5683:
1.383 tempelho 5684: my @specialdocs = (
1.417 droeschl 5685: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
5686: =>$supnewsylform},
5687: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
5688: =>$supnewaboutmeform},
1.534 raeburn 5689: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5690:
1.383 tempelho 5691: );
1.417 droeschl 5692: my @supimportdoc = (
1.515 raeburn 5693: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 5694: =>$supextform});
5695: if (keys(%ltitools)) {
5696: push(@supimportdoc,
5697: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
5698: =>$supexttoolform});
5699: }
5700: push(@supimportdoc,
5701: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 5702: =>$supupdocform},
1.598 raeburn 5703: );
1.501 raeburn 5704:
5705: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5706: my %suporderhash = (
1.390 tempelho 5707: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 5708: 'ee' => ['Upload',$supupdocform],
5709: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5710: );
1.443 www 5711: if ($supplementalflag) {
1.458 raeburn 5712: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.598 raeburn 5713: $supplementalflag,\%suporderhash,$iconpath,$pathitem,\%ltitools);
1.443 www 5714: if ($error) {
5715: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 5716: } else {
5717: if ($suppchanges) {
5718: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5719: my @ids=&Apache::lonnet::current_machine_ids();
5720: foreach my $server (keys(%servers)) {
5721: next if (grep(/^\Q$server\E$/,@ids));
5722: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 5723: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5724: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 5725: }
5726: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5727: undef($suppchanges);
5728: }
5729: }
1.393 raeburn 5730: }
1.443 www 5731: } elsif ($supplementalflag) {
1.458 raeburn 5732: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5733: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5734: if ($error) {
5735: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5736: }
1.393 raeburn 5737: }
1.389 tempelho 5738:
1.510 raeburn 5739: if ($needs_end) {
5740: $r->print(&endContentScreen());
5741: }
1.383 tempelho 5742:
1.329 droeschl 5743: if ($allowed) {
5744: $r->print('
5745: <form method="post" name="extimport" action="/adm/coursedocs">
5746: <input type="hidden" name="title" />
5747: <input type="hidden" name="url" />
5748: <input type="hidden" name="useform" />
5749: <input type="hidden" name="residx" />
5750: </form>');
5751: }
1.484 raeburn 5752: } elsif ($showdoc) {
1.329 droeschl 5753: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5754: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 5755: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5756: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5757: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5758: }
5759: }
5760: $r->print(&Apache::loncommon::end_page());
5761: return OK;
1.364 bisitz 5762: }
1.329 droeschl 5763:
1.440 raeburn 5764: sub embedded_form_elems {
5765: my ($phase,$primaryurl,$newidx) = @_;
5766: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5767: return <<STATE;
5768: <input type="hidden" name="folderpath" value="$folderpath" />
5769: <input type="hidden" name="cmd" value="upload_embedded" />
5770: <input type="hidden" name="newidx" value="$newidx" />
5771: <input type="hidden" name="phase" value="$phase" />
5772: <input type="hidden" name="primaryurl" value="$primaryurl" />
5773: STATE
5774: }
5775:
5776: sub embedded_destination {
5777: my $folder=$env{'form.folder'};
5778: my $destination = 'docs/';
5779: if ($folder =~ /^supplemental/) {
5780: $destination = 'supplemental/';
5781: }
5782: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5783: $destination .= 'default/';
5784: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5785: $destination .= $2.'/';
5786: }
5787: $destination .= $env{'form.newidx'};
5788: my $dir_root = '/userfiles';
5789: return ($destination,$dir_root);
5790: }
5791:
5792: sub return_to_editor {
5793: my $actionurl = '/adm/coursedocs';
5794: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5795: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5796: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5797: '</a></p>';
5798: }
5799:
1.476 raeburn 5800: sub decompression_info {
5801: my ($destination,$dir_root) = &embedded_destination();
5802: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5803: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5804: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5805: my $container='sequence';
1.480 raeburn 5806: my ($pathitem,$hiddenelem);
1.583 raeburn 5807: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 5808: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5809: $container='page';
5810: }
1.480 raeburn 5811: unshift(@hiddens,$pathitem);
5812: foreach my $item (@hiddens) {
5813: if ($env{'form.'.$item}) {
5814: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 5815: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 5816: }
1.477 raeburn 5817: }
1.476 raeburn 5818: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5819: $hiddenelem);
5820: }
5821:
5822: sub decompression_phase_one {
5823: my ($dir,$file,$warning,$error,$output);
5824: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5825: &decompression_info();
1.490 raeburn 5826: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5827: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5828: } else {
5829: my $file = $1;
1.481 raeburn 5830: $output =
5831: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5832: $destination,$dir_root,
5833: $hiddenelem);
5834: if ($env{'form.autoextract_camtasia'}) {
5835: $output .= &remove_archive($docudom,$docuname,$container);
5836: }
1.476 raeburn 5837: }
5838: if ($error) {
5839: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5840: $error.'</p>'."\n";
5841: }
5842: if ($warning) {
5843: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5844: }
5845: return $output;
5846: }
5847:
5848: sub decompression_phase_two {
5849: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5850: &decompression_info();
1.481 raeburn 5851: my $output;
1.480 raeburn 5852: if ($env{'form.archivedelete'}) {
1.481 raeburn 5853: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5854: }
5855: $output .=
1.481 raeburn 5856: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5857: $destination,$dir_root,$hiddenelem);
5858: return $output;
5859: }
5860:
1.480 raeburn 5861: sub remove_archive {
5862: my ($docudom,$docuname,$container) = @_;
5863: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5864: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5865: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5866: if ($fatal) {
5867: if ($container eq 'page') {
5868: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5869: } else {
5870: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5871: }
1.583 raeburn 5872: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5873: } else {
5874: my $currcmd = $env{'form.cmd'};
5875: my $position = $env{'form.position'};
1.583 raeburn 5876: my $archiveidx = $position;
1.563 raeburn 5877: if ($position > 0) {
1.583 raeburn 5878: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
5879: $archiveidx = $position-1;
5880: }
5881: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 5882: my ($title,$url,@rrest) =
1.583 raeburn 5883: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
5884: if ($url eq $env{'form.archiveurl'}) {
5885: if (&handle_edit_cmd($docuname,$docudom)) {
5886: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5887: if ($fatal) {
5888: if ($container eq 'page') {
5889: $delwarning = &mt('An error occurred updating the contents of the current page.');
5890: } else {
5891: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5892: }
1.480 raeburn 5893: } else {
1.583 raeburn 5894: $delresult = &mt('Archive file removed.');
1.480 raeburn 5895: }
5896: }
1.583 raeburn 5897: } else {
5898: $delwarning .= &mt('Archive file had unexpected item number in folder.').
5899: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5900: }
5901: }
5902: $env{'form.cmd'} = $currcmd;
5903: }
5904: if ($delwarning) {
5905: $output = '<p class="LC_warning">'.
5906: $delwarning.
5907: '</p>';
5908: }
5909: if ($delresult) {
5910: $output .= '<p class="LC_info">'.
5911: $delresult.
5912: '</p>';
5913: }
1.481 raeburn 5914: return $output;
1.480 raeburn 5915: }
5916:
1.484 raeburn 5917: sub generate_admin_menu {
5918: my ($crstype) = @_;
5919: my $lc_crstype = lc($crstype);
5920: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 5921: my %lt= ( # do not translate here
1.484 raeburn 5922: 'vc' => 'Verify Content',
5923: 'cv' => 'Check/Set Resource Versions',
5924: 'ls' => 'List Resource Identifiers',
5925: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 5926: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 5927: );
1.484 raeburn 5928: my ($candump,$dumpurl);
5929: if ($home + $other > 0) {
5930: $candump = 'F';
5931: if ($home) {
5932: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5933: } else {
5934: my @hosts;
5935: foreach my $aurole (keys(%outhash)) {
5936: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5937: push(@hosts,$outhash{$aurole});
1.538 raeburn 5938: }
1.484 raeburn 5939: }
5940: if (@hosts == 1) {
5941: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5942: '&role='.
5943: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5944: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5945: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5946: } else {
5947: $dumpurl = "javascript:choose_switchserver_window()";
5948: }
5949: }
5950: }
5951: my @menu=
5952: ({ categorytitle=>'Administration',
5953: items =>[
5954: { linktext => $lt{'vc'},
5955: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
5956: permission => 'F',
1.571 raeburn 5957: help => 'Docs_Verify_Content',
1.484 raeburn 5958: icon => 'verify.png',
5959: linktitle => 'Verify contents can be retrieved/rendered',
5960: },
5961: { linktext => $lt{'cv'},
5962: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
5963: permission => 'F',
1.571 raeburn 5964: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 5965: icon => 'resversion.png',
5966: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
5967: },
5968: { linktext => $lt{'ls'},
5969: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
5970: permission => 'F',
5971: #help => '',
5972: icon => 'symbs.png',
5973: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
5974: },
5975: ]
5976: },
5977: { categorytitle=>'Export',
5978: items =>[
5979: { linktext => $lt{'imse'},
5980: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
5981: permission => 'F',
5982: help => 'Docs_Export_Course_Docs',
5983: icon => 'imsexport.png',
5984: linktitle => $lt{'imse'},
5985: },
5986: { linktext => $lt{'dcd'},
5987: url => $dumpurl,
5988: permission => $candump,
1.571 raeburn 5989: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 5990: icon => 'dump.png',
5991: linktitle => $lt{'dcd'},
5992: },
5993: ]
5994: });
5995: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
5996: '<input type="hidden" id="dummy" />'."\n".
5997: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
5998: '</form>';
1.329 droeschl 5999: }
6000:
6001: sub generate_edit_table {
1.538 raeburn 6002: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
6003: $need_save,$copyfolder) = @_;
1.406 raeburn 6004: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6005: my %orderhash = %{$orderhash_ref};
1.344 bisitz 6006: my $form;
1.371 tempelho 6007: my $activetab;
6008: my $active;
1.570 raeburn 6009: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6010: $activetab = $env{'form.active'};
6011: }
1.472 raeburn 6012: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6013: my $backtext = &mt('Exit Editor');
1.458 raeburn 6014: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6015: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6016: '<li class="goback">'.
1.546 raeburn 6017: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6018: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6019: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6020: '<li>'.
6021: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6022: &mt('Undo Delete').'</a></li>'."\n";
6023: if ($env{'form.docslog'}) {
6024: $form .= '<li class="active">';
6025: } else {
6026: $form .= '<li>';
6027: }
6028: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6029: &mt('History').'</a></li>'."\n";
6030: if ($env{'form.docslog'}) {
6031: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6032: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6033: }
1.458 raeburn 6034: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6035: if($name ne '00'){
1.371 tempelho 6036: if($activetab eq '' || $activetab ne $name){
6037: $active = '';
6038: }elsif($activetab eq $name){
6039: $active = 'class="active"';
6040: }
1.458 raeburn 6041: $form .= '<li style="float:right" '.$active
1.484 raeburn 6042: .' 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 6043: } else {
1.570 raeburn 6044: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6045:
6046: }
1.329 droeschl 6047: }
1.484 raeburn 6048: $form .= '</ul>'."\n";
6049: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6050:
6051: if ($to_show ne '') {
1.538 raeburn 6052: my $saveform;
6053: if ($need_save) {
6054: my $button = &mt('Make changes');
6055: my $path;
6056: if ($env{'form.folderpath'}) {
6057: $path =
6058: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6059: }
6060: $saveform = <<"END";
6061: <div id="multisave" style="display:none; clear:both;" >
6062: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6063: <input type="hidden" name="folderpath" value="$path" />
6064: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6065: <input type="hidden" name="allhiddenresource" value="" />
6066: <input type="hidden" name="allencrypturl" value="" />
6067: <input type="hidden" name="allrandompick" value="" />
6068: <input type="hidden" name="allrandomorder" value="" />
6069: <input type="hidden" name="changeparms" value="" />
6070: <input type="hidden" name="multiremove" value="" />
6071: <input type="hidden" name="multicut" value="" />
6072: <input type="hidden" name="multicopy" value="" />
6073: <input type="hidden" name="multichange" value="" />
6074: <input type="hidden" name="copyfolder" value="$copyfolder" />
6075: <input type="submit" name="savemultiples" value="$button" />
6076: </form>
6077: </div>
6078: END
6079: }
6080: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6081: }
1.363 ehlerst 6082: foreach my $field (keys(%orderhash)){
1.390 tempelho 6083: if($field ne '00'){
1.422 onken 6084: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6085: $active = 'style="display: none;float:left"';
1.422 onken 6086: }elsif($activetab eq $field){
1.458 raeburn 6087: $active = 'style="display:block;float:left"';
1.422 onken 6088: }
6089: $form .= '<div id="'.$field.$tid.'"'
6090: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6091: .'</div>'."\n";
1.363 ehlerst 6092: }
6093: }
1.484 raeburn 6094: unless ($env{'form.docslog'}) {
6095: $form .= '</div></div>'."\n";
6096: }
1.329 droeschl 6097: return $form;
6098: }
6099:
6100: sub editing_js {
1.600 raeburn 6101: my ($udom,$uname,$supplementalflag,$posslti) = @_;
1.594 damieng 6102: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6103: p_mnf => 'Name of New Folder',
6104: t_mnf => 'New Folder',
6105: p_mnp => 'Name of New Page',
6106: t_mnp => 'New Page',
1.451 www 6107: p_mxu => 'Title for the External Score',
1.349 biermanm 6108: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6109: p_msb => 'Title for the Problem',
6110: p_mdb => 'Title for the Drop Box',
1.336 schafran 6111: p_mbb => 'Title for the Discussion Board',
1.534 raeburn 6112: p_mwp => 'Title for Web Page',
1.348 weissno 6113: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6114: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6115: p_mab_alrt1 => 'Not a valid user:domain',
6116: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6117: p_chn => 'New Title',
6118: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 ! raeburn 6119: p_rmr2a => 'Remove',
! 6120: p_rmr2b => '?',
! 6121: p_rmr3a => 'Remove those',
! 6122: p_rmr3b => 'items?',
! 6123: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
! 6124: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6125: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6126: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 ! raeburn 6127: p_ctr2a => 'Cut',
! 6128: p_ctr2b => '?',
! 6129: p_ctr3a => 'Cut those',
! 6130: p_ctr3b => 'items?',
1.478 raeburn 6131: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6132: imsfile => 'You must choose an IMS package for import',
6133: imscms => 'You must select which Course Management System was the source of the IMS package',
6134: invurl => 'Invalid URL',
6135: titbl => 'Title is blank',
1.538 raeburn 6136: more => '(More ...)',
6137: less => '(Less ...)',
1.543 raeburn 6138: noor => 'No actions selected or changes to settings specified.',
6139: noch => 'No changes to settings specified.',
6140: noac => 'No actions selected.',
1.329 droeschl 6141: );
1.594 damieng 6142: &js_escape(\%js_lt);
1.433 raeburn 6143: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6144: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6145: my $main_container_page;
1.519 raeburn 6146: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6147: $main_container_page = 1;
1.434 raeburn 6148: }
1.538 raeburn 6149: my $toplevelmain =
1.548 raeburn 6150: &escape(&mt('Main Content').':::::');
1.446 www 6151: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6152:
1.525 raeburn 6153: my $backtourl;
1.530 raeburn 6154: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6155: my $caller = $1;
1.525 raeburn 6156: if ($caller =~ /^supplemental/) {
6157: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6158: } else {
6159: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6160: $res = &Apache::lonnet::clutter($res);
6161: if (&Apache::lonnet::is_on_map($res)) {
6162: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
6163: &HTML::Entities::encode($caller,'<>&"');
1.590 raeburn 6164: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6165: } else {
6166: $backtourl = '/adm/navmaps';
1.525 raeburn 6167: }
6168: }
6169: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6170: $backtourl = '/adm/menu';
6171: } elsif ($supplementalflag) {
1.472 raeburn 6172: $backtourl = '/adm/supplemental';
1.525 raeburn 6173: } else {
6174: $backtourl = '/adm/navmaps';
1.472 raeburn 6175: }
6176:
1.600 raeburn 6177: my $fieldsets = "'ext','doc'";
6178: if ($posslti) {
6179: $fieldsets .= ",'tool'";
6180: }
1.519 raeburn 6181: unless ($main_container_page) {
6182: $fieldsets .=",'ims'";
6183: }
1.501 raeburn 6184: if ($supplementalflag) {
1.600 raeburn 6185: $fieldsets = "'suppext','suppdoc'";
6186: if ($posslti) {
6187: $fieldsets .= ",'supptool'";
6188: }
1.501 raeburn 6189: }
6190:
1.329 droeschl 6191: return <<ENDNEWSCRIPT;
6192: function makenewfolder(targetform,folderseq) {
1.594 damieng 6193: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6194: if (foldername) {
6195: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6196: targetform.submit();
6197: }
6198: }
6199:
6200: function makenewpage(targetform,folderseq) {
1.594 damieng 6201: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6202: if (pagename) {
6203: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6204: targetform.submit();
6205: }
6206: }
6207:
6208: function makeexamupload() {
1.594 damieng 6209: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6210: if (title) {
1.329 droeschl 6211: this.document.forms.newexamupload.importdetail.value=
6212: escape(title)+'=/res/lib/templates/examupload.problem';
6213: this.document.forms.newexamupload.submit();
6214: }
6215: }
6216:
6217: function makesmppage() {
1.594 damieng 6218: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6219: if (title) {
1.329 droeschl 6220: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6221: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6222: this.document.forms.newsmppg.submit();
6223: }
6224: }
6225:
1.534 raeburn 6226: function makewebpage(type) {
1.594 damieng 6227: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6228: var formname;
6229: if (type == 'supp') {
6230: formname = this.document.forms.supwebpage;
6231: } else {
6232: formname = this.document.forms.newwebpage;
6233: }
6234: if (title) {
6235: var webpage = formname.importdetail.value;
6236: formname.importdetail.value = escape(title)+'='+webpage;
6237: formname.submit();
6238: }
6239: }
6240:
1.329 droeschl 6241: function makesmpproblem() {
1.594 damieng 6242: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6243: if (title) {
1.329 droeschl 6244: this.document.forms.newsmpproblem.importdetail.value=
6245: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6246: this.document.forms.newsmpproblem.submit();
6247: }
6248: }
6249:
6250: function makedropbox() {
1.594 damieng 6251: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6252: if (title) {
1.329 droeschl 6253: this.document.forms.newdropbox.importdetail.value=
6254: escape(title)+'=/res/lib/templates/DropBox.problem';
6255: this.document.forms.newdropbox.submit();
6256: }
6257: }
6258:
6259: function makebulboard() {
1.594 damieng 6260: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6261: if (title) {
6262: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6263: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6264: this.document.forms.newbul.submit();
6265: }
6266: }
6267:
6268: function makeabout() {
1.594 damieng 6269: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6270: if (user) {
6271: var comp=new Array();
6272: comp=user.split(':');
6273: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6274: if ((comp[0]) && (comp[1])) {
6275: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 6276: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 6277: this.document.forms.newaboutsomeone.submit();
6278: } else {
1.594 damieng 6279: alert("$js_lt{'p_mab_alrt1'}");
1.329 droeschl 6280: }
1.335 ehlerst 6281: } else {
1.594 damieng 6282: alert("$js_lt{'p_mab_alrt2'}");
1.335 ehlerst 6283: }
6284: }
1.329 droeschl 6285: }
6286:
1.501 raeburn 6287: function toggleUpload(caller) {
6288: var blocks = Array($fieldsets);
6289: for (var i=0; i<blocks.length; i++) {
6290: var disp = 'none';
6291: if (caller == blocks[i]) {
6292: var curr = document.getElementById('upload'+caller+'form').style.display;
6293: if (curr == 'none') {
6294: disp='block';
6295: }
6296: }
6297: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 6298: if ((caller == 'tool') || (caller == 'supptool')) {
6299: if (disp == 'block') {
6300: if (document.getElementById('LC_exttoolid')) {
6301: var toolselector = document.getElementById('LC_exttoolid');
6302: var suppflag = 0;
6303: if (caller == 'supptool') {
6304: suppflag = 1;
6305: }
6306: currForm = document.getElementById('new'+caller);
6307: updateExttool(toolselector,currForm,suppflag);
6308: }
6309: }
6310: }
1.501 raeburn 6311: }
1.502 raeburn 6312: resize_scrollbox('contentscroll','1','1');
6313: return;
6314: }
6315:
1.514 raeburn 6316: function toggleMap(caller) {
1.502 raeburn 6317: var disp = 'none';
1.510 raeburn 6318: if (document.getElementById('importmapform')) {
1.514 raeburn 6319: if (caller == 'map') {
6320: var curr = document.getElementById('importmapform').style.display;
6321: if (curr == 'none') {
6322: disp='block';
6323: }
1.510 raeburn 6324: }
6325: document.getElementById('importmapform').style.display=disp;
6326: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 6327: }
1.501 raeburn 6328: return;
1.329 droeschl 6329: }
6330:
1.501 raeburn 6331: function makeims(imsform) {
6332: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 6333: alert("$js_lt{'imsfile'}");
1.501 raeburn 6334: return;
6335: }
6336: if (imsform.source.selectedIndex == 0) {
1.594 damieng 6337: alert("$js_lt{'imscms'}");
1.501 raeburn 6338: return;
6339: }
6340: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6341: imsform.submit();
6342: }
6343:
1.519 raeburn 6344: function changename(folderpath,index,oldtitle) {
1.594 damieng 6345: var title=prompt('$js_lt{"p_chn"}',oldtitle);
1.335 ehlerst 6346: if (title) {
1.538 raeburn 6347: this.document.forms.renameform.markcopy.value='';
1.335 ehlerst 6348: this.document.forms.renameform.title.value=title;
6349: this.document.forms.renameform.cmd.value='rename_'+index;
1.519 raeburn 6350: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 6351: this.document.forms.renameform.submit();
6352: }
1.329 droeschl 6353: }
6354:
1.478 raeburn 6355: function updatePick(targetform,index,caller) {
1.537 raeburn 6356: var pickitem;
6357: var picknumitem;
6358: var picknumtext;
6359: if (index == 'all') {
6360: pickitem = document.getElementById('randompickall');
6361: picknumitem = document.getElementById('rpicknumall');
6362: picknumtext = document.getElementById('rpicktextall');
6363: } else {
6364: pickitem = document.getElementById('randompick_'+index);
6365: picknumitem = document.getElementById('rpicknum_'+index);
6366: picknumtext = document.getElementById('randompicknum_'+index);
6367: }
1.478 raeburn 6368: if (pickitem.checked) {
1.594 damieng 6369: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6370: if (picknum == '' || picknum == null) {
6371: if (caller == 'check') {
6372: pickitem.checked=false;
1.537 raeburn 6373: if (index == 'all') {
6374: picknumtext.innerHTML = '';
6375: if (caller == 'link') {
6376: propagateState(targetform,'rpicknum');
6377: }
6378: } else {
1.538 raeburn 6379: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6380: }
1.478 raeburn 6381: }
6382: } else {
6383: picknum.toString();
6384: var regexdigit=/^\\d+\$/;
6385: if (regexdigit.test(picknum)) {
6386: picknumitem.value = picknum;
1.537 raeburn 6387: if (index == 'all') {
1.538 raeburn 6388: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 6389: if (caller == 'link') {
6390: propagateState(targetform,'rpicknum');
6391: }
6392: } else {
6393: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 6394: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6395: }
1.478 raeburn 6396: } else {
6397: if (caller == 'check') {
1.537 raeburn 6398: if (index == 'all') {
6399: picknumtext.innerHTML = '';
6400: if (caller == 'link') {
6401: propagateState(targetform,'rpicknum');
6402: }
6403: } else {
6404: pickitem.checked=false;
1.538 raeburn 6405: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6406: }
1.478 raeburn 6407: }
6408: return;
6409: }
6410: }
6411: } else {
1.537 raeburn 6412: picknumitem.value = '';
6413: picknumtext.innerHTML = '';
6414: if (index == 'all') {
6415: if (caller == 'link') {
6416: propagateState(targetform,'rpicknum');
6417: }
6418: } else {
1.538 raeburn 6419: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6420: }
6421: }
6422: }
6423:
6424: function propagateState(form,param) {
6425: if (document.getElementById(param+'all')) {
6426: var setcheck = 0;
6427: var rpick = 0;
6428: if (param == 'rpicknum') {
6429: if (document.getElementById('randompickall')) {
6430: if (document.getElementById('randompickall').checked) {
6431: if (document.getElementById('rpicknumall')) {
6432: rpick = document.getElementById('rpicknumall').value;
6433: }
6434: }
6435: }
6436: } else {
6437: if (document.getElementById(param+'all').checked) {
6438: setcheck = 1;
6439: }
6440: }
1.538 raeburn 6441: var allidxlist;
6442: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6443: if (document.getElementById('all'+param+'idx')) {
6444: allidxlist = document.getElementById('all'+param+'idx').value;
6445: }
6446: var actions = new Array ('remove','cut','copy');
6447: for (var i=0; i<actions.length; i++) {
6448: if (actions[i] != param) {
6449: if (document.getElementById(actions[i]+'all')) {
6450: document.getElementById(actions[i]+'all').checked = false;
6451: }
6452: }
6453: }
6454: }
1.537 raeburn 6455: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 6456: allidxlist = form.allidx.value;
6457: }
6458: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6459: allidxlist = form.allmapidx.value;
6460: }
6461: if ((allidxlist != '') && (allidxlist != null)) {
6462: var allidxs = allidxlist.split(',');
6463: if (allidxs.length > 1) {
6464: for (var i=0; i<allidxs.length; i++) {
6465: if (document.getElementById(param+'_'+allidxs[i])) {
6466: if (param == 'rpicknum') {
6467: if (document.getElementById('randompick_'+allidxs[i])) {
6468: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6469: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6470: if (rpick > 0) {
6471: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6472: } else {
6473: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6474: }
6475: }
6476: }
6477: } else {
1.537 raeburn 6478: if (setcheck == 1) {
6479: document.getElementById(param+'_'+allidxs[i]).checked = true;
6480: } else {
6481: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 6482: if (param == 'randompick') {
6483: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6484: }
1.537 raeburn 6485: }
6486: }
6487: }
6488: }
1.538 raeburn 6489: if (setcheck == 1) {
6490: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6491: var actions = new Array('copy','cut','remove');
6492: for (var i=0; i<actions.length; i++) {
6493: var otheractions;
6494: var otheridxs;
6495: if (actions[i] === param) {
6496: continue;
6497: } else {
6498: if (document.getElementById('all'+actions[i]+'idx')) {
6499: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6500: otheridxs = otheractions.split(',');
6501: if (otheridxs.length > 1) {
6502: for (var j=0; j<otheridxs.length; j++) {
6503: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6504: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6505: }
1.537 raeburn 6506: }
6507: }
6508: }
1.538 raeburn 6509: }
6510: }
6511: }
6512: }
6513: }
6514: }
6515: }
6516: return;
6517: }
6518:
1.603 ! raeburn 6519: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.539 raeburn 6520: var dosettings;
6521: var doaction;
1.538 raeburn 6522: var control = document.togglemultsettings;
6523: if (context == 'actions') {
6524: control = document.togglemultactions;
1.539 raeburn 6525: doaction = 1;
6526: } else {
6527: dosettings = 1;
1.538 raeburn 6528: }
1.539 raeburn 6529: if (control) {
6530: if (control.showmultpick.length) {
6531: for (var i=0; i<control.showmultpick.length; i++) {
6532: if (control.showmultpick[i].checked) {
6533: if (control.showmultpick[i].value == 1) {
6534: if (context == 'settings') {
6535: dosettings = 0;
6536: } else {
6537: doaction = 0;
1.538 raeburn 6538: }
6539: }
6540: }
1.537 raeburn 6541: }
6542: }
1.539 raeburn 6543: }
6544: if (context == 'settings') {
6545: if (dosettings == 1) {
1.538 raeburn 6546: targetform.changeparms.value=param;
6547: targetform.submit();
6548: }
1.537 raeburn 6549: }
1.539 raeburn 6550: if (context == 'actions') {
6551: if (doaction == 1) {
6552: targetform.cmd.value=param+'_'+index;
6553: targetform.folderpath.value=folderpath;
6554: targetform.markcopy.value=idx+':'+param;
6555: targetform.copyfolder.value=folder+'.'+container;
6556: if (param == 'remove') {
1.603 ! raeburn 6557: var doremove = 0;
! 6558: if (skip_confirm) {
! 6559: if (confirm_removal) {
! 6560: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
! 6561: doremove = 1;
! 6562: }
! 6563: } else {
! 6564: doremove = 1;
! 6565: }
! 6566: } else {
! 6567: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
! 6568: doremove = 1;
! 6569: }
! 6570: }
! 6571: if (doremove) {
1.539 raeburn 6572: targetform.markcopy.value='';
6573: targetform.copyfolder.value='';
6574: targetform.submit();
6575: }
6576: }
6577: if (param == 'cut') {
1.594 damieng 6578: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
1.539 raeburn 6579: targetform.submit();
6580: return;
6581: }
6582: }
6583: if (param == 'copy') {
6584: targetform.submit();
6585: return;
6586: }
6587: targetform.markcopy.value='';
6588: targetform.copyfolder.value='';
6589: targetform.cmd.value='';
6590: targetform.folderpath.value='';
6591: return;
6592: } else {
6593: if (document.getElementById(param+'_'+idx)) {
6594: item = document.getElementById(param+'_'+idx);
6595: if (item.type == 'checkbox') {
6596: if (item.checked) {
6597: item.checked = false;
6598: } else {
6599: item.checked = true;
6600: singleCheck(item,idx,param);
6601: }
6602: }
6603: }
6604: }
6605: }
1.537 raeburn 6606: return;
6607: }
6608:
1.538 raeburn 6609: function singleCheck(caller,idx,action) {
6610: actions = new Array('cut','copy','remove');
6611: if (caller.checked) {
6612: for (var i=0; i<actions.length; i++) {
6613: if (actions[i] != action) {
6614: if (document.getElementById(actions[i]+'_'+idx)) {
6615: if (document.getElementById(actions[i]+'_'+idx).checked) {
6616: document.getElementById(actions[i]+'_'+idx).checked = false;
6617: }
1.537 raeburn 6618: }
6619: }
6620: }
1.478 raeburn 6621: }
1.537 raeburn 6622: return;
1.478 raeburn 6623: }
6624:
1.334 muellerd 6625: function unselectInactive(nav) {
1.335 ehlerst 6626: currentNav = document.getElementById(nav);
6627: currentLis = currentNav.getElementsByTagName('LI');
6628: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6629: if (currentLis[i].className == 'goback') {
6630: currentLis[i].className = 'goback';
6631: } else {
6632: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6633: currentLis[i].className = 'right';
1.472 raeburn 6634: } else {
1.374 tempelho 6635: currentLis[i].className = 'i';
1.472 raeburn 6636: }
6637: }
1.335 ehlerst 6638: }
1.332 tempelho 6639: }
6640:
1.334 muellerd 6641: function hideAll(current, nav, data) {
1.335 ehlerst 6642: unselectInactive(nav);
1.570 raeburn 6643: if (current) {
6644: if (current.className == 'right'){
6645: current.className = 'right active'
6646: } else {
6647: current.className = 'active';
6648: }
1.374 tempelho 6649: }
1.335 ehlerst 6650: currentData = document.getElementById(data);
6651: currentDivs = currentData.getElementsByTagName('DIV');
6652: for (i = 0; i < currentDivs.length; i++) {
6653: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6654: currentDivs[i].style.display = 'none';
1.330 tempelho 6655: }
6656: }
1.335 ehlerst 6657: }
1.330 tempelho 6658:
1.374 tempelho 6659: function openTabs(pageId) {
6660: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6661: if(tabnav.length > 2 ){
1.389 tempelho 6662: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6663: currentLis = currentNav.getElementsByTagName('LI');
6664: for(i = 0; i< currentLis.length; i++){
6665: if(currentLis[i].className == 'active') {
1.375 tempelho 6666: funcString = currentLis[i].onclick.toString();
6667: tab = funcString.split('"');
1.420 onken 6668: if(tab.length < 2) {
6669: tab = funcString.split("'");
6670: }
1.375 tempelho 6671: currentData = document.getElementById(tab[1]);
6672: currentData.style.display = 'block';
1.374 tempelho 6673: }
6674: }
6675: }
6676: }
6677:
1.334 muellerd 6678: function showPage(current, pageId, nav, data) {
1.570 raeburn 6679: currstate = current.className;
1.334 muellerd 6680: hideAll(current, nav, data);
1.375 tempelho 6681: openTabs(pageId);
1.334 muellerd 6682: unselectInactive(nav);
1.570 raeburn 6683: if ((currstate == 'active') || (currstate == 'right active')) {
6684: if (currstate == 'active') {
6685: current.className = '';
6686: } else {
6687: current.className = 'right';
6688: }
6689: activeTab = '';
6690: toggleUpload();
6691: toggleMap();
6692: resize_scrollbox('contentscroll','1','0');
6693: return;
6694: } else {
6695: current.className = 'active';
6696: }
1.330 tempelho 6697: currentData = document.getElementById(pageId);
6698: currentData.style.display = 'block';
1.458 raeburn 6699: activeTab = pageId;
1.501 raeburn 6700: toggleUpload();
1.503 raeburn 6701: toggleMap();
1.433 raeburn 6702: if (nav == 'mainnav') {
6703: var storedpath = "$docs_folderpath";
1.434 raeburn 6704: var storedpage = "$main_container_page";
1.433 raeburn 6705: var reg = new RegExp("^supplemental");
6706: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6707: if (storedpage == 1) {
6708: document.simpleedit.folderpath.value = '';
6709: document.uploaddocument.folderpath.value = '';
6710: } else {
6711: if (reg.test(storedpath)) {
6712: document.simpleedit.folderpath.value = '$toplevelmain';
6713: document.uploaddocument.folderpath.value = '$toplevelmain';
6714: document.newext.folderpath.value = '$toplevelmain';
6715: } else {
6716: document.simpleedit.folderpath.value = storedpath;
6717: document.uploaddocument.folderpath.value = storedpath;
6718: document.newext.folderpath.value = storedpath;
6719: }
1.433 raeburn 6720: }
6721: } else {
1.434 raeburn 6722: if (reg.test(storedpath)) {
6723: document.simpleedit.folderpath.value = storedpath;
6724: document.supuploaddocument.folderpath.value = storedpath;
6725: document.supnewext.folderpath.value = storedpath;
6726: } else {
1.433 raeburn 6727: document.simpleedit.folderpath.value = '$toplevelsupp';
6728: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6729: document.supnewext.folderpath.value = '$toplevelsupp';
6730: }
6731: }
6732: }
1.485 raeburn 6733: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6734: return false;
6735: }
1.329 droeschl 6736:
1.472 raeburn 6737: function toContents(jumpto) {
6738: var newurl = '$backtourl';
1.525 raeburn 6739: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6740: newurl = newurl+'?postdata='+jumpto;
6741: }
6742: location.href=newurl;
6743: }
6744:
1.538 raeburn 6745: function togglePick(caller,value) {
6746: var disp = 'none';
6747: if (document.getElementById('multi'+caller)) {
6748: var curr = document.getElementById('multi'+caller).style.display;
6749: if (value == 1) {
6750: disp='block';
6751: }
6752: if (curr == disp) {
6753: return;
6754: }
6755: document.getElementById('multi'+caller).style.display=disp;
6756: if (value == 1) {
1.594 damieng 6757: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 6758: } else {
6759: document.getElementById('more'+caller).innerHTML = '';
6760: }
6761: if (caller == 'actions') {
6762: setClass(value);
6763: setBoxes(value);
6764: }
6765: }
6766: var showButton = multiSettings();
6767: if (showButton != 1) {
6768: showButton = multiActions();
6769: }
6770: if (document.getElementById('multisave')) {
6771: if (showButton == 1) {
6772: document.getElementById('multisave').style.display='block';
6773: } else {
6774: document.getElementById('multisave').style.display='none';
6775: }
6776: }
6777: resize_scrollbox('contentscroll','1','1');
6778: return;
6779: }
6780:
6781: function toggleCheckUncheck(caller,more) {
6782: if (more == 1) {
1.594 damieng 6783: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 6784: document.getElementById('allfields'+caller).style.display='block';
6785: } else {
1.594 damieng 6786: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 6787: document.getElementById('allfields'+caller).style.display='none';
6788: }
6789: resize_scrollbox('contentscroll','1','1');
6790: }
6791:
6792: function multiSettings() {
6793: var inuse = 0;
6794: var settingsform = document.togglemultsettings;
6795: if (settingsform.showmultpick.length > 1) {
6796: for (var i=0; i<settingsform.showmultpick.length; i++) {
6797: if (settingsform.showmultpick[i].checked) {
6798: if (settingsform.showmultpick[i].value == 1) {
6799: inuse = 1;
6800: }
6801: }
6802: }
6803: }
6804: return inuse;
6805: }
6806:
6807: function multiActions() {
6808: var inuse = 0;
6809: var actionsform = document.togglemultactions;
6810: if (actionsform.showmultpick.length > 1) {
6811: for (var i=0; i<actionsform.showmultpick.length; i++) {
6812: if (actionsform.showmultpick[i].checked) {
6813: if (actionsform.showmultpick[i].value == 1) {
6814: inuse = 1;
6815: }
6816: }
6817: }
6818: }
6819: return inuse;
6820: }
6821:
6822: function checkSubmits() {
6823: var numchanges = 0;
6824: var form = document.saveactions;
6825: var doactions = multiActions();
1.542 raeburn 6826: var cutwarnings = 0;
6827: var remwarnings = 0;
1.603 ! raeburn 6828: var removalinfo = 0;
1.538 raeburn 6829: if (doactions == 1) {
6830: var remidxlist = document.cumulativeactions.allremoveidx.value;
6831: if ((remidxlist != '') && (remidxlist != null)) {
6832: var remidxs = remidxlist.split(',');
6833: for (var i=0; i<remidxs.length; i++) {
6834: if (document.getElementById('remove_'+remidxs[i])) {
6835: if (document.getElementById('remove_'+remidxs[i]).checked) {
6836: form.multiremove.value += remidxs[i]+',';
6837: numchanges ++;
1.542 raeburn 6838: if (document.getElementById('skip_remove_'+remidxs[i])) {
6839: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6840: remwarnings ++;
6841: }
6842: }
1.603 ! raeburn 6843: if (document.getElementById('confirm_removal_'+remidxs[i])) {
! 6844: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
! 6845: removalinfo ++;
! 6846: }
! 6847: }
1.537 raeburn 6848: }
6849: }
1.538 raeburn 6850: }
6851: }
6852: var cutidxlist = document.cumulativeactions.allcutidx.value;
6853: if ((cutidxlist != '') && (cutidxlist != null)) {
6854: var cutidxs = cutidxlist.split(',');
6855: for (var i=0; i<cutidxs.length; i++) {
6856: if (document.getElementById('cut_'+cutidxs[i])) {
6857: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6858: form.multicut.value += cutidxs[i]+',';
6859: numchanges ++;
1.542 raeburn 6860: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6861: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6862: cutwarnings ++;
6863: }
6864: }
1.537 raeburn 6865: }
6866: }
6867: }
6868: }
1.538 raeburn 6869: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6870: if ((copyidxlist != '') && (copyidxlist != null)) {
6871: var copyidxs = copyidxlist.split(',');
6872: for (var i=0; i<copyidxs.length; i++) {
6873: if (document.getElementById('copy_'+copyidxs[i])) {
6874: if (document.getElementById('copy_'+copyidxs[i]).checked) {
6875: form.multicopy.value += copyidxs[i]+',';
6876: numchanges ++;
6877: }
6878: }
6879: }
6880: }
6881: if (numchanges > 0) {
6882: form.multichange.value = numchanges;
6883: }
1.537 raeburn 6884: }
1.538 raeburn 6885: var dosettings = multiSettings();
1.543 raeburn 6886: var haschanges = 0;
1.538 raeburn 6887: if (dosettings == 1) {
6888: form.allencrypturl.value = '';
6889: form.allhiddenresource.value = '';
1.543 raeburn 6890: form.changeparms.value = 'all';
6891: var patt=new RegExp(",\$");
1.538 raeburn 6892: var allidxlist = document.cumulativesettings.allidx.value;
6893: if ((allidxlist != '') && (allidxlist != null)) {
6894: var allidxs = allidxlist.split(',');
6895: if (allidxs.length > 1) {
6896: for (var i=0; i<allidxs.length; i++) {
6897: if (document.getElementById('hiddenresource_'+allidxs[i])) {
6898: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
6899: form.allhiddenresource.value += allidxs[i]+',';
6900: }
6901: }
6902: if (document.getElementById('encrypturl_'+allidxs[i])) {
6903: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
6904: form.allencrypturl.value += allidxs[i]+',';
6905: }
6906: }
6907: }
1.543 raeburn 6908: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
6909: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 6910: }
1.538 raeburn 6911: }
6912: form.allrandompick.value = '';
6913: form.allrandomorder.value = '';
6914: var allmapidxlist = document.cumulativesettings.allmapidx.value;
6915: if ((allmapidxlist != '') && (allmapidxlist != null)) {
6916: var allmapidxs = allmapidxlist.split(',');
6917: for (var i=0; i<allmapidxs.length; i++) {
6918: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
6919: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
6920: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
6921: if ((randompick.checked) && (rpicknum.value != '')) {
6922: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
6923: }
6924: if (randorder.checked) {
6925: form.allrandomorder.value += allmapidxs[i]+',';
6926: }
1.537 raeburn 6927: }
1.543 raeburn 6928: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
6929: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
6930: }
6931: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
6932: haschanges = 1;
6933: }
6934: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
6935: haschanges = 1;
6936: }
6937: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
6938: haschanges = 1;
6939: }
6940: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
6941: haschanges = 1;
1.537 raeburn 6942: }
6943: }
1.543 raeburn 6944: if (doactions == 1) {
1.542 raeburn 6945: if (numchanges > 0) {
1.603 ! raeburn 6946: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 6947: if (remwarnings > 0) {
1.594 damieng 6948: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 6949: return false;
6950: }
6951: }
1.603 ! raeburn 6952: if (removalinfo > 0) {
! 6953: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
! 6954: return false;
! 6955: }
! 6956: }
1.542 raeburn 6957: if (cutwarnings > 0) {
1.594 damieng 6958: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.542 raeburn 6959: return false;
6960: }
6961: }
6962: }
6963: form.submit();
6964: return true;
1.543 raeburn 6965: }
6966: }
6967: if (dosettings == 1) {
6968: if (haschanges == 1) {
1.542 raeburn 6969: form.submit();
6970: return true;
6971: }
1.543 raeburn 6972: }
6973: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 6974: alert("$js_lt{'noor'}");
1.543 raeburn 6975: } else {
6976: if (dosettings == 1) {
1.594 damieng 6977: alert("$js_lt{'noch'}");
1.543 raeburn 6978: } else {
1.594 damieng 6979: alert("$js_lt{'noac'}");
1.543 raeburn 6980: }
6981: }
1.538 raeburn 6982: return false;
6983: }
6984:
6985: function setClass(value) {
6986: var cutclass = 'LC_docs_cut';
6987: var copyclass = 'LC_docs_copy';
6988: var removeclass = 'LC_docs_remove';
6989: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
6990: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
6991: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
6992: var links = document.getElementsByTagName('a');
6993: for (var i=0; i<links.length; i++) {
6994: var classes = links[i].className;
6995: if (cutreg.test(classes)) {
6996: links[i].className = cutclass;
6997: if (value == 1) {
6998: links[i].className += " LC_menubuttons_link";
6999: }
7000: } else {
7001: if (copyreg.test(classes)) {
7002: links[i].className = copyclass;
7003: if (value == 1) {
7004: links[i].className += " LC_menubuttons_link";
7005: }
7006: } else {
7007: if (removereg.test(classes)) {
7008: links[i].className = removeclass;
7009: if (value == 1) {
7010: links[i].className += " LC_menubuttons_link";
7011: }
7012: }
7013: }
7014: }
7015: }
7016: return;
1.537 raeburn 7017: }
7018:
1.538 raeburn 7019: function setBoxes(value) {
7020: var remidxlist = document.cumulativeactions.allremoveidx.value;
7021: if ((remidxlist != '') && (remidxlist != null)) {
7022: var remidxs = remidxlist.split(',');
7023: for (var i=0; i<remidxs.length; i++) {
7024: if (document.getElementById('remove_'+remidxs[i])) {
7025: var item = document.getElementById('remove_'+remidxs[i]);
7026: if (value == 1) {
7027: item.className = 'LC_docs_remove';
7028: } else {
7029: item.className = 'LC_hidden';
7030: }
7031: }
7032: }
7033: }
7034: var cutidxlist = document.cumulativeactions.allcutidx.value;
7035: if ((cutidxlist != '') && (cutidxlist != null)) {
7036: var cutidxs = cutidxlist.split(',');
7037: for (var i=0; i<cutidxs.length; i++) {
7038: if (document.getElementById('cut_'+cutidxs[i])) {
7039: var item = document.getElementById('cut_'+cutidxs[i]);
7040: if (value == 1) {
7041: item.className = 'LC_docs_cut';
7042: } else {
7043: item.className = 'LC_hidden';
7044: }
7045: }
1.537 raeburn 7046: }
7047: }
1.538 raeburn 7048: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7049: if ((copyidxlist != '') && (copyidxlist != null)) {
7050: var copyidxs = copyidxlist.split(',');
7051: for (var i=0; i<copyidxs.length; i++) {
7052: if (document.getElementById('copy_'+copyidxs[i])) {
7053: var item = document.getElementById('copy_'+copyidxs[i]);
7054: if (value == 1) {
7055: item.className = 'LC_docs_copy';
7056: } else {
7057: item.className = 'LC_hidden';
7058: }
7059: }
1.537 raeburn 7060: }
7061: }
7062: return;
7063: }
7064:
1.329 droeschl 7065: ENDNEWSCRIPT
7066: }
1.457 raeburn 7067:
1.483 raeburn 7068: sub history_tab_js {
7069: return <<"ENDHIST";
7070: function toggleHistoryDisp(choice) {
7071: document.docslogform.docslog.value = choice;
7072: document.docslogform.submit();
7073: return;
7074: }
7075:
7076: ENDHIST
7077: }
7078:
1.484 raeburn 7079: sub inject_data_js {
7080: return <<ENDINJECT;
7081:
7082: function injectData(current, hiddenField, name, value) {
7083: currentElement = document.getElementById(hiddenField);
7084: currentElement.name = name;
7085: currentElement.value = value;
7086: current.submit();
7087: }
7088:
7089: ENDINJECT
7090: }
7091:
7092: sub dump_switchserver_js {
7093: my @hosts = @_;
1.594 damieng 7094: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 7095: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7096: swit => 'Switch server?',
1.594 damieng 7097: );
7098: my %html_js_lt = &Apache::lonlocal::texthash(
7099: swit => 'Switch server?',
1.568 raeburn 7100: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7101: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7102: chos => 'Choose server',
7103: );
1.594 damieng 7104: &js_escape(\%js_lt);
7105: &html_escape(\%html_js_lt);
7106: &js_escape(\%html_js_lt);
1.484 raeburn 7107: my $role = $env{'request.role'};
7108: my $js = <<"ENDSWJS";
7109: <script type="text/javascript">
7110: function write_switchserver() {
7111: var server;
7112: if (document.setserver.posshosts.length > 0) {
7113: for (var i=0; i<document.setserver.posshosts.length; i++) {
7114: if (document.setserver.posshosts[i].checked) {
7115: server = document.setserver.posshosts[i].value;
7116: }
7117: }
7118: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7119: }
7120: window.close();
7121: }
7122: </script>
7123:
7124: ENDSWJS
7125:
7126: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7127: {'only_body' => 1,
7128: 'js_ready' => 1,});
7129: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7130:
7131: my $hostpicker;
7132: my $count = 0;
7133: foreach my $host (sort(@hosts)) {
7134: my $checked;
7135: if ($count == 0) {
7136: $checked = ' checked="checked"';
7137: }
7138: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7139: $host.'"'.$checked.' />'.$host.'</label> ';
7140: $count++;
7141: }
7142:
7143: return <<"ENDSWITCHJS";
7144:
7145: function dump_needs_switchserver(url) {
7146: if (url!='' && url!= null) {
1.594 damieng 7147: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7148: go(url);
7149: }
7150: }
7151: return;
7152: }
7153:
7154: function choose_switchserver_window() {
7155: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7156: newWindow.document.open();
7157: newWindow.document.writeln('$startpage');
1.594 damieng 7158: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7159: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7160: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7161: '<form name="setserver" method="post" action="" \\/>\\n'+
7162: '$hostpicker\\n'+
7163: '<br \\/><br \\/>\\n'+
1.594 damieng 7164: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7165: 'onclick="write_switchserver();" \\/>\\n'+
7166: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7167: newWindow.document.writeln('$endpage');
7168: newWindow.document.close();
7169: newWindow.focus();
7170: }
7171:
7172: ENDSWITCHJS
7173: }
7174:
7175: sub makedocslogform {
7176: my ($formelems,$docslog) = @_;
7177: return <<"LOGSFORM";
7178: <form action="/adm/coursedocs" method="post" name="docslogform">
7179: <input type="hidden" name="docslog" value="$docslog" />
7180: $formelems
7181: </form>
7182: LOGSFORM
7183: }
7184:
7185: sub makesimpleeditform {
7186: my ($formelems) = @_;
7187: return <<"SIMPFORM";
7188: <form name="simpleedit" method="post" action="/adm/coursedocs">
7189: <input type="hidden" name="importdetail" value="" />
7190: $formelems
7191: </form>
7192: SIMPFORM
7193: }
7194:
1.329 droeschl 7195: 1;
7196: __END__
7197:
7198:
7199: =head1 NAME
7200:
7201: Apache::londocs.pm
7202:
7203: =head1 SYNOPSIS
7204:
7205: This is part of the LearningOnline Network with CAPA project
7206: described at http://www.lon-capa.org.
7207:
7208: =head1 SUBROUTINES
7209:
7210: =over
7211:
7212: =item %help=()
7213:
7214: Available help topics
7215:
7216: =item mapread()
7217:
1.344 bisitz 7218: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7219: @order and @resources, determines status
7220: sets @order - pointer to resources in right order
7221: sets @resources - array with the resources with correct idx
7222:
7223: =item authorhosts()
7224:
7225: Return hash with valid author names
7226:
7227: =item clean()
7228:
7229: =item dumpcourse()
7230:
7231: Actually dump course
7232:
7233: =item group_import()
7234:
7235: Imports the given (name, url) resources into the course
7236: coursenum, coursedom, and folder must precede the list
7237:
7238: =item breadcrumbs()
7239:
7240: =item log_docs()
7241:
7242: =item docs_change_log()
7243:
7244: =item update_paste_buffer()
7245:
7246: =item print_paste_buffer()
7247:
7248: =item do_paste_from_buffer()
7249:
1.538 raeburn 7250: =item do_buffer_empty()
7251:
7252: =item clear_from_buffer()
7253:
1.492 raeburn 7254: =item get_newmap_url()
7255:
7256: =item dbcopy()
7257:
7258: =item uniqueness_check()
7259:
7260: =item contained_map_check()
7261:
7262: =item url_paste_fixups()
7263:
7264: =item apply_fixups()
7265:
7266: =item copy_dependencies()
7267:
1.329 droeschl 7268: =item update_parameter()
7269:
7270: =item handle_edit_cmd()
7271:
7272: =item editor()
7273:
7274: =item process_file_upload()
7275:
7276: =item process_secondary_uploads()
7277:
7278: =item is_supplemental_title()
7279:
7280: =item entryline()
7281:
7282: =item tiehash()
7283:
7284: =item untiehash()
7285:
7286: =item checkonthis()
7287:
7288: check on this
7289:
7290: =item verifycontent()
7291:
7292: Verify Content
7293:
7294: =item devalidateversioncache() & checkversions()
7295:
7296: Check Versions
7297:
7298: =item mark_hash_old()
7299:
7300: =item is_hash_old()
7301:
7302: =item changewarning()
7303:
7304: =item init_breadcrumbs()
7305:
7306: Breadcrumbs for special functions
7307:
1.484 raeburn 7308: =item create_list_elements()
7309:
7310: =item create_form_ul()
7311:
7312: =item startContentScreen()
7313:
7314: =item endContentScreen()
7315:
7316: =item supplemental_base()
7317:
7318: =item embedded_form_elems()
7319:
7320: =item embedded_destination()
7321:
7322: =item return_to_editor()
7323:
7324: =item decompression_info()
7325:
7326: =item decompression_phase_one()
7327:
7328: =item decompression_phase_two()
7329:
7330: =item remove_archive()
7331:
7332: =item generate_admin_menu()
7333:
7334: =item generate_edit_table()
7335:
7336: =item editing_js()
7337:
7338: =item history_tab_js()
7339:
7340: =item inject_data_js()
7341:
7342: =item dump_switchserver_js()
7343:
1.485 raeburn 7344: =item resize_scrollbox_js()
1.484 raeburn 7345:
7346: =item makedocslogform()
7347:
1.485 raeburn 7348: =item makesimpleeditform()
7349:
1.329 droeschl 7350: =back
7351:
7352: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>