Annotation of loncom/interface/londocs.pm, revision 1.609
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.609 ! raeburn 4: # $Id: londocs.pm,v 1.608 2016/07/01 19:59:36 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.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.329 droeschl 48: use HTML::Entities;
1.488 raeburn 49: use HTML::TokeParser;
1.329 droeschl 50: use GDBM_File;
1.578 raeburn 51: use File::MMagic;
1.606 raeburn 52: use File::Copy;
1.329 droeschl 53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
1.557 raeburn 65: my $suppchanges;
1.329 droeschl 66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
1.492 raeburn 79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
1.329 droeschl 84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 86: $map,1,$report);
1.329 droeschl 87: if ($errtext) { return ($errtext,2); }
1.364 bisitz 88:
1.557 raeburn 89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
1.329 droeschl 94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
1.329 droeschl 126: if ($allowed) {
127: $home++;
1.484 raeburn 128: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 129: } else {
1.484 raeburn 130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 142: return $title;
1.329 droeschl 143: }
144:
145:
146:
147: sub dumpcourse {
148: my ($r) = @_;
1.408 raeburn 149: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 150: my ($starthash,$js);
151: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
152: $js = <<"ENDJS";
153: <script type="text/javascript">
154: // <![CDATA[
155:
156: function hide_searching() {
157: if (document.getElementById('searching')) {
158: document.getElementById('searching').style.display = 'none';
159: }
160: return;
161: }
162:
163: // ]]>
164: </script>
165: ENDJS
166: $starthash = {
167: add_entries => {'onload' => "hide_searching();"},
168: };
169: }
1.568 raeburn 170: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
171: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 172: $r->print(&startContentScreen('tools'));
1.329 droeschl 173: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 174: unless ($home) {
175: $r->print(&endContentScreen());
176: return '';
177: }
1.329 droeschl 178: my $origcrsid=$env{'request.course.id'};
179: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
180: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
181: # Do the dumping
1.484 raeburn 182: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
183: $r->print(&endContentScreen());
184: return '';
185: }
1.531 raeburn 186: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 187: $r->print('<h3>'.&mt('Copying Files').'</h3>');
188: my $title=$env{'form.authorfolder'};
189: $title=&clean($title);
1.567 raeburn 190: my ($navmap,$errormsg) =
191: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
192: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
193: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
194: my (%maps,%resources,%titles);
195: if (!ref($navmap)) {
196: $r->print($errormsg.
197: &endContentScreen());
198: return '';
199: } else {
200: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
201: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 202: }
1.567 raeburn 203: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
204: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
205: %newcontent,%has_simpleprobs);
206: foreach my $item (sort {$a <=> $b} (@todump)) {
207: my $name = $env{'form.namefor_'.$item};
208: if ($resources{$item}) {
209: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
210: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
211: $tocopy{$1} = $name;
212: $display{$item} = $1;
213: $lookup{$1} = $item;
214: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
215: $simpleproblems{$item} = {
216: symb => $resources{$item},
217: name => $name,
218: };
219: $display{$item} = 'simpleproblem_'.$name;
220: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
221: $has_simpleprobs{$1}{$id} = $item;
222: }
223: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
224: my $marker = $1;
225: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
226: $simplepages{$item} = {
227: res => $res,
228: title => $titles{$item},
229: db => $db_name,
230: marker => $marker,
231: symb => $resources{$item},
232: name => $name,
233: };
234: $display{$item} = '/'.$res;
235: }
236: } elsif ($maps{$item}) {
237: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
238: $tocopy{$1} = $name;
239: $display{$item} = $1;
240: $lookup{$1} = $item;
241: }
242: } else {
243: next;
244: }
245: }
1.329 droeschl 246: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
247: $crs=~s/\_/\//g;
1.567 raeburn 248: my $mm = new File::MMagic;
249: my $prefix = "/uploaded/$cdom/$cnum/";
250: %replacehash = %tocopy;
251: foreach my $item (sort(keys(%simpleproblems))) {
252: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
253: $newcontent{$display{$item}} = $content;
254: }
255: my $gateway = Apache::lonhtmlgateway->new('web');
256: foreach my $item (sort(keys(%simplepages))) {
257: if (ref($simplepages{$item}) eq 'HASH') {
258: my $pagetitle = $simplepages{$item}{'title'};
259: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
260: my %contents;
261: foreach my $field (keys(%fields)) {
262: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
263: my $name = $1;
264: my $msg = $fields{$field};
265: if ($name eq 'webreferences') {
266: if ($msg =~ m{^https?://}) {
267: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
268: }
269: } else {
270: $msg = &Encode::decode('utf8',$msg);
271: $msg = $gateway->process_outgoing_html($msg,1);
272: $contents{$name} = $msg;
273: }
274: } elsif ($field eq 'uploaded.photourl') {
275: my $marker = $simplepages{$item}{marker};
276: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
277: my $filepath = $1;
278: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
279: if ($fname ne '') {
280: $fname=~s/\.(\w+)$//;
281: my $ext=$1;
282: $fname = &clean($fname);
283: $fname.='.'.$ext;
284: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
285: $replacehash{$filepath} = $relpath.$fname;
286: $deps{$item}{$filepath} = 1;
287: }
288: }
289: }
290: }
291: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
292: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
293: my $content = '
294: <html>
295: <head>
296: <title>'.$pagetitle.'</title>
297: </head>
298: <body bgcolor="#ffffff">';
299: if ($contents{title}) {
300: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
301: }
302: if ($contents{image}) {
303: $content .= "\n".$contents{image};
304: }
305: if ($contents{content}) {
306: $content .= '
307: <div class="LC_Box">
1.577 bisitz 308: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 309: $contents{content}.'
310: </div>';
311: }
312: if ($contents{webreferences}) {
313: $content .= '
314: <div class="LC_Box">
1.577 bisitz 315: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 316: $contents{webreferences}.'
317: </div>';
318: }
319: $content .= '
320: </body>
321: </html>
322: ';
323: $newcontent{'/'.$simplepages{$item}{res}} = $content;
324: }
325: }
326: foreach my $item (keys(%tocopy)) {
327: unless ($item=~/\.(sequence|page)$/) {
328: my $currurlpath = $prefix.$item;
329: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
330: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
331: }
332: }
333: foreach my $num (sort {$a <=> $b} (@todump)) {
334: my $src = $display{$num};
335: next if ($src eq '');
336: my @needcopy = ();
337: if ($replacehash{$src}) {
338: push(@needcopy,$src);
339: if (ref($deps{$num}) eq 'HASH') {
340: foreach my $dep (sort(keys(%{$deps{$num}}))) {
341: if ($replacehash{$dep}) {
342: push(@needcopy,$dep);
343: }
344: }
345: }
346: } elsif ($src =~ /^simpleproblem_/) {
347: push(@needcopy,$src);
348: }
349: next if (@needcopy == 0);
350: my ($result,$depresult);
351: for (my $i=0; $i<@needcopy; $i++) {
352: my $item = $needcopy[$i];
353: my $newfilename;
354: if ($simpleproblems{$num}) {
355: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
356: } else {
357: $newfilename=$title.'/'.$replacehash{$item};
358: }
359: $newfilename=~s/\.(\w+)$//;
360: my $ext=$1;
361: $newfilename=&clean($newfilename);
362: $newfilename.='.'.$ext;
363: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
364: if ($newrelpath ne $replacehash{$item}) {
365: $replacehash{$item} = $newrelpath;
366: }
367: my @dirs=split(/\//,$newfilename);
368: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
369: my $makepath=$path;
370: my $fail;
371: my $origin;
372: for (my $i=0;$i<$#dirs;$i++) {
373: $makepath.='/'.$dirs[$i];
374: unless (-e $makepath) {
375: unless(mkdir($makepath,0755)) {
376: $fail = &mt('Directory creation failed.');
377: }
378: }
379: }
380: if ($i == 0) {
381: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
382: } else {
383: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
384: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
385: &mt('(dependency)').'</span>: ';
386: }
387: if (-e $path.'/'.$newfilename) {
388: $fail = &mt('Destination already exists -- not overwriting.');
389: } else {
390: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
391: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
392: ($item =~ /^simpleproblem_/)) {
393: print $fh $newcontent{$item};
394: } else {
395: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
396: if (-e $fileloc) {
397: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
398: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
399: (ref($has_simpleprobs{$item}) eq 'HASH')) {
400: my %changes = %{$has_simpleprobs{$item}};
401: my $content = &Apache::lonclonecourse::rewritefile(
402: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
403: (%replacehash,$crs => '')
404: );
405: my $updatedcontent = '';
406: my $parser = HTML::TokeParser->new(\$content);
407: $parser->attr_encoded(1);
408: while (my $token = $parser->get_token) {
409: if ($token->[0] eq 'S') {
410: if (($token->[1] eq 'resource') &&
411: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
412: ($changes{$token->[2]->{'id'}})) {
413: my $id = $token->[2]->{'id'};
414: $updatedcontent .= '<'.$token->[1];
415: foreach my $attrib (@{$token->[3]}) {
416: next unless ($attrib =~ /^(src|type|title|id)$/);
417: if ($attrib eq 'src') {
418: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
419: if ($file) {
420: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
421: } else {
422: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
423: }
424: } else {
425: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
426: }
427: }
428: $updatedcontent .= ' />'."\n";
429: } else {
430: $updatedcontent .= $token->[4]."\n";
431: }
432: } else {
433: $updatedcontent .= $token->[2];
434: }
435: }
436: print $fh $updatedcontent;
437: } else {
438: print $fh &Apache::lonclonecourse::rewritefile(
439: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
440: (%replacehash,$crs => '')
441: );
442: }
443: } else {
444: print $fh
445: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
446: }
447: } else {
448: $fail = &mt('Source does not exist.');
449: }
450: }
451: $fh->close();
452: } else {
453: $fail = &mt('Could not write to destination.');
454: }
455: }
456: my $text;
457: if ($fail) {
458: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
459: } else {
460: $text = '<span class="LC_success">'.&mt('ok').'</span>';
461: }
462: if ($i == 0) {
463: $result .= $text;
464: } else {
465: $depresult .= $text.'</li>';
466: }
467: }
468: $r->print($result);
469: if ($depresult) {
470: $r->print('<ul>'.$depresult.'</ul>');
471: }
472: }
473: } else {
474: my ($navmap,$errormsg) =
475: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
476: if (!ref($navmap)) {
477: $r->print($errormsg);
478: } else {
479: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
480: $r->rflush();
481: my ($preamble,$formname);
482: $formname = 'dumpdoc';
483: unless ($home==1) {
484: $preamble = '<div class="LC_left_float">'.
485: '<fieldset><legend>'.
486: &mt('Select the Authoring Space').
487: '</legend><select name="authorspace">';
1.329 droeschl 488: }
1.567 raeburn 489: my @orderspaces = ();
490: foreach my $key (sort(keys(%outhash))) {
491: if ($key=~/^home_(.+)$/) {
492: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
493: unshift(@orderspaces,$1);
494: } else {
495: push(@orderspaces,$1);
496: }
497: }
498: }
1.569 raeburn 499: if ($home>1) {
500: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
501: }
1.567 raeburn 502: foreach my $user (@orderspaces) {
1.329 droeschl 503: if ($home==1) {
1.567 raeburn 504: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 505: } else {
1.567 raeburn 506: $preamble .= '<option value="'.$user.'">'.$user.' - '.
507: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
508: }
1.329 droeschl 509: }
1.567 raeburn 510: unless ($home==1) {
511: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 512: }
1.567 raeburn 513: my $title=$origcrsdata{'description'};
514: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 515: $title=&clean($title);
1.567 raeburn 516: $preamble .= '<div class="LC_left_float">'.
517: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
518: '<input type="text" size="50" name="authorfolder" value="'.
519: $title.'" />'.
520: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
521: my %uploadedfiles;
522: &tiehash();
523: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
524: my ($ext)=($file=~/\.(\w+)$/);
525: # FIXME Check supplemental here
526: my $title=$hash{'title_'.$hash{
527: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
528: if (!$title) {
529: $title=$file;
530: } else {
531: $title=~s|/|_|g;
532: }
533: $title=~s/\.(\w+)$//;
534: $title=&clean($title);
535: $title.='.'.$ext;
536: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
537: $uploadedfiles{$file} = $title;
538: }
539: &untiehash();
540: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
541: undef,undef,$preamble,$home,\%uploadedfiles));
542: }
1.329 droeschl 543: }
1.484 raeburn 544: $r->print(&endContentScreen());
1.329 droeschl 545: }
546:
1.567 raeburn 547: sub recurse_html {
548: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
549: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
550: my (%allfiles,%codebase);
551: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
552: if (keys(%allfiles)) {
553: foreach my $dependency (keys(%allfiles)) {
554: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
555: my ($depurl,$relfile,$newcontainer);
556: if ($dependency =~ m{^/}) {
557: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
558: $relfile = $1;
559: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
560: $newcontainer = $1;
561: next if ($replacehash->{$newcontainer});
562: }
563: $depurl = $dependency;
564: } else {
565: next;
566: }
567: } else {
568: $relfile = $dependency;
569: $depurl = $currurlpath;
570: $depurl =~ s{[^/]+$}{};
571: $depurl .= $dependency;
572: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
573: }
574: next if ($relfile eq '');
575: my $newname = $replacehash->{$container};
576: $newname =~ s{[^/]+$}{};
577: $replacehash->{$newcontainer} = $newname.$relfile;
578: $deps->{$item}{$newcontainer} = 1;
579: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
580: my $depfile = &Apache::lonnet::filelocation('',$depurl);
581: my $type = $mm->checktype_filename($depfile);
582: if ($type eq 'text/html') {
583: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
584: }
585: }
586: }
587: }
588: return;
589: }
590:
1.329 droeschl 591: sub group_import {
1.598 raeburn 592: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 593: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
594: %removeparam,$importuploaded,$fixuperrors);
595: $allmaps = {};
1.329 droeschl 596: while (@files) {
597: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 598: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 599: && ($caller eq 'londocs')
600: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 601:
1.329 droeschl 602: my $errtext = '';
603: my $fatal = 0;
604: my $newmapstr = '<map>'."\n".
605: '<resource id="1" src="" type="start"></resource>'."\n".
606: '<link from="1" to="2" index="1"></link>'."\n".
607: '<resource id="2" src="" type="finish"></resource>'."\n".
608: '</map>';
609: $env{'form.output'}=$newmapstr;
610: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
611: 'output',$1.$2);
1.534 raeburn 612: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 613: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
614: $fatal = 2;
615: }
616: if ($fatal) {
617: return ($errtext,$fatal);
618: }
619: }
620: if ($url) {
1.598 raeburn 621: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
622: $url = $1;
623: my $marker = $2;
624: my $info = $3;
1.604 raeburn 625: my ($toolid,%toolhash,%toolsettings);
1.598 raeburn 626: my @toolinfo = split(/:/,$info);
627: if ($residx) {
1.604 raeburn 628: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 629: $toolid = $toolsettings{'id'};
630: } else {
1.604 raeburn 631: $toolid = shift(@toolinfo);
1.598 raeburn 632: }
633: $toolid =~ s/\D//g;
1.604 raeburn 634: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
635: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
636: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
637: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
1.598 raeburn 638: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 639: my @deleted;
1.598 raeburn 640: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
641: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
642: $url =~ s/exttool$/exttools/;
643: }
644: $toolhash{'id'} = $toolid;
1.604 raeburn 645: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
646: if ($toolhash{'target'} eq 'window') {
647: foreach my $item ('width','height') {
648: $toolhash{$item} =~ s/^\s+//;
649: $toolhash{$item} =~ s/\s+$//;
650: }
651: }
652: } elsif ($residx) {
653: $toolhash{'target'} = $toolsettings{'target'};
654: if ($toolhash{'target'} eq 'window') {
655: $toolhash{'width'} = $toolsettings{'width'};
656: $toolhash{'height'} = $toolsettings{'height'};
657: }
658: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
659: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
660: if ($toolhash{'target'} eq 'window') {
661: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
662: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
663: }
664: }
1.598 raeburn 665: if ($toolhash{'target'} eq 'iframe') {
666: delete($toolhash{'width'});
667: delete($toolhash{'height'});
1.604 raeburn 668: if ($residx) {
669: if ($toolsettings{'width'}) {
670: push(@deleted,'width');
671: }
672: if ($toolsettings{'height'}) {
673: push(@deleted,'height');
674: }
675: }
676: }
677: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
678: foreach my $item ('label','title') {
679: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
680: $toolhash{'crs'.$item} =~ s/^\s+//;
681: $toolhash{'crs'.$item} =~ s/\s+$//;
682: if ($toolhash{'crs'.$item} eq '') {
683: delete($toolhash{'crs'.$item});
684: }
685: } else {
686: delete($toolhash{'crs'.$item});
687: }
688: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
689: unless (exists($toolhash{'crs'.$item})) {
690: push(@deleted,'crs'.$item);
691: }
692: }
1.598 raeburn 693: }
694: }
695: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 696: if ($putres eq 'ok') {
697: if (@deleted) {
698: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
699: }
700: }
1.598 raeburn 701: }
702: }
703: }
1.529 raeburn 704: if (($caller eq 'londocs') &&
705: ($folder =~ /^default/)) {
1.534 raeburn 706: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 707: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
708: my $cid = $coursedom.'_'.$coursenum;
709: $allmaps =
710: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
711: $chome,$cid);
712: $donechk = 1;
713: }
714: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
715: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
716: \%addedmaps,\%hierarchy,\%titles,$allmaps);
717: $importuploaded = 1;
718: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
719: next if ($allmaps->{$url});
720: }
721: }
1.344 bisitz 722: if (!$residx
1.329 droeschl 723: || defined($LONCAPA::map::zombies[$residx])) {
724: $residx = &LONCAPA::map::getresidx($url,$residx);
725: push(@LONCAPA::map::order, $residx);
726: }
727: my $ext = 'false';
728: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
729: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 730: if ($name eq '') {
1.538 raeburn 731: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 732: }
733: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
734: my $filepath = $1;
735: my $fname = $name;
736: if ($fname =~ /^\W+$/) {
737: $fname = 'web';
738: } else {
739: $fname =~ s/\W/_/g;
740: }
1.599 damieng 741: if (length($fname) > 15) {
1.534 raeburn 742: $fname = substr($fname,0,14);
743: }
744: my $initialtext = &mt('Replace with your own content.');
745: my $newhtml = <<END;
1.545 raeburn 746: <html>
1.534 raeburn 747: <head>
748: <title>$name</title>
749: </head>
750: <body bgcolor="#ffffff">
751: $initialtext
752: </body>
753: </html>
754: END
755: $env{'form.output'}=$newhtml;
756: my $result =
757: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
758: 'output',
759: "$filepath/$residx/$fname.html");
760: if ($result =~ m{^/uploaded/}) {
761: $url = $result;
762: if ($filepath =~ /^supplemental/) {
763: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
764: $env{'user.domain'}.'___&&&___'.$name;
765: }
766: } else {
767: return (&mt('Failed to save new web page.'),1);
768: }
769: }
1.538 raeburn 770: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 771: $LONCAPA::map::resources[$residx] =
1.329 droeschl 772: join(':', ($name, $url, $ext, 'normal', 'res'));
773: }
774: }
1.529 raeburn 775: if ($importuploaded) {
776: my %import_errors;
777: my %updated = (
778: removefrommap => \%removefrommap,
779: removeparam => \%removeparam,
780: );
1.533 raeburn 781: my ($result,$msgsarray,$lockerror) =
782: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 783: if (keys(%import_errors) > 0) {
1.530 raeburn 784: $fixuperrors =
1.529 raeburn 785: '<p span class="LC_warning">'."\n".
786: &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".
787: '<ul>'."\n";
788: foreach my $key (sort(keys(%import_errors))) {
789: $fixuperrors .= '<li>'.$key.'</li>'."\n";
790: }
791: $fixuperrors .= '</ul></p>'."\n";
792: }
1.533 raeburn 793: if (ref($msgsarray) eq 'ARRAY') {
794: if (@{$msgsarray} > 0) {
795: $fixuperrors .= '<p class="LC_info">'.
796: join('<br />',@{$msgsarray}).
797: '</p>';
798: }
799: }
800: if ($lockerror) {
801: $fixuperrors .= '<p class="LC_error">'.
802: $lockerror.
803: '</p>';
804: }
1.529 raeburn 805: }
806: my ($errtext,$fatal) =
807: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 808: unless ($fatal) {
809: if ($folder =~ /^supplemental/) {
810: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 811: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
812: $folder.'.'.$container);
1.557 raeburn 813: }
814: }
1.529 raeburn 815: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 816: }
817:
818: sub log_docs {
1.494 raeburn 819: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 820: }
821:
822: {
823: my @oldresources=();
824: my @oldorder=();
825: my $parmidx;
826: my %parmaction=();
827: my %parmvalue=();
828: my $changedflag;
829:
830: sub snapshotbefore {
831: @oldresources=@LONCAPA::map::resources;
832: @oldorder=@LONCAPA::map::order;
833: $parmidx=undef;
834: %parmaction=();
835: %parmvalue=();
836: $changedflag=0;
837: }
838:
839: sub remember_parms {
840: my ($idx,$parameter,$action,$value)=@_;
841: $parmidx=$idx;
842: $parmaction{$parameter}=$action;
843: $parmvalue{$parameter}=$value;
844: $changedflag=1;
845: }
846:
847: sub log_differences {
848: my ($plain)=@_;
849: my %storehash=('folder' => $plain,
850: 'currentfolder' => $env{'form.folder'});
851: if ($parmidx) {
852: $storehash{'parameter_res'}=$oldresources[$parmidx];
853: foreach my $parm (keys(%parmaction)) {
854: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
855: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
856: }
857: }
858: my $maxidx=$#oldresources;
859: if ($#LONCAPA::map::resources>$#oldresources) {
860: $maxidx=$#LONCAPA::map::resources;
861: }
862: for (my $idx=0; $idx<=$maxidx; $idx++) {
863: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
864: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
865: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
866: $changedflag=1;
867: }
868: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
869: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
870: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
871: $changedflag=1;
872: }
873: }
874: $storehash{'maxidx'}=$maxidx;
875: if ($changedflag) { &log_docs(\%storehash); }
876: }
877: }
878:
879: sub docs_change_log {
1.484 raeburn 880: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486 raeburn 881: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 882: my $js = '<script type="text/javascript">'."\n".
883: '// <![CDATA['."\n".
884: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 885: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
886: $coursedom,$coursenum)."\n".
1.483 raeburn 887: &history_tab_js()."\n".
1.484 raeburn 888: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 889: '// ]]>'."\n".
890: '</script>'."\n";
1.484 raeburn 891: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
892: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 893: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 894: my %orderhash;
895: my $container='sequence';
896: my $pathitem;
1.519 raeburn 897: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 898: $container='page';
899: }
1.519 raeburn 900: my $folderpath=$env{'form.folderpath'};
901: if ($folderpath eq '') {
1.548 raeburn 902: $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
1.519 raeburn 903: }
904: $pathitem = '<input type="hidden" name="folderpath" value="'.
905: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 906: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
907: my $jumpto = $readfile;
908: $jumpto =~ s{^/}{};
909: my $tid = 1;
1.489 raeburn 910: if ($supplementalflag) {
911: $tid = 2;
912: }
1.509 raeburn 913: my ($breadcrumbtrail) =
914: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 915: $r->print($breadcrumbtrail.
916: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
917: $readfile));
1.329 droeschl 918: my %docslog=&Apache::lonnet::dump('nohist_docslog',
919: $env{'course.'.$env{'request.course.id'}.'.domain'},
920: $env{'course.'.$env{'request.course.id'}.'.num'});
921:
922: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
923:
924: my %saveable_parameters = ('show' => 'scalar',);
925: &Apache::loncommon::store_course_settings('docs_log',
926: \%saveable_parameters);
927: &Apache::loncommon::restore_course_settings('docs_log',
928: \%saveable_parameters);
929: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 930: # FIXME: internationalization seems wrong here
1.329 droeschl 931: my %lt=('hiddenresource' => 'Resources hidden',
932: 'encrypturl' => 'URL hidden',
933: 'randompick' => 'Randomly pick',
934: 'randomorder' => 'Randomly ordered',
935: 'set' => 'set to',
936: 'del' => 'deleted');
1.484 raeburn 937: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
938: $pathitem."\n".
939: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
940: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
941: $r->print('<div class="LC_left_float">'.
942: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
943: &makedocslogform($filter,1).
944: '</fieldset></div><br clear="all" />');
1.329 droeschl 945: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
946: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
947: &mt('After').'</th>'.
948: &Apache::loncommon::end_data_table_header_row());
949: my $shown=0;
950: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
951: if ($env{'form.displayfilter'} eq 'currentfolder') {
952: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
953: }
954: my @changes=keys(%{$docslog{$id}{'logentry'}});
955: if ($env{'form.displayfilter'} eq 'containing') {
956: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
957: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
958: foreach my $key (@changes) {
959: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
960: }
1.344 bisitz 961: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 962: }
963: my $count = 0;
964: my $time =
965: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
966: my $plainname =
967: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
968: $docslog{$id}{'exe_udom'});
969: my $about_me_link =
970: &Apache::loncommon::aboutmewrapper($plainname,
971: $docslog{$id}{'exe_uname'},
972: $docslog{$id}{'exe_udom'});
973: my $send_msg_link='';
974: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
975: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
976: $send_msg_link ='<br />'.
977: &Apache::loncommon::messagewrapper(&mt('Send message'),
978: $docslog{$id}{'exe_uname'},
979: $docslog{$id}{'exe_udom'});
980: }
981: $r->print(&Apache::loncommon::start_data_table_row());
982: $r->print('<td>'.$time.'</td>
983: <td>'.$about_me_link.
984: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
985: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
986: $send_msg_link.'</td><td>'.
987: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 988: my $is_supp = 0;
989: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
990: $is_supp = 1;
991: }
1.329 droeschl 992: # Before
993: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
994: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
995: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
996: if ($oldname ne $newname) {
1.488 raeburn 997: my $shown = &LONCAPA::map::qtescape($oldname);
998: if ($is_supp) {
999: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1000: }
1001: $r->print($shown);
1.329 droeschl 1002: }
1003: }
1004: $r->print('<ul>');
1005: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1006: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1007: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1008: if ($is_supp) {
1009: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1010: }
1011: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1012: }
1013: }
1014: $r->print('</ul>');
1015: # After
1016: $r->print('</td><td>');
1017:
1018: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1019: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1020: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1021: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1022: my $shown = &LONCAPA::map::qtescape($newname);
1023: if ($is_supp) {
1024: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1025: }
1026: $r->print($shown);
1.329 droeschl 1027: }
1.364 bisitz 1028: }
1.329 droeschl 1029: $r->print('<ul>');
1030: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1031: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1032: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1033: if ($is_supp) {
1034: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1035: }
1036: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1037: }
1038: }
1039: $r->print('</ul>');
1040: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1041: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1042: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1043: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1044: # FIXME: internationalization seems wrong here
1.329 droeschl 1045: $r->print('<li>'.
1046: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1047: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1048: .'</li>');
1049: }
1050: }
1051: $r->print('</ul>');
1052: }
1053: # End
1054: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1055: $shown++;
1056: if (!($env{'form.show'} eq &mt('all')
1057: || $shown<=$env{'form.show'})) { last; }
1058: }
1.484 raeburn 1059: $r->print(&Apache::loncommon::end_data_table()."\n".
1060: &makesimpleeditform($pathitem)."\n".
1061: '</div></div>');
1062: $r->print(&endContentScreen());
1.329 droeschl 1063: }
1064:
1065: sub update_paste_buffer {
1.492 raeburn 1066: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1067: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1068: if ($env{'form.multiremove'}) {
1069: $env{'form.multiremove'} =~ s/,$//;
1070: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1071: }
1072: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1073: if ($env{'form.multicut'}) {
1074: $env{'form.multicut'} =~ s/,$//;
1075: foreach my $item (split(/,/,$env{'form.multicut'})) {
1076: unless ($removals{$item}) {
1077: $cuts{$item} = 1;
1078: push(@possibles,$item.':cut');
1079: }
1080: }
1081: }
1082: if ($env{'form.multicopy'}) {
1083: $env{'form.multicopy'} =~ s/,$//;
1084: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1085: unless ($removals{$item} || $cuts{$item}) {
1086: push(@possibles,$item.':copy');
1087: }
1088: }
1089: }
1090: } elsif ($env{'form.markcopy'}) {
1091: @possibles = split(/,/,$env{'form.markcopy'});
1092: }
1.329 droeschl 1093:
1.538 raeburn 1094: return if (@possibles == 0);
1.329 droeschl 1095: return if (!defined($env{'form.copyfolder'}));
1096:
1097: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1098: $env{'form.copyfolder'});
1.538 raeburn 1099: return if ($fatal);
1100:
1101: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1102:
1.538 raeburn 1103: # Retrieve current paste buffer suffixes.
1104: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1105: my (%pasteurls,@newpaste);
1106:
1107: # Construct identifiers for current contents of user's paste buffer
1108: if (@currpaste) {
1109: foreach my $suffix (@currpaste) {
1110: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1111: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1112: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1113: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1114: ($url ne '')) {
1.597 raeburn 1115: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1116: }
1117: }
1118: }
1119:
1120: # Mark items for copying (skip any items already in user's paste buffer)
1121: my %addtoenv;
1.597 raeburn 1122:
1123: my @pathitems = split(/\&/,$env{'form.folderpath'});
1124: my @folderconf = split(/\:/,$pathitems[-1]);
1125: my $ispage = $folderconf[4];
1126:
1.538 raeburn 1127: foreach my $item (@possibles) {
1128: my ($orderidx,$cmd) = split(/:/,$item);
1129: next if ($orderidx =~ /\D/);
1130: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1131: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1132: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1133: my %denied = &action_restrictions($coursenum,$coursedom,
1134: &LONCAPA::map::qtescape($url),
1135: $env{'form.folderpath'},\%curr_groups);
1136: next if ($denied{'copy'});
1137: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1138: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1139: my ($suffix,$errortxt,$locknotfreed) =
1140: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1141: if ($suffix ne '') {
1142: push(@newpaste,$suffix);
1143: } else {
1144: if ($locknotfreed) {
1145: return $locknotfreed;
1146: }
1.538 raeburn 1147: }
1148: if (&is_supplemental_title($title)) {
1149: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1150: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1151: }
1.329 droeschl 1152:
1.538 raeburn 1153: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1154: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1155: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1156: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1157: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1158: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1159: my $prefix = $1;
1160: my $subdir =$2;
1161: if ($subdir eq '') {
1162: $subdir = $prefix;
1.492 raeburn 1163: }
1.538 raeburn 1164: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1165: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1166: \%hierarchy,\%titles,\%allmaps);
1167: if (ref($hierarchy{$url}) eq 'HASH') {
1168: my ($nested,$nestednames);
1169: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1170: $nested =~ s/\&$//;
1171: $nestednames =~ s/\Q___&&&___\E$//;
1172: if ($nested ne '') {
1173: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1174: }
1175: if ($nestednames ne '') {
1176: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1177: }
1.492 raeburn 1178: }
1179: }
1.591 raeburn 1180: if ($locknotfreed) {
1181: $output = $locknotfreed;
1182: last;
1183: }
1.492 raeburn 1184: }
1.538 raeburn 1185: if (@newpaste) {
1186: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1187: }
1.492 raeburn 1188: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1189: delete($env{'form.markcopy'});
1.591 raeburn 1190: return $output;
1.329 droeschl 1191: }
1192:
1.492 raeburn 1193: sub recurse_uploaded_maps {
1194: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1195: if (ref($hierarchy->{$url}) eq 'HASH') {
1196: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1197: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1198: my (@uploaded,@names,%shorter);
1199: for (my $i=0; $i<@maps; $i++) {
1200: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1201: if ($inner ne '') {
1202: push(@uploaded,$inner);
1203: push(@names,&escape($titles[$i]));
1204: $shorter{$maps[$i]} = $inner;
1205: }
1206: }
1207: $$nestref .= "$dir:".join(',',@uploaded).'&';
1208: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1209: foreach my $map (@maps) {
1210: if ($shorter{$map} ne '') {
1211: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1212: }
1213: }
1214: }
1215: return;
1216: }
1217:
1.329 droeschl 1218: sub print_paste_buffer {
1.492 raeburn 1219: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1220: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1221:
1.538 raeburn 1222: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1223: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1224: }
1225:
1.538 raeburn 1226: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1227: my ($pasteitems,@pasteable);
1.575 raeburn 1228: my $clipboardcount = 0;
1.488 raeburn 1229:
1.538 raeburn 1230: # Construct identifiers for current contents of user's paste buffer
1231: foreach my $suffix (@currpaste) {
1232: next if ($suffix =~ /\D/);
1233: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1234: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1235: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1236: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1237: ($url ne '')) {
1.575 raeburn 1238: $clipboardcount ++;
1.538 raeburn 1239: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1240: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1241: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1242: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1243: $is_external = 1;
1.598 raeburn 1244: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1245: $is_exttool = 1;
1.538 raeburn 1246: }
1247: if ($folder =~ /^supplemental/) {
1248: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1249: unless ($canpaste) {
1250: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1251: }
1252: } else {
1253: $canpaste = 1;
1254: }
1255: if ($canpaste) {
1256: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1257: my $srcdom = $1;
1258: my $srcnum = $2;
1259: my $rem = $3;
1260: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1261: $othercourse = 1;
1262: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1263: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1264: } else {
1265: $canpaste = 0;
1266: $nopaste = &mt('Paste from another course unavailable.');
1267: }
1268: }
1269: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1270: my $prefix = $1;
1271: $parent = $2;
1272: if ($folder !~ /^\Q$prefix\E/) {
1273: $areachange = 1;
1274: }
1275: $is_uploaded_map = 1;
1.492 raeburn 1276: }
1.597 raeburn 1277: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1278: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1279: if ($cid ne $env{'request.course.id'}) {
1280: my ($srcdom,$srcnum) = split(/_/,$cid);
1281: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1282: $othercrs = '<br />'.&mt('(from another course)');
1283: } else {
1284: $canpaste = 0;
1285: $nopaste = &mt('Paste from another course unavailable.');
1286: }
1287: }
1.492 raeburn 1288: }
1.596 raeburn 1289: if ($canpaste) {
1290: push(@pasteable,$suffix);
1291: }
1.538 raeburn 1292: }
1293: my $buffer;
1.598 raeburn 1294: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1295: $buffer = &mt('External Resource').': '.
1296: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1297: &LONCAPA::map::qtescape($url).')';
1298: } else {
1299: my $icon = &Apache::loncommon::icon($extension);
1300: if ($extension eq 'sequence' &&
1301: $url =~ m{/default_\d+\.sequence$}x) {
1302: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1303: $icon .= '/navmap.folder.closed.gif';
1304: }
1.589 raeburn 1305: my $title = $env{'docs.markedcopy_title_'.$suffix};
1306: if ($title eq '') {
1307: ($title) = ($url =~ m{/([^/]+)$});
1308: }
1.538 raeburn 1309: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1310: ': '.
1311: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1312: &LONCAPA::map::qtescape($title));
1.538 raeburn 1313: }
1314: $pasteitems .= '<div class="LC_left_float">';
1315: my ($options,$onclick);
1316: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1317: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1318: if (($is_uploaded_map) ||
1319: ($url =~ /(bulletinboard|smppg)$/) ||
1320: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1321: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1322: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1323: }
1324: }
1325: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1326: if ($nopaste) {
1327: $pasteitems .= $nopaste;
1328: } else {
1329: if ($othercrs) {
1330: $pasteitems .= $othercrs;
1331: }
1332: if ($options) {
1333: $pasteitems .= $options;
1.492 raeburn 1334: }
1335: }
1.538 raeburn 1336: $pasteitems .= '</div>';
1337: }
1338: }
1339: if ($pasteitems eq '') {
1340: &Apache::lonnet::delenv('docs.markedcopies');
1341: }
1342: my ($pasteform,$form_start,$buttons,$form_end);
1343: if ($pasteitems) {
1344: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1345: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1346: if (@pasteable) {
1.575 raeburn 1347: my $value = &mt('Paste to current folder');
1348: if ($container eq 'page') {
1349: $value = &mt('Paste to current page');
1350: }
1351: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1352: }
1353: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1354: if ($clipboardcount > 1) {
1355: $buttons .=
1356: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1357: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1358: (' 'x2).
1359: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1360: (' 'x2);
1.492 raeburn 1361: }
1.575 raeburn 1362: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1363: '</form>';
1.538 raeburn 1364: } else {
1365: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1366: }
1.538 raeburn 1367: $r->print($form_start
1368: .'<fieldset>'
1369: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1370: .$pasteitems
1371: .'</fieldset>'
1372: .$form_end);
1373: }
1374:
1375: sub paste_options {
1376: my ($suffix,$is_uploaded_map,$parent) = @_;
1377: my ($copytext,$movetext);
1378: if ($is_uploaded_map) {
1379: $copytext = &mt('Copy to new folder');
1380: $movetext = &mt('Move old');
1381: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1382: $copytext = &mt('Copy to new board');
1383: $movetext = &mt('Move (not posts)');
1384: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1385: $copytext = &mt('Copy to new page');
1386: $movetext = &mt('Move');
1.533 raeburn 1387: } else {
1.538 raeburn 1388: $copytext = &mt('Copy to new file');
1389: $movetext = &mt('Move');
1390: }
1391: my $output = '<br />'.
1392: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1393: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1394: '<label>'.
1395: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1396: $copytext.'</label></span>'.(' 'x2).' '.
1397: '<span class="LC_nobreak"><label>'.
1398: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1399: $movetext.'</label></span>';
1400: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1401: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1402: '</legend><table border="0">';
1403: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1404: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1405: my $lastdir = $parent;
1406: my %depths = (
1407: $lastdir => 0,
1408: );
1409: my (%display,%deps);
1410: for (my $i=0; $i<@pastemaps; $i++) {
1411: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1412: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1413: my @subfolders = split(/,/,$subfolderstr);
1414: $deps{$lastdir} = \@subfolders;
1415: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1416: my $depth = $depths{$lastdir} + 1;
1417: my $offset = int($depth * 4);
1418: my $indent = (' ' x $offset);
1419: for (my $j=0; $j<@subfolders; $j++) {
1420: $depths{$subfolders[$j]} = $depth;
1421: $display{$subfolders[$j]} =
1422: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1423: '<td><label>'.
1424: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1425: '<label>'.
1426: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1427: &mt('Move old').'</label>'.
1428: '</td></tr>';
1429: }
1.492 raeburn 1430: }
1.538 raeburn 1431: &recurse_print(\$output,$parent,\%deps,\%display);
1432: $output .= '</table></fieldset>';
1.329 droeschl 1433: }
1.538 raeburn 1434: $output .= '</div>';
1435: return $output;
1.488 raeburn 1436: }
1437:
1.492 raeburn 1438: sub recurse_print {
1.538 raeburn 1439: my ($outputref,$dir,$deps,$display) = @_;
1440: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1441: if (ref($deps->{$dir}) eq 'ARRAY') {
1442: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1443: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1444: }
1445: }
1446: }
1447:
1.488 raeburn 1448: sub supp_pasteable {
1449: my ($url) = @_;
1450: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1451: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1452: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1453: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1454: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1455: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1.488 raeburn 1456: return 1;
1457: }
1458: return;
1.329 droeschl 1459: }
1460:
1.492 raeburn 1461: sub paste_popup_js {
1.594 damieng 1462: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1463: show => 'Show Options',
1464: hide => 'Hide Options',
1.594 damieng 1465: );
1466: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1467: none => 'No items selected from clipboard.',
1.492 raeburn 1468: );
1.594 damieng 1469: &html_escape(\%html_js_lt);
1470: &js_escape(\%html_js_lt);
1471: &js_escape(\%js_lt);
1.492 raeburn 1472: return <<"END";
1473:
1.538 raeburn 1474: function showPasteOptions(suffix) {
1475: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1476: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1477: return;
1478: }
1479:
1.538 raeburn 1480: function hidePasteOptions(suffix) {
1481: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1482: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1483: return;
1484: }
1485:
1486: function showOptions(caller,suffix) {
1487: if (document.getElementById('pasteoptionstext_'+suffix)) {
1488: if (caller.checked) {
1.594 damieng 1489: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1490: } else {
1491: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1492: }
1493: if (document.getElementById('pasteoptions_'+suffix)) {
1494: document.getElementById('pasteoptions_'+suffix).style.display='none';
1495: }
1496: }
1.492 raeburn 1497: return;
1498: }
1499:
1.541 raeburn 1500: function validateClipboard() {
1501: var numchk = 0;
1502: if (document.pasteform.pasting.length > 1) {
1503: for (var i=0; i<document.pasteform.pasting.length; i++) {
1504: if (document.pasteform.pasting[i].checked) {
1505: numchk ++;
1506: }
1507: }
1508: } else {
1509: if (document.pasteform.pasting.type == 'checkbox') {
1510: if (document.pasteform.pasting.checked) {
1511: numchk ++;
1512: }
1513: }
1514: }
1515: if (numchk > 0) {
1516: return true;
1517: } else {
1.594 damieng 1518: alert("$js_lt{'none'}");
1.541 raeburn 1519: return false;
1520: }
1521: }
1522:
1.575 raeburn 1523: function checkClipboard() {
1524: if (document.pasteform.pasting.length > 1) {
1525: for (var i=0; i<document.pasteform.pasting.length; i++) {
1526: document.pasteform.pasting[i].checked = true;
1527: }
1528: }
1529: return;
1530: }
1531:
1532: function uncheckClipboard() {
1533: if (document.pasteform.pasting.length >1) {
1534: for (var i=0; i<document.pasteform.pasting.length; i++) {
1535: document.pasteform.pasting[i].checked = false;
1536: }
1537: }
1538: return;
1539: }
1540:
1.492 raeburn 1541: END
1542:
1543: }
1544:
1.329 droeschl 1545: sub do_paste_from_buffer {
1.492 raeburn 1546: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1547:
1.538 raeburn 1548: # Array of items in paste buffer
1549: my (@currpaste,%pastebuffer,%allerrors);
1550: @currpaste = split(/,/,$env{'docs.markedcopies'});
1551:
1.492 raeburn 1552: # Early out if paste buffer is empty
1.538 raeburn 1553: if (@currpaste == 0) {
1.492 raeburn 1554: return ();
1.538 raeburn 1555: }
1556: map { $pastebuffer{$_} = 1; } @currpaste;
1557:
1558: # Array of items selected items to paste
1559: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1560:
1561: # Early out if nothing selected to paste
1562: if (@reqpaste == 0) {
1563: return();
1564: }
1565: my @topaste;
1566: foreach my $suffix (@reqpaste) {
1567: next if ($suffix =~ /\D/);
1568: next unless (exists($pastebuffer{$suffix}));
1569: push(@topaste,$suffix);
1570: }
1571:
1572: # Early out if nothing available to paste
1573: if (@topaste == 0) {
1574: return();
1.329 droeschl 1575: }
1576:
1.538 raeburn 1577: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1578: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1579:
1580: foreach my $suffix (@topaste) {
1581: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1582: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1583: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1584: # Supplemental content may only include certain types of content
1585: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1586: if ($folder =~ /^supplemental/) {
1587: unless (&supp_pasteable($url)) {
1588: $notinsupp{$suffix} = 1;
1589: next;
1590: }
1.492 raeburn 1591: }
1.538 raeburn 1592: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1593: my $srcd = $1;
1594: my $srcn = $2;
1.492 raeburn 1595: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1596: # check for mdc privilege in the course from which the resource was pasted
1597: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1598: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1599: $notincrs{$suffix} = 1;
1600: next;
1601: }
1.491 raeburn 1602: }
1.538 raeburn 1603: $srcdom{$suffix} = $srcd;
1604: $srcnum{$suffix} = $srcn;
1.597 raeburn 1605: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1606: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1607: my ($srcd,$srcn) = split(/_/,$cid);
1608: # When paste buffer was populated using an active role in a different course
1609: # check for mdc privilege in the course from which the resource was pasted
1610: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1611: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1612: $notincrs{$suffix} = 1;
1613: next;
1614: }
1615: }
1616: $srcdom{$suffix} = $srcd;
1617: $srcnum{$suffix} = $srcn;
1.491 raeburn 1618: }
1.597 raeburn 1619: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1620: push(@dopaste,$suffix);
1621: if ($url=~/\.(page|sequence)$/) {
1622: $is_map{$suffix} = 1;
1623: }
1624:
1625: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1626: my $oldprefix = $1;
1.492 raeburn 1627: # When pasting content from Main Content to Supplemental Content and vice versa
1628: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1629: # a folder/page or a document).
1.538 raeburn 1630: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1631: $prefixchg{$suffix} = 'docstosupp';
1632: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1633: $prefixchg{$suffix} = 'supptodocs';
1634: }
1.491 raeburn 1635:
1.492 raeburn 1636: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1637: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1638: my @nested;
1639: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1640: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1641: my @deps = map { /\d+:([\d,]+$)/ } @items;
1642: foreach my $dep (@deps) {
1643: if ($dep =~ /,/) {
1644: push(@nested,split(/,/,$dep));
1645: } else {
1646: push(@nested,$dep);
1647: }
1.492 raeburn 1648: }
1.538 raeburn 1649: foreach my $item (@nested) {
1650: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1651: push(@{$marktomove{$suffix}},$type.'_'.$item);
1652: }
1.492 raeburn 1653: }
1654: }
1.488 raeburn 1655: }
1656: }
1657:
1.538 raeburn 1658: # Early out if nothing available to paste
1659: if (@dopaste == 0) {
1660: return ();
1661: }
1662:
1663: # Populate message hash and hashes used for main content <=> supplemental content
1664: # changes
1665:
1666: %msgs = &Apache::lonlocal::texthash (
1667: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1668: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1669: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1670: );
1671:
1672: %before = (
1673: docstosupp => {
1674: map => 'default',
1675: doc => 'docs',
1676: },
1677: supptodocs => {
1678: map => 'supplemental',
1679: doc => 'supplemental',
1680: },
1681: );
1682:
1683: %after = (
1684: docstosupp => {
1685: map => 'supplemental',
1686: doc => 'supplemental'
1687: },
1688: supptodocs => {
1689: map => 'default',
1690: doc => 'docs',
1691: },
1692: );
1693:
1694: # Retrieve information about all course maps in main content area
1695:
1696: my $allmaps = {};
1697: if ($folder =~ /^default/) {
1698: $allmaps =
1699: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1700: $env{"course.$env{'request.course.id'}.home"},
1701: $env{'request.course.id'});
1702: }
1703:
1704: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1705:
1706: # Loop over the items to paste
1707: foreach my $suffix (@dopaste) {
1.329 droeschl 1708: # Maps need to be copied first
1.538 raeburn 1709: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1710: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1711: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1712: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1713: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1714: }
1715: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1716: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1717: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1718: my $oldurl = $url;
1719: if ($is_map{$suffix}) {
1.491 raeburn 1720: # If pasting a map, check if map contains other maps
1.538 raeburn 1721: my (%hierarchy,%titles);
1722: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1723: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1724: if ($url=~ m{^/uploaded/}) {
1725: my $newurl;
1726: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1727: ($newurl,my $error) =
1728: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1729: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1730: \$title,$allmaps,\%newurls);
1731: if ($error) {
1732: $allerrors{$suffix} = $error;
1733: next;
1734: }
1735: if ($newurl ne '') {
1736: if ($newurl ne $url) {
1737: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1738: $newsubdir{$url} = $1;
1739: }
1740: $mapchanges{$url} = 1;
1.492 raeburn 1741: }
1.538 raeburn 1742: }
1743: }
1744: if (($srcdom{$suffix} ne $coursedom) ||
1745: ($srcnum{$suffix} ne $coursenum) ||
1746: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1747: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1748: $coursedom,$coursenum,$srcdom{$suffix},
1749: $srcnum{$suffix},$allmaps,\%rewrites,
1750: \%retitles,\%copies,\%dbcopies,
1751: \%zombies,\%params,\%mapmoves,
1752: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1753: \%newurls,\%resdatacopy)) {
1.538 raeburn 1754: $mapmoves{$url} = 1;
1755: }
1756: $url = $newurl;
1757: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1758: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1759: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1760: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1761: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1762: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1763: }
1764: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1765: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1766: push(@toclear,$suffix);
1767: # if pasting published map (main content area only) check map not already in course
1768: if ($folder =~ /^default/) {
1769: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1770: $duplicate{$suffix} = 1;
1771: next;
1.492 raeburn 1772: }
1.491 raeburn 1773: }
1774: }
1.538 raeburn 1775: }
1776: if ($url=~ m{/(bulletinboard|smppg)$}) {
1777: my $prefix = $1;
1.596 raeburn 1778: my $fromothercrs;
1.538 raeburn 1779: #need to copy the db contents to a new one, unless this is a move.
1780: my %info = (
1781: src => $url,
1782: cdom => $coursedom,
1783: cnum => $coursenum,
1.596 raeburn 1784: );
1785: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1786: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1787: $fromothercrs = 1;
1788: $info{'cdom'} = $srcdom{$suffix};
1789: $info{'cnum'} = $srcnum{$suffix};
1790: }
1791: }
1792: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1793: my (%lockerr,$msg);
1794: my ($newurl,$result,$errtext) =
1795: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1796: if ($result eq 'ok') {
1797: $url = $newurl;
1798: $title=&mt('Copy of').' '.$title;
1799: } else {
1800: if ($prefix eq 'smppg') {
1801: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1802: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1803: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1804: }
1805: $results{$suffix} = $result;
1806: $msgerrs{$suffix} = $msg;
1807: $lockerrs{$suffix} = $lockerr{$prefix};
1808: next;
1809: }
1810: if ($lockerr{$prefix}) {
1811: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1812: }
1.489 raeburn 1813: }
1814: }
1.538 raeburn 1815: $title = &LONCAPA::map::qtunescape($title);
1816: my $ext='false';
1817: if ($url=~m{^http(|s)://}) { $ext='true'; }
1818: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1819: if ($folder !~ /^supplemental/) {
1820: (undef,undef,$title) =
1821: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1822: }
1823: } else {
1824: if ($folder=~/^supplemental/) {
1825: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1826: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1827: }
1.533 raeburn 1828: }
1.491 raeburn 1829:
1830: # For uploaded files (excluding pages/sequences) path in copied file is changed
1831: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1832: # courses.
1833:
1.538 raeburn 1834: unless ($is_map{$suffix}) {
1835: my $newidx;
1.492 raeburn 1836: # Now insert the URL at the bottom
1.538 raeburn 1837: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1838: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1839: my $relpath = $1;
1840: if ($relpath ne '') {
1841: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1842: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1843: my $newprefix = $newloc;
1844: if ($newloc eq 'default') {
1845: $newprefix = 'docs';
1846: }
1847: if ($newdocsdir eq '') {
1848: $newdocsdir = 'default';
1849: }
1850: if (($prefixchg{$suffix}) ||
1851: ($srcdom{$suffix} ne $coursedom) ||
1852: ($srcnum{$suffix} ne $coursenum) ||
1853: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1854: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1855: $url =
1856: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1857: &Apache::lonnet::getfile($oldurl));
1858: if ($url eq '/adm/notfound.html') {
1859: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1860: next;
1861: } else {
1862: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1863: $newsubpath =~ s{/+$}{/};
1864: $docmoves{$oldurl} = $newsubpath;
1865: }
1.491 raeburn 1866: }
1867: }
1.597 raeburn 1868: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1869: my $template = $1;
1870: if ($newidx) {
1871: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1872: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1873: }
1.491 raeburn 1874: }
1.538 raeburn 1875: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1876: ':'.$ext.':normal:res';
1877: push(@LONCAPA::map::order,$newidx);
1878: # Store the result
1879: my ($errtext,$fatal) =
1880: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1881: if ($fatal) {
1882: $save_err .= $errtext;
1883: $allresult = 'fail';
1884: }
1.488 raeburn 1885: }
1.538 raeburn 1886:
1.597 raeburn 1887: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1888: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1889: unless ($allresult eq 'fail') {
1890: my %updated = (
1891: rewrites => \%rewrites,
1892: zombies => \%zombies,
1893: removefrommap => \%removefrommap,
1894: removeparam => \%removeparam,
1895: dbcopies => \%dbcopies,
1.597 raeburn 1896: resdatacopy => \%resdatacopy,
1.538 raeburn 1897: retitles => \%retitles,
1898: );
1899: my %info = (
1900: newsubdir => \%newsubdir,
1901: params => \%params,
1902: );
1903: if ($prefixchg{$suffix}) {
1904: $info{'before'} = $before{$prefixchg{$suffix}};
1905: $info{'after'} = $after{$prefixchg{$suffix}};
1906: }
1907: my %moves = (
1908: copies => \%copies,
1909: docmoves => \%docmoves,
1910: mapmoves => \%mapmoves,
1911: );
1912: (my $result,$msgs{$suffix},my $lockerror) =
1913: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1914: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1915: $url,'paste');
1916: $lockerrors .= $lockerror;
1917: if ($result eq 'ok') {
1918: if ($is_map{$suffix}) {
1919: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1920: $folder.'.'.$container);
1921: if ($fatal) {
1922: $allresult = 'failread';
1923: } else {
1924: if ($#LONCAPA::map::order<1) {
1925: my $idx=&LONCAPA::map::getresidx();
1926: if ($idx<=0) { $idx=1; }
1927: $LONCAPA::map::order[0]=$idx;
1928: $LONCAPA::map::resources[$idx]='';
1929: }
1930: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1931: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1932: ':'.$ext.':normal:res';
1933: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1934:
1935: # Store the result
1.538 raeburn 1936: my ($errtext,$fatal) =
1937: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1938: if ($fatal) {
1939: $save_err .= $errtext;
1940: $allresult = 'failstore';
1941: }
1942: }
1943: }
1944: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1945: push(@toclear,$suffix);
1946: }
1947: }
1.492 raeburn 1948: }
1949: }
1.538 raeburn 1950: &clear_from_buffer(\@toclear,\@currpaste);
1951: my $msgsarray;
1952: foreach my $suffix (keys(%msgs)) {
1953: if (ref($msgs{$suffix}) eq 'ARRAY') {
1954: $msgsarray .= join(',',@{$msgs{$suffix}});
1955: }
1956: }
1957: return ($allresult,$save_err,$msgsarray,$lockerrors);
1958: }
1.533 raeburn 1959:
1.538 raeburn 1960: sub do_buffer_empty {
1961: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1962: if (@currpaste == 0) {
1963: return &mt('Clipboard is already empty');
1964: }
1965: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1966: if (@toclear == 0) {
1967: return &mt('Nothing selected to clear from clipboard');
1968: }
1969: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1970: if ($numdel) {
1971: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1972: } else {
1973: return &mt('Clipboard unchanged');
1.492 raeburn 1974: }
1.538 raeburn 1975: return;
1976: }
1977:
1978: sub clear_from_buffer {
1979: my ($toclear,$currpaste) = @_;
1980: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1981: my %pastebuffer;
1982: map { $pastebuffer{$_} = 1; } @{$currpaste};
1983: my $numdel = 0;
1984: foreach my $suffix (@{$toclear}) {
1985: next if ($suffix =~ /\D/);
1986: next unless (exists($pastebuffer{$suffix}));
1987: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1988: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1989: delete($pastebuffer{$suffix});
1990: $numdel ++;
1991: }
1992: }
1993: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1994: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1995: return $numdel;
1.492 raeburn 1996: }
1997:
1998: sub get_newmap_url {
1999: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2000: $titleref,$allmaps,$newurls) = @_;
2001: my $newurl;
2002: if ($url=~ m{^/uploaded/}) {
2003: $$titleref=&mt('Copy of').' '.$$titleref;
2004: }
2005: my $now = time;
2006: my $suffix=$$.int(rand(100)).$now;
2007: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2008: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2009: my $path = $1;
2010: my $prefix = $2;
2011: my $ancestor = $3;
2012: if (length($ancestor) > 10) {
2013: $ancestor = substr($ancestor,-10,10);
2014: }
2015: my $newid;
2016: if ($prefixchg) {
2017: if ($folder =~ /^supplemental/) {
2018: $prefix =~ s/^default/supplemental/;
2019: } else {
2020: $prefix =~ s/^supplemental/default/;
2021: }
2022: }
2023: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2024: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2025: } else {
2026: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2027: }
2028: my $counter = 0;
2029: my $is_unique = &uniqueness_check($newurl);
2030: if ($folder =~ /^default/) {
2031: if ($allmaps->{$newurl}) {
2032: $is_unique = 0;
2033: }
2034: }
2035: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2036: $counter ++;
2037: $suffix ++;
2038: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2039: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2040: } else {
2041: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2042: }
2043: $is_unique = &uniqueness_check($newurl);
2044: }
2045: if ($is_unique) {
2046: $newurls->{$newurl} = 1;
2047: } else {
2048: if ($url=~/\.page$/) {
2049: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2050: } else {
2051: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2052: }
2053: }
1.329 droeschl 2054: }
1.492 raeburn 2055: return ($newurl);
1.329 droeschl 2056: }
2057:
1.488 raeburn 2058: sub dbcopy {
1.533 raeburn 2059: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2060: my ($url,$result,$errtext);
2061: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2062: $url = $dbref->{'src'};
1.533 raeburn 2063: if ($url =~ m{/(smppg|bulletinboard)$}) {
2064: my $prefix = $1;
2065: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2066: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2067: my $db_name;
2068: my $marker = (split(m{/},$url))[4];
2069: $marker=~s/\D//g;
2070: if ($dbref->{'src'} =~ m{/smppg$}) {
2071: $db_name =
2072: &Apache::lonsimplepage::get_db_name($url,$marker,
2073: $dbref->{'cdom'},
2074: $dbref->{'cnum'});
2075: } else {
2076: $db_name = 'bulletinpage_'.$marker;
2077: }
2078: my ($suffix,$freedlock,$error) =
2079: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2080: $coursedom,$coursenum,
2081: 'concat');
2082: if (!$suffix) {
2083: if ($prefix eq 'smppg') {
2084: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2085: } else {
1.565 bisitz 2086: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2087: }
2088: if ($error) {
2089: $errtext .= '<br />'.$error;
2090: }
2091: } else {
2092: #need to copy the db contents to a new one.
2093: my %contents=&Apache::lonnet::dump($db_name,
2094: $dbref->{'cdom'},
2095: $dbref->{'cnum'});
2096: if (exists($contents{'uploaded.photourl'})) {
2097: my $photo = $contents{'uploaded.photourl'};
2098: my ($subdir,$fname) =
2099: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2100: my $newphoto;
1.533 raeburn 2101: if ($fname ne '') {
2102: my $content = &Apache::lonnet::getfile($photo);
2103: unless ($content eq '-1') {
2104: $env{'form.'.$suffix.'.photourl'} = $content;
2105: $newphoto =
2106: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2107: delete($env{'form.'.$suffix.'.photourl'});
2108: }
2109: }
2110: if ($newphoto =~ m{^/uploaded/}) {
2111: $contents{'uploaded.photourl'} = $newphoto;
2112: }
2113: }
2114: $db_name =~ s{_\d*$ }{_$suffix}x;
2115: $result=&Apache::lonnet::put($db_name,\%contents,
2116: $coursedom,$coursenum);
2117: if ($result eq 'ok') {
2118: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2119: }
2120: }
2121: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2122: $lockerrorsref->{$prefix} =
1.533 raeburn 2123: '<div class="LC_error">'.
2124: &mt('There was a problem removing a lockfile.');
2125: if ($prefix eq 'smppg') {
1.560 raeburn 2126: $lockerrorsref->{$prefix} .=
1.559 raeburn 2127: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2128: } else {
1.565 bisitz 2129: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2130: }
1.560 raeburn 2131: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2132: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2133: '</div>';
1.533 raeburn 2134: }
2135: }
2136: } elsif ($url =~ m{/syllabus$}) {
2137: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2138: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2139: if (($dbref->{'cdom'} ne $coursedom) ||
2140: ($dbref->{'cnum'} ne $coursenum)) {
2141: my %contents=&Apache::lonnet::dump('syllabus',
2142: $dbref->{'cdom'},
2143: $dbref->{'cnum'});
2144: $result=&Apache::lonnet::put('syllabus',\%contents,
2145: $coursedom,$coursenum);
2146: }
2147: }
1.488 raeburn 2148: }
2149: }
1.533 raeburn 2150: return ($url,$result,$errtext);
1.488 raeburn 2151: }
2152:
1.597 raeburn 2153: sub copy_templated_files {
2154: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2155: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2156: my $srccontainer = 'sequence';
2157: if ($srcwaspage) {
2158: $srccontainer = 'page';
2159: }
2160: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2161: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2162: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2163: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2164: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2165: $template.'.problem';
2166: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2167: if ($template eq 'simpleproblem') {
2168: $srcprefix .= '.0.';
2169: my $weightprefix = $newprefix;
2170: $newprefix .= '.0.';
2171: my @simpleprobqtypes = qw(radio option string essay numerical);
2172: my $qtype=$srcparms{$srcprefix.'questiontype'};
2173: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2174: my %newdata;
2175: foreach my $type (@simpleprobqtypes) {
2176: if ($type eq $qtype) {
2177: $newdata{"$weightprefix.$type.weight"}=1;
2178: } else {
2179: $newdata{"$weightprefix.$type.weight"}=0;
2180: }
2181: }
2182: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2183: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2184: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2185: if ($qtype eq 'numerical') {
2186: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2187: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2188: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2189: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2190: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2191: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2192: unless (defined($maxfoils)) { $maxfoils=10; }
2193: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2194: if ($maxfoils<=0) { $maxfoils=10; }
2195: my $randomize=$srcparms{$srcprefix.'randomize'};
2196: unless (defined($randomize)) { $randomize='yes'; }
2197: unless ($randomize eq 'no') { $randomize='yes'; }
2198: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2199: $newdata{$newprefix.'randomize'} = $randomize;
2200: if ($qtype eq 'option') {
2201: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2202: }
2203: for (my $i=1; $i<=10; $i++) {
2204: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2205: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2206: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2207: }
2208:
2209: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2210: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2211: unless (defined($maxfoils)) { $maxfoils=10; }
2212: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2213: if ($maxfoils<=0) { $maxfoils=10; }
2214: my $randomize=$srcparms{$srcprefix.'randomize'};
2215: unless (defined($randomize)) { $randomize='yes'; }
2216: unless ($randomize eq 'no') { $randomize='yes'; }
2217: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2218: $newdata{$newprefix.'randomize'} = $randomize;
2219: if ($qtype eq 'option') {
2220: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2221: }
2222: for (my $i=1; $i<=10; $i++) {
2223: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2224: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2225: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2226: }
2227: } elsif ($qtype eq 'string') {
2228: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2229: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2230: }
2231: if (keys(%newdata)) {
2232: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2233: $coursenum);
2234: if ($putres eq 'ok') {
2235: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2236: }
2237: }
2238: }
2239: }
2240: }
2241:
1.329 droeschl 2242: sub uniqueness_check {
2243: my ($newurl) = @_;
2244: my $unique = 1;
2245: foreach my $res (@LONCAPA::map::order) {
2246: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2247: $url=&LONCAPA::map::qtescape($url);
2248: if ($newurl eq $url) {
2249: $unique = 0;
1.344 bisitz 2250: last;
1.329 droeschl 2251: }
2252: }
2253: return $unique;
2254: }
2255:
1.488 raeburn 2256: sub contained_map_check {
1.492 raeburn 2257: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2258: $allmaps) = @_;
1.488 raeburn 2259: my $content = &Apache::lonnet::getfile($url);
2260: unless ($content eq '-1') {
2261: my $parser = HTML::TokeParser->new(\$content);
2262: $parser->attr_encoded(1);
2263: while (my $token = $parser->get_token) {
2264: next if ($token->[0] ne 'S');
2265: if ($token->[1] eq 'resource') {
2266: next if ($token->[2]->{'type'} eq 'zombie');
2267: my $ressrc = $token->[2]->{'src'};
2268: if ($folder =~ /^supplemental/) {
2269: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2270: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2271: next;
2272: }
2273: }
1.492 raeburn 2274: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2275: if ($1 eq 'uploaded') {
2276: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2277: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2278: } else {
1.492 raeburn 2279: if ($allmaps->{$ressrc}) {
1.529 raeburn 2280: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2281: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2282: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2283: } else {
2284: $addedmaps->{$ressrc} = [$url];
2285: }
1.488 raeburn 2286: }
1.492 raeburn 2287: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2288: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2289: }
1.492 raeburn 2290: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2291: if ($folder =~ /^supplemental/) {
1.492 raeburn 2292: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2293: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2294: } else {
2295: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2296: }
1.488 raeburn 2297: }
2298: }
2299: }
2300: }
2301: return;
2302: }
2303:
2304: sub url_paste_fixups {
1.533 raeburn 2305: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2306: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2307: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2308: my $checktitle;
2309: if (($prefixchg) &&
1.492 raeburn 2310: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2311: $checktitle = 1;
2312: }
1.492 raeburn 2313: my $skip;
2314: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2315: my $mapid = $1.$2;
2316: if ($tomove->{$mapid}) {
2317: $skip = 1;
2318: }
2319: }
1.491 raeburn 2320: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2321: return if ($file eq '-1');
2322: my $parser = HTML::TokeParser->new(\$file);
2323: $parser->attr_encoded(1);
1.491 raeburn 2324: my $changed = 0;
1.488 raeburn 2325: while (my $token = $parser->get_token) {
2326: next if ($token->[0] ne 'S');
2327: if ($token->[1] eq 'resource') {
2328: my $ressrc = $token->[2]->{'src'};
2329: next if ($ressrc eq '');
1.491 raeburn 2330: my $id = $token->[2]->{'id'};
1.492 raeburn 2331: my $title = $token->[2]->{'title'};
1.491 raeburn 2332: if ($checktitle) {
2333: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2334: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2335: }
2336: }
1.488 raeburn 2337: next if ($token->[2]->{'type'} eq 'external');
2338: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2339: next if ($skip);
1.532 raeburn 2340: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2341: $changed = 1;
2342: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2343: my $srcdom = $1;
2344: my $srcnum = $2;
1.488 raeburn 2345: my $rem = $3;
1.492 raeburn 2346: my $newurl;
2347: my $mapname;
2348: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2349: my $prefix = $1;
2350: $mapname = $prefix.$2;
2351: if ($tomove->{$mapname}) {
1.533 raeburn 2352: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2353: $srcdom,$srcnum,$allmaps,$rewrites,
2354: $retitles,$copies,$dbcopies,$zombies,
2355: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2356: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2357: next;
2358: } else {
2359: ($newurl,my $error) =
2360: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2361: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2362: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2363: $newsubdir->{$ressrc} = $1;
2364: }
2365: if ($error) {
2366: next;
2367: }
2368: }
2369: }
2370: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2371: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2372:
1.488 raeburn 2373: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2374: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2375: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2376: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2377: $cnum,$srcdom,$srcnum,$allmaps,
2378: $rewrites,$retitles,$copies,$dbcopies,
2379: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2380: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2381: $mapmoves->{$ressrc} = 1;
2382: }
2383: $changed = 1;
1.488 raeburn 2384: } else {
1.532 raeburn 2385: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2386: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2387: $changed = 1;
1.488 raeburn 2388: }
2389: }
1.533 raeburn 2390: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2391: next if ($skip);
1.492 raeburn 2392: my $srcdom = $1;
2393: my $srcnum = $2;
2394: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2395: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2396: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2397: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2398: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2399: $changed = 1;
2400: }
2401: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2402: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2403: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2404: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2405: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2406: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2407: $changed = 1;
1.488 raeburn 2408: }
1.597 raeburn 2409: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2410: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2411: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2412: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2413: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2414: }
1.488 raeburn 2415: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2416: next if ($skip);
2417: my $srcdom = $1;
2418: my $srcnum = $2;
2419: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2420: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2421: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2422: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2423: $changed = 1;
1.488 raeburn 2424: }
2425: }
2426: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2427: next if ($skip);
1.488 raeburn 2428: my $to = $token->[2]->{'to'};
2429: if ($to ne '') {
2430: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2431: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2432: } else {
2433: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2434: }
2435: }
2436: }
2437: }
1.491 raeburn 2438: return $changed;
1.488 raeburn 2439: }
2440:
2441: sub apply_fixups {
1.529 raeburn 2442: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2443: $oldurl,$url,$caller) = @_;
2444: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2445: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2446: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2447: if (ref($updated) eq 'HASH') {
2448: if (ref($updated->{'rewrites'}) eq 'HASH') {
2449: %rewrites = %{$updated->{'rewrites'}};
2450: }
2451: if (ref($updated->{'zombies'}) eq 'HASH') {
2452: %zombies = %{$updated->{'zombies'}};
2453: }
2454: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2455: %removefrommap = %{$updated->{'removefrommap'}};
2456: }
2457: if (ref($updated->{'removeparam'}) eq 'HASH') {
2458: %removeparam = %{$updated->{'removeparam'}};
2459: }
2460: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2461: %dbcopies = %{$updated->{'dbcopies'}};
2462: }
2463: if (ref($updated->{'retitles'}) eq 'HASH') {
2464: %retitles = %{$updated->{'retitles'}};
2465: }
1.597 raeburn 2466: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2467: %resdatacopy = %{$updated->{'resdatacopy'}};
2468: }
1.529 raeburn 2469: }
2470: if (ref($info) eq 'HASH') {
2471: if (ref($info->{'newsubdir'}) eq 'HASH') {
2472: %newsubdir = %{$info->{'newsubdir'}};
2473: }
2474: if (ref($info->{'params'}) eq 'HASH') {
2475: %params = %{$info->{'params'}};
2476: }
2477: if (ref($info->{'before'}) eq 'HASH') {
2478: %before = %{$info->{'before'}};
2479: }
2480: if (ref($info->{'after'}) eq 'HASH') {
2481: %after = %{$info->{'after'}};
2482: }
2483: }
2484: if (ref($moves) eq 'HASH') {
2485: if (ref($moves->{'copies'}) eq 'HASH') {
2486: %copies = %{$moves->{'copies'}};
2487: }
2488: if (ref($moves->{'docmoves'}) eq 'HASH') {
2489: %docmoves = %{$moves->{'docmoves'}};
2490: }
2491: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2492: %mapmoves = %{$moves->{'mapmoves'}};
2493: }
2494: }
2495: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2496: my @allcopies;
1.529 raeburn 2497: if (exists($copies{$key})) {
2498: if (ref($copies{$key}) eq 'HASH') {
2499: my %added;
2500: foreach my $innerkey (keys(%{$copies{$key}})) {
2501: if (($innerkey ne '') && (!$added{$innerkey})) {
2502: push(@allcopies,$innerkey);
2503: $added{$innerkey} = 1;
2504: }
1.491 raeburn 2505: }
1.529 raeburn 2506: undef(%added);
1.491 raeburn 2507: }
2508: }
2509: if ($key eq $oldurl) {
1.529 raeburn 2510: if ((exists($docmoves{$key}))) {
1.532 raeburn 2511: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2512: push(@allcopies,$oldurl);
2513: }
2514: }
2515: }
2516: if (@allcopies > 0) {
2517: foreach my $item (@allcopies) {
1.492 raeburn 2518: my ($relpath,$oldsubdir,$fname) =
2519: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2520: if ($fname ne '') {
2521: my $content = &Apache::lonnet::getfile($item);
2522: unless ($content eq '-1') {
2523: my $storefn;
1.529 raeburn 2524: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2525: $storefn = $docmoves{$key};
1.491 raeburn 2526: } else {
2527: $storefn = $relpath;
2528: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2529: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2530: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2531: }
1.529 raeburn 2532: if ($newsubdir{$key}) {
1.532 raeburn 2533: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2534: }
2535: }
2536: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2537: my $copyurl =
2538: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2539: $storefn.$fname,$content);
2540: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2541: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2542: return &mt('Paste failed: an error occurred copying the file.');
2543: } elsif (ref($errors) eq 'HASH') {
2544: $errors->{$item} = 1;
1.489 raeburn 2545: }
2546: }
1.488 raeburn 2547: }
2548: }
1.491 raeburn 2549: }
2550: }
2551: }
1.529 raeburn 2552: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2553: my $storefn=$key;
2554: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2555: if ($prefixchg && $before{'map'} && $after{'map'}) {
2556: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2557: }
1.529 raeburn 2558: if ($newsubdir{$key}) {
2559: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2560: }
1.491 raeburn 2561: my $mapcontent = &Apache::lonnet::getfile($key);
2562: if ($mapcontent eq '-1') {
2563: if (ref($errors) eq 'HASH') {
2564: $errors->{$key} = 1;
2565: }
2566: } else {
2567: my $newmap =
2568: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2569: $mapcontent);
2570: if ($newmap eq '/adm/notfound.html') {
2571: if (ref($errors) eq 'HASH') {
2572: $errors->{$key} = 1;
1.489 raeburn 2573: }
1.488 raeburn 2574: }
2575: }
2576: }
1.491 raeburn 2577: my %updates;
2578: if ($is_map) {
1.529 raeburn 2579: if (ref($updated) eq 'HASH') {
2580: foreach my $type (keys(%{$updated})) {
2581: if (ref($updated->{$type}) eq 'HASH') {
2582: foreach my $key (keys(%{$updated->{$type}})) {
2583: $updates{$key} = 1;
2584: }
2585: }
2586: }
1.491 raeburn 2587: }
2588: foreach my $key (keys(%updates)) {
1.492 raeburn 2589: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2590: if (ref($rewrites{$key}) eq 'HASH') {
2591: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2592: }
1.529 raeburn 2593: if (ref($retitles{$key}) eq 'HASH') {
2594: %toretitle = %{$retitles{$key}};
1.491 raeburn 2595: }
1.529 raeburn 2596: if (ref($removefrommap{$key}) eq 'HASH') {
2597: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2598: }
1.529 raeburn 2599: if (ref($removeparam{$key}) eq 'HASH') {
2600: %remparam = %{$removeparam{$key}};
1.492 raeburn 2601: }
1.529 raeburn 2602: if (ref($zombies{$key}) eq 'HASH') {
2603: %zombie = %{$zombies{$key}};
1.491 raeburn 2604: }
1.529 raeburn 2605: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2606: foreach my $idx (keys(%{$dbcopies{$key}})) {
2607: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2608: my ($newurl,$result,$errtext) =
2609: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2610: if ($result eq 'ok') {
2611: $newdb{$idx} = $newurl;
2612: } elsif (ref($errors) eq 'HASH') {
2613: $errors->{$key} = 1;
2614: }
2615: push(@msgs,$errtext);
2616: }
1.491 raeburn 2617: }
2618: }
1.597 raeburn 2619: if (ref($resdatacopy{$key}) eq 'HASH') {
2620: if ($newsubdir{$key}) {
2621:
2622: }
2623: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2624: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2625: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2626: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2627: my $template = $1;
2628: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2629: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2630: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2631: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2632: my ($newmapname) = ($key =~ m{/([^/]+)$});
2633: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2634: my $srcmapinfo = $srcfolder.':'.$idx;
2635: if ($srccontainer eq 'page') {
2636: $srcmapinfo .= ':1';
2637: }
2638: if ($newsubdir{$key}) {
2639: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2640: }
2641: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2642: $cnum,$template,$idx,$newmapname);
2643: }
2644: }
2645: }
2646: }
2647: }
1.529 raeburn 2648: if (ref($params{$key}) eq 'HASH') {
2649: %currparam = %{$params{$key}};
1.492 raeburn 2650: }
2651: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2652: if ($fatal) {
1.533 raeburn 2653: return ($errtext);
1.492 raeburn 2654: }
2655: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2656: if (defined($LONCAPA::map::zombies[$i])) {
2657: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2658: if ($zombie{$i} eq $src) {
1.492 raeburn 2659: undef($LONCAPA::map::zombies[$i]);
2660: }
2661: }
2662: }
1.529 raeburn 2663: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2664: my $idx = $LONCAPA::map::order[$i];
2665: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2666: my $changed;
1.529 raeburn 2667: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2668: if ((exists($toremove{$idx})) &&
2669: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2670: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2671: if (ref($currparam{$idx}) eq 'ARRAY') {
2672: foreach my $name (@{$currparam{$idx}}) {
2673: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2674: }
2675: }
2676: next;
2677: }
2678: my $origsrc = $src;
1.532 raeburn 2679: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2680: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2681: $changed = 1;
1.491 raeburn 2682: }
1.492 raeburn 2683: }
1.532 raeburn 2684: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2685: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2686: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2687: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2688: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2689: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2690: } else {
1.529 raeburn 2691: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2692: }
1.491 raeburn 2693: }
1.532 raeburn 2694: if ($origsrc =~ /\.(page|sequence)$/) {
2695: if ($newsubdir{$origsrc}) {
1.529 raeburn 2696: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2697: }
1.532 raeburn 2698: } elsif ($newsubdir{$key}) {
2699: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2700: }
2701: }
1.492 raeburn 2702: $changed = 1;
1.533 raeburn 2703: } elsif ($newdb{$idx} ne '') {
2704: $src = $newdb{$idx};
1.492 raeburn 2705: $changed = 1;
2706: }
2707: if ($changed) {
1.538 raeburn 2708: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2709: }
2710: }
2711: }
2712: foreach my $idx (keys(%remparam)) {
2713: if (ref($remparam{$idx}) eq 'ARRAY') {
2714: foreach my $name (@{$remparam{$idx}}) {
2715: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2716: }
2717: }
2718: }
1.533 raeburn 2719: if (values(%lockerrors) > 0) {
2720: $lockmsg = join('<br />',values(%lockerrors));
2721: }
1.491 raeburn 2722: my $storefn;
2723: if ($key eq $oldurl) {
2724: $storefn = $url;
2725: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2726: } else {
2727: $storefn = $key;
2728: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2729: if ($prefixchg && $before{'map'} && $after{'map'}) {
2730: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2731: }
1.529 raeburn 2732: if ($newsubdir{$key}) {
2733: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2734: }
1.491 raeburn 2735: }
1.492 raeburn 2736: my $report;
2737: if ($folder !~ /^supplemental/) {
2738: $report = 1;
2739: }
1.527 raeburn 2740: (my $outtext,$errtext) =
1.492 raeburn 2741: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2742: if ($errtext) {
1.529 raeburn 2743: if ($caller eq 'paste') {
1.533 raeburn 2744: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2745: }
1.491 raeburn 2746: }
2747: }
2748: }
1.533 raeburn 2749: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2750: }
2751:
2752: sub copy_dependencies {
2753: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2754: my $content;
2755: if (ref($contentref)) {
2756: $content = $$contentref;
2757: } else {
2758: $content = &Apache::lonnet::getfile($item);
2759: }
2760: unless ($content eq '-1') {
2761: my $mm = new File::MMagic;
2762: my $mimetype = $mm->checktype_contents($content);
2763: if ($mimetype eq 'text/html') {
2764: my (%allfiles,%codebase,$state);
2765: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2766: if ($res eq 'ok') {
2767: my ($numexisting,$numpathchanges,$existing);
2768: (undef,$numexisting,$numpathchanges,$existing) =
2769: &Apache::loncommon::ask_for_embedded_content(
2770: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2771: {'error_on_invalid_names' => 1,
2772: 'ignore_remote_references' => 1,
2773: 'docs_url' => $item,
2774: 'context' => 'paste'});
2775: if ($numexisting > 0) {
2776: if (ref($existing) eq 'HASH') {
2777: foreach my $dep (keys(%{$existing})) {
2778: my $depfile = $dep;
2779: unless ($depfile =~ m{^\Q$relpath\E}) {
2780: $depfile = $relpath.$dep;
2781: }
2782: my $depcontent = &Apache::lonnet::getfile($depfile);
2783: unless ($depcontent eq '-1') {
2784: my $storedep = $dep;
2785: $storedep =~ s{^\Q$relpath\E}{};
2786: my $dep_url =
2787: &Apache::lonclonecourse::writefile(
2788: $env{'request.course.id'},
2789: $storefn.$storedep,$depcontent);
2790: if ($dep_url eq '/adm/notfound.html') {
2791: if (ref($errors) eq 'HASH') {
2792: $errors->{$depfile} = 1;
2793: }
2794: } else {
2795: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2796: }
2797: }
2798: }
1.488 raeburn 2799: }
2800: }
2801: }
2802: }
2803: }
2804: return;
2805: }
2806:
1.329 droeschl 2807: my %parameter_type = ( 'randompick' => 'int_pos',
2808: 'hiddenresource' => 'string_yesno',
2809: 'encrypturl' => 'string_yesno',
2810: 'randomorder' => 'string_yesno',);
2811: my $valid_parameters_re = join('|',keys(%parameter_type));
2812: # set parameters
2813: sub update_parameter {
1.537 raeburn 2814: if ($env{'form.changeparms'} eq 'all') {
2815: my (@allidx,@allmapidx,%allchecked,%currchecked);
2816: %allchecked = (
2817: 'hiddenresource' => {},
2818: 'encrypturl' => {},
2819: 'randompick' => {},
2820: 'randomorder' => {},
2821: );
2822: foreach my $which (keys(%allchecked)) {
2823: $env{'form.all'.$which} =~ s/,$//;
2824: if ($which eq 'randompick') {
2825: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2826: my ($res,$value) = split(/:/,$item);
2827: if ($value =~ /^\d+$/) {
2828: $allchecked{$which}{$res} = $value;
2829: }
2830: }
2831: } else {
1.539 raeburn 2832: if ($env{'form.all'.$which}) {
2833: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2834: }
1.537 raeburn 2835: }
2836: }
2837: my $haschanges = 0;
2838: foreach my $res (@LONCAPA::map::order) {
2839: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2840: $name=&LONCAPA::map::qtescape($name);
2841: $url=&LONCAPA::map::qtescape($url);
2842: next unless ($name && $url);
2843: my $is_map;
2844: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2845: $is_map = 1;
2846: }
2847: foreach my $which (keys(%allchecked)) {
2848: if (($which eq 'randompick' || $which eq 'randomorder')) {
2849: next if (!$is_map);
2850: }
2851: my $oldvalue = 0;
2852: my $newvalue = 0;
2853: if ($allchecked{$which}{$res}) {
2854: $newvalue = $allchecked{$which}{$res};
2855: }
2856: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2857: if ($which eq 'randompick') {
2858: if ($current =~ /^(\d+)$/) {
2859: $oldvalue = $1;
2860: }
2861: } else {
2862: if ($current =~ /^yes$/i) {
2863: $oldvalue = 1;
2864: }
2865: }
2866: if ($oldvalue ne $newvalue) {
2867: $haschanges = 1;
2868: if ($newvalue) {
2869: my $storeval = 'yes';
2870: if ($which eq 'randompick') {
2871: $storeval = $newvalue;
2872: }
2873: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2874: $storeval,
2875: $parameter_type{$which});
2876: &remember_parms($res,$which,'set',$storeval);
2877: } elsif ($oldvalue) {
2878: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2879: &remember_parms($res,$which,'del');
2880: }
2881: }
2882: }
2883: }
2884: return $haschanges;
2885: } else {
1.588 raeburn 2886: my $haschanges = 0;
2887: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2888:
1.537 raeburn 2889: my $which = $env{'form.changeparms'};
2890: my $idx = $env{'form.setparms'};
1.588 raeburn 2891: my $oldvalue = 0;
2892: my $newvalue = 0;
2893: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2894: if ($which eq 'randompick') {
2895: if ($current =~ /^(\d+)$/) {
2896: $oldvalue = $1;
2897: }
2898: } elsif ($current =~ /^yes$/i) {
2899: $oldvalue = 1;
2900: }
1.537 raeburn 2901: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2902: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2903: : 1;
2904: }
2905: if ($oldvalue ne $newvalue) {
2906: $haschanges = 1;
2907: if ($newvalue) {
2908: my $storeval = 'yes';
2909: if ($which eq 'randompick') {
2910: $storeval = $newvalue;
2911: }
2912: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($idx,$which,'set',$storeval);
2915: } else {
2916: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2917: &remember_parms($idx,$which,'del');
2918: }
1.537 raeburn 2919: }
1.588 raeburn 2920: return $haschanges;
1.329 droeschl 2921: }
2922: }
2923:
2924: sub handle_edit_cmd {
2925: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2926: if ($env{'form.cmd'} eq '') {
2927: return 0;
2928: }
1.329 droeschl 2929: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2930:
2931: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2932: my ($title, $url, @rrest) = split(':', $ratstr);
2933:
1.538 raeburn 2934: if ($cmd eq 'remove') {
1.329 droeschl 2935: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2936: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2937: &Apache::lonnet::removeuploadedurl($url);
2938: } else {
2939: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2940: }
2941: splice(@LONCAPA::map::order, $idx, 1);
2942:
2943: } elsif ($cmd eq 'cut') {
2944: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2945: splice(@LONCAPA::map::order, $idx, 1);
2946:
1.344 bisitz 2947: } elsif ($cmd eq 'up'
1.329 droeschl 2948: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2949: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2950:
2951: } elsif ($cmd eq 'down'
2952: && defined($LONCAPA::map::order[$idx+1])) {
2953: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2954:
2955: } elsif ($cmd eq 'rename') {
2956: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2957: if ($comment=~/\S/) {
2958: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2959: $comment.':'.join(':', $url, @rrest);
2960: }
2961: # Devalidate title cache
2962: my $renamed_url=&LONCAPA::map::qtescape($url);
2963: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 2964:
1.329 droeschl 2965: } else {
2966: return 0;
2967: }
2968: return 1;
2969: }
2970:
2971: sub editor {
1.458 raeburn 2972: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.598 raeburn 2973: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref)=@_;
1.519 raeburn 2974: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 2975: if ($allowed) {
1.519 raeburn 2976: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2977: $is_random_order,$container) =
1.510 raeburn 2978: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2979: $r->print($breadcrumbtrail);
1.519 raeburn 2980: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2981: $container = 'page';
2982: } else {
2983: $container = 'sequence';
1.510 raeburn 2984: }
1.484 raeburn 2985:
1.525 raeburn 2986: my $jumpto;
2987:
2988: unless ($supplementalflag) {
1.546 raeburn 2989: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 2990: }
1.484 raeburn 2991:
2992: unless ($allowed) {
2993: $randompick = -1;
2994: }
2995:
1.329 droeschl 2996: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2997: $folder.'.'.$container);
2998: return $errtext if ($fatal);
2999:
3000: if ($#LONCAPA::map::order<1) {
3001: my $idx=&LONCAPA::map::getresidx();
3002: if ($idx<=0) { $idx=1; }
3003: $LONCAPA::map::order[0]=$idx;
3004: $LONCAPA::map::resources[$idx]='';
3005: }
1.364 bisitz 3006:
1.329 droeschl 3007: # ------------------------------------------------------------ Process commands
3008:
3009: # ---------------- if they are for this folder and user allowed to make changes
3010: if (($allowed) && ($env{'form.folder'} eq $folder)) {
3011: # set parameters and change order
3012: &snapshotbefore();
3013:
3014: if (&update_parameter()) {
1.588 raeburn 3015: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3016: return $errtext if ($fatal);
3017: }
3018:
3019: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3020: # change order
3021: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3022: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3023:
3024: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3025: return $errtext if ($fatal);
3026: }
1.364 bisitz 3027:
1.329 droeschl 3028: if ($env{'form.pastemarked'}) {
1.491 raeburn 3029: my %paste_errors;
1.533 raeburn 3030: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3031: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3032: \%paste_errors);
1.541 raeburn 3033: if (ref($pastemsgarray) eq 'ARRAY') {
3034: if (@{$pastemsgarray} > 0) {
3035: $r->print('<p class="LC_info">'.
3036: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3037: '</p>');
3038: }
1.541 raeburn 3039: }
3040: if ($lockerror) {
3041: $r->print('<p class="LC_error">'.
3042: $lockerror.
3043: '</p>');
3044: }
3045: if ($save_error ne '') {
3046: return $save_error;
3047: }
3048: if ($paste_res) {
3049: my %errortext = &Apache::lonlocal::texthash (
3050: fail => 'Storage of folder contents failed',
3051: failread => 'Reading folder contents failed',
3052: failstore => 'Storage of folder contents failed',
3053: );
3054: if ($errortext{$paste_res}) {
3055: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3056: }
1.329 droeschl 3057: }
1.491 raeburn 3058: if (keys(%paste_errors) > 0) {
1.538 raeburn 3059: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3060: &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".
3061: '<ul>'."\n");
3062: foreach my $key (sort(keys(%paste_errors))) {
3063: $r->print('<li>'.$key.'</li>'."\n");
3064: }
3065: $r->print('</ul></p>'."\n");
3066: }
1.538 raeburn 3067: } elsif ($env{'form.clearmarked'}) {
3068: my $output = &do_buffer_empty();
3069: if ($output) {
3070: $r->print('<p class="LC_info">'.$output.'</p>');
3071: }
3072: }
1.329 droeschl 3073:
3074: $r->print($upload_output);
3075:
1.538 raeburn 3076: # Rename, cut, copy or remove a single resource
1.602 raeburn 3077: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3078: my $contentchg;
1.592 raeburn 3079: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3080: $contentchg = 1;
3081: }
3082: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3083: return $errtext if ($fatal);
3084: }
1.538 raeburn 3085:
3086: # Cut, copy and/or remove multiple resources
3087: if ($env{'form.multichange'}) {
3088: my %allchecked = (
3089: cut => {},
3090: remove => {},
3091: );
3092: my $needsupdate;
3093: foreach my $which (keys(%allchecked)) {
3094: $env{'form.multi'.$which} =~ s/,$//;
3095: if ($env{'form.multi'.$which}) {
3096: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3097: if (ref($allchecked{$which}) eq 'HASH') {
3098: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3099: }
3100: }
3101: }
3102: if ($needsupdate) {
3103: my $haschanges = 0;
3104: my %curr_groups = &Apache::longroup::coursegroups();
3105: my $total = scalar(@LONCAPA::map::order) - 1;
3106: for (my $i=$total; $i>=0; $i--) {
3107: my $res = $LONCAPA::map::order[$i];
3108: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3109: $name=&LONCAPA::map::qtescape($name);
3110: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3111: next unless $url;
1.538 raeburn 3112: my %denied =
3113: &action_restrictions($coursenum,$coursedom,$url,
3114: $env{'form.folderpath'},\%curr_groups);
3115: foreach my $which (keys(%allchecked)) {
3116: next if ($denied{$which});
3117: next unless ($allchecked{$which}{$res});
3118: if ($which eq 'remove') {
3119: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3120: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3121: &Apache::lonnet::removeuploadedurl($url);
3122: } else {
3123: &LONCAPA::map::makezombie($res);
3124: }
3125: splice(@LONCAPA::map::order,$i,1);
3126: $haschanges ++;
3127: } elsif ($which eq 'cut') {
3128: &LONCAPA::map::makezombie($res);
3129: splice(@LONCAPA::map::order,$i,1);
3130: $haschanges ++;
3131: }
3132: }
3133: }
3134: if ($haschanges) {
3135: ($errtext,$fatal) =
3136: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3137: return $errtext if ($fatal);
3138: }
3139: }
3140: }
3141:
1.329 droeschl 3142: # Group import/search
3143: if ($env{'form.importdetail'}) {
3144: my @imports;
3145: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3146: if (defined($item)) {
3147: my ($name,$url,$residx)=
1.533 raeburn 3148: map { &unescape($_); } split(/\=/,$item);
3149: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3150: my ($suffix,$errortxt,$locknotfreed) =
3151: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3152: if ($locknotfreed) {
3153: $r->print($locknotfreed);
3154: }
3155: if ($suffix) {
3156: $url =~ s/_new\./_$suffix./;
3157: } else {
3158: return $errortxt;
3159: }
1.533 raeburn 3160: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3161: my $type = $1;
3162: my ($suffix,$errortxt,$locknotfreed) =
3163: &new_timebased_suffix($coursedom,$coursenum,$type);
3164: if ($locknotfreed) {
3165: $r->print($locknotfreed);
3166: }
3167: if ($suffix) {
3168: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3169: } else {
3170: return $errortxt;
3171: }
1.598 raeburn 3172: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3173: my ($suffix,$errortxt,$locknotfreed) =
3174: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3175: if ($locknotfreed) {
3176: $r->print($locknotfreed);
3177: }
3178: if ($suffix) {
3179: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3180: } else {
3181: return $errortxt;
3182: }
1.534 raeburn 3183: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3184: if ($supplementalflag) {
3185: next unless ($1 eq 'supplemental');
3186: if ($folder eq 'supplemental') {
3187: next unless ($2 eq 'default');
3188: } else {
3189: next unless ($folder eq 'supplemental_'.$2);
3190: }
3191: } else {
3192: next unless ($1 eq 'docs');
3193: if ($folder eq 'default') {
3194: next unless ($2 eq 'default');
3195: } else {
3196: next unless ($folder eq 'default_'.$2);
3197: }
3198: }
1.504 raeburn 3199: }
1.329 droeschl 3200: push(@imports, [$name, $url, $residx]);
3201: }
3202: }
1.530 raeburn 3203: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3204: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3205: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3206: return $errtext if ($fatal);
1.529 raeburn 3207: if ($fixuperrors) {
3208: $r->print($fixuperrors);
3209: }
1.329 droeschl 3210: }
3211: # Loading a complete map
3212: if ($env{'form.loadmap'}) {
3213: if ($env{'form.importmap'}=~/\w/) {
3214: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3215: my ($title,$url,$ext,$type)=split(/\:/,$res);
3216: my $idx=&LONCAPA::map::getresidx($url);
3217: $LONCAPA::map::resources[$idx]=$res;
3218: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3219: }
3220: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3221: $folder.'.'.$container,1);
1.329 droeschl 3222: return $errtext if ($fatal);
3223: } else {
3224: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3225:
1.329 droeschl 3226: }
3227: }
3228: &log_differences($plain);
3229: }
3230: # ---------------------------------------------------------------- End commands
3231: # ---------------------------------------------------------------- Print screen
3232: my $idx=0;
3233: my $shown=0;
3234: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3235: $r->print('<div class="LC_Box">'.
1.432 raeburn 3236: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3237: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3238: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3239: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3240: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3241: '</ol>');
1.381 bisitz 3242: if ($randompick>=0) {
3243: $r->print('<p class="LC_warning">'
3244: .&mt('Caution: this folder is set to randomly pick a subset'
3245: .' of resources. Adding or removing resources from this'
3246: .' folder will change the set of resources that the'
3247: .' students see, resulting in spurious or missing credit'
3248: .' for completed problems, not limited to ones you'
3249: .' modify. Do not modify the contents of this folder if'
3250: .' it is in active student use.')
3251: .'</p>'
3252: );
3253: }
3254: if ($is_random_order) {
3255: $r->print('<p class="LC_warning">'
3256: .&mt('Caution: this folder is set to randomly order its'
3257: .' contents. Adding or removing resources from this folder'
3258: .' will change the order of resources shown.')
3259: .'</p>'
3260: );
3261: }
3262: $r->print('</div>');
1.364 bisitz 3263: }
1.381 bisitz 3264:
1.538 raeburn 3265: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3266: %filters = (
1.543 raeburn 3267: canremove => [],
3268: cancut => [],
3269: cancopy => [],
3270: hiddenresource => [],
3271: encrypturl => [],
3272: randomorder => [],
3273: randompick => [],
1.538 raeburn 3274: );
3275: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3276: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3277: foreach my $res (@LONCAPA::map::order) {
3278: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3279: $name=&LONCAPA::map::qtescape($name);
3280: $url=&LONCAPA::map::qtescape($url);
3281: unless ($name) { $name=(split(/\//,$url))[-1]; }
3282: unless ($name) { $idx++; next; }
1.537 raeburn 3283: push(@allidx,$res);
3284: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3285: push(@allmapidx,$res);
3286: }
1.381 bisitz 3287: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3288: $coursenum,$coursedom,$crstype,
1.538 raeburn 3289: $pathitem,$supplementalflag,$container,
1.598 raeburn 3290: \%filters,\%curr_groups,$ltitoolsref);
1.381 bisitz 3291: $idx++;
3292: $shown++;
1.329 droeschl 3293: }
1.424 onken 3294: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3295:
1.538 raeburn 3296: my $need_save;
1.510 raeburn 3297: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3298: my $toolslink;
3299: if ($allowed || &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
3300: $toolslink = '<table><tr><td>'
1.520 raeburn 3301: .&Apache::loncommon::help_open_menu('Navigation Screen',
3302: 'Navigation_Screen',undef,'RAT')
3303: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3304: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3305: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3306: .'id="LC_content_toolbar_edittoplevel" '
3307: .'class="LC_toolbarItem" '
3308: .'title="'.&mt('Supplemental Content Editor').'">'
3309: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3310: }
1.510 raeburn 3311: if ($shown) {
3312: if ($allowed) {
3313: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3314: .&Apache::loncommon::start_data_table(undef,'contentlist')
3315: .&Apache::loncommon::start_data_table_header_row()
3316: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3317: .'<th colspan="2">'.&mt('Actions').'</th>'
3318: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3319: if ($folder !~ /^supplemental/) {
3320: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3321: }
1.537 raeburn 3322: $to_show .= &Apache::loncommon::end_data_table_header_row();
3323: if ($folder !~ /^supplemental/) {
1.538 raeburn 3324: $lists{'canhide'} = join(',',@allidx);
3325: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3326: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3327: 'randomorder','randompick');
3328: foreach my $item (@possfilters) {
1.538 raeburn 3329: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3330: if (@{$filters{$item}} > 0) {
3331: $lists{$item} = join(',',@{$filters{$item}});
3332: }
1.538 raeburn 3333: }
3334: }
1.537 raeburn 3335: if (@allidx > 0) {
3336: my $path;
3337: if ($env{'form.folderpath'}) {
3338: $path =
3339: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3340: }
1.538 raeburn 3341: if (@allidx > 1) {
3342: $to_show .=
3343: &Apache::loncommon::continue_data_table_row().
3344: '<td colspan="2"> </td>'.
3345: '<td>'.
3346: &multiple_check_form('actions',\%lists).
3347: '</td>'.
3348: '<td> </td>'.
3349: '<td> </td>'.
3350: '<td colspan="4">'.
3351: &multiple_check_form('settings',\%lists).
3352: '</td>'.
3353: &Apache::loncommon::end_data_table_row();
3354: $need_save = 1;
3355: }
1.537 raeburn 3356: }
3357: }
3358: $to_show .= $output.' '
1.510 raeburn 3359: .&Apache::loncommon::end_data_table()
3360: .'<br style="line-height:2px;" />'
3361: .&Apache::loncommon::end_scrollbox();
3362: } else {
1.520 raeburn 3363: $to_show .= $toolslink
1.510 raeburn 3364: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3365: .$output.' '
3366: .&Apache::loncommon::end_data_table();
1.393 raeburn 3367: }
1.510 raeburn 3368: } else {
1.520 raeburn 3369: if (!$allowed) {
3370: $to_show .= $toolslink;
3371: }
1.510 raeburn 3372: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3373: .'<div class="LC_info" id="contentlist">'
1.550 raeburn 3374: .&mt('Currently empty')
1.510 raeburn 3375: .'</div>'
3376: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3377: }
3378: } else {
1.510 raeburn 3379: if ($shown) {
3380: $to_show = '<div>'
3381: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3382: .$output
3383: .&Apache::loncommon::end_data_table()
3384: .'</div>';
3385: } else {
3386: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3387: .&mt('Currently empty')
1.510 raeburn 3388: .'</div>'
3389: }
1.458 raeburn 3390: }
3391: my $tid = 1;
3392: if ($supplementalflag) {
3393: $tid = 2;
1.329 droeschl 3394: }
3395: if ($allowed) {
1.484 raeburn 3396: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3397: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3398: $jumpto,$readfile,$need_save,"$folder.$container"));
1.492 raeburn 3399: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 3400: } else {
3401: $r->print($to_show);
1.329 droeschl 3402: }
3403: return;
3404: }
3405:
1.538 raeburn 3406: sub multiple_check_form {
3407: my ($caller,$listsref) = @_;
3408: return unless (ref($listsref) eq 'HASH');
3409: my $output =
3410: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3411: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3412: '<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>'.
3413: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3414: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3415: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3416: if ($caller eq 'settings') {
3417: $output .=
3418: '<table><tr>'.
3419: '<td class="LC_docs_entry_parameter">'.
3420: '<span class="LC_nobreak"><label>'.
3421: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').
3422: '</label></span></td>'.
3423: '<td class="LC_docs_entry_parameter">'.
3424: '<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="" />'.
3425: '</span></td>'.
3426: '</tr>'."\n".
3427: '<tr>'.
3428: '<td class="LC_docs_entry_parameter">'.
3429: '<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').
3430: '</label></span>'.
3431: '</td></tr></table>'."\n";
3432: } else {
3433: $output .=
3434: '<table><tr>'.
3435: '<td class="LC_docs_entry_parameter">'.
3436: '<span class="LC_nobreak LC_docs_remove">'.
3437: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')" />'.&mt('Remove').
3438: '</label></span></td>'.
3439: '<td class="LC_docs_entry_parameter">'.
3440: '<span class="LC_nobreak LC_docs_cut">'.
3441: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');" />'.&mt('Cut').
3442: '</label></span></td>'."\n".
3443: '<td class="LC_docs_entry_parameter">'.
3444: '<span class="LC_nobreak LC_docs_copy">'.
3445: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')" />'.&mt('Copy').
3446: '</label></span></td>'.
3447: '</tr></table>'."\n";
3448: }
3449: $output .=
3450: '</fieldset>'.
3451: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3452: if ($caller eq 'settings') {
3453: $output .=
1.543 raeburn 3454: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3455: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3456: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3457: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3458: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3459: } elsif ($caller eq 'actions') {
3460: $output .=
3461: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3462: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3463: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3464: }
3465: $output .=
3466: '</form>'.
3467: '</div>';
3468: return $output;
3469: }
3470:
1.329 droeschl 3471: sub process_file_upload {
1.552 raeburn 3472: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3473: # upload a file, if present
1.552 raeburn 3474: my $filesize = length($env{'form.uploaddoc'});
3475: if (!$filesize) {
3476: $$upload_output = '<div class="LC_error">'.
3477: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3478: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3479: $filesize).'<br />'.
3480: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3481: '</div>';
3482: return;
3483: }
3484: my $quotatype = 'unofficial';
3485: if ($crstype eq 'Community') {
1.601 raeburn 3486: $quotatype = 'community';
3487: } elsif ($crstype eq 'Placement') {
3488: $quotatype = 'placement';
1.580 raeburn 3489: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3490: $quotatype = 'official';
1.573 raeburn 3491: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3492: $quotatype = 'textbook';
1.552 raeburn 3493: }
3494: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3495: $filesize = int($filesize/1000); #expressed in kb
3496: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3497: $env{'form.uploaddoc.filename'},$filesize,
3498: 'upload',$quotatype);
1.552 raeburn 3499: return if ($$upload_output);
3500: }
1.440 raeburn 3501: my ($parseaction,$showupload,$nextphase,$mimetype);
3502: if ($env{'form.parserflag'}) {
1.329 droeschl 3503: $parseaction = 'parse';
3504: }
3505: my $folder=$env{'form.folder'};
3506: if ($folder eq '') {
3507: $folder='default';
3508: }
3509: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3510: my $errtext='';
3511: my $fatal=0;
3512: my $container='sequence';
1.519 raeburn 3513: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3514: $container='page';
3515: }
3516: ($errtext,$fatal)=
1.534 raeburn 3517: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3518: if ($#LONCAPA::map::order<1) {
3519: $LONCAPA::map::order[0]=1;
3520: $LONCAPA::map::resources[1]='';
3521: }
3522: my $destination = 'docs/';
3523: if ($folder =~ /^supplemental/) {
3524: $destination = 'supplemental/';
3525: }
3526: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3527: $destination .= 'default/';
3528: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3529: $destination .= $2.'/';
3530: }
1.534 raeburn 3531: if ($fatal) {
3532: $$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>';
3533: return;
3534: }
1.440 raeburn 3535: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3536: my $newidx=&LONCAPA::map::getresidx();
3537: $destination .= $newidx;
1.439 raeburn 3538: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3539: $parseaction,$allfiles,
1.440 raeburn 3540: $codebase,undef,undef,undef,undef,
3541: undef,undef,\$mimetype);
3542: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3543: my $stored = $1;
3544: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3545: $stored.'</span>').'</p>';
3546: } else {
3547: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3548:
1.457 raeburn 3549: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3550: return;
3551: }
1.329 droeschl 3552: my $ext='false';
3553: if ($url=~m{^http://}) { $ext='true'; }
3554: $url = &LONCAPA::map::qtunescape($url);
3555: my $comment=$env{'form.comment'};
3556: $comment = &LONCAPA::map::qtunescape($comment);
3557: if ($folder=~/^supplemental/) {
3558: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3559: $env{'user.domain'}.'___&&&___'.$comment;
3560: }
3561:
3562: $LONCAPA::map::resources[$newidx]=
3563: $comment.':'.$url.':'.$ext.':normal:res';
3564: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3565: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3566: $folder.'.'.$container,1);
1.329 droeschl 3567: if ($fatal) {
1.457 raeburn 3568: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3569: return;
1.329 droeschl 3570: } else {
1.440 raeburn 3571: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3572: $$upload_output = $showupload;
1.384 raeburn 3573: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3574: if ($total_embedded > 0) {
1.440 raeburn 3575: my $uploadphase = 'upload_embedded';
3576: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3577: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3578: my ($embedded,$num) =
3579: &Apache::loncommon::ask_for_embedded_content(
3580: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3581: if ($embedded) {
3582: if ($num) {
3583: $$upload_output .=
3584: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3585: $nextphase = $uploadphase;
3586: } else {
3587: $$upload_output .= $embedded;
3588: }
3589: } else {
3590: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3591: }
1.329 droeschl 3592: } else {
1.440 raeburn 3593: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3594: }
1.457 raeburn 3595: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3596: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3597: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3598: $nextphase = 'decompress_uploaded';
3599: my $position = scalar(@LONCAPA::map::order)-1;
3600: my $noextract = &return_to_editor();
3601: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3602: my %archiveitems = (
3603: folderpath => $env{'form.folderpath'},
3604: cmd => $nextphase,
3605: newidx => $newidx,
3606: position => $position,
3607: phase => $nextphase,
1.477 raeburn 3608: comment => $comment,
1.480 raeburn 3609: );
3610: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3611: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3612: $$upload_output = $showupload.
3613: &Apache::loncommon::decompress_form($mimetype,
3614: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3615: \%archiveitems,\@current);
1.329 droeschl 3616: }
3617: }
3618: }
1.440 raeburn 3619: return $nextphase;
1.329 droeschl 3620: }
3621:
1.480 raeburn 3622: sub get_dir_list {
3623: my ($url,$coursenum,$coursedom,$newidx) = @_;
3624: my ($destination,$dir_root) = &embedded_destination();
3625: my ($dirlistref,$listerror) =
3626: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3627: my @dir_lines;
3628: my $dirptr=16384;
3629: if (ref($dirlistref) eq 'ARRAY') {
3630: foreach my $dir_line (sort
3631: {
3632: my ($afile)=split('&',$a,2);
3633: my ($bfile)=split('&',$b,2);
3634: return (lc($afile) cmp lc($bfile));
3635: } (@{$dirlistref})) {
3636: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3637: $filename =~ s/\s+$//;
3638: next if ($filename =~ /^\.\.?$/);
3639: my $isdir = 0;
3640: if ($dirptr&$testdir) {
3641: $isdir = 1;
3642: }
3643: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3644: }
3645: }
3646: return @dir_lines;
3647: }
3648:
1.329 droeschl 3649: sub is_supplemental_title {
3650: my ($title) = @_;
3651: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3652: }
3653:
3654: # --------------------------------------------------------------- An entry line
3655:
3656: sub entryline {
1.501 raeburn 3657: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3658: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3659: $ltitoolsref)=@_;
1.581 raeburn 3660: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3661: if (&is_supplemental_title($title)) {
1.488 raeburn 3662: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3663: } else {
3664: $title=&HTML::Entities::encode($title,'"<>&\'');
3665: $renametitle=$title;
3666: $foldertitle=$title;
3667: }
3668:
3669: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3670:
1.329 droeschl 3671: $renametitle=~s/\\/\\\\/g;
3672: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3673: $renametitle=~s/"/%22/g;
1.581 raeburn 3674: $renametitle=~s/ /%20/g;
3675: $oldtitle = $renametitle;
1.576 raeburn 3676: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3677: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3678: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3679: # Edit commands
1.535 raeburn 3680: my ($esc_path, $path, $symb);
1.329 droeschl 3681: if ($env{'form.folderpath'}) {
3682: $esc_path=&escape($env{'form.folderpath'});
3683: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3684: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3685: }
1.505 raeburn 3686: my $isexternal;
1.510 raeburn 3687: if ($residx) {
1.501 raeburn 3688: my $currurl = $url;
3689: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3690: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3691: $isexternal = 1;
3692: }
1.510 raeburn 3693: if (!$supplementalflag) {
3694: my $path = 'uploaded/'.
3695: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3696: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3697: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3698: $residx,
3699: &Apache::lonnet::declutter($currurl));
3700: }
1.501 raeburn 3701: }
1.538 raeburn 3702: my ($renamelink,%lt,$ishash);
3703: if (ref($filtersref) eq 'HASH') {
3704: $ishash = 1;
3705: }
3706:
1.329 droeschl 3707: if ($allowed) {
1.538 raeburn 3708: $form_start = '
3709: <form action="/adm/coursedocs" method="post">
3710: ';
3711: $form_common=(<<END);
3712: <input type="hidden" name="folderpath" value="$path" />
3713: <input type="hidden" name="symb" value="$symb" />
3714: END
3715: $form_param=(<<END);
3716: <input type="hidden" name="setparms" value="$orderidx" />
3717: <input type="hidden" name="changeparms" value="0" />
3718: END
3719: $form_end = '</form>';
3720:
1.329 droeschl 3721: my $incindex=$index+1;
3722: my $selectbox='';
1.471 raeburn 3723: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3724: ((split(/\:/,
1.344 bisitz 3725: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3726: ne '') &&
1.329 droeschl 3727: ((split(/\:/,
1.344 bisitz 3728: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3729: ne '')) {
3730: $selectbox=
3731: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 3732: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 3733: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3734: if ($i==$incindex) {
1.358 bisitz 3735: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3736: } else {
3737: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3738: }
3739: }
3740: $selectbox.='</select>';
3741: }
1.501 raeburn 3742: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3743: 'up' => 'Move Up',
3744: 'dw' => 'Move Down',
3745: 'rm' => 'Remove',
3746: 'ct' => 'Cut',
3747: 'rn' => 'Rename',
1.501 raeburn 3748: 'cp' => 'Copy',
3749: 'ex' => 'External Resource',
1.598 raeburn 3750: 'et' => 'External Tool',
1.501 raeburn 3751: 'ed' => 'Edit',
3752: 'pr' => 'Preview',
3753: 'sv' => 'Save',
3754: 'ul' => 'URL',
3755: 'ti' => 'Title',
3756: );
1.538 raeburn 3757: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3758: $env{'form.folderpath'},
3759: $currgroups);
1.517 raeburn 3760: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3761: my $skip_confirm = 0;
1.603 raeburn 3762: my $confirm_removal = 0;
1.329 droeschl 3763: if ( $folder =~ /^supplemental/
3764: || ($url =~ m{( /smppg$
3765: |/syllabus$
3766: |/aboutme$
3767: |/navmaps$
3768: |/bulletinboard$
1.598 raeburn 3769: |/exttools?$
1.505 raeburn 3770: |\.html$)}x)
3771: || $isexternal) {
1.329 droeschl 3772: $skip_confirm = 1;
3773: }
1.603 raeburn 3774: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3775: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3776: $confirm_removal = 1;
3777: }
1.329 droeschl 3778:
1.538 raeburn 3779: if ($denied{'copy'}) {
1.543 raeburn 3780: $copylink=(<<ENDCOPY)
1.507 raeburn 3781: <span style="visibility: hidden;">$lt{'cp'}</span>
3782: ENDCOPY
3783: } else {
1.538 raeburn 3784: my $formname = 'edit_copy_'.$orderidx;
3785: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3786: $copylink=(<<ENDCOPY);
1.538 raeburn 3787: <form name="$formname" method="post" action="/adm/coursedocs">
3788: $form_common
1.540 raeburn 3789: <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 3790: $form_end
1.329 droeschl 3791: ENDCOPY
1.538 raeburn 3792: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3793: push(@{$filtersref->{'cancopy'}},$orderidx);
3794: }
1.329 droeschl 3795: }
1.538 raeburn 3796: if ($denied{'cut'}) {
1.507 raeburn 3797: $cutlink=(<<ENDCUT);
3798: <span style="visibility: hidden;">$lt{'ct'}</span>
3799: ENDCUT
3800: } else {
1.538 raeburn 3801: my $formname = 'edit_cut_'.$orderidx;
3802: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3803: $cutlink=(<<ENDCUT);
1.538 raeburn 3804: <form name="$formname" method="post" action="/adm/coursedocs">
3805: $form_common
1.542 raeburn 3806: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.540 raeburn 3807: <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 3808: $form_end
1.329 droeschl 3809: ENDCUT
1.538 raeburn 3810: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3811: push(@{$filtersref->{'cancut'}},$orderidx);
3812: }
1.329 droeschl 3813: }
1.538 raeburn 3814: if ($denied{'remove'}) {
1.507 raeburn 3815: $removelink=(<<ENDREM);
3816: <span style="visibility: hidden;">$lt{'rm'}</a>
3817: ENDREM
3818: } else {
1.538 raeburn 3819: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3820: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3821: $removelink=(<<ENDREM);
1.538 raeburn 3822: <form name="$formname" method="post" action="/adm/coursedocs">
3823: $form_common
1.542 raeburn 3824: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3825: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.540 raeburn 3826: <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 3827: $form_end
1.497 raeburn 3828: ENDREM
1.538 raeburn 3829: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3830: push(@{$filtersref->{'canremove'}},$orderidx);
3831: }
1.497 raeburn 3832: }
1.551 raeburn 3833: $renamelink=(<<ENDREN);
1.581 raeburn 3834: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3835: ENDREN
1.329 droeschl 3836: $line.=(<<END);
3837: <td>
1.379 bisitz 3838: <div class="LC_docs_entry_move">
1.535 raeburn 3839: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3840: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3841: </a>
3842: </div>
3843: <div class="LC_docs_entry_move">
1.536 raeburn 3844: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3845: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3846: </a>
3847: </div>
1.329 droeschl 3848: </td>
3849: <td>
3850: $form_start
1.538 raeburn 3851: $form_param
1.478 raeburn 3852: $form_common
1.329 droeschl 3853: $selectbox
3854: $form_end
3855: </td>
1.540 raeburn 3856: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3857: $removelink
1.329 droeschl 3858: $cutlink
3859: $copylink
3860: </td>
3861: END
3862: }
3863: # Figure out what kind of a resource this is
3864: my ($extension)=($url=~/\.(\w+)$/);
3865: my $uploaded=($url=~/^\/*uploaded\//);
3866: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3867: my $isfolder;
3868: my $ispage;
3869: my $containerarg;
1.329 droeschl 3870: if ($uploaded) {
1.472 raeburn 3871: if (($extension eq 'sequence') || ($extension eq 'page')) {
3872: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3873: $containerarg = $1;
1.472 raeburn 3874: if ($extension eq 'sequence') {
3875: $icon=$iconpath.'navmap.folder.closed.gif';
3876: $isfolder=1;
3877: } else {
3878: $icon=$iconpath.'page.gif';
3879: $ispage=1;
3880: }
3881: if ($allowed) {
3882: $url='/adm/coursedocs?';
3883: } else {
3884: $url='/adm/supplemental?';
3885: }
1.329 droeschl 3886: } else {
3887: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3888: }
3889: }
1.364 bisitz 3890:
1.609 ! raeburn 3891: my ($editlink,$extresform,$anchor);
1.329 droeschl 3892: my $orig_url = $url;
1.340 raeburn 3893: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3894: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3895: if (!$supplementalflag && $residx && $symb) {
3896: if ((!$isfolder) && (!$ispage)) {
3897: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3898: $url=&Apache::lonnet::clutter($url);
3899: if ($url=~/^\/*uploaded\//) {
3900: $url=~/\.(\w+)$/;
3901: my $embstyle=&Apache::loncommon::fileembstyle($1);
3902: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3903: $url='/adm/wrapper'.$url;
3904: } elsif ($embstyle eq 'ssi') {
3905: #do nothing with these
3906: } elsif ($url!~/\.(sequence|page)$/) {
3907: $url='/adm/coursedocs/showdoc'.$url;
3908: }
3909: } elsif ($url=~m|^/ext/|) {
3910: $url='/adm/wrapper'.$url;
1.598 raeburn 3911: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3912: $url='/adm/wrapper'.$url;
3913: }
1.501 raeburn 3914: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 ! raeburn 3915: my $shownsymb = $symb;
! 3916: if ($isexternal) {
! 3917: if ($url =~ /^([^#]+)#([^#]+)$/) {
! 3918: $url = $1;
! 3919: $anchor = $2;
! 3920: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
! 3921: $shownsymb = $1.&escape('#').$anchor;
! 3922: }
! 3923: }
! 3924: }
! 3925: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
1.501 raeburn 3926: } else {
3927: $url='';
3928: }
1.329 droeschl 3929: }
3930: }
1.478 raeburn 3931: my ($rand_pick_text,$rand_order_text);
1.519 raeburn 3932: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3933: my $foldername=&escape($foldertitle);
3934: my $folderpath=$env{'form.folderpath'};
3935: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 3936: if (!$allowed && $supplementalflag) {
1.519 raeburn 3937: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 3938: $url.='folderpath='.&escape($folderpath);
3939: } else {
1.344 bisitz 3940: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 3941: # so it gets transferred between levels
1.519 raeburn 3942: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 3943: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 3944: 'parameter_randompick'))[0]
3945: .':'.((&LONCAPA::map::getparameter($orderidx,
3946: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3947: .':'.((&LONCAPA::map::getparameter($orderidx,
3948: 'parameter_encrypturl'))[0]=~/^yes$/i)
3949: .':'.((&LONCAPA::map::getparameter($orderidx,
1.519 raeburn 3950: 'parameter_randomorder'))[0]=~/^yes$/i)
3951: .':'.$ispage;
1.510 raeburn 3952: $url.='folderpath='.&escape($folderpath);
3953: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3954: 'parameter_randompick'))[0];
3955: my $rpckchk;
3956: if ($rpicknum) {
3957: $rpckchk = ' checked="checked"';
1.543 raeburn 3958: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3959: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3960: }
1.510 raeburn 3961: }
1.537 raeburn 3962: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 3963: $rand_pick_text =
1.478 raeburn 3964: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3965: $form_param."\n".
1.478 raeburn 3966: $form_common."\n".
1.537 raeburn 3967: '<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 3968: if ($rpicknum ne '') {
3969: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3970: }
1.537 raeburn 3971: $rand_pick_text .= '</span></span>'.
3972: $form_end;
1.543 raeburn 3973: my $ro_set;
3974: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
3975: $ro_set = 'checked="checked"';
3976: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3977: push(@{$filtersref->{'randomorder'}},$orderidx);
3978: }
3979: }
1.564 raeburn 3980: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 3981: $rand_order_text =
1.537 raeburn 3982: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3983: $form_param."\n".
1.537 raeburn 3984: $form_common."\n".
1.538 raeburn 3985: '<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 3986: $form_end;
1.510 raeburn 3987: }
1.509 raeburn 3988: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 3989: my $isexttool;
3990: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3991: $url='/adm/wrapper'.$url;
3992: $isexttool = 1;
3993: }
1.510 raeburn 3994: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 3995: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 3996: if ($title) {
3997: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3998: }
1.598 raeburn 3999: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4000: $url .= '&idx='.$orderidx;
4001: }
1.329 droeschl 4002: }
1.519 raeburn 4003: my ($tdalign,$tdwidth);
1.501 raeburn 4004: if ($allowed) {
4005: my $fileloc =
4006: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4007: if ($isexternal) {
1.518 raeburn 4008: ($editlink,$extresform) =
1.510 raeburn 4009: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.598 raeburn 4010: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4011: ($editlink,$extresform) =
4012: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4013: undef,undef,undef,'tool',$coursedom,
4014: $coursenum,$ltitoolsref);
1.511 raeburn 4015: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4016: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4017: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4018: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 4019: my $jscall =
4020: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4021: $switchserver,
1.503 raeburn 4022: $forceedit,
1.511 raeburn 4023: undef,$symb,
4024: &escape($env{'form.folderpath'}),
1.524 raeburn 4025: $renametitle,'','',1);
1.501 raeburn 4026: if ($jscall) {
1.518 raeburn 4027: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4028: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4029: }
4030: }
4031: }
1.519 raeburn 4032: $tdalign = ' align="right" valign="top"';
4033: $tdwidth = ' width="80%"';
1.329 droeschl 4034: }
1.408 raeburn 4035: my $reinit;
4036: if ($crstype eq 'Community') {
4037: $reinit = &mt('(re-initialize community to access)');
4038: } else {
4039: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4040: }
4041: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 4042: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4043: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4044: } elsif ($url) {
1.609 ! raeburn 4045: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
! 4046: (($anchor ne '')?'#'.&HTML::Entities::encode($anchor,'"<>&'):''),
1.470 raeburn 4047: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 4048: } else {
4049: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4050: }
1.519 raeburn 4051: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4052: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4053: $line.='<a href="'.$url.'">'.$title.'</a>';
4054: } elsif ($url) {
1.609 ! raeburn 4055: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
! 4056: (($anchor ne '')?'#'.&HTML::Entities::encode($anchor,'"<>&'):''),
1.470 raeburn 4057: $title,600,500);
1.469 www 4058: } else {
4059: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4060: }
1.518 raeburn 4061: $line.="$extresform</td>";
1.478 raeburn 4062: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4063: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4064: if (($allowed) && ($folder!~/^supplemental/)) {
4065: my %lt=&Apache::lonlocal::texthash(
4066: 'hd' => 'Hidden',
4067: 'ec' => 'URL hidden');
1.543 raeburn 4068: my ($enctext,$hidtext);
4069: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4070: $enctext = ' checked="checked"';
4071: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4072: push(@{$filtersref->{'encrypturl'}},$orderidx);
4073: }
4074: }
4075: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4076: $hidtext = ' checked="checked"';
4077: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4078: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4079: }
4080: }
1.537 raeburn 4081: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4082: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4083: $line.=(<<ENDPARMS);
4084: <td class="LC_docs_entry_parameter">
1.537 raeburn 4085: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4086: $form_param
1.478 raeburn 4087: $form_common
1.538 raeburn 4088: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 4089: $form_end
1.458 raeburn 4090: <br />
1.537 raeburn 4091: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4092: $form_param
1.478 raeburn 4093: $form_common
1.538 raeburn 4094: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext /> $lt{'ec'}</label>
1.329 droeschl 4095: $form_end
4096: </td>
1.478 raeburn 4097: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4098: $rand_order_text</td>
1.329 droeschl 4099: ENDPARMS
4100: }
1.379 bisitz 4101: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4102: return $line;
4103: }
4104:
1.538 raeburn 4105: sub action_restrictions {
4106: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4107: my %denied = (
4108: cut => 0,
4109: copy => 0,
4110: remove => 0,
4111: );
4112: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4113: # no copy for published maps
4114: $denied{'copy'} = 1;
1.597 raeburn 4115: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4116: unless ($1 eq 'simpleproblem') {
4117: $denied{'copy'} = 1;
4118: }
4119: $denied{'cut'} = 1;
1.538 raeburn 4120: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4121: if ($folderpath =~ /^default&[^\&]+$/) {
4122: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4123: $denied{'remove'} = 1;
4124: }
4125: $denied{'cut'} = 1;
4126: $denied{'copy'} = 1;
4127: }
4128: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4129: my $group = $1;
4130: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4131: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4132: $denied{'remove'} = 1;
4133: }
4134: }
4135: $denied{'cut'} = 1;
4136: $denied{'copy'} = 1;
4137: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4138: my $group = $1;
4139: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4140: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4141: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4142: if (keys(%groupsettings) > 0) {
4143: $denied{'remove'} = 1;
4144: }
4145: $denied{'cut'} = 1;
4146: $denied{'copy'} = 1;
4147: }
4148: }
4149: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4150: my $group = $1;
4151: if ($url =~ /group_boards_\Q$group\E/) {
4152: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4153: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4154: if (keys(%groupsettings) > 0) {
4155: if (ref($groupsettings{'functions'}) eq 'HASH') {
4156: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4157: $denied{'remove'} = 1;
4158: }
4159: }
4160: }
4161: $denied{'cut'} = 1;
4162: $denied{'copy'} = 1;
4163: }
4164: }
4165: }
4166: return %denied;
4167: }
4168:
1.533 raeburn 4169: sub new_timebased_suffix {
1.538 raeburn 4170: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4171: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4172: if ($type eq 'paste') {
4173: $prefix = $type;
4174: $namespace = 'courseeditor';
1.587 raeburn 4175: $idtype = 'addcode';
1.538 raeburn 4176: } elsif ($type eq 'map') {
1.533 raeburn 4177: $prefix = 'docs';
4178: if ($area eq 'supplemental') {
4179: $prefix = 'supp';
4180: }
4181: $prefix .= $container;
4182: $namespace = 'uploadedmaps';
4183: } else {
4184: $prefix = $type;
4185: $namespace = 'templated';
1.504 raeburn 4186: }
4187: my ($suffix,$freedlock,$error) =
1.587 raeburn 4188: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4189: if (!$suffix) {
1.538 raeburn 4190: if ($type eq 'paste') {
4191: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4192: } elsif ($type eq 'map') {
1.533 raeburn 4193: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4194: } elsif ($type eq 'smppg') {
4195: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4196: } else {
1.565 bisitz 4197: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4198: }
1.504 raeburn 4199: if ($error) {
4200: $errtext .= '<br />'.$error;
4201: }
4202: }
4203: if ($freedlock ne 'ok') {
1.533 raeburn 4204: $locknotfreed =
4205: '<div class="LC_error">'.
4206: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4207: if ($type eq 'paste') {
1.591 raeburn 4208: if ($freedlock eq 'nolock') {
4209: $locknotfreed =
4210: '<div class="LC_error">'.
4211: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4212:
1.593 droeschl 4213: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4214: } else {
4215: $locknotfreed .=
4216: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4217: }
1.538 raeburn 4218: } elsif ($type eq 'map') {
1.591 raeburn 4219: $locknotfreed .=
4220: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4221: } elsif ($type eq 'smppg') {
4222: $locknotfreed .=
4223: &mt('This will prevent creation of additional simple pages in this course.');
4224: } else {
4225: $locknotfreed .=
1.565 bisitz 4226: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4227: }
1.538 raeburn 4228: unless ($type eq 'paste') {
4229: $locknotfreed .=
1.560 raeburn 4230: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4231: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4232: }
4233: $locknotfreed .= '</div>';
1.504 raeburn 4234: }
4235: return ($suffix,$errtext,$locknotfreed);
4236: }
4237:
1.329 droeschl 4238: =pod
4239:
4240: =item tiehash()
4241:
4242: tie the hash
4243:
4244: =cut
4245:
4246: sub tiehash {
4247: my ($mode)=@_;
4248: $hashtied=0;
4249: if ($env{'request.course.fn'}) {
4250: if ($mode eq 'write') {
4251: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4252: &GDBM_WRCREAT(),0640)) {
4253: $hashtied=2;
4254: }
4255: } else {
4256: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4257: &GDBM_READER(),0640)) {
4258: $hashtied=1;
4259: }
4260: }
1.364 bisitz 4261: }
1.329 droeschl 4262: }
4263:
4264: sub untiehash {
4265: if ($hashtied) { untie %hash; }
4266: $hashtied=0;
4267: return OK;
4268: }
4269:
4270:
4271:
4272:
4273: sub checkonthis {
4274: my ($r,$url,$level,$title)=@_;
4275: $url=&unescape($url);
4276: $alreadyseen{$url}=1;
4277: $r->rflush();
4278: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4279: $r->print("\n<br />");
4280: if ($level==0) {
4281: $r->print("<br />");
4282: }
4283: for (my $i=0;$i<=$level*5;$i++) {
4284: $r->print(' ');
4285: }
4286: $r->print('<a href="'.$url.'" target="cat">'.
4287: ($title?$title:$url).'</a> ');
4288: if ($url=~/^\/res\//) {
4289: my $result=&Apache::lonnet::repcopy(
4290: &Apache::lonnet::filelocation('',$url));
4291: if ($result eq 'ok') {
4292: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4293: $r->rflush();
4294: &Apache::lonnet::countacc($url);
4295: $url=~/\.(\w+)$/;
4296: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4297: $r->print('<br />');
4298: $r->rflush();
4299: for (my $i=0;$i<=$level*5;$i++) {
4300: $r->print(' ');
4301: }
4302: $r->print('- '.&mt('Rendering:').' ');
4303: my ($errorcount,$warningcount)=split(/:/,
4304: &Apache::lonnet::ssi_body($url,
4305: ('grade_target'=>'web',
4306: 'return_only_error_and_warning_counts' => 1)));
4307: if (($errorcount) ||
4308: ($warningcount)) {
4309: if ($errorcount) {
1.369 bisitz 4310: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4311: &mt('[quant,_1,error]',$errorcount).'</span>');
4312: }
4313: if ($warningcount) {
4314: $r->print('<span class="LC_warning">'.
4315: &mt('[quant,_1,warning]',$warningcount).'</span>');
4316: }
4317: } else {
4318: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4319: }
4320: $r->rflush();
4321: }
4322: my $dependencies=
4323: &Apache::lonnet::metadata($url,'dependencies');
4324: foreach my $dep (split(/\,/,$dependencies)) {
4325: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4326: &checkonthis($r,$dep,$level+1);
4327: }
4328: }
4329: } elsif ($result eq 'unavailable') {
4330: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4331: } elsif ($result eq 'not_found') {
4332: unless ($url=~/\$/) {
1.521 bisitz 4333: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4334: } else {
1.366 bisitz 4335: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4336: }
4337: } else {
4338: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4339: }
4340: }
4341: }
4342: }
4343:
4344:
4345:
4346: =pod
4347:
4348: =item list_symbs()
4349:
1.485 raeburn 4350: List Content Identifiers
1.329 droeschl 4351:
4352: =cut
4353:
4354: sub list_symbs {
4355: my ($r) = @_;
4356:
1.408 raeburn 4357: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4358: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4359: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4360: $r->print(&startContentScreen('tools'));
1.329 droeschl 4361: my $navmap = Apache::lonnavmaps::navmap->new();
4362: if (!defined($navmap)) {
4363: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4364: '<div class="LC_error">'.
4365: &mt('Unable to retrieve information about course contents').
4366: '</div>');
1.408 raeburn 4367: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4368: } else {
1.484 raeburn 4369: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4370: &Apache::loncommon::start_data_table().
4371: &Apache::loncommon::start_data_table_header_row().
4372: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4373: &Apache::loncommon::end_data_table_header_row()."\n");
4374: my $count;
1.329 droeschl 4375: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4376: $r->print(&Apache::loncommon::start_data_table_row().
4377: '<td>'.$res->compTitle().'</td>'.
4378: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4379: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4380: $count ++;
4381: }
4382: if (!$count) {
4383: $r->print(&Apache::loncommon::start_data_table_row().
4384: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4385: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4386: }
1.484 raeburn 4387: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4388: }
1.521 bisitz 4389: $r->print(&endContentScreen());
1.329 droeschl 4390: }
4391:
4392:
4393: sub verifycontent {
4394: my ($r) = @_;
1.408 raeburn 4395: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4396: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4397: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4398: $r->print(&startContentScreen('tools'));
4399: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4400: $hashtied=0;
4401: undef %alreadyseen;
4402: %alreadyseen=();
4403: &tiehash();
1.484 raeburn 4404:
1.329 droeschl 4405: foreach my $key (keys(%hash)) {
4406: if ($hash{$key}=~/\.(page|sequence)$/) {
4407: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4408: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4409: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4410: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4411: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4412: }
4413: }
4414: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4415: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4416: }
4417: }
4418: &untiehash();
1.442 www 4419: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4420: $r->print(&endContentScreen());
1.329 droeschl 4421: }
4422:
4423:
4424: sub devalidateversioncache {
4425: my $src=shift;
4426: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4427: &Apache::lonnet::clutter($src));
4428: }
4429:
4430: sub checkversions {
4431: my ($r) = @_;
1.408 raeburn 4432: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4433: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4434: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4435: $r->print(&startContentScreen('tools'));
1.442 www 4436:
1.329 droeschl 4437: my $header='';
4438: my $startsel='';
4439: my $monthsel='';
4440: my $weeksel='';
4441: my $daysel='';
4442: my $allsel='';
4443: my %changes=();
4444: my $starttime=0;
4445: my $haschanged=0;
4446: my %setversions=&Apache::lonnet::dump('resourceversions',
4447: $env{'course.'.$env{'request.course.id'}.'.domain'},
4448: $env{'course.'.$env{'request.course.id'}.'.num'});
4449:
4450: $hashtied=0;
4451: &tiehash();
4452: my %newsetversions=();
4453: if ($env{'form.setmostrecent'}) {
4454: $haschanged=1;
4455: foreach my $key (keys(%hash)) {
4456: if ($key=~/^ids\_(\/res\/.+)$/) {
4457: $newsetversions{$1}='mostrecent';
4458: &devalidateversioncache($1);
4459: }
4460: }
4461: } elsif ($env{'form.setcurrent'}) {
4462: $haschanged=1;
4463: foreach my $key (keys(%hash)) {
4464: if ($key=~/^ids\_(\/res\/.+)$/) {
4465: my $getvers=&Apache::lonnet::getversion($1);
4466: if ($getvers>0) {
4467: $newsetversions{$1}=$getvers;
4468: &devalidateversioncache($1);
4469: }
4470: }
4471: }
4472: } elsif ($env{'form.setversions'}) {
4473: $haschanged=1;
4474: foreach my $key (keys(%env)) {
4475: if ($key=~/^form\.set_version_(.+)$/) {
4476: my $src=$1;
4477: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4478: $newsetversions{$src}=$env{$key};
4479: &devalidateversioncache($src);
4480: }
4481: }
4482: }
4483: }
4484: if ($haschanged) {
4485: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4486: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 4487: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 4488: $r->print(&Apache::loncommon::confirmwrapper(
4489: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 4490: } else {
1.479 golterma 4491: $r->print(&Apache::loncommon::confirmwrapper(
4492: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4493: }
4494: &mark_hash_old();
4495: }
4496: &changewarning($r,'');
4497: if ($env{'form.timerange'} eq 'all') {
4498: # show all documents
1.549 raeburn 4499: $header=&mt('All content in '.$crstype);
1.521 bisitz 4500: $allsel=' selected="selected"';
1.329 droeschl 4501: foreach my $key (keys(%hash)) {
4502: if ($key=~/^ids\_(\/res\/.+)$/) {
4503: my $src=$1;
4504: $changes{$src}=1;
4505: }
4506: }
4507: } else {
4508: # show documents which changed
4509: %changes=&Apache::lonnet::dump
4510: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4511: $env{'course.'.$env{'request.course.id'}.'.num'});
4512: my $firstkey=(keys(%changes))[0];
4513: unless ($firstkey=~/^error\:/) {
4514: unless ($env{'form.timerange'}) {
4515: $env{'form.timerange'}=604800;
4516: }
4517: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4518: .&mt('seconds');
4519: if ($env{'form.timerange'}==-1) {
4520: $seltext='since start of course';
1.521 bisitz 4521: $startsel=' selected="selected"';
1.329 droeschl 4522: $env{'form.timerange'}=time;
4523: }
4524: $starttime=time-$env{'form.timerange'};
4525: if ($env{'form.timerange'}==2592000) {
4526: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4527: $monthsel=' selected="selected"';
1.329 droeschl 4528: } elsif ($env{'form.timerange'}==604800) {
4529: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4530: $weeksel=' selected="selected"';
1.329 droeschl 4531: } elsif ($env{'form.timerange'}==86400) {
4532: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4533: $daysel=' selected="selected"';
1.329 droeschl 4534: }
4535: $header=&mt('Content changed').' '.$seltext;
4536: } else {
4537: $header=&mt('No content modifications yet.');
4538: }
4539: }
4540: %setversions=&Apache::lonnet::dump('resourceversions',
4541: $env{'course.'.$env{'request.course.id'}.'.domain'},
4542: $env{'course.'.$env{'request.course.id'}.'.num'});
4543: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4544: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4545: 'lm' => 'Version changes since last Month',
4546: 'lw' => 'Version changes since last Week',
4547: 'sy' => 'Version changes since Yesterday',
4548: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4549: 'cd' => 'Change display',
1.329 droeschl 4550: 'sd' => 'Display',
4551: 'fi' => 'File',
4552: 'md' => 'Modification Date',
4553: 'mr' => 'Most recently published Version',
1.408 raeburn 4554: 've' => 'Version used in '.$crstype,
4555: 'vu' => 'Set Version to be used in '.$crstype,
4556: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4557: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4558: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4559: 'di' => 'Differences',
1.484 raeburn 4560: 'save' => 'Save changes',
4561: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4562: 'act' => 'Actions');
1.329 droeschl 4563: $r->print(<<ENDHEADERS);
1.484 raeburn 4564: <h4 class="LC_info">$header</h4>
1.329 droeschl 4565: <form action="/adm/coursedocs" method="post">
4566: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4567: <div class="LC_left_float">
1.479 golterma 4568: <fieldset>
1.484 raeburn 4569: <legend>$lt{'cd'}</legend>
1.329 droeschl 4570: <select name="timerange">
1.521 bisitz 4571: <option value='all'$allsel>$lt{'al'}</option>
4572: <option value="-1"$startsel>$lt{'st'}</option>
4573: <option value="2592000"$monthsel>$lt{'lm'}</option>
4574: <option value="604800"$weeksel>$lt{'lw'}</option>
4575: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4576: </select>
4577: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4578: </fieldset>
4579: </div>
4580: <div class="LC_left_float">
4581: <fieldset>
4582: <legend>$lt{'act'}</legend>
4583: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
4584: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
4585: </fieldset>
4586: </div>
4587: <br clear="all" />
4588: <hr />
4589: <h4>$lt{'vers'}</h4>
1.329 droeschl 4590: ENDHEADERS
1.479 golterma 4591: #number of columns for version history
1.571 raeburn 4592: my %changedbytime;
4593: foreach my $key (keys(%changes)) {
4594: #excludes not versionable problems from resource version history:
4595: next if ($key =~ /^\/res\/lib\/templates/);
4596: my $chg;
4597: if ($env{'form.timerange'} eq 'all') {
4598: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4599: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4600: } else {
4601: $chg = $changes{$key};
4602: next if ($chg < $starttime);
4603: }
4604: push(@{$changedbytime{$chg}},$key);
4605: }
4606: if (keys(%changedbytime) == 0) {
4607: &untiehash();
4608: $r->print(&mt('No content changes in imported content in specified time frame').
4609: &endContentScreen());
4610: return;
4611: }
1.479 golterma 4612: $r->print(
1.571 raeburn 4613: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
1.521 bisitz 4614: &Apache::loncommon::start_data_table().
4615: &Apache::loncommon::start_data_table_header_row().
4616: '<th>'.&mt('Resources').'</th>'.
4617: "<th>$lt{'mr'}</th>".
4618: "<th>$lt{'ve'}</th>".
4619: "<th>$lt{'vu'}</th>".
4620: '<th>'.&mt('History').'</th>'.
4621: &Apache::loncommon::end_data_table_header_row()
4622: );
1.571 raeburn 4623: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4624: foreach my $key (sort(@{$changedbytime{$chg}})) {
4625: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4626: my $currentversion=&Apache::lonnet::getversion($key);
4627: if ($currentversion<0) {
4628: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4629: }
4630: my $linkurl=&Apache::lonnet::clutter($key);
4631: $r->print(
4632: &Apache::loncommon::start_data_table_row().
4633: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4634: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4635: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4636: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4637: '<td align="right">'
4638: );
4639: # Used in course
4640: my $usedversion=$hash{'version_'.$linkurl};
4641: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4642: if ($usedversion != $currentversion) {
1.479 golterma 4643: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4644: } else {
1.479 golterma 4645: $r->print($usedversion);
4646: }
1.329 droeschl 4647: } else {
1.521 bisitz 4648: $r->print($currentversion);
1.329 droeschl 4649: }
1.571 raeburn 4650: $r->print('</td><td title="'.$lt{'vu'}.'">');
4651: # Set version
4652: $r->print(&Apache::loncommon::select_form(
4653: $setversions{$linkurl},
4654: 'set_version_'.$linkurl,
4655: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4656: '' => '',
4657: 'mostrecent' => &mt('most recent'),
4658: map {$_,$_} (1..$currentversion)}));
4659: my $lastold=1;
4660: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4661: my $url=$root.'.'.$prevvers.'.'.$extension;
4662: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4663: $lastold=$prevvers;
4664: }
4665: }
4666: $r->print('</td>');
4667: # List all available versions
4668: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4669: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4670: my $url=$root.'.'.$prevvers.'.'.$extension;
4671: $r->print(
4672: '<span class="LC_nobreak">'
4673: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4674: .&mt('Version [_1]',$prevvers).'</a>'
4675: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4676: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4677: .')');
4678: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4679: $r->print(
4680: ' <a href="/adm/diff?filename='.
4681: &Apache::lonnet::clutter($root.'.'.$extension).
4682: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4683: '" target="diffs">'.&mt('Diffs').'</a>');
4684: }
4685: $r->print('</span><br />');
1.329 droeschl 4686: }
1.571 raeburn 4687: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4688: }
1.329 droeschl 4689: }
1.521 bisitz 4690: $r->print(
4691: &Apache::loncommon::end_data_table().
4692: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
4693: '</form>'
4694: );
1.329 droeschl 4695:
4696: &untiehash();
1.521 bisitz 4697: $r->print(&endContentScreen());
1.571 raeburn 4698: return;
1.329 droeschl 4699: }
4700:
4701: sub mark_hash_old {
4702: my $retie_hash=0;
4703: if ($hashtied) {
4704: $retie_hash=1;
4705: &untiehash();
4706: }
4707: &tiehash('write');
4708: $hash{'old'}=1;
4709: &untiehash();
4710: if ($retie_hash) { &tiehash(); }
4711: }
4712:
4713: sub is_hash_old {
4714: my $untie_hash=0;
4715: if (!$hashtied) {
4716: $untie_hash=1;
4717: &tiehash();
4718: }
4719: my $return=$hash{'old'};
4720: if ($untie_hash) { &untiehash(); }
4721: return $return;
4722: }
4723:
4724: sub changewarning {
4725: my ($r,$postexec,$message,$url)=@_;
4726: if (!&is_hash_old()) { return; }
4727: my $pathvar='folderpath';
4728: my $path=&escape($env{'form.folderpath'});
4729: if (!defined($url)) {
4730: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4731: }
4732: my $course_type = &Apache::loncommon::course_type();
4733: if (!defined($message)) {
4734: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4735: }
4736: $r->print("\n\n".
1.372 bisitz 4737: '<script type="text/javascript">'."\n".
4738: '// <![CDATA['."\n".
4739: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4740: '// ]]>'."\n".
1.369 bisitz 4741: '</script>'."\n".
1.375 tempelho 4742: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4743: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4744: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4745: &mt($message,' <input type="hidden" name="'.
4746: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4747: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4748: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4749: }
4750:
4751:
4752: sub init_breadcrumbs {
1.571 raeburn 4753: my ($form,$text,$help)=@_;
1.329 droeschl 4754: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4755: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4756: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4757: faq=>273,
4758: bug=>'Instructor Interface',
1.571 raeburn 4759: help => $help});
1.329 droeschl 4760: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4761: text=>$text,
4762: faq=>273,
4763: bug=>'Instructor Interface'});
4764: }
4765:
1.441 www 4766: # subroutine to list form elements
4767: sub create_list_elements {
4768: my @formarr = @_;
4769: my $list = '';
1.501 raeburn 4770: foreach my $button (@formarr){
4771: foreach my $picture (keys(%{$button})) {
4772: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4773: }
4774: }
4775: return $list;
4776: }
1.329 droeschl 4777:
1.441 www 4778: # subroutine to create ul from list elements
4779: sub create_form_ul {
4780: my $list = shift;
4781: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4782: return $ul;
4783: }
1.329 droeschl 4784:
1.442 www 4785: #
4786: # Start tabs
4787: #
4788:
4789: sub startContentScreen {
1.484 raeburn 4790: my ($mode) = @_;
4791: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4792: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4793: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4794: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4795: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4796: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4797: } else {
1.549 raeburn 4798: $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 4799: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4800: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4801: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4802: }
4803: $output .= "\n".'</ul>'."\n";
4804: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4805: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4806: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4807: return $output;
1.442 www 4808: }
4809:
4810: #
4811: # End tabs
4812: #
4813:
4814: sub endContentScreen {
1.484 raeburn 4815: return '</div></div></div>';
1.442 www 4816: }
1.329 droeschl 4817:
1.446 www 4818: sub supplemental_base {
1.548 raeburn 4819: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4820: }
4821:
1.329 droeschl 4822: sub handler {
4823: my $r = shift;
4824: &Apache::loncommon::content_type($r,'text/html');
4825: $r->send_http_header;
4826: return OK if $r->header_only;
1.484 raeburn 4827:
4828: # get course data
1.408 raeburn 4829: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4830: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4831: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4832:
1.606 raeburn 4833: # get docroot
4834: my $londocroot = $r->dir_config('lonDocRoot');
4835:
1.484 raeburn 4836: # graphics settings
4837: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4838:
1.443 www 4839: #
1.329 droeschl 4840: # --------------------------------------------- Initialize help topics for this
4841: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4842: 'Adding_External_Resource','Navigate_Content',
4843: 'Adding_Folders','Docs_Overview', 'Load_Map',
4844: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 4845: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 4846: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 4847: 'Dropbox','Simple_Problem') {
1.329 droeschl 4848: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4849: }
4850: # Composite help files
4851: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4852: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4853: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4854: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4855: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4856: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4857: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4858: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4859: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4860: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 4861:
1.606 raeburn 4862: my ($allowed,$noendpage);
1.472 raeburn 4863: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4864: unless ($r->uri eq '/adm/supplemental') {
4865: # does this user have privileges to modify content.
4866: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4867: }
4868:
1.582 raeburn 4869: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4870: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 4871: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4872: &verifycontent($r);
4873: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4874: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4875: &list_symbs($r);
4876: } elsif ($allowed && $env{'form.docslog'}) {
4877: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4878: my $folder = $env{'form.folder'};
4879: if ($folder eq '') {
4880: $folder='default';
4881: }
4882: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 4883: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 4884: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.329 droeschl 4885: &checkversions($r);
4886: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.568 raeburn 4887: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4888: &dumpcourse($r);
4889: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4890: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4891: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4892: } else {
1.606 raeburn 4893: if ($allowed && $env{'form.authorrole'}) {
4894: $noendpage = 1;
4895: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
4896: if ($redirect) {
4897: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
4898: my $container = 'sequence';
4899: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4900: $is_random_order,$container) =
4901: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4902: my (@folders)=split('&',$env{'form.folderpath'});
4903: $env{'form.foldername'}=&unescape(pop(@folders));
4904: my $folder=pop(@folders);
4905: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4906: $folder.'.'.$container);
4907: my $warning;
4908: if ($fatal) {
4909: if ($container eq 'page') {
4910: $warning = &mt('An error occurred retrieving the contents of the current page.');
4911: } else {
4912: $warning = &mt('An error occurred retrieving the contents of the current folder.');
4913: }
4914: } else {
4915: my $url = $redirect;
4916: my $srcfile = $londocroot.$url;
4917: $url =~ s{^/priv/}{/res/};
4918: my $targetfile = $londocroot.$url;
4919: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
4920: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
4921: $env{'form.folder'} = $folder;
4922: &snapshotbefore();
4923: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
4924: my $ext = 'false';
4925: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
4926: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
4927: ':'.$ext.':normal:res';
4928: push(@LONCAPA::map::order,$newidx);
4929: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
4930: 'string_yesno');
4931: &remember_parms($newidx,'hiddenresource','set','yes');
4932: ($errtext,$fatal) =
4933: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
4934: &log_differences($plain);
4935: &mark_hash_old();
4936: $r->internal_redirect($redirect);
4937: return OK;
4938: }
4939: }
4940: }
4941: }
1.445 www 4942: #
4943: # Done catching special calls
1.484 raeburn 4944: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4945: # Get the parameters that may be needed
4946: #
4947: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 4948: ['folderpath',
4949: 'forcesupplement','forcestandard',
1.510 raeburn 4950: 'tools','symb','command','supppath']);
1.445 www 4951:
4952: # standard=1: this is a "new-style" course with an uploaded map as top level
4953: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4954:
4955: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4956:
1.484 raeburn 4957: # Decide whether this should display supplemental or main content or utilities
1.445 www 4958: # supplementalflag=1: show supplemental documents
4959: # supplementalflag=0: show standard documents
1.484 raeburn 4960: # toolsflag=1: show utilities
1.445 www 4961:
1.561 raeburn 4962: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4963: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4964: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4965: $supplementalflag=0;
4966: }
4967: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4968: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4969: unless ($allowed) { $supplementalflag=1; }
4970: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4971: my $toolsflag=0;
4972: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4973:
1.329 droeschl 4974: my $script='';
4975: my $showdoc=0;
1.457 raeburn 4976: my $addentries = {};
1.475 raeburn 4977: my $container;
1.329 droeschl 4978: my $containertag;
1.508 raeburn 4979: my $pathitem;
1.598 raeburn 4980: my %ltitools;
1.329 droeschl 4981:
1.464 www 4982: # Do we directly jump somewhere?
1.466 www 4983:
1.525 raeburn 4984: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4985: if ($env{'form.symb'} ne '') {
1.522 raeburn 4986: $env{'form.folderpath'}=
4987: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 4988: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4989: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4990: } elsif ($env{'form.supppath'} ne '') {
4991: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 4992: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4993: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4994: }
1.472 raeburn 4995: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 4996: $env{'form.folderpath'} = 'default&'.
1.548 raeburn 4997: &escape(&mt('Main Content').':::::');
1.525 raeburn 4998: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4999: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 5000: $env{'form.folderpath'} = 'supplemental&'.
1.538 raeburn 5001: &escape('Supplemental Content');
1.525 raeburn 5002: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5003: } elsif ($env{'form.command'} eq 'contents') {
5004: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5005: } elsif ($env{'form.command'} eq 'home') {
5006: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5007: }
5008:
1.525 raeburn 5009:
1.445 www 5010: # Where do we store these for when we come back?
5011: my $stored_folderpath='docs_folderpath';
5012: if ($supplementalflag) {
5013: $stored_folderpath='docs_sup_folderpath';
5014: }
1.464 www 5015:
1.519 raeburn 5016: # No folderpath, and in edit mode, see if we have something stored
5017: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5018: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5019: {'folderpath' => 'scalar'});
1.523 raeburn 5020: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5021: undef($env{'form.folderpath'});
5022: }
1.329 droeschl 5023: }
1.446 www 5024:
5025: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5026: if (!$allowed) {
1.446 www 5027: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5028: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5029: }
5030: }
1.446 www 5031: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5032: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5033: $env{'form.folderpath'} = &supplemental_base()
5034: .'&'.
1.329 droeschl 5035: $env{'form.folderpath'};
5036: }
1.446 www 5037: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5038: unless ($env{'form.folderpath'}) {
1.446 www 5039: if ($supplementalflag) {
5040: $env{'form.folderpath'}=&supplemental_base();
5041: } else {
1.548 raeburn 5042: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
1.538 raeburn 5043: ':::::');
1.446 www 5044: }
1.472 raeburn 5045: }
1.446 www 5046:
1.445 www 5047: # Store this
1.484 raeburn 5048: unless ($toolsflag) {
1.510 raeburn 5049: if ($allowed) {
5050: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5051: {'folderpath' => 'scalar'});
1.510 raeburn 5052: }
1.519 raeburn 5053: my $folderpath;
1.484 raeburn 5054: if ($env{'form.folderpath'}) {
1.519 raeburn 5055: $folderpath = $env{'form.folderpath'};
5056: my (@folders)=split('&',$env{'form.folderpath'});
5057: $env{'form.foldername'}=&unescape(pop(@folders));
5058: if ($env{'form.foldername'} =~ /\:1$/) {
5059: $container = 'page';
5060: } else {
5061: $container = 'sequence';
5062: }
5063: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5064: } else {
1.519 raeburn 5065: if ($env{'form.folder'} eq '' ||
5066: $env{'form.folder'} eq 'supplemental') {
5067: $folderpath='default&'.
1.548 raeburn 5068: &escape(&mt('Main Content').':::::');
1.484 raeburn 5069: }
5070: }
1.519 raeburn 5071: $containertag = '<input type="hidden" name="folderpath" value="" />';
5072: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5073: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5074: $showdoc='/'.$1;
5075: }
5076: if ($showdoc) { # got called in sequence from course
5077: $allowed=0;
5078: } else {
5079: if ($allowed) {
5080: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5081: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5082: }
5083: }
1.329 droeschl 5084: }
5085:
1.344 bisitz 5086: # get personal data
1.329 droeschl 5087: my $uname=$env{'user.name'};
5088: my $udom=$env{'user.domain'};
5089: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5090:
5091: if ($allowed) {
1.484 raeburn 5092: if ($toolsflag) {
5093: $script .= &inject_data_js();
5094: my ($home,$other,%outhash)=&authorhosts();
5095: if (!$home && $other) {
5096: my @hosts;
5097: foreach my $aurole (keys(%outhash)) {
5098: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5099: push(@hosts,$outhash{$aurole});
5100: }
5101: }
5102: $script .= &dump_switchserver_js(@hosts);
5103: }
1.458 raeburn 5104: } else {
1.570 raeburn 5105: my $tid = 1;
1.484 raeburn 5106: my @tabids;
5107: if ($supplementalflag) {
5108: @tabids = ('002','ee2','ff2');
1.570 raeburn 5109: $tid = 2;
1.484 raeburn 5110: } else {
5111: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5112: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5113: unshift(@tabids,'001');
5114: push(@tabids,('dd1','ee1'));
5115: }
1.458 raeburn 5116: }
1.484 raeburn 5117: my $tabidstr = join("','",@tabids);
1.598 raeburn 5118: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5119: my $posslti = keys(%ltitools);
1.606 raeburn 5120: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5121: $londocroot).
1.484 raeburn 5122: &history_tab_js().
5123: &inject_data_js().
1.570 raeburn 5124: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5125: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5126: $addentries = {
1.485 raeburn 5127: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5128: };
1.458 raeburn 5129: }
1.538 raeburn 5130: $script .= &paste_popup_js();
1.501 raeburn 5131: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5132: &mt('Switch server?');
5133:
5134:
1.329 droeschl 5135: }
5136: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5137: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5138: .'// <![CDATA['."\n"
5139: .$script."\n"
5140: .'// ]]>'."\n"
1.595 musolffc 5141: .'</script>'."\n"
5142: .'<script type="text/javascript"
5143: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5144:
5145: # Breadcrumbs
5146: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5147:
5148: if ($showdoc) {
5149: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5150: {'force_register' => $showdoc,}));
1.571 raeburn 5151: } elsif ($toolsflag) {
5152: &Apache::lonhtmlcommon::add_breadcrumb({
5153: href=>"/adm/coursedocs",text=>"$crstype Contents"});
5154: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5155: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5156: .&Apache::lonhtmlcommon::breadcrumbs(
5157: 'Editing Course Contents')
5158: );
1.510 raeburn 5159: } elsif ($r->uri eq '/adm/supplemental') {
5160: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5161: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5162: {'bread_crumbs' => $brcrum,}));
5163: } else {
1.392 raeburn 5164: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 5165: href=>"/adm/coursedocs",text=>"$crstype Contents"});
5166: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5167: {'add_entries' => $addentries}
5168: )
1.392 raeburn 5169: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5170: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 5171: 'Editing '.$crstype.' Contents',
1.392 raeburn 5172: 'Docs_Adding_Course_Doc')
5173: );
5174: }
1.364 bisitz 5175:
1.329 droeschl 5176: my %allfiles = ();
5177: my %codebase = ();
1.440 raeburn 5178: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 5179: if ($allowed) {
5180: if (($env{'form.uploaddoc.filename'}) &&
5181: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5182: my $context = $1;
5183: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5184: undef($hadchanges);
1.440 raeburn 5185: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5186: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5187: if ($hadchanges) {
5188: &mark_hash_old();
5189: }
1.440 raeburn 5190: $r->print($upload_output);
5191: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5192: # Process file upload - phase two - upload embedded objects
5193: $uploadphase = 'check_embedded';
5194: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5195: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5196: $env{'form.newidx'});
5197: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5198: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5199: my ($destination,$dir_root) = &embedded_destination();
5200: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5201: my $actionurl = '/adm/coursedocs';
5202: my ($result,$flag) =
5203: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5204: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5205: $actionurl);
5206: $r->print($result.&return_to_editor());
5207: } elsif ($env{'form.phase'} eq 'check_embedded') {
5208: # Process file upload - phase three - modify references in HTML file
5209: $uploadphase = 'modified_orightml';
5210: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5211: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5212: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5213: my $result =
5214: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5215: $docuname,$docudom,undef,
5216: $dir_root);
5217: $r->print($result.&return_to_editor());
1.476 raeburn 5218: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5219: $uploadphase = 'decompress_phase_one';
5220: $r->print(&decompression_phase_one().
5221: &return_to_editor());
5222: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5223: $uploadphase = 'decompress_phase_two';
5224: $r->print(&decompression_phase_two().
5225: &return_to_editor());
1.329 droeschl 5226: }
5227: }
5228:
1.484 raeburn 5229: if ($allowed && $toolsflag) {
5230: $r->print(&startContentScreen('tools'));
5231: $r->print(&generate_admin_menu($crstype));
5232: $r->print(&endContentScreen());
5233: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5234: # -----------------------------------------------------------------------------
5235: my %lt=&Apache::lonlocal::texthash(
5236: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5237: 'upfi' => 'Upload File',
1.553 raeburn 5238: 'upld' => 'Upload Content',
1.329 droeschl 5239: 'srch' => 'Search',
5240: 'impo' => 'Import',
1.487 raeburn 5241: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5242: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5243: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5244: 'extr' => 'External Resource',
5245: 'extt' => 'External Tool',
1.329 droeschl 5246: 'selm' => 'Select Map',
5247: 'load' => 'Load Map',
5248: 'newf' => 'New Folder',
5249: 'newp' => 'New Composite Page',
5250: 'syll' => 'Syllabus',
1.425 raeburn 5251: 'navc' => 'Table of Contents',
1.343 biermanm 5252: 'sipa' => 'Simple Course Page',
1.329 droeschl 5253: 'sipr' => 'Simple Problem',
1.534 raeburn 5254: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5255: 'stpr' => 'Standard Problem',
5256: 'news' => 'New sub-directory',
5257: 'crpr' => 'Create Problem',
1.329 droeschl 5258: 'drbx' => 'Drop Box',
1.451 www 5259: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5260: 'bull' => 'Discussion Board',
1.347 weissno 5261: 'mypi' => 'My Personal Information Page',
1.353 weissno 5262: 'grpo' => 'Group Portfolio',
1.329 droeschl 5263: 'rost' => 'Course Roster',
1.528 raeburn 5264: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5265: 'imsf' => 'IMS Upload',
5266: 'imsl' => 'Upload IMS package',
1.501 raeburn 5267: 'cms' => 'Origin of IMS package',
5268: 'se' => 'Select',
1.329 droeschl 5269: 'file' => 'File',
5270: 'title' => 'Title',
1.606 raeburn 5271: 'addp' => 'Add Placeholder to course?',
5272: 'uste' => 'Use Template?',
5273: 'fnam' => 'File Name:',
5274: 'loca' => 'Location:',
5275: 'dire' => 'Directory:',
5276: 'cate' => 'Category:',
5277: 'tmpl' => 'Template:',
1.329 droeschl 5278: 'comment' => 'Comment',
1.403 raeburn 5279: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5280: 'bb5' => 'Blackboard 5',
5281: 'bb6' => 'Blackboard 6',
5282: 'angel5' => 'ANGEL 5.5',
5283: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5284: 'yes' => 'Yes',
5285: 'no' => 'No',
1.577 bisitz 5286: );
1.329 droeschl 5287: # -----------------------------------------------------------------------------
1.595 musolffc 5288:
5289: # Calculate free quota space for a user or course. A javascript function checks
5290: # file size to determine if upload should be allowed.
5291: my $quotatype = 'unofficial';
5292: if ($crstype eq 'Community') {
1.601 raeburn 5293: $quotatype = 'community';
5294: } elsif ($crstype eq 'Placement') {
5295: $quotatype = 'placement';
1.595 musolffc 5296: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5297: $quotatype = 'official';
5298: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5299: $quotatype = 'textbook';
5300: }
5301: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5302: 'course',$quotatype); # expressed in MB
5303: my $current_disk_usage = 0;
5304: foreach my $subdir ('docs','supplemental') {
5305: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5306: "userfiles/$subdir",1); # expressed in kB
5307: }
5308: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5309: my $usage = $current_disk_usage/1024; # in MB
5310: my $quota = $disk_quota;
5311: my $percent;
5312: if ($disk_quota == 0) {
5313: $percent = 100.0;
5314: } else {
5315: $percent = 100*($current_disk_usage/$disk_quota);
5316: }
5317: $usage = sprintf("%.2f",$usage);
5318: $quota = sprintf("%.2f",$quota);
5319: $percent = sprintf("%.0f",$percent);
5320: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5321: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5322:
1.329 droeschl 5323: my $fileupload=(<<FIUP);
1.605 raeburn 5324: $quotainfo
1.329 droeschl 5325: $lt{'file'}:<br />
1.595 musolffc 5326: <input type="file" name="uploaddoc" class="flUpload" size="40" />
1.606 raeburn 5327: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5328: FIUP
5329:
5330: my $checkbox=(<<CHBO);
5331: <!-- <label>$lt{'parse'}?
5332: <input type="checkbox" name="parserflag" />
5333: </label> -->
5334: <label>
5335: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
5336: </label>
5337: CHBO
1.501 raeburn 5338: my $imsfolder = $env{'form.folder'};
5339: if ($imsfolder eq '') {
5340: $imsfolder = 'default';
5341: }
5342: my $imspform=(<<IMSFORM);
5343: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5344: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5345: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5346: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5347: <legend>$lt{'imsf'}</legend>
5348: $fileupload
5349: <br />
5350: <p>
5351: $lt{'cms'}:
5352: <select name="source">
5353: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5354: <option value="bb5">$lt{'bb5'}</option>
5355: <option value="bb6">$lt{'bb6'}</option>
5356: <option value="angel5">$lt{'angel5'}</option>
5357: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5358: </select>
5359: <input type="hidden" name="folder" value="$imsfolder" />
5360: </p>
5361: <input type="hidden" name="phase" value="one" />
5362: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
5363: </fieldset>
5364: </form>
5365: IMSFORM
1.329 droeschl 5366:
5367: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5368: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5369: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5370: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5371: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5372: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5373: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5374: $fileupload
1.329 droeschl 5375: <br />
5376: $lt{'title'}:<br />
1.458 raeburn 5377: <input type="text" size="60" name="comment" />
1.508 raeburn 5378: $pathitem
1.329 droeschl 5379: <input type="hidden" name="cmd" value="upload_default" />
5380: <br />
1.458 raeburn 5381: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5382: $checkbox
5383: </span>
1.501 raeburn 5384: <br clear="all" />
5385: <input type="submit" value="$lt{'upld'}" />
5386: </fieldset>
5387: </form>
1.383 tempelho 5388: FUFORM
1.329 droeschl 5389:
1.502 raeburn 5390: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5391: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5392: $lt{'impm'}</a>$help{'Load_Map'}
5393: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5394: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5395: <legend>$lt{'impm'}</legend>
1.371 tempelho 5396: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5397: $lt{'copm'}<br />
5398: <span class="LC_nobreak">
5399: <input type="text" name="importmap" size="40" value=""
5400: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 5401: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 5402: <input type="submit" name="loadmap" value="$lt{'load'}" />
5403: </fieldset>
5404: </form>
5405:
1.383 tempelho 5406: SEDFFORM
1.606 raeburn 5407: my $importcrsresform;
1.608 raeburn 5408: my ($numdirs,$pickfile) =
5409: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5410: "resize_scrollbox('contentscroll','1','0');",
5411: undef,'res');
1.606 raeburn 5412: if ($pickfile) {
5413: $importcrsresform=(<<CRSFORM);
5414: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5415: $lt{'imcr'}</a>$help{'Course_Resources'}
5416: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5417: <fieldset id="importcrsresform" style="display: none;">
5418: <legend>$lt{'imcr'}</legend>
5419: <input type="hidden" name="active" value="bb" />
5420: $pickfile
5421: <p>
5422: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" />
5423: </p>
5424: <input type="hidden" name="importdetail" value="" />
5425: <input type="submit" name="crsres" value="$lt{'impo'}" />
5426: </fieldset>
5427: </form>
5428: CRSFORM
5429: }
5430:
1.502 raeburn 5431: my @importpubforma = (
1.508 raeburn 5432: { '<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 5433: { '<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 5434: { '<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.606 raeburn 5435: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5436: );
5437: if ($pickfile) {
5438: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5439: }
1.502 raeburn 5440: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5441: my $extresourcesform =
5442: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5443: $help{'Adding_External_Resource'});
1.598 raeburn 5444: my $exttoolform =
5445: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5446: $help{'Adding_External_Tool'},undef,
5447: undef,'tool',$coursedom,$coursenum,
5448: \%ltitools);
1.329 droeschl 5449: if ($allowed) {
1.492 raeburn 5450: my $folder = $env{'form.folder'};
5451: if ($folder eq '') {
5452: $folder='default';
5453: }
1.538 raeburn 5454: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5455: if ($output) {
5456: $r->print($output);
5457: }
1.337 ehlerst 5458: $r->print(<<HIDDENFORM);
5459: <form name="renameform" method="post" action="/adm/coursedocs">
5460: <input type="hidden" name="title" />
5461: <input type="hidden" name="cmd" />
5462: <input type="hidden" name="markcopy" />
5463: <input type="hidden" name="copyfolder" />
5464: $containertag
5465: </form>
1.484 raeburn 5466:
1.337 ehlerst 5467: HIDDENFORM
1.508 raeburn 5468: $r->print(&makesimpleeditform($pathitem)."\n".
5469: &makedocslogform($pathitem."\n".
1.484 raeburn 5470: '<input type="hidden" name="folder" value="'.
5471: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5472: }
1.442 www 5473:
5474: # Generate the tabs
1.510 raeburn 5475: my ($mode,$needs_end);
1.472 raeburn 5476: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5477: my @folders = split('&',$env{'form.folderpath'});
5478: unless (@folders > 2) {
5479: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5480: $needs_end = 1;
5481: }
1.472 raeburn 5482: } else {
1.484 raeburn 5483: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5484: $needs_end = 1;
1.472 raeburn 5485: }
1.443 www 5486:
1.442 www 5487: #
5488:
5489: my $savefolderpath;
5490:
1.395 raeburn 5491: if ($allowed) {
1.329 droeschl 5492: my $folder=$env{'form.folder'};
1.443 www 5493: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 5494: $folder='default';
1.356 tempelho 5495: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5496: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5497: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5498: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5499: }
5500: my $postexec='';
5501: if ($folder eq 'default') {
1.372 bisitz 5502: $r->print('<script type="text/javascript">'."\n"
5503: .'// <![CDATA['."\n"
5504: .'this.window.name="loncapaclient";'."\n"
5505: .'// ]]>'."\n"
5506: .'</script>'."\n"
1.369 bisitz 5507: );
1.329 droeschl 5508: } else {
5509: #$postexec='self.close();';
5510: }
1.504 raeburn 5511: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5512: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5513: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5514:
5515: my $newnavform=(<<NNFORM);
5516: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5517: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5518: $pathitem
1.329 droeschl 5519: <input type="hidden" name="importdetail"
5520: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 5521: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 5522: $help{'Navigate_Content'}
5523: </form>
5524: NNFORM
5525: my $newsmppageform=(<<NSPFORM);
5526: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5527: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5528: $pathitem
1.329 droeschl 5529: <input type="hidden" name="importdetail" value="" />
1.423 onken 5530: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5531: $help{'Simple Page'}
1.329 droeschl 5532: </form>
5533: NSPFORM
5534:
5535: my $newsmpproblemform=(<<NSPROBFORM);
5536: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5537: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5538: $pathitem
1.329 droeschl 5539: <input type="hidden" name="importdetail" value="" />
1.423 onken 5540: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5541: $help{'Simple_Problem'}
1.329 droeschl 5542: </form>
5543:
5544: NSPROBFORM
5545:
5546: my $newdropboxform=(<<NDBFORM);
5547: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5548: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5549: $pathitem
1.329 droeschl 5550: <input type="hidden" name="importdetail" value="" />
1.423 onken 5551: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5552: $help{'Dropbox'}
1.344 bisitz 5553: </form>
1.329 droeschl 5554: NDBFORM
5555:
5556: my $newexuploadform=(<<NEXUFORM);
5557: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5558: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5559: $pathitem
1.329 droeschl 5560: <input type="hidden" name="importdetail" value="" />
1.423 onken 5561: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5562: $help{'Score_Upload_Form'}
5563: </form>
5564: NEXUFORM
5565:
5566: my $newbulform=(<<NBFORM);
5567: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5568: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5569: $pathitem
1.329 droeschl 5570: <input type="hidden" name="importdetail" value="" />
1.423 onken 5571: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5572: $help{'Bulletin Board'}
5573: </form>
5574: NBFORM
5575:
5576: my $newaboutmeform=(<<NAMFORM);
5577: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5578: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5579: $pathitem
1.329 droeschl 5580: <input type="hidden" name="importdetail"
5581: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5582: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5583: $help{'My Personal Information Page'}
1.329 droeschl 5584: </form>
5585: NAMFORM
5586:
5587: my $newaboutsomeoneform=(<<NASOFORM);
5588: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5589: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5590: $pathitem
1.329 droeschl 5591: <input type="hidden" name="importdetail" value="" />
1.423 onken 5592: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5593: </form>
5594: NASOFORM
5595:
5596: my $newrosterform=(<<NROSTFORM);
5597: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5598: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5599: $pathitem
1.329 droeschl 5600: <input type="hidden" name="importdetail"
5601: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 5602: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.556 raeburn 5603: $help{'Course_Roster'}
1.329 droeschl 5604: </form>
5605: NROSTFORM
5606:
1.534 raeburn 5607: my $newwebpage;
5608: if ($folder =~ /^default_?(\d*)$/) {
5609: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5610: if ($1) {
5611: $newwebpage .= $1;
5612: } else {
5613: $newwebpage .= 'default';
5614: }
5615: $newwebpage .= '/new.html';
5616: }
5617: my $newwebpageform =(<<NWEBFORM);
5618: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5619: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5620: $pathitem
5621: <input type="hidden" name="importdetail" value="$newwebpage" />
5622: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5623: $help{'Web_Page'}
1.534 raeburn 5624: </form>
5625: NWEBFORM
1.604 raeburn 5626:
1.606 raeburn 5627: my @ids=&Apache::lonnet::current_machine_ids();
5628: my %select_menus;
5629: my $numauthor = 0;
5630: my $numcrsdirs = 0;
5631: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5632: if ($env{'user.author'}) {
5633: $numauthor ++;
5634: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5635: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5636: my $is_home = 1;
5637: my %subdirs;
1.608 raeburn 5638: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5639: $select_menus{'author'}->{'default'} = '/';
5640: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5641: my @ordered = ('/');
5642: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5643: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5644: push(@ordered,$relpath);
5645: }
5646: $select_menus{'author'}->{'order'} = \@ordered;
5647: } else {
5648: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5649: $select_menus{'author'}->{'default'} = 'switch';
5650: $select_menus{'author'}->{'order'} = ['switch'];
5651: }
5652: }
5653: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5654: ['active'],['ca','aa']);
5655: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5656: my %by_roletype;
5657: if (keys(%roleshash)) {
5658: foreach my $entry (keys(%roleshash)) {
5659: my ($auname,$audom,$roletype) = split(/:/,$entry);
5660: my $key = $entry;
5661: $key =~ s/:/___/g;
5662: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5663: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5664: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5665: if (grep(/^\Q$rolehome\E$/,@ids)) {
5666: my $is_home = 1;
5667: my (%subdirs,@ordered);
5668: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5669: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5670: $select_menus{$key}->{'default'} = '/';
5671: $select_menus{$key}->{'select2'}->{'/'} = '/';
5672: my @ordered = ('/');
5673: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5674: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5675: push(@ordered,$relpath);
5676: }
5677: $select_menus{$key}->{'order'} = \@ordered;
5678: } else {
5679: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5680: $select_menus{$key}->{'default'} = 'switch';
5681: $select_menus{$key}->{'order'} = ['switch'];
5682: }
5683: $numauthor ++;
5684: }
5685: }
5686: my ($pickdir,$showtitle);;
5687: if ($numauthor) {
5688: my @order;
5689: my $defrole;
5690: if ($env{'user.author'}) {
5691: push(@order,'author');
5692: $defrole = 'author';
5693: }
5694: if (keys(%by_roletype)) {
5695: foreach my $possrole ('ca','aa') {
5696: if (ref($by_roletype{$possrole}) eq 'HASH') {
5697: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5698: unless ($defrole) {
5699: $defrole = $author;
5700: }
5701: push(@order,$author.'___'.$possrole);
5702: }
5703: }
5704: }
5705: }
5706: $select_menus{'course'}->{'text'} = &mt('Course Resource');
5707: if (grep(/^\Q$crshome\E$/,@ids)) {
5708: my $is_home = 1;
5709: my %subdirs;
5710: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 5711: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5712: $numcrsdirs = keys(%subdirs);
5713: $select_menus{'course'}->{'default'} = '/';
5714: $select_menus{'course'}->{'select2'}->{'/'} = '/';
5715: my @ordered = ('/');
5716: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5717: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
5718: push(@ordered,$relpath);
5719: }
5720: $select_menus{'course'}->{'order'} = \@ordered;
5721: } else {
5722: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
5723: $select_menus{'course'}->{'default'} = 'switch';
5724: $select_menus{'course'}->{'order'} = ['switch'];
5725: }
5726: push(@order,'course');
5727: $pickdir = $lt{'loca'}.
5728: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
5729: $defrole,'authorrole','authorpath',
5730: \%select_menus,\@order,'toggleCrsResTitle();',
5731: '','priv').'<br />';
5732: $showtitle = 'none';
5733: } else {
5734: my $is_home;
5735: $showtitle = 'inline';
5736: if (grep(/^\Q$crshome\E$/,@ids)) {
5737: $is_home = 1;
5738: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
5739: my $toppath="/priv/$coursedom/$coursenum'}";
5740: my %subdirs;
1.608 raeburn 5741: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5742: $numcrsdirs = keys(%subdirs);
5743: if ($numcrsdirs) {
5744: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
5745: '<option value="/">/</option>'."\n";
5746: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 5747: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 5748: }
5749: $pickdir .= '</select>';
5750: } else {
5751: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
5752: }
5753: }
5754: }
5755:
5756: my %seltemplate_menus;
5757: my @files = &Apache::lonhomework::get_template_list('problem');
5758: my @noexamplelink = ('blank.problem','blank.library','script.library');
5759: my $currentcategory = '';
5760: my @ordered = ('');
5761: my %templatehelp;
5762: my $defcategory = '';
5763: my @catorder = ($defcategory);
5764: $seltemplate_menus{$defcategory}->{'order'} = [''];
5765: $seltemplate_menus{$defcategory}->{'text'} = '';
5766: foreach my $file (@files) {
5767: if (ref($file) eq 'ARRAY') {
5768: my ($path,$title,$category,$help) = @{$file};
5769: next if ($title !~ /\S/);
5770: if (&js_escape($category) ne $currentcategory) {
5771: $currentcategory = &js_escape($category);
5772: push(@catorder,&js_escape($currentcategory));
5773: $seltemplate_menus{$currentcategory}->{'text'} = $category;
5774: $seltemplate_menus{$currentcategory}->{'default'} = '';
5775: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
5776: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
5777: }
5778: if ($path) {
5779: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
5780: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
5781: if ($help) {
5782: $templatehelp{$path} = $help;
5783: }
5784: }
5785: }
5786: }
5787:
5788: my $templates = $lt{'cate'}.' '.
5789: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
5790: $defcategory,'tempcategory','template',
5791: \%seltemplate_menus,\@catorder,
5792: "resize_scrollbox('contentscroll','1','0');",
5793: "toggleExampleText();",'template').'<br />';
5794: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
5795: '<span id="newresexample">'.&mt('Example').'<span></a>';
5796: my $crsresform=(<<RESFORM);
5797: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
5798: $lt{'stpr'}</a>$help{'Course_Resource'}
5799: <form action="/adm/coursedocs" method="post" name="courseresform">
5800: <fieldset id="crsresform" style="display:none;">
5801: <legend>$lt{'stpr'}</legend>
5802: <input type="hidden" name="active" value="ee" />
5803: <p>
5804: $pickdir
5805: <span class="LC_nobreak">$lt{'news'}?
5806: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" />No</label>
5807:
5808: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" />Yes</label>
5809: </span><span id="newsubdir"></span>
5810: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
5811: </p>
5812: $lt{'fnam'}
5813: <input type="text" size="20" name="newresourcename" autocomplete="off" />
5814: <p>
5815: <div id="newresource" style="display:$showtitle">
5816: $lt{'addp'}
5817: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" />
5818: $lt{'no'}</label>
5819: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" />
5820: $lt{'yes'}</label>
5821: <span id="newrestitle"></span>
5822: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" />
5823: </div>
5824: </p>
5825: <p>
5826: $lt{'uste'}
5827: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" />
5828: $lt{'no'}</label>
5829: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" />
5830: $lt{'yes'}</label>
5831: <div id="newrestemplate" style="display:none">
5832: $templates
5833: $templatepreview
5834: </div>
5835: </p>
5836: <span class="LC_nobreak">
5837: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
5838: <input type="submit" name="newcrs" value="$lt{'crpr'}" />
5839: </span>
5840: </fieldset>
5841: </form>
5842:
5843: RESFORM
1.534 raeburn 5844:
1.342 ehlerst 5845: my $specialdocumentsform;
1.383 tempelho 5846: my @specialdocumentsforma;
1.451 www 5847: my $gradingform;
5848: my @gradingforma;
5849: my $communityform;
5850: my @communityforma;
1.351 ehlerst 5851: my $newfolderform;
1.390 tempelho 5852: my $newfolderb;
1.342 ehlerst 5853:
1.451 www 5854: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5855:
1.329 droeschl 5856: my $newpageform=(<<NPFORM);
5857: <form action="/adm/coursedocs" method="post" name="newpage">
5858: <input type="hidden" name="folderpath" value="$path" />
5859: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5860: <input type="hidden" name="active" value="ee" />
1.423 onken 5861: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5862: $help{'Adding_Pages'}
1.329 droeschl 5863: </form>
5864: NPFORM
1.390 tempelho 5865:
5866:
1.351 ehlerst 5867: $newfolderform=(<<NFFORM);
1.329 droeschl 5868: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 5869: $pathitem
1.329 droeschl 5870: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5871: <input type="hidden" name="active" value="" />
1.422 onken 5872: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5873: </form>
5874: NFFORM
5875:
5876: my $newsylform=(<<NSYLFORM);
5877: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 5878: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5879: $pathitem
1.329 droeschl 5880: <input type="hidden" name="importdetail"
5881: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5882: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5883: $help{'Syllabus'}
1.383 tempelho 5884:
1.329 droeschl 5885: </form>
5886: NSYLFORM
1.364 bisitz 5887:
1.329 droeschl 5888: my $newgroupfileform=(<<NGFFORM);
5889: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 5890: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5891: $pathitem
1.329 droeschl 5892: <input type="hidden" name="importdetail"
5893: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 5894: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 5895: $help{'Group Portfolio'}
1.329 droeschl 5896: </form>
5897: NGFFORM
1.383 tempelho 5898: @specialdocumentsforma=(
1.421 onken 5899: {'<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 5900: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 5901: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
5902: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 5903: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5904: );
5905: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5906:
1.434 raeburn 5907:
5908: my @importdoc = (
1.519 raeburn 5909: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5910: );
1.598 raeburn 5911: if (keys(%ltitools)) {
5912: push(@importdoc,
5913: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
5914: );
5915: }
1.519 raeburn 5916: unless ($container eq 'page') {
5917: push(@importdoc,
5918: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5919: );
5920: }
5921: push(@importdoc,
1.558 raeburn 5922: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 5923: );
1.501 raeburn 5924: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5925:
1.451 www 5926: @gradingforma=(
5927: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5928: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5929: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 5930: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
1.451 www 5931: );
5932: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5933:
5934: @communityforma=(
5935: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5936: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5937: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
5938: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
5939: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
5940: );
5941: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5942:
1.330 tempelho 5943: my %orderhash = (
1.553 raeburn 5944: 'aa' => ['Upload',$fileuploadform],
5945: 'bb' => ['Import',$importpubform],
5946: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5947: );
1.519 raeburn 5948: unless ($container eq 'page') {
1.434 raeburn 5949: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5950: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 5951: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5952: }
5953:
1.341 ehlerst 5954: $hadchanges=0;
1.484 raeburn 5955: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5956: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.598 raeburn 5957: $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools);
1.443 www 5958: if ($error) {
5959: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5960: }
5961: if ($hadchanges) {
5962: &mark_hash_old();
5963: }
1.341 ehlerst 5964:
1.443 www 5965: &changewarning($r,'');
5966: }
1.458 raeburn 5967: }
1.442 www 5968:
1.443 www 5969: # Supplemental documents start here
5970:
1.329 droeschl 5971: my $folder=$env{'form.folder'};
1.443 www 5972: unless ($supplementalflag) {
1.329 droeschl 5973: $folder='supplemental';
5974: }
5975: if ($folder =~ /^supplemental$/ &&
5976: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5977: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5978: } elsif ($allowed) {
1.356 tempelho 5979: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5980: }
1.508 raeburn 5981: $pathitem = '<input type="hidden" name="folderpath" value="'.
5982: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5983: if ($allowed) {
5984: my $folderseq=
1.504 raeburn 5985: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5986:
5987: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 5988: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5989: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5990: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 5991: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 5992: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5993: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5994: $fileupload
5995: <br />
5996: <br />
5997: <span class="LC_nobreak">
5998: $checkbox
5999: </span>
6000: <br /><br />
6001: $lt{'comment'}:<br />
1.383 tempelho 6002: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6003: <br />
1.508 raeburn 6004: $pathitem
1.329 droeschl 6005: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6006: <input type='submit' value="$lt{'upld'}" />
6007: </form>
1.329 droeschl 6008: SUPDOCFORM
6009:
6010: my $supnewfolderform=(<<SNFFORM);
6011: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6012: <input type="hidden" name="active" value="" />
1.508 raeburn 6013: $pathitem
1.329 droeschl 6014: <input type="hidden" name="importdetail" value="" />
1.423 onken 6015: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6016: $help{'Adding_Folders'}
1.329 droeschl 6017: </form>
6018: SNFFORM
1.383 tempelho 6019:
1.510 raeburn 6020: my $supextform =
6021: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6022: $help{'Adding_External_Resource'});
1.329 droeschl 6023:
1.598 raeburn 6024: my $supexttoolform =
6025: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6026: $help{'Adding_External_Tool'},
6027: undef,undef,'tool',$coursedom,
6028: $coursenum,\%ltitools);
6029:
1.329 droeschl 6030: my $supnewsylform=(<<SNSFORM);
6031: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6032: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6033: $pathitem
1.329 droeschl 6034: <input type="hidden" name="importdetail"
6035: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 6036: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 6037: $help{'Syllabus'}
6038: </form>
6039: SNSFORM
6040:
6041: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6042: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6043: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6044: $pathitem
1.329 droeschl 6045: <input type="hidden" name="importdetail"
6046: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 6047: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 6048: $help{'My Personal Information Page'}
1.329 droeschl 6049: </form>
6050: SNAMFORM
6051:
1.534 raeburn 6052: my $supwebpage;
6053: if ($folder =~ /^supplemental_?(\d*)$/) {
6054: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6055: if ($1) {
6056: $supwebpage .= $1;
6057: } else {
6058: $supwebpage .= 'default';
6059: }
6060: $supwebpage .= '/new.html';
6061: }
6062: my $supwebpageform =(<<SWEBFORM);
6063: <form action="/adm/coursedocs" method="post" name="supwebpage">
6064: <input type="hidden" name="active" value="cc" />
6065: $pathitem
6066: <input type="hidden" name="importdetail" value="$supwebpage" />
6067: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6068: $help{'Web_Page'}
1.534 raeburn 6069: </form>
6070: SWEBFORM
6071:
1.333 muellerd 6072:
1.383 tempelho 6073: my @specialdocs = (
1.417 droeschl 6074: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
6075: =>$supnewsylform},
6076: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
6077: =>$supnewaboutmeform},
1.534 raeburn 6078: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6079:
1.383 tempelho 6080: );
1.417 droeschl 6081: my @supimportdoc = (
1.515 raeburn 6082: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6083: =>$supextform});
6084: if (keys(%ltitools)) {
6085: push(@supimportdoc,
6086: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6087: =>$supexttoolform});
6088: }
6089: push(@supimportdoc,
6090: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6091: =>$supupdocform},
1.598 raeburn 6092: );
1.501 raeburn 6093:
6094: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6095: my %suporderhash = (
1.390 tempelho 6096: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6097: 'ee' => ['Upload',$supupdocform],
6098: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6099: );
1.443 www 6100: if ($supplementalflag) {
1.458 raeburn 6101: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.598 raeburn 6102: $supplementalflag,\%suporderhash,$iconpath,$pathitem,\%ltitools);
1.443 www 6103: if ($error) {
6104: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6105: } else {
6106: if ($suppchanges) {
6107: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6108: my @ids=&Apache::lonnet::current_machine_ids();
6109: foreach my $server (keys(%servers)) {
6110: next if (grep(/^\Q$server\E$/,@ids));
6111: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6112: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6113: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6114: }
6115: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6116: undef($suppchanges);
6117: }
6118: }
1.393 raeburn 6119: }
1.443 www 6120: } elsif ($supplementalflag) {
1.458 raeburn 6121: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 6122: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 6123: if ($error) {
6124: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6125: }
1.393 raeburn 6126: }
1.389 tempelho 6127:
1.510 raeburn 6128: if ($needs_end) {
6129: $r->print(&endContentScreen());
6130: }
1.383 tempelho 6131:
1.329 droeschl 6132: if ($allowed) {
6133: $r->print('
6134: <form method="post" name="extimport" action="/adm/coursedocs">
6135: <input type="hidden" name="title" />
6136: <input type="hidden" name="url" />
6137: <input type="hidden" name="useform" />
6138: <input type="hidden" name="residx" />
6139: </form>');
6140: }
1.484 raeburn 6141: } elsif ($showdoc) {
1.329 droeschl 6142: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6143: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6144: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6145: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6146: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6147: }
6148: }
1.606 raeburn 6149: unless ($noendpage) {
6150: $r->print(&Apache::loncommon::end_page());
6151: }
1.329 droeschl 6152: return OK;
1.364 bisitz 6153: }
1.329 droeschl 6154:
1.440 raeburn 6155: sub embedded_form_elems {
6156: my ($phase,$primaryurl,$newidx) = @_;
6157: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6158: return <<STATE;
6159: <input type="hidden" name="folderpath" value="$folderpath" />
6160: <input type="hidden" name="cmd" value="upload_embedded" />
6161: <input type="hidden" name="newidx" value="$newidx" />
6162: <input type="hidden" name="phase" value="$phase" />
6163: <input type="hidden" name="primaryurl" value="$primaryurl" />
6164: STATE
6165: }
6166:
6167: sub embedded_destination {
6168: my $folder=$env{'form.folder'};
6169: my $destination = 'docs/';
6170: if ($folder =~ /^supplemental/) {
6171: $destination = 'supplemental/';
6172: }
6173: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6174: $destination .= 'default/';
6175: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6176: $destination .= $2.'/';
6177: }
6178: $destination .= $env{'form.newidx'};
6179: my $dir_root = '/userfiles';
6180: return ($destination,$dir_root);
6181: }
6182:
6183: sub return_to_editor {
6184: my $actionurl = '/adm/coursedocs';
6185: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6186: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6187: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6188: '</a></p>';
6189: }
6190:
1.476 raeburn 6191: sub decompression_info {
6192: my ($destination,$dir_root) = &embedded_destination();
6193: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6194: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6195: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6196: my $container='sequence';
1.480 raeburn 6197: my ($pathitem,$hiddenelem);
1.583 raeburn 6198: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6199: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6200: $container='page';
6201: }
1.480 raeburn 6202: unshift(@hiddens,$pathitem);
6203: foreach my $item (@hiddens) {
6204: if ($env{'form.'.$item}) {
6205: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6206: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6207: }
1.477 raeburn 6208: }
1.476 raeburn 6209: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6210: $hiddenelem);
6211: }
6212:
6213: sub decompression_phase_one {
6214: my ($dir,$file,$warning,$error,$output);
6215: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6216: &decompression_info();
1.490 raeburn 6217: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6218: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6219: } else {
6220: my $file = $1;
1.481 raeburn 6221: $output =
6222: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6223: $destination,$dir_root,
6224: $hiddenelem);
6225: if ($env{'form.autoextract_camtasia'}) {
6226: $output .= &remove_archive($docudom,$docuname,$container);
6227: }
1.476 raeburn 6228: }
6229: if ($error) {
6230: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6231: $error.'</p>'."\n";
6232: }
6233: if ($warning) {
6234: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6235: }
6236: return $output;
6237: }
6238:
6239: sub decompression_phase_two {
6240: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6241: &decompression_info();
1.481 raeburn 6242: my $output;
1.480 raeburn 6243: if ($env{'form.archivedelete'}) {
1.481 raeburn 6244: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6245: }
6246: $output .=
1.481 raeburn 6247: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6248: $destination,$dir_root,$hiddenelem);
6249: return $output;
6250: }
6251:
1.480 raeburn 6252: sub remove_archive {
6253: my ($docudom,$docuname,$container) = @_;
6254: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6255: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6256: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6257: if ($fatal) {
6258: if ($container eq 'page') {
6259: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6260: } else {
6261: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6262: }
1.583 raeburn 6263: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6264: } else {
6265: my $currcmd = $env{'form.cmd'};
6266: my $position = $env{'form.position'};
1.583 raeburn 6267: my $archiveidx = $position;
1.563 raeburn 6268: if ($position > 0) {
1.583 raeburn 6269: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6270: $archiveidx = $position-1;
6271: }
6272: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6273: my ($title,$url,@rrest) =
1.583 raeburn 6274: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6275: if ($url eq $env{'form.archiveurl'}) {
6276: if (&handle_edit_cmd($docuname,$docudom)) {
6277: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6278: if ($fatal) {
6279: if ($container eq 'page') {
6280: $delwarning = &mt('An error occurred updating the contents of the current page.');
6281: } else {
6282: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6283: }
1.480 raeburn 6284: } else {
1.583 raeburn 6285: $delresult = &mt('Archive file removed.');
1.480 raeburn 6286: }
6287: }
1.583 raeburn 6288: } else {
6289: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6290: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6291: }
6292: }
6293: $env{'form.cmd'} = $currcmd;
6294: }
6295: if ($delwarning) {
6296: $output = '<p class="LC_warning">'.
6297: $delwarning.
6298: '</p>';
6299: }
6300: if ($delresult) {
6301: $output .= '<p class="LC_info">'.
6302: $delresult.
6303: '</p>';
6304: }
1.481 raeburn 6305: return $output;
1.480 raeburn 6306: }
6307:
1.484 raeburn 6308: sub generate_admin_menu {
6309: my ($crstype) = @_;
6310: my $lc_crstype = lc($crstype);
6311: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6312: my %lt= ( # do not translate here
1.484 raeburn 6313: 'vc' => 'Verify Content',
6314: 'cv' => 'Check/Set Resource Versions',
6315: 'ls' => 'List Resource Identifiers',
6316: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6317: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6318: );
1.484 raeburn 6319: my ($candump,$dumpurl);
6320: if ($home + $other > 0) {
6321: $candump = 'F';
6322: if ($home) {
6323: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6324: } else {
6325: my @hosts;
6326: foreach my $aurole (keys(%outhash)) {
6327: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6328: push(@hosts,$outhash{$aurole});
1.538 raeburn 6329: }
1.484 raeburn 6330: }
6331: if (@hosts == 1) {
6332: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6333: '&role='.
6334: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6335: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6336: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6337: } else {
6338: $dumpurl = "javascript:choose_switchserver_window()";
6339: }
6340: }
6341: }
6342: my @menu=
6343: ({ categorytitle=>'Administration',
6344: items =>[
6345: { linktext => $lt{'vc'},
6346: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6347: permission => 'F',
1.571 raeburn 6348: help => 'Docs_Verify_Content',
1.484 raeburn 6349: icon => 'verify.png',
6350: linktitle => 'Verify contents can be retrieved/rendered',
6351: },
6352: { linktext => $lt{'cv'},
6353: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6354: permission => 'F',
1.571 raeburn 6355: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6356: icon => 'resversion.png',
6357: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6358: },
6359: { linktext => $lt{'ls'},
6360: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6361: permission => 'F',
6362: #help => '',
6363: icon => 'symbs.png',
6364: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6365: },
6366: ]
6367: },
6368: { categorytitle=>'Export',
6369: items =>[
6370: { linktext => $lt{'imse'},
6371: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6372: permission => 'F',
6373: help => 'Docs_Export_Course_Docs',
6374: icon => 'imsexport.png',
6375: linktitle => $lt{'imse'},
6376: },
6377: { linktext => $lt{'dcd'},
6378: url => $dumpurl,
6379: permission => $candump,
1.571 raeburn 6380: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6381: icon => 'dump.png',
6382: linktitle => $lt{'dcd'},
6383: },
6384: ]
6385: });
6386: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6387: '<input type="hidden" id="dummy" />'."\n".
6388: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6389: '</form>';
1.329 droeschl 6390: }
6391:
6392: sub generate_edit_table {
1.538 raeburn 6393: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
6394: $need_save,$copyfolder) = @_;
1.406 raeburn 6395: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6396: my %orderhash = %{$orderhash_ref};
1.344 bisitz 6397: my $form;
1.371 tempelho 6398: my $activetab;
6399: my $active;
1.570 raeburn 6400: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6401: $activetab = $env{'form.active'};
6402: }
1.472 raeburn 6403: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6404: my $backtext = &mt('Exit Editor');
1.458 raeburn 6405: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6406: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6407: '<li class="goback">'.
1.546 raeburn 6408: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6409: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6410: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6411: '<li>'.
6412: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6413: &mt('Undo Delete').'</a></li>'."\n";
6414: if ($env{'form.docslog'}) {
6415: $form .= '<li class="active">';
6416: } else {
6417: $form .= '<li>';
6418: }
6419: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6420: &mt('History').'</a></li>'."\n";
6421: if ($env{'form.docslog'}) {
6422: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6423: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6424: }
1.458 raeburn 6425: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6426: if($name ne '00'){
1.371 tempelho 6427: if($activetab eq '' || $activetab ne $name){
6428: $active = '';
6429: }elsif($activetab eq $name){
6430: $active = 'class="active"';
6431: }
1.458 raeburn 6432: $form .= '<li style="float:right" '.$active
1.484 raeburn 6433: .' 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 6434: } else {
1.570 raeburn 6435: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6436:
6437: }
1.329 droeschl 6438: }
1.484 raeburn 6439: $form .= '</ul>'."\n";
6440: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6441:
6442: if ($to_show ne '') {
1.538 raeburn 6443: my $saveform;
6444: if ($need_save) {
6445: my $button = &mt('Make changes');
6446: my $path;
6447: if ($env{'form.folderpath'}) {
6448: $path =
6449: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6450: }
6451: $saveform = <<"END";
6452: <div id="multisave" style="display:none; clear:both;" >
6453: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6454: <input type="hidden" name="folderpath" value="$path" />
6455: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6456: <input type="hidden" name="allhiddenresource" value="" />
6457: <input type="hidden" name="allencrypturl" value="" />
6458: <input type="hidden" name="allrandompick" value="" />
6459: <input type="hidden" name="allrandomorder" value="" />
6460: <input type="hidden" name="changeparms" value="" />
6461: <input type="hidden" name="multiremove" value="" />
6462: <input type="hidden" name="multicut" value="" />
6463: <input type="hidden" name="multicopy" value="" />
6464: <input type="hidden" name="multichange" value="" />
6465: <input type="hidden" name="copyfolder" value="$copyfolder" />
6466: <input type="submit" name="savemultiples" value="$button" />
6467: </form>
6468: </div>
6469: END
6470: }
6471: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6472: }
1.363 ehlerst 6473: foreach my $field (keys(%orderhash)){
1.390 tempelho 6474: if($field ne '00'){
1.422 onken 6475: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6476: $active = 'style="display: none;float:left"';
1.422 onken 6477: }elsif($activetab eq $field){
1.458 raeburn 6478: $active = 'style="display:block;float:left"';
1.422 onken 6479: }
6480: $form .= '<div id="'.$field.$tid.'"'
6481: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6482: .'</div>'."\n";
1.363 ehlerst 6483: }
6484: }
1.484 raeburn 6485: unless ($env{'form.docslog'}) {
6486: $form .= '</div></div>'."\n";
6487: }
1.329 droeschl 6488: return $form;
6489: }
6490:
6491: sub editing_js {
1.606 raeburn 6492: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot) = @_;
1.594 damieng 6493: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6494: p_mnf => 'Name of New Folder',
6495: t_mnf => 'New Folder',
6496: p_mnp => 'Name of New Page',
6497: t_mnp => 'New Page',
1.451 www 6498: p_mxu => 'Title for the External Score',
1.349 biermanm 6499: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6500: p_msb => 'Title for the Problem',
6501: p_mdb => 'Title for the Drop Box',
1.336 schafran 6502: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6503: p_mwp => 'Title for Web Page',
1.606 raeburn 6504: p_mnr => 'Title for the Resource',
1.348 weissno 6505: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6506: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6507: p_mab_alrt1 => 'Not a valid user:domain',
6508: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6509: p_chn => 'New Title',
6510: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6511: p_rmr2a => 'Remove',
6512: p_rmr2b => '?',
6513: p_rmr3a => 'Remove those',
6514: p_rmr3b => 'items?',
6515: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6516: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6517: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6518: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6519: p_ctr2a => 'Cut',
6520: p_ctr2b => '?',
6521: p_ctr3a => 'Cut those',
6522: p_ctr3b => 'items?',
1.478 raeburn 6523: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6524: imsfile => 'You must choose an IMS package for import',
6525: imscms => 'You must select which Course Management System was the source of the IMS package',
6526: invurl => 'Invalid URL',
6527: titbl => 'Title is blank',
1.538 raeburn 6528: more => '(More ...)',
6529: less => '(Less ...)',
1.543 raeburn 6530: noor => 'No actions selected or changes to settings specified.',
6531: noch => 'No changes to settings specified.',
6532: noac => 'No actions selected.',
1.606 raeburn 6533: nofi => 'No file selected',
6534: tinc => 'Title in course',
6535: sunm => 'Sub-directory name',
1.329 droeschl 6536: );
1.594 damieng 6537: &js_escape(\%js_lt);
1.433 raeburn 6538: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6539: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6540: my $main_container_page;
1.519 raeburn 6541: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6542: $main_container_page = 1;
1.434 raeburn 6543: }
1.538 raeburn 6544: my $toplevelmain =
1.548 raeburn 6545: &escape(&mt('Main Content').':::::');
1.446 www 6546: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6547:
1.525 raeburn 6548: my $backtourl;
1.530 raeburn 6549: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6550: my $caller = $1;
1.525 raeburn 6551: if ($caller =~ /^supplemental/) {
6552: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6553: } else {
6554: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6555: $res = &Apache::lonnet::clutter($res);
6556: if (&Apache::lonnet::is_on_map($res)) {
1.609 ! raeburn 6557: my ($url,$anchor);
! 6558: if ($res =~ /^([^#]+)#([^#]+)$/) {
! 6559: $url = $1;
! 6560: $anchor = $2;
! 6561: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
! 6562: $caller = $1.&escape('#').$anchor;
! 6563: }
! 6564: }
! 6565: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6566: &HTML::Entities::encode($caller,'<>&"');
1.609 ! raeburn 6567: if ($anchor ne '') {
! 6568: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
! 6569: }
1.590 raeburn 6570: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6571: } else {
6572: $backtourl = '/adm/navmaps';
1.525 raeburn 6573: }
6574: }
6575: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6576: $backtourl = '/adm/menu';
6577: } elsif ($supplementalflag) {
1.472 raeburn 6578: $backtourl = '/adm/supplemental';
1.525 raeburn 6579: } else {
6580: $backtourl = '/adm/navmaps';
1.472 raeburn 6581: }
6582:
1.600 raeburn 6583: my $fieldsets = "'ext','doc'";
6584: if ($posslti) {
6585: $fieldsets .= ",'tool'";
6586: }
1.519 raeburn 6587: unless ($main_container_page) {
6588: $fieldsets .=",'ims'";
6589: }
1.501 raeburn 6590: if ($supplementalflag) {
1.600 raeburn 6591: $fieldsets = "'suppext','suppdoc'";
6592: if ($posslti) {
6593: $fieldsets .= ",'supptool'";
6594: }
1.501 raeburn 6595: }
6596:
1.329 droeschl 6597: return <<ENDNEWSCRIPT;
6598: function makenewfolder(targetform,folderseq) {
1.594 damieng 6599: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6600: if (foldername) {
6601: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6602: targetform.submit();
6603: }
6604: }
6605:
6606: function makenewpage(targetform,folderseq) {
1.594 damieng 6607: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6608: if (pagename) {
6609: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6610: targetform.submit();
6611: }
6612: }
6613:
6614: function makeexamupload() {
1.594 damieng 6615: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6616: if (title) {
1.329 droeschl 6617: this.document.forms.newexamupload.importdetail.value=
6618: escape(title)+'=/res/lib/templates/examupload.problem';
6619: this.document.forms.newexamupload.submit();
6620: }
6621: }
6622:
6623: function makesmppage() {
1.594 damieng 6624: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6625: if (title) {
1.329 droeschl 6626: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6627: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6628: this.document.forms.newsmppg.submit();
6629: }
6630: }
6631:
1.534 raeburn 6632: function makewebpage(type) {
1.594 damieng 6633: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6634: var formname;
6635: if (type == 'supp') {
6636: formname = this.document.forms.supwebpage;
6637: } else {
6638: formname = this.document.forms.newwebpage;
6639: }
6640: if (title) {
6641: var webpage = formname.importdetail.value;
6642: formname.importdetail.value = escape(title)+'='+webpage;
6643: formname.submit();
6644: }
6645: }
6646:
1.329 droeschl 6647: function makesmpproblem() {
1.594 damieng 6648: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6649: if (title) {
1.329 droeschl 6650: this.document.forms.newsmpproblem.importdetail.value=
6651: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6652: this.document.forms.newsmpproblem.submit();
6653: }
6654: }
6655:
6656: function makedropbox() {
1.594 damieng 6657: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6658: if (title) {
1.329 droeschl 6659: this.document.forms.newdropbox.importdetail.value=
6660: escape(title)+'=/res/lib/templates/DropBox.problem';
6661: this.document.forms.newdropbox.submit();
6662: }
6663: }
6664:
6665: function makebulboard() {
1.594 damieng 6666: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6667: if (title) {
6668: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6669: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6670: this.document.forms.newbul.submit();
6671: }
6672: }
6673:
6674: function makeabout() {
1.594 damieng 6675: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6676: if (user) {
6677: var comp=new Array();
6678: comp=user.split(':');
6679: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6680: if ((comp[0]) && (comp[1])) {
6681: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 6682: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 6683: this.document.forms.newaboutsomeone.submit();
6684: } else {
1.594 damieng 6685: alert("$js_lt{'p_mab_alrt1'}");
1.329 droeschl 6686: }
1.335 ehlerst 6687: } else {
1.594 damieng 6688: alert("$js_lt{'p_mab_alrt2'}");
1.335 ehlerst 6689: }
6690: }
1.329 droeschl 6691: }
6692:
1.501 raeburn 6693: function toggleUpload(caller) {
6694: var blocks = Array($fieldsets);
6695: for (var i=0; i<blocks.length; i++) {
6696: var disp = 'none';
6697: if (caller == blocks[i]) {
6698: var curr = document.getElementById('upload'+caller+'form').style.display;
6699: if (curr == 'none') {
6700: disp='block';
6701: }
6702: }
6703: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 6704: if ((caller == 'tool') || (caller == 'supptool')) {
6705: if (disp == 'block') {
6706: if (document.getElementById('LC_exttoolid')) {
6707: var toolselector = document.getElementById('LC_exttoolid');
6708: var suppflag = 0;
6709: if (caller == 'supptool') {
6710: suppflag = 1;
6711: }
6712: currForm = document.getElementById('new'+caller);
6713: updateExttool(toolselector,currForm,suppflag);
6714: }
6715: }
6716: }
1.501 raeburn 6717: }
1.502 raeburn 6718: resize_scrollbox('contentscroll','1','1');
6719: return;
6720: }
6721:
1.514 raeburn 6722: function toggleMap(caller) {
1.502 raeburn 6723: var disp = 'none';
1.510 raeburn 6724: if (document.getElementById('importmapform')) {
1.514 raeburn 6725: if (caller == 'map') {
6726: var curr = document.getElementById('importmapform').style.display;
6727: if (curr == 'none') {
6728: disp='block';
6729: }
1.510 raeburn 6730: }
6731: document.getElementById('importmapform').style.display=disp;
6732: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 6733: }
1.501 raeburn 6734: return;
1.329 droeschl 6735: }
6736:
1.606 raeburn 6737: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
6738: var disp = 'none';
6739: if (document.getElementById('crsresform')) {
6740: if (caller == 'res') {
6741: var curr = document.getElementById('crsresform').style.display;
6742: if (curr == 'none') {
6743: disp='block';
6744: numauthor = parseInt(numauthorrole);
6745: if (numauthor > 0) {
6746: document.courseresform.authorrole.selectedIndex = 0;
6747: select1priv_changed();
6748: document.courseresform.authorpath.selectedIndex = 0;
6749: document.courseresform.newresourceadd.selectedIndex = 0;
6750: toggleNewInCourse(document.courseresform);
6751: if (document.getElementById('newresource')) {
6752: document.getElementById('newresource').style.display = 'none';
6753: }
6754: } else {
6755: if (numcrsdirs) {
6756: document.courseresform.authorpath.selectedIndex = 0;
6757: }
6758: }
6759: if (document.courseresform.newresusetemp.length) {
6760: document.courseresform.newresusetemp[0].checked = true;
6761: toggleWithTemplate(document.courseresform);
6762: }
6763: document.courseresform.newresourcename.value = '';
6764: }
6765: }
6766: if (document.courseresform.newsubdir.length) {
6767: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
6768: if (document.courseresform.newsubdir[j].value == 0) {
6769: document.courseresform.newsubdir[j].checked = true;
6770: }
6771: break;
6772: }
6773: if (document.getElementById('newsubdirname')) {
6774: document.getElementById('newsubdirname').type = "hidden";
6775: document.getElementById('newsubdirname').value = "";
6776: }
6777: if (document.getElementById('newsubdir')) {
6778: document.getElementById('newsubdir').innerHTML = "";
6779: }
6780: }
6781: document.getElementById('crsresform').style.display=disp;
6782: resize_scrollbox('contentscroll','1','0');
6783: }
6784: return;
6785: }
6786:
6787: function toggleNewsubdir(form) {
6788: if (form.newsubdir.length) {
6789: for (var j=0; j<form.newsubdir.length; j++) {
6790: if (form.newsubdir[j].checked) {
6791: if (document.getElementById('newsubdirname')) {
6792: if (form.newsubdir[j].value == '1') {
6793: document.getElementById('newsubdirname').type = "text";
6794: if (document.getElementById('newsubdir')) {
6795: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
6796: }
6797: } else {
6798: document.getElementById('newsubdirname').type = "hidden";
6799: document.getElementById('newsubdirname').value = "";
6800: document.getElementById('newsubdir').innerHTML = "";
6801: }
6802: }
6803: break;
6804: }
6805: }
6806: }
6807: }
6808:
6809: function toggleCrsResTitle() {
6810: if (document.getElementById('newresource')) {
6811: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
6812: document.getElementById('newresource').style.display = 'inline';
6813: document.courseresform.newresourceadd[0].checked = true;
6814: toggleNewInCourse(document.courseresform);
6815: } else {
6816: document.getElementById('newresource').style.display = 'none';
6817: }
6818: }
6819: }
6820:
6821: function toggleNewInCourse(form) {
6822: if (form.newresourceadd.length) {
6823: for (var i=0; i<form.newresourceadd.length; i++) {
6824: if (form.newresourceadd[i].checked) {
6825: if (document.getElementById('newresourcetitle')) {
6826: if (form.newresourceadd[i].value == '1') {
6827: document.getElementById('newresourcetitle').type = 'text';
6828: if (document.getElementById('newrestitle')) {
6829: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
6830: }
6831: } else {
6832: document.getElementById('newresourcetitle').type = 'hidden';
6833: document.getElementById('newresourcetitle').value = '';
6834: if (document.getElementById('newrestitle')) {
6835: document.getElementById('newrestitle').innerHTML = '';
6836: }
6837: }
6838: }
6839: break;
6840: }
6841: }
6842: }
6843: }
6844:
6845: function toggleWithTemplate(form) {
6846: if (form.newresusetemp.length) {
6847: for (var i=0; i<form.newresusetemp.length; i++) {
6848: if (form.newresusetemp[i].checked) {
6849: if (document.getElementById('newrestemplate')) {
6850: if (form.newresusetemp[i].value == '1') {
6851: document.getElementById('newrestemplate').style.display = 'inline';
6852: toggleExampleText();
6853: } else {
6854: form.tempcategory.selectedIndex = 0;
6855: select1template_changed();
6856: document.getElementById('newrestemplate').style.display = 'none';
6857: }
6858: }
6859: }
6860: }
6861: }
6862: }
6863:
6864: function toggleExampleText() {
6865: if (document.getElementById('newresexample')) {
6866: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
6867: if (url == '') {
6868: document.getElementById('newresexample').style.fontWeight = 'normal';
6869: } else {
6870: document.getElementById('newresexample').style.fontWeight = 'bold';
6871: }
6872: }
6873: }
6874:
6875: function getExample(width,height,scrolling,transparency) {
6876: var url;
6877: if (document.courseresform.newresusetemp.length) {
6878: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
6879: if (document.courseresform.newresusetemp[i].checked) {
6880: if (document.courseresform.newresusetemp[i].value == '1') {
6881: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
6882: if (url == '') {
6883: alert('Pick a category and template');
6884: } else {
6885: url = url.replace("$londocroot","");
6886: url += '?inhibitmenu=yes';
6887: }
6888: }
6889: break;
6890: }
6891: }
6892: }
6893: if (url != '') {
6894: openMyModal(url,width,height,scrolling,transparency,'');
6895: }
6896: }
6897:
6898: function toggleImportCrsres(caller,dircount) {
6899: var disp = 'none';
6900: if (document.getElementById('importcrsresform')) {
6901: if (caller == 'res') {
6902: var numdirs = parseInt(dircount);
6903: var curr = document.getElementById('importcrsresform').style.display;
6904: if (curr == 'none') {
6905: disp='block';
6906: if (numdirs > 1) {
6907: select1res_changed();
6908: }
6909: }
6910: }
6911: document.getElementById('importcrsresform').style.display=disp;
6912: resize_scrollbox('contentscroll','1','0');
6913: }
6914: return;
6915: }
6916:
1.501 raeburn 6917: function makeims(imsform) {
6918: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 6919: alert("$js_lt{'imsfile'}");
1.501 raeburn 6920: return;
6921: }
6922: if (imsform.source.selectedIndex == 0) {
1.594 damieng 6923: alert("$js_lt{'imscms'}");
1.501 raeburn 6924: return;
6925: }
6926: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6927: imsform.submit();
6928: }
6929:
1.519 raeburn 6930: function changename(folderpath,index,oldtitle) {
1.594 damieng 6931: var title=prompt('$js_lt{"p_chn"}',oldtitle);
1.335 ehlerst 6932: if (title) {
1.538 raeburn 6933: this.document.forms.renameform.markcopy.value='';
1.335 ehlerst 6934: this.document.forms.renameform.title.value=title;
6935: this.document.forms.renameform.cmd.value='rename_'+index;
1.519 raeburn 6936: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 6937: this.document.forms.renameform.submit();
6938: }
1.329 droeschl 6939: }
6940:
1.478 raeburn 6941: function updatePick(targetform,index,caller) {
1.537 raeburn 6942: var pickitem;
6943: var picknumitem;
6944: var picknumtext;
6945: if (index == 'all') {
6946: pickitem = document.getElementById('randompickall');
6947: picknumitem = document.getElementById('rpicknumall');
6948: picknumtext = document.getElementById('rpicktextall');
6949: } else {
6950: pickitem = document.getElementById('randompick_'+index);
6951: picknumitem = document.getElementById('rpicknum_'+index);
6952: picknumtext = document.getElementById('randompicknum_'+index);
6953: }
1.478 raeburn 6954: if (pickitem.checked) {
1.594 damieng 6955: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6956: if (picknum == '' || picknum == null) {
6957: if (caller == 'check') {
6958: pickitem.checked=false;
1.537 raeburn 6959: if (index == 'all') {
6960: picknumtext.innerHTML = '';
6961: if (caller == 'link') {
6962: propagateState(targetform,'rpicknum');
6963: }
6964: } else {
1.538 raeburn 6965: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6966: }
1.478 raeburn 6967: }
6968: } else {
6969: picknum.toString();
6970: var regexdigit=/^\\d+\$/;
6971: if (regexdigit.test(picknum)) {
6972: picknumitem.value = picknum;
1.537 raeburn 6973: if (index == 'all') {
1.538 raeburn 6974: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 6975: if (caller == 'link') {
6976: propagateState(targetform,'rpicknum');
6977: }
6978: } else {
6979: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 6980: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6981: }
1.478 raeburn 6982: } else {
6983: if (caller == 'check') {
1.537 raeburn 6984: if (index == 'all') {
6985: picknumtext.innerHTML = '';
6986: if (caller == 'link') {
6987: propagateState(targetform,'rpicknum');
6988: }
6989: } else {
6990: pickitem.checked=false;
1.538 raeburn 6991: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 6992: }
1.478 raeburn 6993: }
6994: return;
6995: }
6996: }
6997: } else {
1.537 raeburn 6998: picknumitem.value = '';
6999: picknumtext.innerHTML = '';
7000: if (index == 'all') {
7001: if (caller == 'link') {
7002: propagateState(targetform,'rpicknum');
7003: }
7004: } else {
1.538 raeburn 7005: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7006: }
7007: }
7008: }
7009:
7010: function propagateState(form,param) {
7011: if (document.getElementById(param+'all')) {
7012: var setcheck = 0;
7013: var rpick = 0;
7014: if (param == 'rpicknum') {
7015: if (document.getElementById('randompickall')) {
7016: if (document.getElementById('randompickall').checked) {
7017: if (document.getElementById('rpicknumall')) {
7018: rpick = document.getElementById('rpicknumall').value;
7019: }
7020: }
7021: }
7022: } else {
7023: if (document.getElementById(param+'all').checked) {
7024: setcheck = 1;
7025: }
7026: }
1.538 raeburn 7027: var allidxlist;
7028: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7029: if (document.getElementById('all'+param+'idx')) {
7030: allidxlist = document.getElementById('all'+param+'idx').value;
7031: }
7032: var actions = new Array ('remove','cut','copy');
7033: for (var i=0; i<actions.length; i++) {
7034: if (actions[i] != param) {
7035: if (document.getElementById(actions[i]+'all')) {
7036: document.getElementById(actions[i]+'all').checked = false;
7037: }
7038: }
7039: }
7040: }
1.537 raeburn 7041: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7042: allidxlist = form.allidx.value;
7043: }
7044: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7045: allidxlist = form.allmapidx.value;
7046: }
7047: if ((allidxlist != '') && (allidxlist != null)) {
7048: var allidxs = allidxlist.split(',');
7049: if (allidxs.length > 1) {
7050: for (var i=0; i<allidxs.length; i++) {
7051: if (document.getElementById(param+'_'+allidxs[i])) {
7052: if (param == 'rpicknum') {
7053: if (document.getElementById('randompick_'+allidxs[i])) {
7054: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7055: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7056: if (rpick > 0) {
7057: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7058: } else {
7059: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7060: }
7061: }
7062: }
7063: } else {
1.537 raeburn 7064: if (setcheck == 1) {
7065: document.getElementById(param+'_'+allidxs[i]).checked = true;
7066: } else {
7067: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7068: if (param == 'randompick') {
7069: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7070: }
1.537 raeburn 7071: }
7072: }
7073: }
7074: }
1.538 raeburn 7075: if (setcheck == 1) {
7076: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7077: var actions = new Array('copy','cut','remove');
7078: for (var i=0; i<actions.length; i++) {
7079: var otheractions;
7080: var otheridxs;
7081: if (actions[i] === param) {
7082: continue;
7083: } else {
7084: if (document.getElementById('all'+actions[i]+'idx')) {
7085: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7086: otheridxs = otheractions.split(',');
7087: if (otheridxs.length > 1) {
7088: for (var j=0; j<otheridxs.length; j++) {
7089: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7090: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7091: }
1.537 raeburn 7092: }
7093: }
7094: }
1.538 raeburn 7095: }
7096: }
7097: }
7098: }
7099: }
7100: }
7101: }
7102: return;
7103: }
7104:
1.603 raeburn 7105: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.539 raeburn 7106: var dosettings;
7107: var doaction;
1.538 raeburn 7108: var control = document.togglemultsettings;
7109: if (context == 'actions') {
7110: control = document.togglemultactions;
1.539 raeburn 7111: doaction = 1;
7112: } else {
7113: dosettings = 1;
1.538 raeburn 7114: }
1.539 raeburn 7115: if (control) {
7116: if (control.showmultpick.length) {
7117: for (var i=0; i<control.showmultpick.length; i++) {
7118: if (control.showmultpick[i].checked) {
7119: if (control.showmultpick[i].value == 1) {
7120: if (context == 'settings') {
7121: dosettings = 0;
7122: } else {
7123: doaction = 0;
1.538 raeburn 7124: }
7125: }
7126: }
1.537 raeburn 7127: }
7128: }
1.539 raeburn 7129: }
7130: if (context == 'settings') {
7131: if (dosettings == 1) {
1.538 raeburn 7132: targetform.changeparms.value=param;
7133: targetform.submit();
7134: }
1.537 raeburn 7135: }
1.539 raeburn 7136: if (context == 'actions') {
7137: if (doaction == 1) {
7138: targetform.cmd.value=param+'_'+index;
7139: targetform.folderpath.value=folderpath;
7140: targetform.markcopy.value=idx+':'+param;
7141: targetform.copyfolder.value=folder+'.'+container;
7142: if (param == 'remove') {
1.603 raeburn 7143: var doremove = 0;
7144: if (skip_confirm) {
7145: if (confirm_removal) {
7146: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7147: doremove = 1;
7148: }
7149: } else {
7150: doremove = 1;
7151: }
7152: } else {
7153: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7154: doremove = 1;
7155: }
7156: }
7157: if (doremove) {
1.539 raeburn 7158: targetform.markcopy.value='';
7159: targetform.copyfolder.value='';
7160: targetform.submit();
7161: }
7162: }
7163: if (param == 'cut') {
1.594 damieng 7164: 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 7165: targetform.submit();
7166: return;
7167: }
7168: }
7169: if (param == 'copy') {
7170: targetform.submit();
7171: return;
7172: }
7173: targetform.markcopy.value='';
7174: targetform.copyfolder.value='';
7175: targetform.cmd.value='';
7176: targetform.folderpath.value='';
7177: return;
7178: } else {
7179: if (document.getElementById(param+'_'+idx)) {
7180: item = document.getElementById(param+'_'+idx);
7181: if (item.type == 'checkbox') {
7182: if (item.checked) {
7183: item.checked = false;
7184: } else {
7185: item.checked = true;
7186: singleCheck(item,idx,param);
7187: }
7188: }
7189: }
7190: }
7191: }
1.537 raeburn 7192: return;
7193: }
7194:
1.538 raeburn 7195: function singleCheck(caller,idx,action) {
7196: actions = new Array('cut','copy','remove');
7197: if (caller.checked) {
7198: for (var i=0; i<actions.length; i++) {
7199: if (actions[i] != action) {
7200: if (document.getElementById(actions[i]+'_'+idx)) {
7201: if (document.getElementById(actions[i]+'_'+idx).checked) {
7202: document.getElementById(actions[i]+'_'+idx).checked = false;
7203: }
1.537 raeburn 7204: }
7205: }
7206: }
1.478 raeburn 7207: }
1.537 raeburn 7208: return;
1.478 raeburn 7209: }
7210:
1.334 muellerd 7211: function unselectInactive(nav) {
1.335 ehlerst 7212: currentNav = document.getElementById(nav);
7213: currentLis = currentNav.getElementsByTagName('LI');
7214: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7215: if (currentLis[i].className == 'goback') {
7216: currentLis[i].className = 'goback';
7217: } else {
7218: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7219: currentLis[i].className = 'right';
1.472 raeburn 7220: } else {
1.374 tempelho 7221: currentLis[i].className = 'i';
1.472 raeburn 7222: }
7223: }
1.335 ehlerst 7224: }
1.332 tempelho 7225: }
7226:
1.334 muellerd 7227: function hideAll(current, nav, data) {
1.335 ehlerst 7228: unselectInactive(nav);
1.570 raeburn 7229: if (current) {
7230: if (current.className == 'right'){
7231: current.className = 'right active'
7232: } else {
7233: current.className = 'active';
7234: }
1.374 tempelho 7235: }
1.335 ehlerst 7236: currentData = document.getElementById(data);
7237: currentDivs = currentData.getElementsByTagName('DIV');
7238: for (i = 0; i < currentDivs.length; i++) {
7239: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7240: currentDivs[i].style.display = 'none';
1.330 tempelho 7241: }
7242: }
1.335 ehlerst 7243: }
1.330 tempelho 7244:
1.374 tempelho 7245: function openTabs(pageId) {
7246: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7247: if(tabnav.length > 2 ){
1.389 tempelho 7248: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7249: currentLis = currentNav.getElementsByTagName('LI');
7250: for(i = 0; i< currentLis.length; i++){
7251: if(currentLis[i].className == 'active') {
1.375 tempelho 7252: funcString = currentLis[i].onclick.toString();
7253: tab = funcString.split('"');
1.420 onken 7254: if(tab.length < 2) {
7255: tab = funcString.split("'");
7256: }
1.375 tempelho 7257: currentData = document.getElementById(tab[1]);
7258: currentData.style.display = 'block';
1.374 tempelho 7259: }
7260: }
7261: }
7262: }
7263:
1.334 muellerd 7264: function showPage(current, pageId, nav, data) {
1.570 raeburn 7265: currstate = current.className;
1.334 muellerd 7266: hideAll(current, nav, data);
1.375 tempelho 7267: openTabs(pageId);
1.334 muellerd 7268: unselectInactive(nav);
1.570 raeburn 7269: if ((currstate == 'active') || (currstate == 'right active')) {
7270: if (currstate == 'active') {
7271: current.className = '';
7272: } else {
7273: current.className = 'right';
7274: }
7275: activeTab = '';
7276: toggleUpload();
7277: toggleMap();
1.606 raeburn 7278: toggleCrsRes();
7279: toggleImportCrsres();
1.570 raeburn 7280: resize_scrollbox('contentscroll','1','0');
7281: return;
7282: } else {
7283: current.className = 'active';
7284: }
1.330 tempelho 7285: currentData = document.getElementById(pageId);
7286: currentData.style.display = 'block';
1.458 raeburn 7287: activeTab = pageId;
1.501 raeburn 7288: toggleUpload();
1.503 raeburn 7289: toggleMap();
1.606 raeburn 7290: toggleCrsRes();
7291: toggleImportCrsres();
1.433 raeburn 7292: if (nav == 'mainnav') {
7293: var storedpath = "$docs_folderpath";
1.434 raeburn 7294: var storedpage = "$main_container_page";
1.433 raeburn 7295: var reg = new RegExp("^supplemental");
7296: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7297: if (storedpage == 1) {
7298: document.simpleedit.folderpath.value = '';
7299: document.uploaddocument.folderpath.value = '';
7300: } else {
7301: if (reg.test(storedpath)) {
7302: document.simpleedit.folderpath.value = '$toplevelmain';
7303: document.uploaddocument.folderpath.value = '$toplevelmain';
7304: document.newext.folderpath.value = '$toplevelmain';
7305: } else {
7306: document.simpleedit.folderpath.value = storedpath;
7307: document.uploaddocument.folderpath.value = storedpath;
7308: document.newext.folderpath.value = storedpath;
7309: }
1.433 raeburn 7310: }
7311: } else {
1.434 raeburn 7312: if (reg.test(storedpath)) {
7313: document.simpleedit.folderpath.value = storedpath;
7314: document.supuploaddocument.folderpath.value = storedpath;
7315: document.supnewext.folderpath.value = storedpath;
7316: } else {
1.433 raeburn 7317: document.simpleedit.folderpath.value = '$toplevelsupp';
7318: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7319: document.supnewext.folderpath.value = '$toplevelsupp';
7320: }
7321: }
7322: }
1.485 raeburn 7323: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7324: return false;
7325: }
1.329 droeschl 7326:
1.472 raeburn 7327: function toContents(jumpto) {
7328: var newurl = '$backtourl';
1.525 raeburn 7329: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7330: newurl = newurl+'?postdata='+jumpto;
7331: }
7332: location.href=newurl;
7333: }
7334:
1.538 raeburn 7335: function togglePick(caller,value) {
7336: var disp = 'none';
7337: if (document.getElementById('multi'+caller)) {
7338: var curr = document.getElementById('multi'+caller).style.display;
7339: if (value == 1) {
7340: disp='block';
7341: }
7342: if (curr == disp) {
7343: return;
7344: }
7345: document.getElementById('multi'+caller).style.display=disp;
7346: if (value == 1) {
1.594 damieng 7347: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7348: } else {
7349: document.getElementById('more'+caller).innerHTML = '';
7350: }
7351: if (caller == 'actions') {
7352: setClass(value);
7353: setBoxes(value);
7354: }
7355: }
7356: var showButton = multiSettings();
7357: if (showButton != 1) {
7358: showButton = multiActions();
7359: }
7360: if (document.getElementById('multisave')) {
7361: if (showButton == 1) {
7362: document.getElementById('multisave').style.display='block';
7363: } else {
7364: document.getElementById('multisave').style.display='none';
7365: }
7366: }
7367: resize_scrollbox('contentscroll','1','1');
7368: return;
7369: }
7370:
7371: function toggleCheckUncheck(caller,more) {
7372: if (more == 1) {
1.594 damieng 7373: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7374: document.getElementById('allfields'+caller).style.display='block';
7375: } else {
1.594 damieng 7376: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7377: document.getElementById('allfields'+caller).style.display='none';
7378: }
7379: resize_scrollbox('contentscroll','1','1');
7380: }
7381:
7382: function multiSettings() {
7383: var inuse = 0;
7384: var settingsform = document.togglemultsettings;
7385: if (settingsform.showmultpick.length > 1) {
7386: for (var i=0; i<settingsform.showmultpick.length; i++) {
7387: if (settingsform.showmultpick[i].checked) {
7388: if (settingsform.showmultpick[i].value == 1) {
7389: inuse = 1;
7390: }
7391: }
7392: }
7393: }
7394: return inuse;
7395: }
7396:
7397: function multiActions() {
7398: var inuse = 0;
7399: var actionsform = document.togglemultactions;
7400: if (actionsform.showmultpick.length > 1) {
7401: for (var i=0; i<actionsform.showmultpick.length; i++) {
7402: if (actionsform.showmultpick[i].checked) {
7403: if (actionsform.showmultpick[i].value == 1) {
7404: inuse = 1;
7405: }
7406: }
7407: }
7408: }
7409: return inuse;
7410: }
7411:
7412: function checkSubmits() {
7413: var numchanges = 0;
7414: var form = document.saveactions;
7415: var doactions = multiActions();
1.542 raeburn 7416: var cutwarnings = 0;
7417: var remwarnings = 0;
1.603 raeburn 7418: var removalinfo = 0;
1.538 raeburn 7419: if (doactions == 1) {
7420: var remidxlist = document.cumulativeactions.allremoveidx.value;
7421: if ((remidxlist != '') && (remidxlist != null)) {
7422: var remidxs = remidxlist.split(',');
7423: for (var i=0; i<remidxs.length; i++) {
7424: if (document.getElementById('remove_'+remidxs[i])) {
7425: if (document.getElementById('remove_'+remidxs[i]).checked) {
7426: form.multiremove.value += remidxs[i]+',';
7427: numchanges ++;
1.542 raeburn 7428: if (document.getElementById('skip_remove_'+remidxs[i])) {
7429: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7430: remwarnings ++;
7431: }
7432: }
1.603 raeburn 7433: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7434: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7435: removalinfo ++;
7436: }
7437: }
1.537 raeburn 7438: }
7439: }
1.538 raeburn 7440: }
7441: }
7442: var cutidxlist = document.cumulativeactions.allcutidx.value;
7443: if ((cutidxlist != '') && (cutidxlist != null)) {
7444: var cutidxs = cutidxlist.split(',');
7445: for (var i=0; i<cutidxs.length; i++) {
7446: if (document.getElementById('cut_'+cutidxs[i])) {
7447: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7448: form.multicut.value += cutidxs[i]+',';
7449: numchanges ++;
1.542 raeburn 7450: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7451: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7452: cutwarnings ++;
7453: }
7454: }
1.537 raeburn 7455: }
7456: }
7457: }
7458: }
1.538 raeburn 7459: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7460: if ((copyidxlist != '') && (copyidxlist != null)) {
7461: var copyidxs = copyidxlist.split(',');
7462: for (var i=0; i<copyidxs.length; i++) {
7463: if (document.getElementById('copy_'+copyidxs[i])) {
7464: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7465: form.multicopy.value += copyidxs[i]+',';
7466: numchanges ++;
7467: }
7468: }
7469: }
7470: }
7471: if (numchanges > 0) {
7472: form.multichange.value = numchanges;
7473: }
1.537 raeburn 7474: }
1.538 raeburn 7475: var dosettings = multiSettings();
1.543 raeburn 7476: var haschanges = 0;
1.538 raeburn 7477: if (dosettings == 1) {
7478: form.allencrypturl.value = '';
7479: form.allhiddenresource.value = '';
1.543 raeburn 7480: form.changeparms.value = 'all';
7481: var patt=new RegExp(",\$");
1.538 raeburn 7482: var allidxlist = document.cumulativesettings.allidx.value;
7483: if ((allidxlist != '') && (allidxlist != null)) {
7484: var allidxs = allidxlist.split(',');
7485: if (allidxs.length > 1) {
7486: for (var i=0; i<allidxs.length; i++) {
7487: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7488: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7489: form.allhiddenresource.value += allidxs[i]+',';
7490: }
7491: }
7492: if (document.getElementById('encrypturl_'+allidxs[i])) {
7493: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7494: form.allencrypturl.value += allidxs[i]+',';
7495: }
7496: }
7497: }
1.543 raeburn 7498: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7499: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7500: }
1.538 raeburn 7501: }
7502: form.allrandompick.value = '';
7503: form.allrandomorder.value = '';
7504: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7505: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7506: var allmapidxs = allmapidxlist.split(',');
7507: for (var i=0; i<allmapidxs.length; i++) {
7508: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7509: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7510: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7511: if ((randompick.checked) && (rpicknum.value != '')) {
7512: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7513: }
7514: if (randorder.checked) {
7515: form.allrandomorder.value += allmapidxs[i]+',';
7516: }
1.537 raeburn 7517: }
1.543 raeburn 7518: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7519: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7520: }
7521: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7522: haschanges = 1;
7523: }
7524: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7525: haschanges = 1;
7526: }
7527: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7528: haschanges = 1;
7529: }
7530: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7531: haschanges = 1;
1.537 raeburn 7532: }
7533: }
1.543 raeburn 7534: if (doactions == 1) {
1.542 raeburn 7535: if (numchanges > 0) {
1.603 raeburn 7536: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7537: if (remwarnings > 0) {
1.594 damieng 7538: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7539: return false;
7540: }
7541: }
1.603 raeburn 7542: if (removalinfo > 0) {
7543: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7544: return false;
7545: }
7546: }
1.542 raeburn 7547: if (cutwarnings > 0) {
1.594 damieng 7548: 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 7549: return false;
7550: }
7551: }
7552: }
7553: form.submit();
7554: return true;
1.543 raeburn 7555: }
7556: }
7557: if (dosettings == 1) {
7558: if (haschanges == 1) {
1.542 raeburn 7559: form.submit();
7560: return true;
7561: }
1.543 raeburn 7562: }
7563: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7564: alert("$js_lt{'noor'}");
1.543 raeburn 7565: } else {
7566: if (dosettings == 1) {
1.594 damieng 7567: alert("$js_lt{'noch'}");
1.543 raeburn 7568: } else {
1.594 damieng 7569: alert("$js_lt{'noac'}");
1.543 raeburn 7570: }
7571: }
1.538 raeburn 7572: return false;
7573: }
7574:
7575: function setClass(value) {
7576: var cutclass = 'LC_docs_cut';
7577: var copyclass = 'LC_docs_copy';
7578: var removeclass = 'LC_docs_remove';
7579: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7580: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7581: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7582: var links = document.getElementsByTagName('a');
7583: for (var i=0; i<links.length; i++) {
7584: var classes = links[i].className;
7585: if (cutreg.test(classes)) {
7586: links[i].className = cutclass;
7587: if (value == 1) {
7588: links[i].className += " LC_menubuttons_link";
7589: }
7590: } else {
7591: if (copyreg.test(classes)) {
7592: links[i].className = copyclass;
7593: if (value == 1) {
7594: links[i].className += " LC_menubuttons_link";
7595: }
7596: } else {
7597: if (removereg.test(classes)) {
7598: links[i].className = removeclass;
7599: if (value == 1) {
7600: links[i].className += " LC_menubuttons_link";
7601: }
7602: }
7603: }
7604: }
7605: }
7606: return;
1.537 raeburn 7607: }
7608:
1.538 raeburn 7609: function setBoxes(value) {
7610: var remidxlist = document.cumulativeactions.allremoveidx.value;
7611: if ((remidxlist != '') && (remidxlist != null)) {
7612: var remidxs = remidxlist.split(',');
7613: for (var i=0; i<remidxs.length; i++) {
7614: if (document.getElementById('remove_'+remidxs[i])) {
7615: var item = document.getElementById('remove_'+remidxs[i]);
7616: if (value == 1) {
7617: item.className = 'LC_docs_remove';
7618: } else {
7619: item.className = 'LC_hidden';
7620: }
7621: }
7622: }
7623: }
7624: var cutidxlist = document.cumulativeactions.allcutidx.value;
7625: if ((cutidxlist != '') && (cutidxlist != null)) {
7626: var cutidxs = cutidxlist.split(',');
7627: for (var i=0; i<cutidxs.length; i++) {
7628: if (document.getElementById('cut_'+cutidxs[i])) {
7629: var item = document.getElementById('cut_'+cutidxs[i]);
7630: if (value == 1) {
7631: item.className = 'LC_docs_cut';
7632: } else {
7633: item.className = 'LC_hidden';
7634: }
7635: }
1.537 raeburn 7636: }
7637: }
1.538 raeburn 7638: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7639: if ((copyidxlist != '') && (copyidxlist != null)) {
7640: var copyidxs = copyidxlist.split(',');
7641: for (var i=0; i<copyidxs.length; i++) {
7642: if (document.getElementById('copy_'+copyidxs[i])) {
7643: var item = document.getElementById('copy_'+copyidxs[i]);
7644: if (value == 1) {
7645: item.className = 'LC_docs_copy';
7646: } else {
7647: item.className = 'LC_hidden';
7648: }
7649: }
1.537 raeburn 7650: }
7651: }
7652: return;
7653: }
7654:
1.606 raeburn 7655: function validImportCrsRes() {
7656: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
7657: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
7658: if ((fname == '') || (fname == null)) {
7659: alert("$js_lt{'nofi'}");
7660: return false;
7661: }
7662: var url = '/res/$coursedom/$coursenum/';
7663: if (path && path != '/') {
7664: url += path+'/';
7665: }
7666: if (fname != '') {
7667: url += fname;
7668: }
7669: var title = document.crsresimportform.crsrestitle.value;
7670: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
7671: return true;
7672: }
7673:
7674: function validateNewRes(caller) {
7675: if (caller == 'single') {
7676: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7677: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
7678: var resname = document.courseresform.newresourcename.value;
7679: }
7680: }
7681:
1.329 droeschl 7682: ENDNEWSCRIPT
7683: }
1.457 raeburn 7684:
1.483 raeburn 7685: sub history_tab_js {
7686: return <<"ENDHIST";
7687: function toggleHistoryDisp(choice) {
7688: document.docslogform.docslog.value = choice;
7689: document.docslogform.submit();
7690: return;
7691: }
7692:
7693: ENDHIST
7694: }
7695:
1.484 raeburn 7696: sub inject_data_js {
7697: return <<ENDINJECT;
7698:
7699: function injectData(current, hiddenField, name, value) {
7700: currentElement = document.getElementById(hiddenField);
7701: currentElement.name = name;
7702: currentElement.value = value;
7703: current.submit();
7704: }
7705:
7706: ENDINJECT
7707: }
7708:
7709: sub dump_switchserver_js {
7710: my @hosts = @_;
1.594 damieng 7711: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 7712: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7713: swit => 'Switch server?',
1.594 damieng 7714: );
7715: my %html_js_lt = &Apache::lonlocal::texthash(
7716: swit => 'Switch server?',
1.568 raeburn 7717: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7718: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7719: chos => 'Choose server',
7720: );
1.594 damieng 7721: &js_escape(\%js_lt);
7722: &html_escape(\%html_js_lt);
7723: &js_escape(\%html_js_lt);
1.484 raeburn 7724: my $role = $env{'request.role'};
7725: my $js = <<"ENDSWJS";
7726: <script type="text/javascript">
7727: function write_switchserver() {
7728: var server;
7729: if (document.setserver.posshosts.length > 0) {
7730: for (var i=0; i<document.setserver.posshosts.length; i++) {
7731: if (document.setserver.posshosts[i].checked) {
7732: server = document.setserver.posshosts[i].value;
7733: }
7734: }
7735: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7736: }
7737: window.close();
7738: }
7739: </script>
7740:
7741: ENDSWJS
7742:
7743: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7744: {'only_body' => 1,
7745: 'js_ready' => 1,});
7746: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7747:
7748: my $hostpicker;
7749: my $count = 0;
7750: foreach my $host (sort(@hosts)) {
7751: my $checked;
7752: if ($count == 0) {
7753: $checked = ' checked="checked"';
7754: }
7755: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7756: $host.'"'.$checked.' />'.$host.'</label> ';
7757: $count++;
7758: }
7759:
7760: return <<"ENDSWITCHJS";
7761:
7762: function dump_needs_switchserver(url) {
7763: if (url!='' && url!= null) {
1.594 damieng 7764: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7765: go(url);
7766: }
7767: }
7768: return;
7769: }
7770:
7771: function choose_switchserver_window() {
7772: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7773: newWindow.document.open();
7774: newWindow.document.writeln('$startpage');
1.594 damieng 7775: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7776: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7777: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7778: '<form name="setserver" method="post" action="" \\/>\\n'+
7779: '$hostpicker\\n'+
7780: '<br \\/><br \\/>\\n'+
1.594 damieng 7781: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7782: 'onclick="write_switchserver();" \\/>\\n'+
7783: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7784: newWindow.document.writeln('$endpage');
7785: newWindow.document.close();
7786: newWindow.focus();
7787: }
7788:
7789: ENDSWITCHJS
7790: }
7791:
7792: sub makedocslogform {
7793: my ($formelems,$docslog) = @_;
7794: return <<"LOGSFORM";
7795: <form action="/adm/coursedocs" method="post" name="docslogform">
7796: <input type="hidden" name="docslog" value="$docslog" />
7797: $formelems
7798: </form>
7799: LOGSFORM
7800: }
7801:
7802: sub makesimpleeditform {
7803: my ($formelems) = @_;
7804: return <<"SIMPFORM";
7805: <form name="simpleedit" method="post" action="/adm/coursedocs">
7806: <input type="hidden" name="importdetail" value="" />
7807: $formelems
7808: </form>
7809: SIMPFORM
7810: }
7811:
1.606 raeburn 7812: sub makenewproblem {
7813: my ($r,$coursedom,$coursenum) = @_;
7814: # Creating a new problem
7815: my ($redirect,$error);
7816: if ($env{'form.authorrole'}) {
7817: my ($newsubdir,$filename);
7818: if ($env{'form.newsubdir'}) {
7819: if ($env{'form.newsubdirname'} ne '') {
7820: $newsubdir = $env{'form.newsubdirname'};
7821: }
7822: }
7823: if ($env{'form.newresourcename'}) {
7824: $filename = $env{'form.newresourcename'};
7825: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
7826: $filename =~ s/`//g;
7827: $filename =~ s{/\.\./}{_}g;
7828: $filename =~ s/\.+/./g;
7829: $filename =~ s{/+}{_}g;
7830: if ($filename ne '') {
7831: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
7832: if (($ext) && ($ext ne '.problem')) {
7833: $filename = $name.'.problem';
7834: } elsif ($ext eq '') {
7835: $filename .= '.problem';
7836: }
7837: my $docroot = $r->dir_config('lonDocRoot');
7838: my @ids=&Apache::lonnet::current_machine_ids();
7839: if ($env{'form.authorrole'} eq 'author') {
7840: if ($env{'user.author'}) {
7841: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
7842: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
7843: my $path = $docroot.$url;
7844: my $subdir = $env{'form.authorpath'};
7845: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
7846: }
7847: }
7848: } elsif ($env{'form.authorrole'} eq 'course') {
7849: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
7850: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
7851: my $url = "/priv/$coursedom/$coursenum";
7852: my $path=$docroot.$url;
7853: my $subdir = $env{'form.authorpath'};
7854: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
7855: if ($redirect) {
7856: my $rightsfile = 'default.rights';
7857: my $sourcerights = "$path/$rightsfile";
7858: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
7859: my $now = time;
7860: if (!-e $sourcerights) {
7861: my $cid = $coursedom.'_'.$coursenum;
7862: if (open(my $fh,">$sourcerights")) {
7863: print $fh <<END;
7864: <accessrule effect="deny" realm="" type="course" role="" />
7865: <accessrule effect="allow" realm="$cid" type="course" role="" />
7866: END
7867: close($fh);
7868: }
7869: }
7870: if (!-e "$sourcerights.meta") {
7871: if (open(my $fh,">$sourcerights.meta")) {
7872: my $author=$env{'environment.firstname'}.' '.
7873: $env{'environment.middlename'}.' '.
7874: $env{'environment.lastname'}.' '.
7875: $env{'environment.generation'};
7876: $author =~ s/\s+$//;
7877: print $fh <<"END";
7878:
7879: <abstract></abstract>
7880: <author>$author</author>
7881: <authorspace>$coursenum:$coursedom</authorspace>
7882: <copyright>private</copyright>
7883: <creationdate>$now</creationdate>
7884: <customdistributionfile></customdistributionfile>
7885: <dependencies></dependencies>
7886: <domain>$coursedom</domain>
7887: <highestgradelevel>0</highestgradelevel>
7888: <keywords></keywords>
7889: <language>notset </language>
7890: <lastrevisiondate>$now</lastrevisiondate>
7891: <lowestgradelevel>0</lowestgradelevel>
7892: <mime>rights</mime>
7893: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
7894: <notes></notes>
7895: <obsolete></obsolete>
7896: <obsoletereplacement></obsoletereplacement>
7897: <owner>$coursenum:$coursedom</owner>
7898: <rule>deny:::course,allow:$cid::course</rule>
7899: <sourceavail></sourceavail>
7900: <standards></standards>
7901: <subject></subject>
7902: <title></title>
7903: END
7904: close($fh);
7905: }
7906: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
7907: if (!-e "$docroot/res/$coursedom") {
7908: mkdir("$docroot/res/$coursedom",0755);
7909: }
7910: if (!-e "$docroot/res/$coursedom/$coursenum") {
7911: mkdir("$docroot/res/$coursedom/$coursenum",0755);
7912: }
7913: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
7914: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
7915: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
7916: }
7917: }
7918: }
7919: if ($env{'form.newresourceadd'}) {
7920: my $template = $env{'form.template'};
7921: my $source = $docroot.$redirect;
7922: my $target = $redirect;
7923: $target =~ s{^/priv/}{/res/};
7924: $target = $docroot.$target;
7925: if (!-e $source) {
7926: my $copyfrom;
7927: if ($template) {
7928: my %templates;
7929: my @files = &Apache::lonhomework::get_template_list('problem');
7930: foreach my $poss (@files) {
7931: if (ref($poss) eq 'ARRAY') {
7932: if ($template eq $poss->[0]) {
7933: $templates{$template} = 1;
7934: last;
7935: }
7936: }
7937: }
7938: if ($templates{$template}) {
7939: $copyfrom = $template;
7940: }
7941: }
7942: unless ($copyfrom) {
7943: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
7944: }
7945: &File::Copy::copy($copyfrom,$source);
7946: }
7947: if (!-e "$source.meta") {
7948: my $cid = $coursedom.'_'.$coursenum;
7949: my $now = time;
7950: if (open(my $fh,">$source.meta")) {
7951: my $author=$env{'environment.firstname'}.' '.
7952: $env{'environment.middlename'}.' '.
7953: $env{'environment.lastname'}.' '.
7954: $env{'environment.generation'};
7955: $author =~ s/\s+$//;
7956: my $title = $env{'form.newresourcetitle'};
7957: $title =~ s/^\s+|\s+$//g;
7958: print $fh <<END;
7959:
7960: <abstract></abstract>
7961: <author>$author</author>
7962: <authorspace>$coursenum:$coursedom</authorspace>
7963: <copyright>custom</copyright>
7964: <creationdate>$now</creationdate>
7965: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
7966: <dependencies></dependencies>
7967: <domain>$coursedom</domain>
7968: <highestgradelevel>0</highestgradelevel>
7969: <keywords></keywords>
7970: <language>notset </language>
7971: <lastrevisiondate>$now</lastrevisiondate>
7972: <lowestgradelevel>0</lowestgradelevel>
7973: <mime>problem</mime>
7974: <modifyinguser>$coursenum:$coursedom</modifyinguser>
7975: <notes></notes>
7976: <obsolete></obsolete>
7977: <obsoletereplacement></obsoletereplacement>
7978: <owner>$coursenum:$coursedom</owner>
7979: <sourceavail></sourceavail>
7980: <standards></standards>
7981: <subject></subject>
7982: <title>$title</title>
7983: END
7984: close($fh);
7985: }
7986: }
7987: }
7988: }
7989: }
7990: } else {
7991: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
7992: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
7993: if (grep(/^\Q$rolehome\E$/,@ids)) {
7994: my $now = time;
7995: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
7996: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
7997: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
7998: my $url = "/priv/$audom/$auname";
7999: my $path = $r->dir_config('lonDocRoot').$url;
8000: my $subdir = $env{'form.authorpath'};
8001: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8002: }
8003: }
8004: }
8005: }
8006: }
8007: }
8008: }
8009: return ($redirect,$error);
8010: }
8011:
8012: sub finishnewprob {
8013: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8014: unless (-d $path) {
8015: unless (mkdir($path,02770)) {
8016: return;
8017: }
8018: }
1.606 raeburn 8019: my $redirect;
8020: if ($subdir ne '/') {
8021: $subdir = &cleandir($subdir);
8022: if (($subdir ne '') && (-d "$path/$subdir")) {
8023: $path .= "/$subdir";
8024: $url .= "/$subdir";
8025: }
8026: }
8027: my $dest;
8028: if ($newsubdir ne '') {
8029: $newsubdir = &cleandir($newsubdir);
8030: }
8031: if ($newsubdir ne '') {
8032: if (-d "$path/$newsubdir") {
8033: $dest = "$path/$newsubdir/$filename";
8034: } else {
8035: my $dirok;
8036: unless (-e "$path/$newsubdir") {
8037: if (mkdir("$path/$newsubdir",02770)) {
8038: if (chmod(02770,"$path/$newsubdir")) {
8039: $dirok = 1;
8040: }
8041: }
8042: }
8043: if ($dirok) {
8044: $dest = "$path/$newsubdir/$filename";
8045: }
8046: }
8047: if (($dest ne '') && (!-e $dest)) {
8048: $redirect = "$url/$newsubdir/$filename";
8049: }
8050: } else {
8051: $dest = "$path/$filename";
8052: if (($dest ne '') && (!-e $dest)) {
8053: $redirect = "$url/$filename";
8054: }
8055: }
8056: return $redirect;
8057: }
8058:
8059: sub cleandir {
8060: my ($dir) = @_;
8061: $dir =~ s/^\s+//;
8062: $dir =~ s/\s+$//;
8063: $dir =~ s/\.+//g;
8064: $dir =~ s/[\#\?&%\":]//g;
8065: return $dir;
8066: }
8067:
1.329 droeschl 8068: 1;
8069: __END__
8070:
8071:
8072: =head1 NAME
8073:
8074: Apache::londocs.pm
8075:
8076: =head1 SYNOPSIS
8077:
8078: This is part of the LearningOnline Network with CAPA project
8079: described at http://www.lon-capa.org.
8080:
8081: =head1 SUBROUTINES
8082:
8083: =over
8084:
8085: =item %help=()
8086:
8087: Available help topics
8088:
8089: =item mapread()
8090:
1.344 bisitz 8091: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8092: @order and @resources, determines status
8093: sets @order - pointer to resources in right order
8094: sets @resources - array with the resources with correct idx
8095:
8096: =item authorhosts()
8097:
8098: Return hash with valid author names
8099:
8100: =item clean()
8101:
8102: =item dumpcourse()
8103:
8104: Actually dump course
8105:
8106: =item group_import()
8107:
8108: Imports the given (name, url) resources into the course
8109: coursenum, coursedom, and folder must precede the list
8110:
8111: =item breadcrumbs()
8112:
8113: =item log_docs()
8114:
8115: =item docs_change_log()
8116:
8117: =item update_paste_buffer()
8118:
8119: =item print_paste_buffer()
8120:
8121: =item do_paste_from_buffer()
8122:
1.538 raeburn 8123: =item do_buffer_empty()
8124:
8125: =item clear_from_buffer()
8126:
1.492 raeburn 8127: =item get_newmap_url()
8128:
8129: =item dbcopy()
8130:
8131: =item uniqueness_check()
8132:
8133: =item contained_map_check()
8134:
8135: =item url_paste_fixups()
8136:
8137: =item apply_fixups()
8138:
8139: =item copy_dependencies()
8140:
1.329 droeschl 8141: =item update_parameter()
8142:
8143: =item handle_edit_cmd()
8144:
8145: =item editor()
8146:
8147: =item process_file_upload()
8148:
8149: =item process_secondary_uploads()
8150:
8151: =item is_supplemental_title()
8152:
8153: =item entryline()
8154:
8155: =item tiehash()
8156:
8157: =item untiehash()
8158:
8159: =item checkonthis()
8160:
8161: check on this
8162:
8163: =item verifycontent()
8164:
8165: Verify Content
8166:
8167: =item devalidateversioncache() & checkversions()
8168:
8169: Check Versions
8170:
8171: =item mark_hash_old()
8172:
8173: =item is_hash_old()
8174:
8175: =item changewarning()
8176:
8177: =item init_breadcrumbs()
8178:
8179: Breadcrumbs for special functions
8180:
1.484 raeburn 8181: =item create_list_elements()
8182:
8183: =item create_form_ul()
8184:
8185: =item startContentScreen()
8186:
8187: =item endContentScreen()
8188:
8189: =item supplemental_base()
8190:
8191: =item embedded_form_elems()
8192:
8193: =item embedded_destination()
8194:
8195: =item return_to_editor()
8196:
8197: =item decompression_info()
8198:
8199: =item decompression_phase_one()
8200:
8201: =item decompression_phase_two()
8202:
8203: =item remove_archive()
8204:
8205: =item generate_admin_menu()
8206:
8207: =item generate_edit_table()
8208:
8209: =item editing_js()
8210:
8211: =item history_tab_js()
8212:
8213: =item inject_data_js()
8214:
8215: =item dump_switchserver_js()
8216:
1.485 raeburn 8217: =item resize_scrollbox_js()
1.484 raeburn 8218:
8219: =item makedocslogform()
8220:
1.485 raeburn 8221: =item makesimpleeditform()
8222:
1.329 droeschl 8223: =back
8224:
8225: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>